internal static XmlReader CreateSqlReader(Stream input, XmlReaderSettings settings, XmlParserContext inputContext)
 {
     XmlReader reader;
     int num2;
     if (input == null)
     {
         throw new ArgumentNullException("input");
     }
     if (settings == null)
     {
         settings = new XmlReaderSettings();
     }
     byte[] buffer = new byte[CalcBufferSize(input)];
     int offset = 0;
     do
     {
         num2 = input.Read(buffer, offset, buffer.Length - offset);
         offset += num2;
     }
     while ((num2 > 0) && (offset < 2));
     if (((offset >= 2) && (buffer[0] == 0xdf)) && (buffer[1] == 0xff))
     {
         if (inputContext != null)
         {
             throw new ArgumentException(Res.GetString("XmlBinary_NoParserContext"), "inputContext");
         }
         reader = new XmlSqlBinaryReader(input, buffer, offset, string.Empty, settings.CloseInput, settings);
     }
     else
     {
         reader = new XmlTextReaderImpl(input, buffer, offset, settings, null, string.Empty, inputContext, settings.CloseInput);
     }
     if (settings.ValidationType != ValidationType.None)
     {
         reader = settings.AddValidation(reader);
     }
     return reader;
 }
Example #2
0
		// TODO: Validate if this comment is still valid
        // !!!!!!
        // NOTE: This method is called via reflection from System.Data.dll and from Analysis Services in Yukon. 
        // Do not change its signature without notifying the appropriate teams!
        // !!!!!!
        internal static XmlReader CreateSqlReader(Stream input, XmlReaderSettings settings, XmlParserContext inputContext)
        {
            if (input == null)
            {
                throw new ArgumentNullException(nameof(input));
            }
            if (settings == null)
            {
                settings = new XmlReaderSettings();
            }

            XmlReader reader;

            // allocate byte buffer
            byte[] bytes = new byte[CalcBufferSize(input)];

            int byteCount = 0;
            int read;
            do
            {
                read = input.Read(bytes, byteCount, bytes.Length - byteCount);
                byteCount += read;
            } while (read > 0 && byteCount < 2);

            // create text or binary XML reader depenting on the stream first 2 bytes
            if (byteCount >= 2 && (bytes[0] == 0xdf && bytes[1] == 0xff))
            {
                if (inputContext != null)
                    throw new ArgumentException(SR.XmlBinary_NoParserContext, "inputContext");
                reader = new XmlSqlBinaryReader(input, bytes, byteCount, string.Empty, settings.CloseInput, settings);
            }
            else
            {
                reader = new XmlTextReaderImpl(input, bytes, byteCount, settings, null, string.Empty, inputContext, settings.CloseInput);
            }

            // wrap with validating reader
            if (settings.ValidationType != ValidationType.None)
            {
                reader = settings.AddValidation(reader);
            }

            if (settings.Async)
            {
                reader = XmlAsyncCheckReader.CreateAsyncCheckWrapper(reader);
            }

            return reader;
        }
        // !!!!!!
        // NOTE: This method is called via reflection from System.Data.dll and from Analysis Services in Yukon. 
        // Do not change its signature without notifying the appropriate teams!
        // !!!!!!
        internal static XmlReader CreateSqlReader(Stream input, XmlReaderSettings settings, XmlParserContext inputContext) {
            if (input == null) {
                throw new ArgumentNullException("input");
            }
            if (settings == null) {
                settings = new XmlReaderSettings();
            }

            XmlReader reader;

            // allocate byte buffer
            byte[] bytes = new byte[CalcBufferSize(input)];

#if false
            {
                // catch the binary XML input and dump it into a local file (for debugging and testing purposes)

                // create dump file name
                string dumpFileNameBase = "~CreateSqlReaderInputDump";
                string dumpFileName;
                int i = 0;
                do {
                    i++;
                    dumpFileName = Path.GetFullPath(string.Concat(dumpFileNameBase, i.ToString(), ".bmx"));
                } while (File.Exists(dumpFileName));

                // dump the input into the file
                FileStream fs = new FileStream(dumpFileName, FileMode.Create, FileAccess.ReadWrite);
                byte[] buffer = new byte[4096];
                int bytesRead;
                while ((bytesRead = input.Read(buffer, 0, buffer.Length)) > 0) {
                    fs.Write(buffer, 0, bytesRead);
                }
                fs.Seek(0, SeekOrigin.Begin);

                // make sure it will get closed
                if (settings.CloseInput) {
                    input.Close();
                }
                input = fs;
                settings = settings.Clone();
                settings.CloseInput = true;
            }
#endif
            int byteCount = 0;
            int read;
            do {
                read = input.Read(bytes, byteCount, bytes.Length - byteCount);
                byteCount += read;
            } while (read > 0 && byteCount < 2);

            // create text or binary XML reader depenting on the stream first 2 bytes
            if (byteCount >= 2 && (bytes[0] == 0xdf && bytes[1] == 0xff)) {
                if ( inputContext != null )
                    throw new ArgumentException(Res.GetString(Res.XmlBinary_NoParserContext), "inputContext");
                reader = new XmlSqlBinaryReader(input, bytes, byteCount, string.Empty, settings.CloseInput, settings);
            }
            else {
                reader = new XmlTextReaderImpl(input, bytes, byteCount, settings, null, string.Empty, inputContext, settings.CloseInput);
            }
            
            // wrap with validating reader
            if ( settings.ValidationType != ValidationType.None ) {
                reader = settings.AddValidation( reader );
            }

            if (settings.Async) {
                reader = XmlAsyncCheckReader.CreateAsyncCheckWrapper(reader);
            }

            return reader;
        }
 public NestedBinXml(XmlSqlBinaryReader.SymbolTables symbolTables, int docState, XmlSqlBinaryReader.NestedBinXml next)
 {
     this.symbolTables = symbolTables;
     this.docState = docState;
     this.next = next;
 }
 public NamespaceDecl(string prefix, string nsuri, XmlSqlBinaryReader.NamespaceDecl nextInScope, XmlSqlBinaryReader.NamespaceDecl prevDecl, int scope, bool implied)
 {
     this.prefix = prefix;
     this.uri = nsuri;
     this.scopeLink = nextInScope;
     this.prevLink = prevDecl;
     this.scope = scope;
     this.implied = implied;
 }
 public void Set(XmlSqlBinaryReader.QName name, bool xmlspacePreserve)
 {
     this.name = name;
     this.xmlLang = null;
     this.xmlSpace = XmlSpace.None;
     this.xmlspacePreserve = xmlspacePreserve;
 }
 public void Set(XmlSqlBinaryReader.QName n, int pos)
 {
     this.name = n;
     this.val = null;
     this.contentPos = pos;
     this.hashCode = 0;
     this.prevHash = 0;
 }
 public void Set(XmlSqlBinaryReader.QName n, string v)
 {
     this.name = n;
     this.val = v;
     this.contentPos = 0;
     this.hashCode = 0;
     this.prevHash = 0;
 }