internal void ValidateMultipleNestedRelations()
 {
     if ((this.Nested && this.CheckMultipleNested) && (0 < this.ChildTable.NestedParentRelations.Length))
     {
         DataColumn[] childColumns = this.ChildColumns;
         if ((childColumns.Length != 1) || !this.IsAutoGenerated(childColumns[0]))
         {
             throw ExceptionBuilder.TableCantBeNestedInTwoTables(this.ChildTable.TableName);
         }
         if (!XmlTreeGen.AutoGenerated(this))
         {
             throw ExceptionBuilder.TableCantBeNestedInTwoTables(this.ChildTable.TableName);
         }
         foreach (Constraint constraint in this.ChildTable.Constraints)
         {
             if (constraint is ForeignKeyConstraint)
             {
                 ForeignKeyConstraint fk = (ForeignKeyConstraint)constraint;
                 if (!XmlTreeGen.AutoGenerated(fk, true))
                 {
                     throw ExceptionBuilder.TableCantBeNestedInTwoTables(this.ChildTable.TableName);
                 }
             }
             else
             {
                 UniqueConstraint unique = (UniqueConstraint)constraint;
                 if (!XmlTreeGen.AutoGenerated(unique))
                 {
                     throw ExceptionBuilder.TableCantBeNestedInTwoTables(this.ChildTable.TableName);
                 }
             }
         }
     }
 }
Пример #2
0
        private bool AutoGenerated(Constraint constraint)
        {
            ForeignKeyConstraint fk = constraint as ForeignKeyConstraint;

            if (fk != null)
            {
                return(XmlTreeGen.AutoGenerated(fk, false));
            }
            UniqueConstraint unique = (UniqueConstraint)constraint;

            return(XmlTreeGen.AutoGenerated(unique));
        }
Пример #3
0
        private bool AutoGenerated(Constraint constraint)
        {
            ForeignKeyConstraint fk = (constraint as ForeignKeyConstraint);

            if (null != fk)
            {
                return(XmlTreeGen.AutoGenerated(fk, false));
            }
            else
            {
                UniqueConstraint unique = (UniqueConstraint)constraint;
                return(XmlTreeGen.AutoGenerated(unique));
            }
        }
Пример #4
0
        internal void ValidateMultipleNestedRelations()
        {
            // find all nested relations that this child table has
            // if this relation is the only relation it has, then fine,
            // otherwise check if all relations are created from XSD, without using Key/KeyRef
            // check all keys to see autogenerated

            if (!Nested || !CheckMultipleNested) // no need for this verification
            {
                return;
            }

            if (0 < ChildTable.NestedParentRelations.Length)
            {
                DataColumn[] childCols = ChildColumns;
                if (childCols.Length != 1 || !IsAutoGenerated(childCols[0]))
                {
                    throw ExceptionBuilder.TableCantBeNestedInTwoTables(ChildTable.TableName);
                }

                if (!XmlTreeGen.AutoGenerated(this))
                {
                    throw ExceptionBuilder.TableCantBeNestedInTwoTables(ChildTable.TableName);
                }

                foreach (Constraint cs in ChildTable.Constraints)
                {
                    if (cs is ForeignKeyConstraint)
                    {
                        ForeignKeyConstraint fk = (ForeignKeyConstraint)cs;
                        if (!XmlTreeGen.AutoGenerated(fk, true))
                        {
                            throw ExceptionBuilder.TableCantBeNestedInTwoTables(ChildTable.TableName);
                        }
                    }
                    else
                    {
                        UniqueConstraint unique = (UniqueConstraint)cs;
                        if (!XmlTreeGen.AutoGenerated(unique))
                        {
                            throw ExceptionBuilder.TableCantBeNestedInTwoTables(ChildTable.TableName);
                        }
                    }
                }
            }
        }
        private void GenerateColumn(DataRow row, DataColumn col, DataRowVersion version)
        {
            string columnValueAsString = null;

            columnValueAsString = col.GetColumnValueAsString(row, version);
            if (columnValueAsString == null)
            {
                if (col.ColumnMapping == MappingType.SimpleContent)
                {
                    this._xmlw.WriteAttributeString("xsi", "nil", "http://www.w3.org/2001/XMLSchema-instance", "true");
                }
            }
            else
            {
                bool   flag;
                string prefix = (col.Namespace.Length != 0) ? col.Prefix : string.Empty;
                switch (col.ColumnMapping)
                {
                case MappingType.Element:
                {
                    flag = true;
                    object obj2 = row[col, version];
                    if ((!col.IsCustomType || !col.IsValueCustomTypeInstance(obj2)) || typeof(IXmlSerializable).IsAssignableFrom(obj2.GetType()))
                    {
                        this._xmlw.WriteStartElement(prefix, col.EncodedColumnName, col.Namespace);
                        flag = false;
                    }
                    Type type = obj2.GetType();
                    if (col.IsCustomType)
                    {
                        if ((obj2 != DBNull.Value) && (!col.ImplementsINullable || !DataStorage.IsObjectSqlNull(obj2)))
                        {
                            if (col.IsValueCustomTypeInstance(obj2))
                            {
                                if (!flag && (obj2.GetType() != col.DataType))
                                {
                                    this._xmlw.WriteAttributeString("msdata", "InstanceType", "urn:schemas-microsoft-com:xml-msdata", DataStorage.GetQualifiedName(type));
                                }
                                if (!flag)
                                {
                                    col.ConvertObjectToXml(obj2, this._xmlw, null);
                                }
                                else
                                {
                                    if (obj2.GetType() != col.DataType)
                                    {
                                        throw ExceptionBuilder.PolymorphismNotSupported(type.AssemblyQualifiedName);
                                    }
                                    XmlRootAttribute xmlAttrib = new XmlRootAttribute(col.EncodedColumnName)
                                    {
                                        Namespace = col.Namespace
                                    };
                                    col.ConvertObjectToXml(obj2, this._xmlw, xmlAttrib);
                                }
                            }
                            else
                            {
                                if (((type == typeof(Type)) || (type == typeof(Guid))) || ((type == typeof(char)) || DataStorage.IsSqlType(type)))
                                {
                                    this._xmlw.WriteAttributeString("msdata", "InstanceType", "urn:schemas-microsoft-com:xml-msdata", type.FullName);
                                }
                                else if (obj2 is Type)
                                {
                                    this._xmlw.WriteAttributeString("msdata", "InstanceType", "urn:schemas-microsoft-com:xml-msdata", "Type");
                                }
                                else
                                {
                                    string str3 = "xs:" + XmlTreeGen.XmlDataTypeName(type);
                                    this._xmlw.WriteAttributeString("xsi", "type", "http://www.w3.org/2001/XMLSchema-instance", str3);
                                    this._xmlw.WriteAttributeString("xmlns:xs", "http://www.w3.org/2001/XMLSchema");
                                }
                                if (!DataStorage.IsSqlType(type))
                                {
                                    this._xmlw.WriteString(col.ConvertObjectToXml(obj2));
                                }
                                else
                                {
                                    col.ConvertObjectToXml(obj2, this._xmlw, null);
                                }
                            }
                        }
                        break;
                    }
                    if (((type == typeof(char)) || (type == typeof(string))) && XmlDataTreeWriter.PreserveSpace(columnValueAsString))
                    {
                        this._xmlw.WriteAttributeString("xml", "space", "http://www.w3.org/XML/1998/namespace", "preserve");
                    }
                    this._xmlw.WriteString(columnValueAsString);
                    break;
                }

                case MappingType.Attribute:
                    this._xmlw.WriteAttributeString(prefix, col.EncodedColumnName, col.Namespace, columnValueAsString);
                    return;

                case MappingType.SimpleContent:
                    this._xmlw.WriteString(columnValueAsString);
                    return;

                case MappingType.Hidden:
                    this._xmlw.WriteAttributeString("msdata", "hidden" + col.EncodedColumnName, "urn:schemas-microsoft-com:xml-msdata", columnValueAsString);
                    return;

                default:
                    return;
                }
                if (!flag)
                {
                    this._xmlw.WriteEndElement();
                }
            }
        }
Пример #6
0
        internal void XmlDataRowWriter(DataRow row, string encodedTableName)
        {
            object obj2;
            string prefix = (row.Table.Namespace.Length == 0) ? "" : row.Table.Prefix;

            this._xmlw.WriteStartElement(prefix, encodedTableName, row.Table.Namespace);
            if (this.isDiffgram)
            {
                this._xmlw.WriteAttributeString("diffgr", "id", "urn:schemas-microsoft-com:xml-diffgram-v1", row.Table.TableName + row.rowID.ToString(CultureInfo.InvariantCulture));
                this._xmlw.WriteAttributeString("msdata", "rowOrder", "urn:schemas-microsoft-com:xml-msdata", this.rowsOrder[row].ToString());
                if (row.RowState == DataRowState.Added)
                {
                    this._xmlw.WriteAttributeString("diffgr", "hasChanges", "urn:schemas-microsoft-com:xml-diffgram-v1", "inserted");
                }
                if (row.RowState == DataRowState.Modified)
                {
                    this._xmlw.WriteAttributeString("diffgr", "hasChanges", "urn:schemas-microsoft-com:xml-diffgram-v1", "modified");
                }
                if (RowHasErrors(row))
                {
                    this._xmlw.WriteAttributeString("diffgr", "hasErrors", "urn:schemas-microsoft-com:xml-diffgram-v1", "true");
                }
            }
            foreach (DataColumn column2 in row.Table.Columns)
            {
                if (column2.columnMapping == MappingType.Attribute)
                {
                    obj2 = row[column2];
                    string str3 = (column2.Namespace.Length == 0) ? "" : column2.Prefix;
                    if ((obj2 != DBNull.Value) && (!column2.ImplementsINullable || !DataStorage.IsObjectSqlNull(obj2)))
                    {
                        XmlTreeGen.ValidateColumnMapping(column2.DataType);
                        this._xmlw.WriteAttributeString(str3, column2.EncodedColumnName, column2.Namespace, column2.ConvertObjectToXml(obj2));
                    }
                }
                if (this.isDiffgram && (column2.columnMapping == MappingType.Hidden))
                {
                    obj2 = row[column2];
                    if ((obj2 != DBNull.Value) && (!column2.ImplementsINullable || !DataStorage.IsObjectSqlNull(obj2)))
                    {
                        XmlTreeGen.ValidateColumnMapping(column2.DataType);
                        this._xmlw.WriteAttributeString("msdata", "hidden" + column2.EncodedColumnName, "urn:schemas-microsoft-com:xml-msdata", column2.ConvertObjectToXml(obj2));
                    }
                }
            }
            foreach (DataColumn column in row.Table.Columns)
            {
                if (column.columnMapping != MappingType.Hidden)
                {
                    obj2 = row[column];
                    string str2 = (column.Namespace.Length == 0) ? "" : column.Prefix;
                    bool   flag = true;
                    if (((obj2 == DBNull.Value) || (column.ImplementsINullable && DataStorage.IsObjectSqlNull(obj2))) && (column.ColumnMapping == MappingType.SimpleContent))
                    {
                        this._xmlw.WriteAttributeString("xsi", "nil", "http://www.w3.org/2001/XMLSchema-instance", "true");
                    }
                    if (((obj2 != DBNull.Value) && (!column.ImplementsINullable || !DataStorage.IsObjectSqlNull(obj2))) && (column.columnMapping != MappingType.Attribute))
                    {
                        if ((column.columnMapping != MappingType.SimpleContent) && ((!column.IsCustomType || !column.IsValueCustomTypeInstance(obj2)) || typeof(IXmlSerializable).IsAssignableFrom(obj2.GetType())))
                        {
                            this._xmlw.WriteStartElement(str2, column.EncodedColumnName, column.Namespace);
                            flag = false;
                        }
                        Type type = obj2.GetType();
                        if (!column.IsCustomType)
                        {
                            if (((type == typeof(char)) || (type == typeof(string))) && PreserveSpace(obj2))
                            {
                                this._xmlw.WriteAttributeString("xml", "space", "http://www.w3.org/XML/1998/namespace", "preserve");
                            }
                            this._xmlw.WriteString(column.ConvertObjectToXml(obj2));
                        }
                        else if (column.IsValueCustomTypeInstance(obj2))
                        {
                            if (!flag && (type != column.DataType))
                            {
                                this._xmlw.WriteAttributeString("msdata", "InstanceType", "urn:schemas-microsoft-com:xml-msdata", DataStorage.GetQualifiedName(type));
                            }
                            if (!flag)
                            {
                                column.ConvertObjectToXml(obj2, this._xmlw, null);
                            }
                            else
                            {
                                if (obj2.GetType() != column.DataType)
                                {
                                    throw ExceptionBuilder.PolymorphismNotSupported(type.AssemblyQualifiedName);
                                }
                                XmlRootAttribute xmlAttrib = new XmlRootAttribute(column.EncodedColumnName)
                                {
                                    Namespace = column.Namespace
                                };
                                column.ConvertObjectToXml(obj2, this._xmlw, xmlAttrib);
                            }
                        }
                        else
                        {
                            if (((type == typeof(Type)) || (type == typeof(Guid))) || ((type == typeof(char)) || DataStorage.IsSqlType(type)))
                            {
                                this._xmlw.WriteAttributeString("msdata", "InstanceType", "urn:schemas-microsoft-com:xml-msdata", type.FullName);
                            }
                            else if (obj2 is Type)
                            {
                                this._xmlw.WriteAttributeString("msdata", "InstanceType", "urn:schemas-microsoft-com:xml-msdata", "Type");
                            }
                            else
                            {
                                string str = "xs:" + XmlTreeGen.XmlDataTypeName(type);
                                this._xmlw.WriteAttributeString("xsi", "type", "http://www.w3.org/2001/XMLSchema-instance", str);
                                this._xmlw.WriteAttributeString("xmlns:xs", "http://www.w3.org/2001/XMLSchema");
                            }
                            if (!DataStorage.IsSqlType(type))
                            {
                                this._xmlw.WriteString(column.ConvertObjectToXml(obj2));
                            }
                            else
                            {
                                column.ConvertObjectToXml(obj2, this._xmlw, null);
                            }
                        }
                        if ((column.columnMapping != MappingType.SimpleContent) && !flag)
                        {
                            this._xmlw.WriteEndElement();
                        }
                    }
                }
            }
            if (this._ds != null)
            {
                foreach (DataRelation relation in this.GetNestedChildRelations(row))
                {
                    foreach (DataRow row2 in row.GetChildRows(relation))
                    {
                        this.XmlDataRowWriter(row2, relation.ChildTable.EncodedTableName);
                    }
                }
            }
            this._xmlw.WriteEndElement();
        }