private SetNestedParentRow ( |
||
parentRow | ||
setNonNested | bool | |
return | void |
private void AttachRows(DataRow parentRow, XmlNode parentElement) { if (parentElement != null) { for (XmlNode node = parentElement.FirstChild; node != null; node = node.NextSibling) { if (node.NodeType == XmlNodeType.Element) { XmlElement e = (XmlElement)node; DataRow rowFromElement = this.GetRowFromElement(e); if ((rowFromElement != null) && (rowFromElement.RowState == DataRowState.Detached)) { if (parentRow != null) { rowFromElement.SetNestedParentRow(parentRow, false); } rowFromElement.Table.Rows.Add(rowFromElement); } else if (rowFromElement == null) { this.AttachRows(parentRow, node); } this.AttachRows(rowFromElement, node); } } } }
private void LoadTopMostTable(DataTable table) { DataColumn columnSchema; bool flag3 = this.isTableLevel || (this.dataSet.DataSetName != table.TableName); DataRow parentRow = null; bool flag = false; int num3 = this.dataReader.Depth - 1; int count = this.childRowsStack.Count; DataColumnCollection columns = table.Columns; object[] foundColumns = new object[columns.Count]; foreach (XmlAttribute attribute in this.topMostNode.Attributes) { columnSchema = this.nodeToSchemaMap.GetColumnSchema(attribute, this.FIgnoreNamespace(attribute)) as DataColumn; if ((columnSchema != null) && (columnSchema.ColumnMapping == MappingType.Attribute)) { XmlNode firstChild = attribute.FirstChild; foundColumns[columnSchema.Ordinal] = columnSchema.ConvertXmlToObject(this.GetInitialTextFromNodes(ref firstChild)); flag = true; } } while (num3 < this.dataReader.Depth) { DataTable table2; object obj2; switch (this.dataReader.NodeType) { case XmlNodeType.Element: { obj2 = this.nodeToSchemaMap.GetColumnSchema(table, this.dataReader, this.FIgnoreNamespace(this.dataReader)); columnSchema = obj2 as DataColumn; if (columnSchema == null) { goto Label_017F; } if (foundColumns[columnSchema.Ordinal] != null) { break; } this.LoadColumn(columnSchema, foundColumns); flag = true; continue; } case XmlNodeType.Text: case XmlNodeType.CDATA: case XmlNodeType.Whitespace: case XmlNodeType.SignificantWhitespace: { string s = this.dataReader.ReadString(); columnSchema = table.xmlText; if ((columnSchema != null) && (foundColumns[columnSchema.Ordinal] == null)) { foundColumns[columnSchema.Ordinal] = columnSchema.ConvertXmlToObject(s); } continue; } case XmlNodeType.EntityReference: throw ExceptionBuilder.FoundEntity(); default: goto Label_01F2; } this.dataReader.Read(); continue; Label_017F: table2 = obj2 as DataTable; if (table2 != null) { this.LoadTable(table2, true); flag = true; } else if (!this.ProcessXsdSchema()) { if (!flag && !flag3) { return; } this.dataReader.Read(); } continue; Label_01F2: this.dataReader.Read(); } this.dataReader.Read(); for (int i = foundColumns.Length - 1; i >= 0; i--) { if (foundColumns[i] == null) { columnSchema = columns[i]; if ((columnSchema.AllowDBNull && (columnSchema.ColumnMapping != MappingType.Hidden)) && !columnSchema.AutoIncrement) { foundColumns[i] = DBNull.Value; } } } parentRow = table.Rows.AddWithColumnEvents(foundColumns); while (count < this.childRowsStack.Count) { DataRow row = (DataRow)this.childRowsStack.Pop(); bool flag2 = row.RowState == DataRowState.Unchanged; row.SetNestedParentRow(parentRow, false); if (flag2) { row.oldRecord = row.newRecord; } } }
private void LoadTable(DataTable table, bool isNested) { DataColumn xmlText; DataRow row = null; int depth = this.dataReader.Depth; int count = this.childRowsStack.Count; DataColumnCollection columns = table.Columns; object[] foundColumns = new object[columns.Count]; int pos = -1; string str3 = string.Empty; string str2 = null; bool flag = false; for (int i = this.dataReader.AttributeCount - 1; i >= 0; i--) { this.dataReader.MoveToAttribute(i); xmlText = this.nodeToSchemaMap.GetColumnSchema(table, this.dataReader, this.FIgnoreNamespace(this.dataReader)) as DataColumn; if ((xmlText != null) && (xmlText.ColumnMapping == MappingType.Attribute)) { foundColumns[xmlText.Ordinal] = xmlText.ConvertXmlToObject(this.dataReader.Value); } if (this.isDiffgram) { if (!(this.dataReader.NamespaceURI == "urn:schemas-microsoft-com:xml-diffgram-v1")) { goto Label_0161; } string localName = this.dataReader.LocalName; if (localName != null) { if (!(localName == "id")) { if (localName == "hasChanges") { goto Label_0124; } if (localName == "hasErrors") { goto Label_0136; } } else { str3 = this.dataReader.Value; } } } continue; Label_0124: str2 = this.dataReader.Value; continue; Label_0136: flag = (bool)Convert.ChangeType(this.dataReader.Value, typeof(bool), CultureInfo.InvariantCulture); continue; Label_0161: if (this.dataReader.NamespaceURI == "urn:schemas-microsoft-com:xml-msdata") { if (this.dataReader.LocalName == "rowOrder") { pos = (int)Convert.ChangeType(this.dataReader.Value, typeof(int), CultureInfo.InvariantCulture); } else if (this.dataReader.LocalName.StartsWith("hidden", StringComparison.Ordinal)) { xmlText = columns[XmlConvert.DecodeName(this.dataReader.LocalName.Substring(6))]; if ((xmlText != null) && (xmlText.ColumnMapping == MappingType.Hidden)) { foundColumns[xmlText.Ordinal] = xmlText.ConvertXmlToObject(this.dataReader.Value); } } } } if (this.dataReader.Read() && (depth < this.dataReader.Depth)) { while (depth < this.dataReader.Depth) { DataTable table3; object obj2; switch (this.dataReader.NodeType) { case XmlNodeType.Element: { obj2 = this.nodeToSchemaMap.GetColumnSchema(table, this.dataReader, this.FIgnoreNamespace(this.dataReader)); xmlText = obj2 as DataColumn; if (xmlText == null) { goto Label_02DE; } if (foundColumns[xmlText.Ordinal] != null) { break; } this.LoadColumn(xmlText, foundColumns); continue; } case XmlNodeType.Text: case XmlNodeType.CDATA: case XmlNodeType.Whitespace: case XmlNodeType.SignificantWhitespace: { string s = this.dataReader.ReadString(); xmlText = table.xmlText; if ((xmlText != null) && (foundColumns[xmlText.Ordinal] == null)) { foundColumns[xmlText.Ordinal] = xmlText.ConvertXmlToObject(s); } continue; } case XmlNodeType.EntityReference: throw ExceptionBuilder.FoundEntity(); default: goto Label_0379; } this.dataReader.Read(); continue; Label_02DE: table3 = obj2 as DataTable; if (table3 != null) { this.LoadTable(table3, true); } else if (!this.ProcessXsdSchema()) { DataTable tableForNode = this.nodeToSchemaMap.GetTableForNode(this.dataReader, this.FIgnoreNamespace(this.dataReader)); if (tableForNode != null) { this.LoadTable(tableForNode, false); } else { this.dataReader.Read(); } } continue; Label_0379: this.dataReader.Read(); } this.dataReader.Read(); } if (this.isDiffgram) { row = table.NewRow(table.NewUninitializedRecord()); row.BeginEdit(); for (int j = foundColumns.Length - 1; j >= 0; j--) { xmlText = columns[j]; xmlText[row.tempRecord] = (foundColumns[j] != null) ? foundColumns[j] : DBNull.Value; } row.EndEdit(); table.Rows.DiffInsertAt(row, pos); if (str2 == null) { row.oldRecord = row.newRecord; } if ((str2 == "modified") || flag) { table.RowDiffId[str3] = row; } } else { for (int k = foundColumns.Length - 1; k >= 0; k--) { if (foundColumns[k] == null) { xmlText = columns[k]; if ((xmlText.AllowDBNull && (xmlText.ColumnMapping != MappingType.Hidden)) && !xmlText.AutoIncrement) { foundColumns[k] = DBNull.Value; } } } row = table.Rows.AddWithColumnEvents(foundColumns); } while (count < this.childRowsStack.Count) { DataRow row2 = (DataRow)this.childRowsStack.Pop(); bool flag2 = row2.RowState == DataRowState.Unchanged; row2.SetNestedParentRow(row, false); if (flag2) { row2.oldRecord = row2.newRecord; } } if (isNested) { this.childRowsStack.Push(row); } }