internal void ReadXmlSchema(XmlReader reader, bool denyResolving) { IntPtr hscp; Bid.ScopeEnter(out hscp, "<ds.DataTable.ReadXmlSchema|INFO> %d#, denyResolving=%d{bool}\n", ObjectID, denyResolving); try{ DataSet ds = new DataSet(); SerializationFormat cachedRemotingFormat = this.RemotingFormat; // fxcop: ReadXmlSchema will provide the CaseSensitive, Locale, Namespace information ds.ReadXmlSchema(reader, denyResolving); string CurrentTableFullName = ds.MainTableName; if (Common.ADP.IsEmpty(this.tableName) && Common.ADP.IsEmpty(CurrentTableFullName)) return; DataTable currentTable = null; if (!Common.ADP.IsEmpty(this.tableName)) { if (!Common.ADP.IsEmpty(this.Namespace)) { currentTable = ds.Tables[this.tableName, this.Namespace]; } else {//SQL BU defect tracking 240293 int tableIndex = ds.Tables.InternalIndexOf(this.tableName); if (tableIndex > -1) { currentTable = ds.Tables[tableIndex]; } } } else{ //!Common.ADP.IsEmpty(CurrentTableFullName) string CurrentTableNamespace = ""; int nsSeperator = CurrentTableFullName.IndexOf(':'); if (nsSeperator > -1) { CurrentTableNamespace = CurrentTableFullName.Substring(0, nsSeperator); } string CurrentTableName = CurrentTableFullName.Substring(nsSeperator + 1, CurrentTableFullName.Length - nsSeperator -1); currentTable = ds.Tables[CurrentTableName, CurrentTableNamespace]; } if (currentTable == null) { // bug fix :99186 string qTableName = string.Empty; if (!Common.ADP.IsEmpty(this.tableName)) { qTableName = (this.Namespace.Length > 0)? (this.Namespace + ":" + this.tableName):this.tableName; } else { qTableName = CurrentTableFullName ; } throw ExceptionBuilder.TableNotFound(qTableName); } currentTable._remotingFormat = cachedRemotingFormat; List<DataTable> tableList = new List<DataTable>(); tableList.Add(currentTable); CreateTableList(currentTable, tableList); List<DataRelation> relationList = new List<DataRelation>(); CreateRelationList(tableList, relationList); if (relationList.Count == 0) { if (this.Columns.Count == 0) { DataTable tempTable = currentTable; if (tempTable != null) tempTable.CloneTo(this, null, false); // we may have issue Amir if (this.DataSet == null && this.tableNamespace == null) { // webdata 105506 // for standalone table, clone wont get these correctly, since they may come with inheritance this.tableNamespace = tempTable.Namespace; } } return; } else { if (Common.ADP.IsEmpty(this.TableName)) { this.TableName = currentTable.TableName; if (!Common.ADP.IsEmpty(currentTable.Namespace)) { this.Namespace = currentTable.Namespace; } } if (this.DataSet == null) { DataSet dataset = new DataSet(ds.DataSetName); // webdata 105506 // if user set values on DataTable, it isn't necessary // to set them on the DataSet because they won't be inherited // but it is simpler to set them in both places // if user did not set values on DataTable, it is required // to set them on the DataSet so the table will inherit // the value already on the Datatable dataset.SetLocaleValue(ds.Locale, ds.ShouldSerializeLocale()); dataset.CaseSensitive = ds.CaseSensitive; dataset.Namespace = ds.Namespace; dataset.mainTableName = ds.mainTableName; dataset.RemotingFormat = ds.RemotingFormat; dataset.Tables.Add(this); } DataTable targetTable = CloneHierarchy(currentTable, this.DataSet, null); foreach(DataTable tempTable in tableList) { DataTable destinationTable = this.DataSet.Tables[tempTable.tableName, tempTable.Namespace]; DataTable sourceTable = ds.Tables[tempTable.tableName, tempTable.Namespace]; foreach(Constraint tempConstrain in sourceTable.Constraints) { ForeignKeyConstraint fkc = tempConstrain as ForeignKeyConstraint; // we have already cloned the UKC when cloning the datatable if (fkc != null) { if (fkc.Table != fkc.RelatedTable) { if (tableList.Contains(fkc.Table) && tableList.Contains(fkc.RelatedTable)) { ForeignKeyConstraint newFKC = (ForeignKeyConstraint)fkc.Clone(destinationTable.DataSet); if (!destinationTable.Constraints.Contains(newFKC.ConstraintName)) destinationTable.Constraints.Add(newFKC); // we know that the dest table is already in the table } } } } } foreach(DataRelation rel in relationList) { if (!this.DataSet.Relations.Contains(rel.RelationName)) this.DataSet.Relations.Add(rel.Clone(this.DataSet)); } bool hasExternaldependency = false; foreach(DataTable tempTable in tableList) { foreach(DataColumn dc in tempTable.Columns) { hasExternaldependency = false; if (dc.Expression.Length != 0) { DataColumn[] dependency = dc.DataExpression.GetDependency(); for (int j = 0; j < dependency.Length; j++) { if (!tableList.Contains(dependency[j].Table)) { hasExternaldependency = true; break; } } } if (!hasExternaldependency) { this.DataSet.Tables[tempTable.TableName, tempTable.Namespace].Columns[dc.ColumnName].Expression = dc.Expression; } } hasExternaldependency = false; } } } finally{ Bid.ScopeLeave(ref hscp); } }
public void WriteXmlSchema(XmlWriter writer, bool writeHierarchy) { IntPtr hscp; Bid.ScopeEnter(out hscp, "<ds.DataTable.WriteXmlSchema|API> %d#\n", ObjectID); try{ if (this.tableName.Length == 0) { throw ExceptionBuilder.CanNotSerializeDataTableWithEmptyName(); } if (!CheckForClosureOnExpressions(this, writeHierarchy)) { throw ExceptionBuilder.CanNotSerializeDataTableHierarchy(); } DataSet ds = null; string tablenamespace = this.tableNamespace;//SQL BU Defect Tracking 286968 // Generate SchemaTree and write it out if (null == this.DataSet) { ds = new DataSet(); // if user set values on DataTable, it isn't necessary // to set them on the DataSet because they won't be inherited // but it is simpler to set them in both places // if user did not set values on DataTable, it is required // to set them on the DataSet so the table will inherit // the value already on the Datatable ds.SetLocaleValue(_culture, _cultureUserSet); ds.CaseSensitive = this.CaseSensitive; ds.Namespace = this.Namespace; ds.RemotingFormat = this.RemotingFormat; ds.Tables.Add(this); } if (writer != null) { XmlTreeGen treeGen = new XmlTreeGen(SchemaFormat.Public); treeGen.Save(null, this, writer, writeHierarchy); } if (null != ds) { ds.Tables.Remove(this); this.tableNamespace = tablenamespace; } } finally { Bid.ScopeLeave(ref hscp); } }
// Serialize the table schema and data. private void SerializeDataTable(SerializationInfo info, StreamingContext context, bool isSingleTable, SerializationFormat remotingFormat) { info.AddValue("DataTable.RemotingVersion", new Version(2, 0)); // SqlHotFix 299, SerializationFormat enumeration types don't exist in V1.1 SP1 if (SerializationFormat.Xml != remotingFormat) { info.AddValue("DataTable.RemotingFormat", remotingFormat); } if (remotingFormat != SerializationFormat.Xml) {//Binary SerializeTableSchema(info, context, isSingleTable); if (isSingleTable) { SerializeTableData(info, context, 0); } } else {//XML/V1.0/V1.1 string tempDSNamespace = ""; Boolean fCreatedDataSet = false; if (dataSet == null) { DataSet ds = new DataSet("tmpDataSet"); // if user set values on DataTable, it isn't necessary // to set them on the DataSet because they won't be inherited // but it is simpler to set them in both places // if user did not set values on DataTable, it is required // to set them on the DataSet so the table will inherit // the value already on the Datatable ds.SetLocaleValue(_culture, _cultureUserSet); ds.CaseSensitive = this.CaseSensitive; ds.namespaceURI = this.Namespace; Debug.Assert(ds.RemotingFormat == SerializationFormat.Xml, "RemotingFormat must be SerializationFormat.Xml"); ds.Tables.Add(this); fCreatedDataSet = true; } else { tempDSNamespace = this.DataSet.Namespace; this.DataSet.namespaceURI = this.Namespace; //this.DataSet.Namespace = this.Namespace; ?? } info.AddValue(KEY_XMLSCHEMA, dataSet.GetXmlSchemaForRemoting(this)); info.AddValue(KEY_XMLDIFFGRAM, dataSet.GetRemotingDiffGram(this)); if (fCreatedDataSet) { dataSet.Tables.Remove(this); } else{ dataSet.namespaceURI = tempDSNamespace; } } }
public void WriteXml(XmlWriter writer, XmlWriteMode mode, bool writeHierarchy) { IntPtr hscp; Bid.ScopeEnter(out hscp, "<ds.DataTable.WriteXml|API> %d#, mode=%d{ds.XmlWriteMode}\n", ObjectID, (int)mode); try{ if (this.tableName.Length == 0) { throw ExceptionBuilder.CanNotSerializeDataTableWithEmptyName(); } // Generate SchemaTree and write it out if (writer != null) { if (mode == XmlWriteMode.DiffGram) { // FIX THIS // Create and save the updates new NewDiffgramGen(this, writeHierarchy).Save(writer, this); } else { // Create and save xml data if (mode == XmlWriteMode.WriteSchema) { DataSet ds = null; string tablenamespace = this.tableNamespace; if (null == this.DataSet) { ds = new DataSet(); // if user set values on DataTable, it isn't necessary // to set them on the DataSet because they won't be inherited // but it is simpler to set them in both places // if user did not set values on DataTable, it is required // to set them on the DataSet so the table will inherit // the value already on the Datatable ds.SetLocaleValue(_culture, _cultureUserSet); ds.CaseSensitive = this.CaseSensitive; ds.Namespace = this.Namespace; ds.RemotingFormat = this.RemotingFormat; ds.Tables.Add(this); } if (writer != null) { XmlDataTreeWriter xmldataWriter = new XmlDataTreeWriter(this, writeHierarchy); xmldataWriter.Save(writer, /*mode == XmlWriteMode.WriteSchema*/true); } if (null != ds) { ds.Tables.Remove(this); this.tableNamespace = tablenamespace; } } else { XmlDataTreeWriter xmldataWriter = new XmlDataTreeWriter(this, writeHierarchy); xmldataWriter.Save(writer,/*mode == XmlWriteMode.WriteSchema*/ false); } } } } finally { Bid.ScopeLeave(ref hscp); } }
public void WriteXml(XmlWriter writer, XmlWriteMode mode, bool writeHierarchy) { long logScopeId = DataCommonEventSource.Log.EnterScope("<ds.DataTable.WriteXml|API> {0}, mode={1}", ObjectID, mode); try { if (_tableName.Length == 0) { throw ExceptionBuilder.CanNotSerializeDataTableWithEmptyName(); } // Generate SchemaTree and write it out if (writer != null) { if (mode == XmlWriteMode.DiffGram) { // Create and save the updates new NewDiffgramGen(this, writeHierarchy).Save(writer, this); } else { // Create and save xml data if (mode == XmlWriteMode.WriteSchema) { DataSet ds = null; string tablenamespace = _tableNamespace; if (null == DataSet) { ds = new DataSet(); // if user set values on DataTable, it isn't necessary // to set them on the DataSet because they won't be inherited // but it is simpler to set them in both places // if user did not set values on DataTable, it is required // to set them on the DataSet so the table will inherit // the value already on the Datatable ds.SetLocaleValue(_culture, _cultureUserSet); ds.CaseSensitive = CaseSensitive; ds.Namespace = Namespace; ds.RemotingFormat = RemotingFormat; ds.Tables.Add(this); } if (writer != null) { XmlDataTreeWriter xmldataWriter = new XmlDataTreeWriter(this, writeHierarchy); xmldataWriter.Save(writer, /*mode == XmlWriteMode.WriteSchema*/true); } if (null != ds) { ds.Tables.Remove(this); _tableNamespace = tablenamespace; } } else { XmlDataTreeWriter xmldataWriter = new XmlDataTreeWriter(this, writeHierarchy); xmldataWriter.Save(writer,/*mode == XmlWriteMode.WriteSchema*/ false); } } } } finally { DataCommonEventSource.Log.ExitScope(logScopeId); } }