refactor: Move a few low-level DataStream types to DataStreamCore
So the lex/yacc generators can reference them
This commit is contained in:
1 parent
d1f5ae86fd
commit
ac1ede5986
10 files changed
+6
-30
No files matched your search
@@ -0,0 +1,184 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Data;
|
||||
|
||||
using BCG.Utilities;
|
||||
|
||||
namespace BCG
|
||||
{
|
||||
public class TableStream : ViewStream
|
||||
{
|
||||
public string tableName;
|
||||
private ITableAccumulator myTA;
|
||||
private bool myGotData = false;
|
||||
|
||||
public TableStream(string tableName)
|
||||
:
|
||||
this(tableName, null, null)
|
||||
{
|
||||
}
|
||||
|
||||
public TableStream(string tableName, ViewStreamDatabase db)
|
||||
:
|
||||
this(tableName, db, null)
|
||||
{}
|
||||
|
||||
public TableStream(string tableName, string colExp)
|
||||
:
|
||||
this(tableName,
|
||||
null,
|
||||
colExp)
|
||||
{}
|
||||
|
||||
|
||||
public TableStream(string ttableName, ViewStreamDatabase db, string colExp)
|
||||
{
|
||||
tableName = PubStreamPrefixer.prefix (ttableName);
|
||||
// if (colExp != null)
|
||||
// mySetRealSource (new ProjectStream (new TableStream (tableName, db), colExp));
|
||||
// else
|
||||
{
|
||||
if (db == null)
|
||||
myTA = ViewStreamDatabase.instance.getITableAccumulator (tableName);
|
||||
else
|
||||
myTA = db.getITableAccumulator (tableName);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void myOnFirstSubscriber()
|
||||
{
|
||||
myTA.onUpdate += new TableUpdateDelegate (myHandleUpdates);
|
||||
}
|
||||
|
||||
protected override void myOnLastSubscriber()
|
||||
{
|
||||
myTA.onUpdate -= new TableUpdateDelegate (myHandleUpdates);
|
||||
}
|
||||
|
||||
protected virtual void myHandleUpdates (IBlueRowCollection newRows, IBlueRowCollection addedRows, IBlueRowCollection deletedRows)
|
||||
{
|
||||
if (!myGotData)
|
||||
{
|
||||
myGotData = true;
|
||||
// BlueEventLog.logEvent("Received data for " + tableName + " for the first time", BlueEventLevel.Information);
|
||||
}
|
||||
myFireEvent (new DataPacket (newRows, addedRows, deletedRows));
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return GetType() + " table = " + tableName;
|
||||
}
|
||||
}
|
||||
|
||||
public class ThreadedTableStream : TableStream, IExportableDataStream
|
||||
{
|
||||
static private Lazy<ViewStreamDatabase> _vsd = new Lazy<ViewStreamDatabase>(() => new ViewStreamDatabase(), true);
|
||||
public ThreadedTableStream(string table) : base(table, _vsd.Value)
|
||||
{
|
||||
}
|
||||
|
||||
public void begin_subscription()
|
||||
{
|
||||
this.onChange += _stream_onChange;
|
||||
}
|
||||
|
||||
public event ExportableChangeDelegate on_change;
|
||||
void _stream_onChange(object newValue)
|
||||
{
|
||||
if(on_change != null)
|
||||
on_change(newValue);
|
||||
}
|
||||
}
|
||||
|
||||
// public class ExportableTableStream : IExportableDataStream
|
||||
// {
|
||||
// TableStream _stream;
|
||||
// public ExportableTableStream(string table, IDataPump pump)
|
||||
// {
|
||||
// _stream = new TableStream(table, ((ExportableDataPump)pump).vsd.Value);
|
||||
// }
|
||||
|
||||
// public void begin_subscription()
|
||||
// {
|
||||
// _stream.onChange += _stream_onChange;
|
||||
// }
|
||||
|
||||
// public event ExportableChangeDelegate on_change;
|
||||
// void _stream_onChange(object newValue)
|
||||
// {
|
||||
// if(on_change != null)
|
||||
// on_change(newValue);
|
||||
// }
|
||||
// }
|
||||
|
||||
// public class ExportableQuery : IExportableDataStream
|
||||
// {
|
||||
// ViewStream _stream;
|
||||
// public ExportableQuery(string query, BCG.IDataPump _)
|
||||
// {
|
||||
// // BCG.Evaluator.DataStreamExpression.syntax parser = new BCG.Evaluator.DataStreamExpression.syntax();
|
||||
// // BCG.Evaluator.DataStreamExpression.DataStreamExpression exp =
|
||||
// // (BCG.Evaluator.DataStreamExpression.DataStreamExpression)parser.Parse(query);
|
||||
|
||||
// _stream = exp.getView(new System.Collections.Hashtable());
|
||||
// }
|
||||
|
||||
// public void begin_subscription()
|
||||
// {
|
||||
// _stream.onChange += _stream_onChange;
|
||||
// }
|
||||
|
||||
// public event ExportableChangeDelegate on_change;
|
||||
// void _stream_onChange(object newValue)
|
||||
// {
|
||||
// if(on_change != null)
|
||||
// on_change(newValue);
|
||||
// }
|
||||
// }
|
||||
|
||||
// public class ExportableDataPump : IDataPump
|
||||
// {
|
||||
// public Lazy<ViewStreamDatabase> vsd = new Lazy<ViewStreamDatabase>(() => new ViewStreamDatabase(), true);
|
||||
// System.Threading.Thread _thread;
|
||||
// bool _continue = true;
|
||||
// public ExportableDataPump(string pumpname)
|
||||
// {
|
||||
// tag = pumpname;
|
||||
// _thread = new System.Threading.Thread(new System.Threading.ParameterizedThreadStart((_) =>
|
||||
// {
|
||||
// while(_continue)
|
||||
// {
|
||||
// vsd.Value.doWork();
|
||||
// System.Threading.Thread.Sleep(50);
|
||||
// }
|
||||
// }));
|
||||
// _thread.Name = "DataPump " + pumpname;
|
||||
// _thread.IsBackground = true;
|
||||
// }
|
||||
// public string tag
|
||||
// {
|
||||
// get;
|
||||
// private set;
|
||||
// }
|
||||
// public void start()
|
||||
// {
|
||||
// try
|
||||
// {
|
||||
// if(_thread.ThreadState != System.Threading.ThreadState.Running)
|
||||
// _thread.Start();
|
||||
// }
|
||||
// catch(System.Threading.ThreadStateException) { }
|
||||
// }
|
||||
// public void stop()
|
||||
// {
|
||||
// try
|
||||
// {
|
||||
// _continue = false;
|
||||
// if(_thread.ThreadState == System.Threading.ThreadState.Running)
|
||||
// _thread.Join(500);
|
||||
// }
|
||||
// catch(System.Threading.ThreadStateException) { }
|
||||
// }
|
||||
// }
|
||||
}
|
||||
Reference in new issue
Block a user