public void WriteXmlSchema(XmlWriter writer, bool writeHierarchy) { IntPtr ptr; Bid.ScopeEnter(out ptr, "<ds.DataTable.WriteXmlSchema|API> %d#\n", this.ObjectID); try { if (this.tableName.Length == 0) { throw ExceptionBuilder.CanNotSerializeDataTableWithEmptyName(); } if (!this.CheckForClosureOnExpressions(this, writeHierarchy)) { throw ExceptionBuilder.CanNotSerializeDataTableHierarchy(); } System.Data.DataSet set = null; string tableNamespace = this.tableNamespace; if (this.DataSet == null) { set = new System.Data.DataSet(); set.SetLocaleValue(this._culture, this._cultureUserSet); set.CaseSensitive = this.CaseSensitive; set.Namespace = this.Namespace; set.RemotingFormat = this.RemotingFormat; set.Tables.Add(this); } if (writer != null) { new XmlTreeGen(SchemaFormat.Public).Save(null, this, writer, writeHierarchy); } if (set != null) { set.Tables.Remove(this); this.tableNamespace = tableNamespace; } } finally { Bid.ScopeLeave(ref ptr); } }
private void SerializeDataTable(SerializationInfo info, StreamingContext context, bool isSingleTable, SerializationFormat remotingFormat) { info.AddValue("DataTable.RemotingVersion", new Version(2, 0)); if (remotingFormat != SerializationFormat.Xml) { info.AddValue("DataTable.RemotingFormat", remotingFormat); } if (remotingFormat != SerializationFormat.Xml) { this.SerializeTableSchema(info, context, isSingleTable); if (isSingleTable) { this.SerializeTableData(info, context, 0); } } else { string str = ""; bool flag = false; if (this.dataSet == null) { System.Data.DataSet set = new System.Data.DataSet("tmpDataSet"); set.SetLocaleValue(this._culture, this._cultureUserSet); set.CaseSensitive = this.CaseSensitive; set.namespaceURI = this.Namespace; set.Tables.Add(this); flag = true; } else { str = this.DataSet.Namespace; this.DataSet.namespaceURI = this.Namespace; } info.AddValue("XmlSchema", this.dataSet.GetXmlSchemaForRemoting(this)); info.AddValue("XmlDiffGram", this.dataSet.GetRemotingDiffGram(this)); if (flag) { this.dataSet.Tables.Remove(this); } else { this.dataSet.namespaceURI = str; } } }
public void WriteXml(XmlWriter writer, XmlWriteMode mode, bool writeHierarchy) { IntPtr ptr; Bid.ScopeEnter(out ptr, "<ds.DataTable.WriteXml|API> %d#, mode=%d{ds.XmlWriteMode}\n", this.ObjectID, (int) mode); try { if (this.tableName.Length == 0) { throw ExceptionBuilder.CanNotSerializeDataTableWithEmptyName(); } if (writer != null) { if (mode == XmlWriteMode.DiffGram) { new NewDiffgramGen(this, writeHierarchy).Save(writer, this); } else if (mode == XmlWriteMode.WriteSchema) { System.Data.DataSet set = null; string tableNamespace = this.tableNamespace; if (this.DataSet == null) { set = new System.Data.DataSet(); set.SetLocaleValue(this._culture, this._cultureUserSet); set.CaseSensitive = this.CaseSensitive; set.Namespace = this.Namespace; set.RemotingFormat = this.RemotingFormat; set.Tables.Add(this); } if (writer != null) { new XmlDataTreeWriter(this, writeHierarchy).Save(writer, true); } if (set != null) { set.Tables.Remove(this); this.tableNamespace = tableNamespace; } } else { new XmlDataTreeWriter(this, writeHierarchy).Save(writer, false); } } } finally { Bid.ScopeLeave(ref ptr); } }
internal void ReadXmlSchema(XmlReader reader, bool denyResolving) { IntPtr ptr; Bid.ScopeEnter(out ptr, "<ds.DataTable.ReadXmlSchema|INFO> %d#, denyResolving=%d{bool}\n", this.ObjectID, denyResolving); try { System.Data.DataSet set = new System.Data.DataSet(); SerializationFormat remotingFormat = this.RemotingFormat; set.ReadXmlSchema(reader, denyResolving); string mainTableName = set.MainTableName; if (!ADP.IsEmpty(this.tableName) || !ADP.IsEmpty(mainTableName)) { DataTable currentTable = null; if (!ADP.IsEmpty(this.tableName)) { if (!ADP.IsEmpty(this.Namespace)) { currentTable = set.Tables[this.tableName, this.Namespace]; } else { int num3 = set.Tables.InternalIndexOf(this.tableName); if (num3 > -1) { currentTable = set.Tables[num3]; } } } else { string str3 = ""; int index = mainTableName.IndexOf(':'); if (index > -1) { str3 = mainTableName.Substring(0, index); } string str4 = mainTableName.Substring(index + 1, (mainTableName.Length - index) - 1); currentTable = set.Tables[str4, str3]; } if (currentTable == null) { string tableName = string.Empty; if (!ADP.IsEmpty(this.tableName)) { tableName = (this.Namespace.Length > 0) ? (this.Namespace + ":" + this.tableName) : this.tableName; } else { tableName = mainTableName; } throw ExceptionBuilder.TableNotFound(tableName); } currentTable._remotingFormat = remotingFormat; List<DataTable> tableList = new List<DataTable> { currentTable }; this.CreateTableList(currentTable, tableList); List<DataRelation> relationList = new List<DataRelation>(); this.CreateRelationList(tableList, relationList); if (relationList.Count == 0) { if (this.Columns.Count == 0) { DataTable table5 = currentTable; if (table5 != null) { table5.CloneTo(this, null, false); } if ((this.DataSet == null) && (this.tableNamespace == null)) { this.tableNamespace = table5.Namespace; } } } else { if (ADP.IsEmpty(this.TableName)) { this.TableName = currentTable.TableName; if (!ADP.IsEmpty(currentTable.Namespace)) { this.Namespace = currentTable.Namespace; } } if (this.DataSet == null) { System.Data.DataSet set2 = new System.Data.DataSet(set.DataSetName); set2.SetLocaleValue(set.Locale, set.ShouldSerializeLocale()); set2.CaseSensitive = set.CaseSensitive; set2.Namespace = set.Namespace; set2.mainTableName = set.mainTableName; set2.RemotingFormat = set.RemotingFormat; set2.Tables.Add(this); } this.CloneHierarchy(currentTable, this.DataSet, null); foreach (DataTable table2 in tableList) { DataTable table4 = this.DataSet.Tables[table2.tableName, table2.Namespace]; DataTable table6 = set.Tables[table2.tableName, table2.Namespace]; foreach (Constraint constraint3 in table6.Constraints) { ForeignKeyConstraint constraint = constraint3 as ForeignKeyConstraint; if (((constraint != null) && (constraint.Table != constraint.RelatedTable)) && (tableList.Contains(constraint.Table) && tableList.Contains(constraint.RelatedTable))) { ForeignKeyConstraint constraint2 = (ForeignKeyConstraint) constraint.Clone(table4.DataSet); if (!table4.Constraints.Contains(constraint2.ConstraintName)) { table4.Constraints.Add(constraint2); } } } } foreach (DataRelation relation in relationList) { if (!this.DataSet.Relations.Contains(relation.RelationName)) { this.DataSet.Relations.Add(relation.Clone(this.DataSet)); } } bool flag = false; foreach (DataTable table3 in tableList) { foreach (DataColumn column in table3.Columns) { flag = false; if (column.Expression.Length != 0) { DataColumn[] dependency = column.DataExpression.GetDependency(); for (int i = 0; i < dependency.Length; i++) { if (!tableList.Contains(dependency[i].Table)) { flag = true; break; } } } if (!flag) { this.DataSet.Tables[table3.TableName, table3.Namespace].Columns[column.ColumnName].Expression = column.Expression; } } flag = false; } } } } finally { Bid.ScopeLeave(ref ptr); } }