Adding meta data to DataPacket, NLStream adds nl -> dsl as a name value pair in the meta data. Also removing windows ref from DataStreamStudio.sln
This commit is contained in:
1 parent
5305b32c04
commit
66c0baa150
6 files changed
+107
-137
No files matched your search
@@ -1,185 +1,163 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
|
||||
using BCG.Utilities.General;
|
||||
|
||||
using Bts.DataStreamCore;
|
||||
|
||||
namespace BCG
|
||||
{
|
||||
[Serializable]
|
||||
public class DataPacket : ICloneable, IDataPacket
|
||||
{
|
||||
public class BlueRowIdComparator
|
||||
{
|
||||
private string[] myIdColumns = new string[]{"id"};
|
||||
namespace BCG {
|
||||
[Serializable]
|
||||
public class DataPacket : ICloneable, IDataPacket {
|
||||
public class BlueRowIdComparator {
|
||||
private string[] myIdColumns = new string[] { "id" };
|
||||
|
||||
public BlueRowIdComparator(string[] idCols)
|
||||
{
|
||||
if ( idCols.Length != 0 )
|
||||
{
|
||||
public BlueRowIdComparator(string[] idCols) {
|
||||
if (idCols.Length != 0) {
|
||||
myIdColumns = idCols;
|
||||
}
|
||||
}
|
||||
|
||||
public bool blueRowIdEqualEvaluator(object a, object b)
|
||||
{
|
||||
if ( a == null || b == null )
|
||||
{
|
||||
|
||||
public bool blueRowIdEqualEvaluator(object a, object b) {
|
||||
if (a == null || b == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( !(a is IBlueRow) || !(b is IBlueRow) )
|
||||
{
|
||||
if (!(a is IBlueRow) || !(b is IBlueRow)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
IBlueRow lhs = (IBlueRow)a;
|
||||
IBlueRow rhs = (IBlueRow)b;
|
||||
|
||||
|
||||
bool result = true;
|
||||
foreach(string idColumn in myIdColumns)
|
||||
{
|
||||
foreach (string idColumn in myIdColumns) {
|
||||
result = result && lhs[idColumn].Equals(rhs[idColumn]);
|
||||
if ( !result )
|
||||
if (!result)
|
||||
break;
|
||||
}
|
||||
|
||||
return result;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
public IBlueRowCollection newRows, addedRows, deletedRows;
|
||||
public DataPacket () {}
|
||||
public DataPacket (IBlueRowCollection newRows, IBlueRowCollection addedRows, IBlueRowCollection deletedRows)
|
||||
{
|
||||
public IDictionary<string, object> meta_data = null;
|
||||
public DataPacket() { }
|
||||
public DataPacket(IBlueRowCollection newRows, IBlueRowCollection addedRows, IBlueRowCollection deletedRows) {
|
||||
this.newRows = newRows;
|
||||
this.addedRows = addedRows;
|
||||
this.deletedRows = deletedRows;
|
||||
}
|
||||
|
||||
public void get_new_added_deleted(out ICollection new_rows, out ICollection added_rows, out ICollection deleted_rows)
|
||||
{
|
||||
public void get_new_added_deleted(out ICollection new_rows, out ICollection added_rows, out ICollection deleted_rows) {
|
||||
new_rows = newRows;
|
||||
added_rows = addedRows;
|
||||
deleted_rows = deletedRows;
|
||||
}
|
||||
|
||||
public IBlueRowCollection getTrulyAddedRows(params string[] idColumns)
|
||||
{
|
||||
public IBlueRowCollection getTrulyAddedRows(params string[] idColumns) {
|
||||
BlueTable truly = new BlueTable(addedRows.schema);
|
||||
BlueRowIdComparator c = new BlueRowIdComparator(idColumns);
|
||||
|
||||
CollectionHelpers.EqualDelegate ed =
|
||||
CollectionHelpers.EqualDelegate ed =
|
||||
new CollectionHelpers.EqualDelegate(c.blueRowIdEqualEvaluator);
|
||||
|
||||
ICollection ta = CollectionHelpers.difference(addedRows, deletedRows, ed);
|
||||
|
||||
foreach(IBlueRow r in ta)
|
||||
{
|
||||
|
||||
foreach (IBlueRow r in ta) {
|
||||
truly.addRow(r);
|
||||
}
|
||||
|
||||
|
||||
return truly;
|
||||
|
||||
|
||||
}
|
||||
|
||||
public virtual IBlueRowCollection getTrulyAddedRows ()
|
||||
{
|
||||
BlueTable retVal = new BlueTable (schema);
|
||||
public virtual IBlueRowCollection getTrulyAddedRows() {
|
||||
BlueTable retVal = new BlueTable(schema);
|
||||
foreach (IBlueRow r in addedRows)
|
||||
if (!deletedRows.containsID ((int)r["id"]))
|
||||
retVal.addRow (r);
|
||||
if (!deletedRows.containsID((int)r["id"]))
|
||||
retVal.addRow(r);
|
||||
return retVal;
|
||||
}
|
||||
|
||||
public virtual IBlueRowCollection getTrulyDeletedRows ()
|
||||
{
|
||||
BlueTable retVal = new BlueTable (schema);
|
||||
public virtual IBlueRowCollection getTrulyDeletedRows() {
|
||||
BlueTable retVal = new BlueTable(schema);
|
||||
foreach (IBlueRow r in deletedRows)
|
||||
if (!addedRows.containsID ((int)r["id"]))
|
||||
retVal.addRow (r);
|
||||
if (!addedRows.containsID((int)r["id"]))
|
||||
retVal.addRow(r);
|
||||
return retVal;
|
||||
}
|
||||
|
||||
public virtual IBlueRowCollection getTrulyChangedRows ()
|
||||
{
|
||||
BlueTable retVal = new BlueTable (schema);
|
||||
public virtual IBlueRowCollection getTrulyChangedRows() {
|
||||
BlueTable retVal = new BlueTable(schema);
|
||||
foreach (IBlueRow r in addedRows)
|
||||
if (deletedRows.containsID ((int)r["id"]))
|
||||
retVal.addRow (r);
|
||||
if (deletedRows.containsID((int)r["id"]))
|
||||
retVal.addRow(r);
|
||||
return retVal;
|
||||
}
|
||||
|
||||
|
||||
public IBlueRowCollection getTrulyDeletedRows(params string[] idColumns)
|
||||
{
|
||||
|
||||
public IBlueRowCollection getTrulyDeletedRows(params string[] idColumns) {
|
||||
BlueTable truly = new BlueTable(deletedRows.schema);
|
||||
BlueRowIdComparator c = new BlueRowIdComparator(idColumns);
|
||||
|
||||
CollectionHelpers.EqualDelegate ed =
|
||||
CollectionHelpers.EqualDelegate ed =
|
||||
new CollectionHelpers.EqualDelegate(c.blueRowIdEqualEvaluator);
|
||||
|
||||
ICollection td = CollectionHelpers.difference(deletedRows, addedRows, ed);
|
||||
|
||||
foreach(IBlueRow r in td)
|
||||
{
|
||||
|
||||
foreach (IBlueRow r in td) {
|
||||
truly.addRow(r);
|
||||
}
|
||||
|
||||
return truly;
|
||||
return truly;
|
||||
}
|
||||
|
||||
public IBlueRowCollection getTrulyChangedRows(params string[] idColumns)
|
||||
{
|
||||
|
||||
|
||||
public IBlueRowCollection getTrulyChangedRows(params string[] idColumns) {
|
||||
|
||||
BlueTable truly = new BlueTable(addedRows.schema);
|
||||
BlueRowIdComparator c = new BlueRowIdComparator(idColumns);
|
||||
|
||||
CollectionHelpers.EqualDelegate ed =
|
||||
CollectionHelpers.EqualDelegate ed =
|
||||
new CollectionHelpers.EqualDelegate(c.blueRowIdEqualEvaluator);
|
||||
|
||||
ICollection ta = CollectionHelpers.difference(addedRows, deletedRows, ed);
|
||||
ICollection tc = CollectionHelpers.difference(addedRows, ta, ed);
|
||||
|
||||
foreach(IBlueRow r in tc)
|
||||
{
|
||||
|
||||
foreach (IBlueRow r in tc) {
|
||||
truly.addRow(r);
|
||||
}
|
||||
|
||||
return truly;
|
||||
}
|
||||
|
||||
return truly;
|
||||
}
|
||||
|
||||
public IBlueRowCollection getTrulyChangedOldRows(params string[] idColumns)
|
||||
{
|
||||
|
||||
public IBlueRowCollection getTrulyChangedOldRows(params string[] idColumns) {
|
||||
BlueTable truly = new BlueTable(deletedRows.schema);
|
||||
BlueRowIdComparator c = new BlueRowIdComparator(idColumns);
|
||||
|
||||
CollectionHelpers.EqualDelegate ed =
|
||||
CollectionHelpers.EqualDelegate ed =
|
||||
new CollectionHelpers.EqualDelegate(c.blueRowIdEqualEvaluator);
|
||||
|
||||
ICollection td = CollectionHelpers.difference(deletedRows, addedRows, ed);
|
||||
ICollection tco = CollectionHelpers.difference(deletedRows, td, ed);
|
||||
|
||||
foreach(IBlueRow r in tco)
|
||||
{
|
||||
|
||||
foreach (IBlueRow r in tco) {
|
||||
truly.addRow(r);
|
||||
}
|
||||
}
|
||||
|
||||
return truly;
|
||||
}
|
||||
|
||||
public TablePacket toTablePacket ()
|
||||
{
|
||||
return new TablePacket (BlueDataUtility.toDataTable (newRows), BlueDataUtility.toDataTable (addedRows),
|
||||
BlueDataUtility.toDataTable (deletedRows));
|
||||
|
||||
return truly;
|
||||
}
|
||||
|
||||
public IBlueTableSchema schema
|
||||
{
|
||||
get
|
||||
{
|
||||
public TablePacket toTablePacket() {
|
||||
return new TablePacket(BlueDataUtility.toDataTable(newRows), BlueDataUtility.toDataTable(addedRows),
|
||||
BlueDataUtility.toDataTable(deletedRows));
|
||||
|
||||
}
|
||||
|
||||
public IBlueTableSchema schema {
|
||||
get {
|
||||
IBlueTableSchema retVal = newRows.schema != null ? newRows.schema :
|
||||
addedRows.schema != null ? addedRows.schema : deletedRows.schema;
|
||||
return retVal;
|
||||
@@ -209,19 +187,17 @@ namespace BCG
|
||||
d' = dthis - (dthis intersect a) + d // keep the old delete
|
||||
a' = a - (dthis intersect a) + athis // keep the new add
|
||||
* */
|
||||
public static DataPacket combineWithIds(ICollection packets, string[] idColumns)
|
||||
{
|
||||
if ( packets.Count == 0 )
|
||||
{
|
||||
public static DataPacket combineWithIds(ICollection packets, string[] idColumns) {
|
||||
if (packets.Count == 0) {
|
||||
return new DataPacket(
|
||||
new BlueTable(new DataTable()),
|
||||
new BlueTable(new DataTable()),
|
||||
new BlueTable(new DataTable()));
|
||||
new BlueTable(new DataTable()));
|
||||
}
|
||||
|
||||
DataPacket.BlueRowIdComparator c = new DataPacket.BlueRowIdComparator(idColumns);
|
||||
|
||||
CollectionHelpers.EqualDelegate ed =
|
||||
|
||||
CollectionHelpers.EqualDelegate ed =
|
||||
new CollectionHelpers.EqualDelegate(c.blueRowIdEqualEvaluator);
|
||||
|
||||
ArrayList added = new ArrayList();
|
||||
@@ -230,80 +206,70 @@ namespace BCG
|
||||
BlueTable at = null;
|
||||
IBlueRowCollection nt = null;
|
||||
|
||||
foreach(DataPacket dp in packets)
|
||||
{
|
||||
foreach (DataPacket dp in packets) {
|
||||
ArrayList oldDeleted = deleted;
|
||||
ArrayList oldAdded = added;
|
||||
|
||||
added = new ArrayList();
|
||||
deleted = new ArrayList();
|
||||
if ( dt == null )
|
||||
{
|
||||
if (dt == null) {
|
||||
dt = new BlueTable(dp.schema);
|
||||
at = new BlueTable(dp.schema);
|
||||
}
|
||||
|
||||
|
||||
deleted.AddRange(oldDeleted);
|
||||
deleted.AddRange( CollectionHelpers.difference(
|
||||
deleted.AddRange(CollectionHelpers.difference(
|
||||
CollectionHelpers.difference(dp.deletedRows, oldAdded, ed),
|
||||
oldDeleted, ed) );
|
||||
oldDeleted, ed));
|
||||
|
||||
added.AddRange(dp.addedRows);
|
||||
added.AddRange( CollectionHelpers.difference(
|
||||
added.AddRange(CollectionHelpers.difference(
|
||||
CollectionHelpers.difference(oldAdded, dp.deletedRows, ed),
|
||||
added, ed) );
|
||||
added, ed));
|
||||
nt = dp.newRows;
|
||||
}
|
||||
|
||||
foreach ( IBlueRow dr in added )
|
||||
{
|
||||
}
|
||||
|
||||
foreach (IBlueRow dr in added) {
|
||||
at.addRow(dr);
|
||||
}
|
||||
|
||||
foreach ( IBlueRow dr in deleted )
|
||||
{
|
||||
foreach (IBlueRow dr in deleted) {
|
||||
dt.addRow(dr);
|
||||
}
|
||||
|
||||
return new DataPacket(nt,at,dt);
|
||||
return new DataPacket(nt, at, dt);
|
||||
}
|
||||
|
||||
public DataPacket deepCopy ()
|
||||
{
|
||||
return new DataPacket (new OrderedBlueTable (newRows),
|
||||
new OrderedBlueTable (newRows),
|
||||
new BlueTable (deletedRows));
|
||||
public DataPacket deepCopy() {
|
||||
return new DataPacket(new OrderedBlueTable(newRows),
|
||||
new OrderedBlueTable(newRows),
|
||||
new BlueTable(deletedRows));
|
||||
}
|
||||
|
||||
public virtual DataPacket createImmutable ()
|
||||
{
|
||||
return
|
||||
public virtual DataPacket createImmutable() {
|
||||
return
|
||||
new DataPacket(
|
||||
newRows is IImmutableRowCollection ? newRows : new ImmutableBlueTable(newRows),
|
||||
addedRows,
|
||||
addedRows,
|
||||
deletedRows);
|
||||
}
|
||||
#region ICloneable Members
|
||||
|
||||
public object Clone()
|
||||
{
|
||||
public object Clone() {
|
||||
return MemberwiseClone();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
public string toIncrementalIDString()
|
||||
{
|
||||
public string toIncrementalIDString() {
|
||||
System.Text.StringBuilder sb = new System.Text.StringBuilder(schema.tableName);
|
||||
sb.Append ("\ndeleted : ");
|
||||
foreach (IBlueRow r in deletedRows)
|
||||
{
|
||||
sb.Append("\ndeleted : ");
|
||||
foreach (IBlueRow r in deletedRows) {
|
||||
sb.Append(r["id"]);
|
||||
sb.Append(',');
|
||||
}
|
||||
sb.Append("\nadded : ");
|
||||
foreach (IBlueRow r in addedRows)
|
||||
{
|
||||
foreach (IBlueRow r in addedRows) {
|
||||
sb.Append(r["id"]);
|
||||
sb.Append(',');
|
||||
}
|
||||
@@ -311,8 +277,7 @@ namespace BCG
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
public override string ToString() {
|
||||
return String.Format("DataPacket, schema {0} n {1} d {2} a {3}", schema.tableName, newRows.Count, deletedRows.Count, addedRows.Count);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user