Ejemplo n.º 1
0
        private int ReadOldRowData(DataSet ds, ref DataTable table, ref int pos, XmlReader row)
        {
            // read table information
            if (ds != null)
            {
                table = ds.Tables.GetTable(XmlConvert.DecodeName(row.LocalName), row.NamespaceURI);
            }
            else
            {
                table = GetTable(XmlConvert.DecodeName(row.LocalName), row.NamespaceURI);
            }

            if (table == null)
            {
                row.Skip(); // need to skip this element if we dont know about it, before returning -1
                return(-1);
            }

            int    iRowDepth = row.Depth;
            string value     = null;

            if (table == null)
            {
                throw ExceptionBuilder.DiffgramMissingTable(XmlConvert.DecodeName(row.LocalName));
            }


            value = row.GetAttribute(Keywords.ROWORDER, Keywords.MSDNS);
            if (!string.IsNullOrEmpty(value))
            {
                pos = (int)Convert.ChangeType(value, typeof(int), null);
            }

            int record = table.NewRecord();

            foreach (DataColumn col in table.Columns)
            {
                col[record] = DBNull.Value;
            }

            foreach (DataColumn col in table.Columns)
            {
                if ((col.ColumnMapping == MappingType.Element) ||
                    (col.ColumnMapping == MappingType.SimpleContent))
                {
                    continue;
                }

                if (col.ColumnMapping == MappingType.Hidden)
                {
                    value = row.GetAttribute("hidden" + col.EncodedColumnName, Keywords.MSDNS);
                }
                else
                {
                    value = row.GetAttribute(col.EncodedColumnName, col.Namespace);
                }

                if (value == null)
                {
                    continue;
                }

                col[record] = col.ConvertXmlToObject(value);
            }

            row.Read();
            SkipWhitespaces(row);

            int currentDepth = row.Depth;

            if (currentDepth <= iRowDepth)
            {
                // the node is empty
                if (currentDepth == iRowDepth && row.NodeType == XmlNodeType.EndElement)
                {
                    // read past the EndElement of the current row
                    // note: (currentDepth == iRowDepth) check is needed so we do not skip elements on parent rows.
                    row.Read();
                    SkipWhitespaces(row);
                }
                return(record);
            }

            if (table.XmlText != null)
            {
                DataColumn col = table.XmlText;
                col[record] = col.ConvertXmlToObject(row.ReadString());
            }
            else
            {
                while (row.Depth > iRowDepth)
                {
                    string     ln     = XmlConvert.DecodeName(row.LocalName);
                    string     ns     = row.NamespaceURI;
                    DataColumn column = table.Columns[ln, ns];

                    if (column == null)
                    {
                        while ((row.NodeType != XmlNodeType.EndElement) && (row.LocalName != ln) && (row.NamespaceURI != ns))
                        {
                            row.Read(); // consume the current node
                        }
                        row.Read();     // now points to the next column
                        //SkipWhitespaces(row); seems no need, just in case if we see other issue , this will be here as hint
                        continue;       // add a read here!
                    }

                    if (column.IsCustomType)
                    {
                        // if column's type is object or column type does not implement IXmlSerializable
                        bool isPolymorphism = (column.DataType == typeof(object) || (row.GetAttribute(Keywords.MSD_INSTANCETYPE, Keywords.MSDNS) != null) ||
                                               (row.GetAttribute(Keywords.TYPE, Keywords.XSINS) != null));

                        bool skipped = false;
                        if (column.Table.DataSet != null && column.Table.DataSet._udtIsWrapped)
                        {
                            row.Read(); // if UDT is wrapped, skip the wrapper
                            skipped = true;
                        }

                        XmlRootAttribute xmlAttrib = null;

                        if (!isPolymorphism && !column.ImplementsIXMLSerializable)
                        { // THIS CHECK MAY BE IS WRONG think more
                            // if does not implement IXLSerializable, need to go with XmlSerializer: pass XmlRootAttribute
                            if (skipped)
                            {
                                xmlAttrib           = new XmlRootAttribute(row.LocalName);
                                xmlAttrib.Namespace = row.NamespaceURI;
                            }
                            else
                            {
                                xmlAttrib           = new XmlRootAttribute(column.EncodedColumnName);
                                xmlAttrib.Namespace = column.Namespace;
                            }
                        }
                        // for else case xmlAttrib MUST be null
                        column[record] = column.ConvertXmlToObject(row, xmlAttrib); // you need to pass null XmlAttib here


                        if (skipped)
                        {
                            row.Read(); // if Wrapper is skipped, skip its end tag
                        }
                    }
                    else
                    {
                        int iColumnDepth = row.Depth;
                        row.Read();

                        // SkipWhitespaces(row);seems no need, just in case if we see other issue , this will be here as hint
                        if (row.Depth > iColumnDepth)
                        { //we are inside the column
                            if (row.NodeType == XmlNodeType.Text || row.NodeType == XmlNodeType.Whitespace || row.NodeType == XmlNodeType.SignificantWhitespace)
                            {
                                string text = row.ReadString();
                                column[record] = column.ConvertXmlToObject(text);

                                row.Read(); // now points to the next column
                            }
                        }
                        else
                        {
                            // <element></element> case
                            if (column.DataType == typeof(string))
                            {
                                column[record] = string.Empty;
                            }
                        }
                    }
                }
            }
            row.Read(); //now it should point to next row
            SkipWhitespaces(row);
            return(record);
        }
Ejemplo n.º 2
0
        private int ReadOldRowData(DataSet ds, ref DataTable table, ref int pos, XmlReader row)
        {
            // read table information
            table = ds.Tables[XmlConvert.DecodeName(row.LocalName), row.NamespaceURI];
            int    iRowDepth = row.Depth;
            string value     = null;

            if (table == null)
            {
                throw ExceptionBuilder.DiffgramMissingTable(XmlConvert.DecodeName(row.LocalName));
            }


            value = row.GetAttribute(Keywords.ROWORDER, Keywords.MSDNS);
            if ((value != null) && (value.Length > 0))
            {
                pos = (Int32)Convert.ChangeType(value, typeof(Int32));
            }

            int record = table.NewRecord();

            foreach (DataColumn col in table.Columns)
            {
                col[record] = DBNull.Value;
            }

            foreach (DataColumn col in table.Columns)
            {
                if ((col.ColumnMapping == MappingType.Element) ||
                    (col.ColumnMapping == MappingType.SimpleContent))
                {
                    continue;
                }

                if (col.ColumnMapping == MappingType.Hidden)
                {
                    value = row.GetAttribute("hidden" + col.EncodedColumnName, Keywords.MSDNS);
                }
                else
                {
                    value = row.GetAttribute(col.EncodedColumnName, col.Namespace);
                }

                if (value == null)
                {
                    continue;
                }

                col[record] = col.ConvertXmlToObject(value);
            }

            row.Read();
            if (row.Depth <= iRowDepth)
            {
                // the node is empty
                return(record);
            }

            if (table.XmlText != null)
            {
                DataColumn col = table.XmlText;
                col[record] = col.ConvertXmlToObject(row.ReadString());
            }
            else
            {
                while (row.Depth > iRowDepth)
                {
                    String     ln     = XmlConvert.DecodeName(row.LocalName);
                    String     ns     = row.NamespaceURI;
                    DataColumn column = table.Columns[ln, ns];

                    if (column == null)
                    {
                        while ((row.NodeType != XmlNodeType.EndElement) && (row.LocalName != ln) && (row.NamespaceURI != ns))
                        {
                            row.Read(); // consume the current node
                        }
                        row.Read();     // now points to the next column
                        continue;       // add a read here!
                    }


                    int iColumnDepth = row.Depth;
                    row.Read();
                    if (row.Depth > iColumnDepth)   //we are inside the column
                    {
                        if (row.NodeType == XmlNodeType.Text)
                        {
                            String text = row.ReadString();
                            column[record] = column.ConvertXmlToObject(text);

                            row.Read(); // now points to the next column
                        }
                    }
                    else
                    {
                        // <element></element> case
                        if (column.DataType == typeof(string))
                        {
                            column[record] = string.Empty;
                        }
                    }
                }
            }
            row.Read(); //now it should point to next row
            return(record);
        }
        private int ReadOldRowData(DataSet ds, ref DataTable table, ref int pos, XmlReader row)
        {
            if (ds != null)
            {
                table = ds.Tables.GetTable(XmlConvert.DecodeName(row.LocalName), row.NamespaceURI);
            }
            else
            {
                table = this.GetTable(XmlConvert.DecodeName(row.LocalName), row.NamespaceURI);
            }
            if (table == null)
            {
                row.Skip();
                return(-1);
            }
            int    depth = row.Depth;
            string str   = null;

            if (table == null)
            {
                throw ExceptionBuilder.DiffgramMissingTable(XmlConvert.DecodeName(row.LocalName));
            }
            str = row.GetAttribute("rowOrder", "urn:schemas-microsoft-com:xml-msdata");
            if (!ADP.IsEmpty(str))
            {
                pos = (int)Convert.ChangeType(str, typeof(int), null);
            }
            int num = table.NewRecord();

            foreach (DataColumn column4 in table.Columns)
            {
                column4[num] = DBNull.Value;
            }
            foreach (DataColumn column2 in table.Columns)
            {
                if ((column2.ColumnMapping != MappingType.Element) && (column2.ColumnMapping != MappingType.SimpleContent))
                {
                    if (column2.ColumnMapping == MappingType.Hidden)
                    {
                        str = row.GetAttribute("hidden" + column2.EncodedColumnName, "urn:schemas-microsoft-com:xml-msdata");
                    }
                    else
                    {
                        str = row.GetAttribute(column2.EncodedColumnName, column2.Namespace);
                    }
                    if (str != null)
                    {
                        column2[num] = column2.ConvertXmlToObject(str);
                    }
                }
            }
            row.Read();
            this.SkipWhitespaces(row);
            if (row.Depth > depth)
            {
                if (table.XmlText == null)
                {
                    while (row.Depth > depth)
                    {
                        string     str3         = XmlConvert.DecodeName(row.LocalName);
                        string     namespaceURI = row.NamespaceURI;
                        DataColumn column       = table.Columns[str3, namespaceURI];
                        if (column == null)
                        {
                            while (((row.NodeType != XmlNodeType.EndElement) && (row.LocalName != str3)) && (row.NamespaceURI != namespaceURI))
                            {
                                row.Read();
                            }
                            row.Read();
                        }
                        else if (column.IsCustomType)
                        {
                            bool flag2 = ((column.DataType == typeof(object)) || (row.GetAttribute("InstanceType", "urn:schemas-microsoft-com:xml-msdata") != null)) || (row.GetAttribute("type", "http://www.w3.org/2001/XMLSchema-instance") != null);
                            bool flag  = false;
                            if ((column.Table.DataSet != null) && column.Table.DataSet.UdtIsWrapped)
                            {
                                row.Read();
                                flag = true;
                            }
                            XmlRootAttribute xmlAttrib = null;
                            if (!flag2 && !column.ImplementsIXMLSerializable)
                            {
                                if (flag)
                                {
                                    xmlAttrib = new XmlRootAttribute(row.LocalName)
                                    {
                                        Namespace = row.NamespaceURI
                                    };
                                }
                                else
                                {
                                    xmlAttrib = new XmlRootAttribute(column.EncodedColumnName)
                                    {
                                        Namespace = column.Namespace
                                    };
                                }
                            }
                            column[num] = column.ConvertXmlToObject(row, xmlAttrib);
                            if (flag)
                            {
                                row.Read();
                            }
                        }
                        else
                        {
                            int num3 = row.Depth;
                            row.Read();
                            if (row.Depth > num3)
                            {
                                if (((row.NodeType == XmlNodeType.Text) || (row.NodeType == XmlNodeType.Whitespace)) || (row.NodeType == XmlNodeType.SignificantWhitespace))
                                {
                                    string s = row.ReadString();
                                    column[num] = column.ConvertXmlToObject(s);
                                    row.Read();
                                }
                            }
                            else if (column.DataType == typeof(string))
                            {
                                column[num] = string.Empty;
                            }
                        }
                    }
                }
                else
                {
                    DataColumn xmlText = table.XmlText;
                    xmlText[num] = xmlText.ConvertXmlToObject(row.ReadString());
                }
                row.Read();
                this.SkipWhitespaces(row);
            }
            return(num);
        }