62 lines
1.7 KiB
C#
62 lines
1.7 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
|
|
namespace BCG
|
|
{
|
|
public class CrushingCollectorStream : ViewStream
|
|
{
|
|
|
|
/* Arguments: a single
|
|
* Every time one of input the streams updates, it is crushed down to a single row,
|
|
* and added to the collection of output rows.
|
|
*
|
|
* The column 'tableIdentifierColumnName' is added to the schema, and each row from the viewstream
|
|
* is put into the
|
|
*
|
|
* */
|
|
public CrushingCollectorStream(ViewStream toCrush, ITableCrusher crusher)
|
|
{
|
|
myToCrush = toCrush;
|
|
myRows = new List<IBlueRow>();
|
|
myCrusher = crusher;
|
|
}
|
|
|
|
private ViewStream myToCrush;
|
|
private List<IBlueRow> myRows;
|
|
private ITableCrusher myCrusher;
|
|
private int myNextId = 0;
|
|
|
|
protected override void myOnFirstSubscriber()
|
|
{
|
|
myToCrush.onChange += new ChangeDelegate(myToCrush_onChange);
|
|
}
|
|
|
|
protected override void myOnLastSubscriber()
|
|
{
|
|
myToCrush.onChange -= myToCrush_onChange;
|
|
}
|
|
|
|
void myToCrush_onChange(object newValue)
|
|
{
|
|
DataPacket dp = (DataPacket)newValue;
|
|
|
|
IBlueRow crushed = myCrusher.crush(dp.newRows, myNextId++);
|
|
|
|
BlueTable newRows = new BlueTable(dp.schema);
|
|
newRows.addRows(myRows);
|
|
newRows.addRow(crushed);
|
|
myRows.Add(crushed);
|
|
|
|
BlueTable added = new BlueTable(dp.schema);
|
|
added.addRow(crushed);
|
|
|
|
myFireEvent(new DataPacket(newRows, added, new BlueTable(dp.schema)));
|
|
|
|
}
|
|
|
|
|
|
}
|
|
}
|