39 lines
1.1 KiB
C#
39 lines
1.1 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Data;
|
|
|
|
using BCG.Utilities;
|
|
|
|
namespace BCG {
|
|
public class ViewPublisher : IDisposable {
|
|
protected ViewPublisher() { }
|
|
private readonly PubTableBroker _broker;
|
|
protected readonly ViewStream _stream;
|
|
private int _n_updates = 0;
|
|
|
|
/// If an name IsNullOrEmpty then it uses the name
|
|
/// in the schema (be careful with that because this
|
|
/// could lead to double publishes if the schema name
|
|
/// is not uniquely chosen)
|
|
public ViewPublisher(string name, PubTableBroker broker, ViewStream vs) {
|
|
_stream = String.IsNullOrEmpty(name) ? vs : new ChangeTableNameStream(vs, name);
|
|
_broker = broker;
|
|
_stream.onChange += _handle_update;
|
|
}
|
|
|
|
public void Dispose() {
|
|
_stream.onChange -= _handle_update;
|
|
}
|
|
|
|
private void _handle_update(object o) {
|
|
DataPacket dp = o as DataPacket;
|
|
if (_n_updates == 0) {
|
|
_broker.create_table(dp.newRows);
|
|
_n_updates++;
|
|
} else {
|
|
_broker.make_batch_changes(dp.newRows, dp.deletedRows, dp.addedRows);
|
|
}
|
|
}
|
|
}
|
|
}
|