private void ReadXmlDiffgram(XmlReader reader) { // fill correctly
int d = reader.Depth;
bool fEnforce = this.EnforceConstraints;
this.EnforceConstraints =false;
DataTable newDt;
bool isEmpty;
if (this.Rows.Count == 0) {
isEmpty = true;
newDt = this;
}
else {
isEmpty = false;
newDt = this.Clone();
newDt.EnforceConstraints = false;
}
newDt.Rows.nullInList = 0;
reader.MoveToContent();
if ((reader.LocalName != Keywords.DIFFGRAM) && (reader.NamespaceURI != Keywords.DFFNS))
return;
reader.Read();
if (reader.NodeType == XmlNodeType.Whitespace) {
MoveToElement(reader, reader.Depth - 1 /*iCurrentDepth*/); // skip over whitespaces.
}
newDt.fInLoadDiffgram = true;
if (reader.Depth > d) {
if ((reader.NamespaceURI != Keywords.DFFNS) && (reader.NamespaceURI != Keywords.MSDNS)) {
//we should be inside the dataset part
XmlDocument xdoc = new XmlDocument();
XmlElement node = xdoc.CreateElement(reader.Prefix, reader.LocalName, reader.NamespaceURI);
reader.Read();
if (reader.Depth-1 > d) {
XmlDataLoader xmlload = new XmlDataLoader(newDt, false, node, false);
xmlload.isDiffgram = true; // turn on the special processing
xmlload.LoadData(reader);
}
ReadEndElement(reader);
}
if (((reader.LocalName == Keywords.SQL_BEFORE) && (reader.NamespaceURI == Keywords.DFFNS)) ||
((reader.LocalName == Keywords.MSD_ERRORS) && (reader.NamespaceURI == Keywords.DFFNS)))
{
//this will consume the changes and the errors part
XMLDiffLoader diffLoader = new XMLDiffLoader();
diffLoader.LoadDiffGram(newDt, reader);
}
// get to the closing diff tag
while(reader.Depth > d) {
reader.Read();
}
// read the closing tag
ReadEndElement(reader);
}
if (newDt.Rows.nullInList > 0)
throw ExceptionBuilder.RowInsertMissing(newDt.TableName);
newDt.fInLoadDiffgram = false;
List<DataTable> tableList = new List<DataTable>();
tableList.Add(this);
CreateTableList(this, tableList);
// this is terrible, optimize it
for (int i = 0; i < tableList.Count ; i++) {
DataRelation[] relations = tableList[i].NestedParentRelations;
foreach(DataRelation rel in relations) {
if (rel != null && rel.ParentTable == tableList[i]) {
foreach (DataRow r in tableList[i].Rows) {
foreach (DataRelation rel2 in relations) {
r.CheckForLoops(rel2);
}
}
}
}
}
if (!isEmpty) {
this.Merge(newDt);
}
this.EnforceConstraints = fEnforce;
}