59 lines
1.8 KiB
C#
59 lines
1.8 KiB
C#
using BCG;
|
|
|
|
using System.Linq;
|
|
|
|
namespace BCG
|
|
{
|
|
public class StreamOffloadRequestor
|
|
{
|
|
public class OffloadOp
|
|
{
|
|
string name;
|
|
string stream_exp;
|
|
}
|
|
private IBlueTableSchema _schema;
|
|
private IBlueRowCollection _rows;
|
|
private PubTableBroker _broker = new PubTableBroker();
|
|
ViewStream _existing_offloads_vs = new TableStream("cloud_streams");
|
|
public StreamOffloadRequestor()
|
|
{
|
|
_schema = new BlueTableSchema("cloud_streams",
|
|
new ColumnInfo("id", 0, typeof(int)),
|
|
new ColumnInfo("name", 1, typeof(string)),
|
|
new ColumnInfo("persist", 2, typeof(bool)),
|
|
new ColumnInfo("stream_exp", 3, typeof(string)));
|
|
_existing_offloads_vs.onChange += _on_str;
|
|
}
|
|
private void _on_str(object obj)
|
|
{
|
|
DataPacket dp = obj as DataPacket;
|
|
_rows = dp.newRows;
|
|
// this is needed so the broker knows the state of the table
|
|
_broker.createTable(_rows);
|
|
}
|
|
public void add_to_cloud(string name, string stream_exp, bool persist)
|
|
{
|
|
// check if it exists
|
|
if (_rows == null)
|
|
{
|
|
BlueTable table = new BlueTable(_schema);
|
|
IBlueRow nr = new BlueRow(_schema, 0, name, persist, stream_exp);
|
|
table.addRow(nr);
|
|
_broker.createTable(table);
|
|
// create table
|
|
}
|
|
else
|
|
{
|
|
if (exists(name))
|
|
return;
|
|
IBlueRow nr = new BlueRow(_schema, _rows.Count, name, persist, stream_exp);
|
|
_broker.addRow(nr);
|
|
}
|
|
}
|
|
|
|
bool exists(string name)
|
|
{
|
|
return _rows.to_ienum().Where(r => name == r.get<string>("name")).Count() > 0;
|
|
}
|
|
}
|
|
} |