Пример #1
0
        private static ODataInnerError ReadInnerErrorElement(BufferingXmlReader xmlReader, int recursionDepth, int maxInnerErrorDepth)
        {
            ValidationUtils.IncreaseAndValidateRecursionDepth(ref recursionDepth, maxInnerErrorDepth);
            ODataInnerError error = new ODataInnerError();
            DuplicateInnerErrorElementPropertyBitMask none = DuplicateInnerErrorElementPropertyBitMask.None;
            if (xmlReader.IsEmptyElement)
            {
                goto Label_010F;
            }
            xmlReader.Read();
        Label_0022:
            switch (xmlReader.NodeType)
            {
                case XmlNodeType.Element:
                    string str;
                    if (xmlReader.NamespaceEquals(xmlReader.ODataMetadataNamespace) && ((str = xmlReader.LocalName) != null))
                    {
                        if (!(str == "message"))
                        {
                            if (str == "type")
                            {
                                VerifyInnerErrorElementNotFound(ref none, DuplicateInnerErrorElementPropertyBitMask.TypeName, "type");
                                error.TypeName = xmlReader.ReadElementValue();
                                goto Label_0102;
                            }
                            if (str == "stacktrace")
                            {
                                VerifyInnerErrorElementNotFound(ref none, DuplicateInnerErrorElementPropertyBitMask.StackTrace, "stacktrace");
                                error.StackTrace = xmlReader.ReadElementValue();
                                goto Label_0102;
                            }
                            if (str == "internalexception")
                            {
                                VerifyInnerErrorElementNotFound(ref none, DuplicateInnerErrorElementPropertyBitMask.InternalException, "internalexception");
                                error.InnerError = ReadInnerErrorElement(xmlReader, recursionDepth, maxInnerErrorDepth);
                                goto Label_0102;
                            }
                        }
                        else
                        {
                            VerifyInnerErrorElementNotFound(ref none, DuplicateInnerErrorElementPropertyBitMask.Message, "message");
                            error.Message = xmlReader.ReadElementValue();
                            goto Label_0102;
                        }
                    }
                    break;

                case XmlNodeType.EndElement:
                    goto Label_0102;
            }
            xmlReader.Skip();
        Label_0102:
            if (xmlReader.NodeType != XmlNodeType.EndElement)
            {
                goto Label_0022;
            }
        Label_010F:
            xmlReader.Read();
            return error;
        }
Пример #2
0
        internal BufferingXmlReader PopCustomReader()
        {
            BufferingXmlReader reader = this.xmlCustomizationReaders.Pop();

            this.xmlReader = this.xmlCustomizationReaders.Peek();
            return(reader);
        }
Пример #3
0
        internal void PushCustomReader(XmlReader customXmlReader, Uri xmlBaseUri)
        {
            DebugUtils.CheckNoExternalCallers();
            Debug.Assert(this.xmlCustomizationReaders != null, "The reader customization was not initialized.");
            Debug.Assert(
                object.ReferenceEquals(this.xmlCustomizationReaders.Peek(), this.xmlReader),
                "The this.xmlReader must always be the same reader as the top of the XML customization stack.");
            Debug.Assert(this.xmlCustomizationReaders.Count > 0, "The root must always be on the stack.");

            if (!object.ReferenceEquals(this.xmlReader, customXmlReader))
            {
                Debug.Assert(!this.UseServerFormatBehavior, "Xml reader customizations are not supported on the server.");

                BufferingXmlReader bufferingCustomXmlReader = new BufferingXmlReader(
                    customXmlReader,
                    xmlBaseUri,
                    this.MessageReaderSettings.BaseUri,
                    /*disableXmlBase*/ false,
                    this.MessageReaderSettings.MessageQuotas.MaxNestingDepth,
                    this.MessageReaderSettings.ReaderBehavior.ODataNamespace);
                this.xmlCustomizationReaders.Push(bufferingCustomXmlReader);
                this.xmlReader = bufferingCustomXmlReader;
            }
            else
            {
                // If it's the exact same reader, just push it to the stack so that we know what happened when we pop it.
                this.xmlCustomizationReaders.Push(this.xmlReader);
            }
        }
Пример #4
0
        internal static void AssertBuffering(this BufferingXmlReader bufferedXmlReader)
        {
            DebugUtils.CheckNoExternalCallers();

#if DEBUG
            Debug.Assert(bufferedXmlReader.IsBuffering, "bufferedXmlReader.IsBuffering");
#endif
        }
        internal static ODataError ReadErrorElement(BufferingXmlReader xmlReader, int maxInnerErrorDepth)
        {
            ODataError error = new ODataError();
            DuplicateErrorElementPropertyBitMask none = DuplicateErrorElementPropertyBitMask.None;

            if (xmlReader.IsEmptyElement)
            {
                return(error);
            }
            xmlReader.Read();
Label_001A:
            switch (xmlReader.NodeType)
            {
            case XmlNodeType.Element:
                string str;
                if (xmlReader.NamespaceEquals(xmlReader.ODataMetadataNamespace) && ((str = xmlReader.LocalName) != null))
                {
                    if (!(str == "code"))
                    {
                        if (str == "message")
                        {
                            VerifyErrorElementNotFound(ref none, DuplicateErrorElementPropertyBitMask.Message, "message");
                            error.MessageLanguage = xmlReader.GetAttribute(xmlReader.XmlLangAttributeName, xmlReader.XmlNamespace);
                            error.Message         = xmlReader.ReadElementValue();
                            goto Label_00EA;
                        }
                        if (str == "innererror")
                        {
                            VerifyErrorElementNotFound(ref none, DuplicateErrorElementPropertyBitMask.InnerError, "innererror");
                            error.InnerError = ReadInnerErrorElement(xmlReader, 0, maxInnerErrorDepth);
                            goto Label_00EA;
                        }
                    }
                    else
                    {
                        VerifyErrorElementNotFound(ref none, DuplicateErrorElementPropertyBitMask.Code, "code");
                        error.ErrorCode = xmlReader.ReadElementValue();
                        goto Label_00EA;
                    }
                }
                break;

            case XmlNodeType.EndElement:
                goto Label_00EA;
            }
            xmlReader.Skip();
Label_00EA:
            if (xmlReader.NodeType != XmlNodeType.EndElement)
            {
                goto Label_001A;
            }
            return(error);
        }
Пример #6
0
        internal static ODataError ReadErrorElement(BufferingXmlReader xmlReader, int maxInnerErrorDepth)
        {
            ODataError error = new ODataError();
            DuplicateErrorElementPropertyBitMask none = DuplicateErrorElementPropertyBitMask.None;
            if (xmlReader.IsEmptyElement)
            {
                return error;
            }
            xmlReader.Read();
        Label_001A:
            switch (xmlReader.NodeType)
            {
                case XmlNodeType.Element:
                    string str;
                    if (xmlReader.NamespaceEquals(xmlReader.ODataMetadataNamespace) && ((str = xmlReader.LocalName) != null))
                    {
                        if (!(str == "code"))
                        {
                            if (str == "message")
                            {
                                VerifyErrorElementNotFound(ref none, DuplicateErrorElementPropertyBitMask.Message, "message");
                                error.MessageLanguage = xmlReader.GetAttribute(xmlReader.XmlLangAttributeName, xmlReader.XmlNamespace);
                                error.Message = xmlReader.ReadElementValue();
                                goto Label_00EA;
                            }
                            if (str == "innererror")
                            {
                                VerifyErrorElementNotFound(ref none, DuplicateErrorElementPropertyBitMask.InnerError, "innererror");
                                error.InnerError = ReadInnerErrorElement(xmlReader, 0, maxInnerErrorDepth);
                                goto Label_00EA;
                            }
                        }
                        else
                        {
                            VerifyErrorElementNotFound(ref none, DuplicateErrorElementPropertyBitMask.Code, "code");
                            error.ErrorCode = xmlReader.ReadElementValue();
                            goto Label_00EA;
                        }
                    }
                    break;

                case XmlNodeType.EndElement:
                    goto Label_00EA;
            }
            xmlReader.Skip();
        Label_00EA:
            if (xmlReader.NodeType != XmlNodeType.EndElement)
            {
                goto Label_001A;
            }
            return error;
        }
Пример #7
0
 internal void PushCustomReader(System.Xml.XmlReader customXmlReader, Uri xmlBaseUri)
 {
     if (!object.ReferenceEquals(this.xmlReader, customXmlReader))
     {
         BufferingXmlReader item = new BufferingXmlReader(customXmlReader, xmlBaseUri, base.MessageReaderSettings.BaseUri, false, base.MessageReaderSettings.MessageQuotas.MaxNestingDepth, base.MessageReaderSettings.ReaderBehavior.ODataNamespace);
         this.xmlCustomizationReaders.Push(item);
         this.xmlReader = item;
     }
     else
     {
         this.xmlCustomizationReaders.Push(this.xmlReader);
     }
 }
Пример #8
0
        /// <summary>
        /// Pops a reader from the top of the customization stack.
        /// </summary>
        /// <returns>The popped reader, the one which was on the top of the stack before the operation.</returns>
        internal BufferingXmlReader PopCustomReader()
        {
            DebugUtils.CheckNoExternalCallers();
            Debug.Assert(this.xmlCustomizationReaders != null, "The reader customization was not initialized.");
            Debug.Assert(
                object.ReferenceEquals(this.xmlCustomizationReaders.Peek(), this.xmlReader),
                "The this.xmlReader must always be the same readers as the top of the XML customization stack.");
            Debug.Assert(this.xmlCustomizationReaders.Count > 1, "To Pop we need the root and the reader to pop on the stack.");

            BufferingXmlReader bufferingCustomXmlReader = this.xmlCustomizationReaders.Pop();

            this.xmlReader = this.xmlCustomizationReaders.Peek();
            return(bufferingCustomXmlReader);
        }
Пример #9
0
 protected override void DisposeImplementation()
 {
     try
     {
         if (this.baseXmlReader != null)
         {
             this.baseXmlReader.Dispose();
         }
     }
     finally
     {
         this.baseXmlReader = null;
         this.xmlReader = null;
     }
 }
Пример #10
0
 /// <summary>
 /// Disposes the input context.
 /// </summary>
 protected override void DisposeImplementation()
 {
     try
     {
         if (this.baseXmlReader != null)
         {
             ((IDisposable)this.baseXmlReader).Dispose();
         }
     }
     finally
     {
         this.baseXmlReader = null;
         this.xmlReader     = null;
     }
 }
Пример #11
0
 internal ODataAtomInputContext(ODataFormat format, Stream messageStream, Encoding encoding, ODataMessageReaderSettings messageReaderSettings, ODataVersion version, bool readingResponse, bool synchronous, IEdmModel model, IODataUrlResolver urlResolver) : base(format, messageReaderSettings, version, readingResponse, synchronous, model, urlResolver)
 {
     ExceptionUtils.CheckArgumentNotNull <ODataFormat>(format, "format");
     ExceptionUtils.CheckArgumentNotNull <ODataMessageReaderSettings>(messageReaderSettings, "messageReaderSettings");
     try
     {
         this.baseXmlReader = ODataAtomReaderUtils.CreateXmlReader(messageStream, encoding, messageReaderSettings);
         this.xmlReader     = new BufferingXmlReader(this.baseXmlReader, null, messageReaderSettings.BaseUri, base.UseServerFormatBehavior && (base.Version < ODataVersion.V3), messageReaderSettings.MessageQuotas.MaxNestingDepth, messageReaderSettings.ReaderBehavior.ODataNamespace);
     }
     catch (Exception exception)
     {
         if (ExceptionUtils.IsCatchableExceptionType(exception) && (messageStream != null))
         {
             messageStream.Dispose();
         }
         throw;
     }
 }
Пример #12
0
 private ODataMetadataInputContext(ODataFormat format, Stream messageStream, Encoding encoding, ODataMessageReaderSettings messageReaderSettings, ODataVersion version, bool readingResponse, bool synchronous, IEdmModel model, IODataUrlResolver urlResolver) : base(format, messageReaderSettings, version, readingResponse, synchronous, model, urlResolver)
 {
     ExceptionUtils.CheckArgumentNotNull<ODataFormat>(format, "format");
     ExceptionUtils.CheckArgumentNotNull<ODataMessageReaderSettings>(messageReaderSettings, "messageReaderSettings");
     try
     {
         this.baseXmlReader = ODataAtomReaderUtils.CreateXmlReader(messageStream, encoding, messageReaderSettings);
         this.xmlReader = new BufferingXmlReader(this.baseXmlReader, null, messageReaderSettings.BaseUri, false, messageReaderSettings.MessageQuotas.MaxNestingDepth, messageReaderSettings.ReaderBehavior.ODataNamespace);
     }
     catch (Exception exception)
     {
         if (ExceptionUtils.IsCatchableExceptionType(exception) && (messageStream != null))
         {
             messageStream.Dispose();
         }
         throw;
     }
 }
Пример #13
0
        /// <summary>Constructor.</summary>
        /// <param name="format">The format for this input context.</param>
        /// <param name="messageStream">The stream to read data from.</param>
        /// <param name="encoding">The encoding to use to read the input.</param>
        /// <param name="messageReaderSettings">Configuration settings of the OData reader.</param>
        /// <param name="version">The OData protocol version to be used for reading the payload.</param>
        /// <param name="readingResponse">true if reading a response message; otherwise false.</param>
        /// <param name="synchronous">true if the input should be read synchronously; false if it should be read asynchronously.</param>
        /// <param name="model">The model to use.</param>
        /// <param name="urlResolver">The optional URL resolver to perform custom URL resolution for URLs read from the payload.</param>
        internal ODataAtomInputContext(
            ODataFormat format,
            Stream messageStream,
            Encoding encoding,
            ODataMessageReaderSettings messageReaderSettings,
            ODataVersion version,
            bool readingResponse,
            bool synchronous,
            IEdmModel model,
            IODataUrlResolver urlResolver)
            : base(format, messageReaderSettings, version, readingResponse, synchronous, model, urlResolver)
        {
            DebugUtils.CheckNoExternalCallers();
            Debug.Assert(messageStream != null, "stream != null");

            try
            {
                ExceptionUtils.CheckArgumentNotNull(format, "format");
                ExceptionUtils.CheckArgumentNotNull(messageReaderSettings, "messageReaderSettings");

                this.baseXmlReader = ODataAtomReaderUtils.CreateXmlReader(messageStream, encoding, messageReaderSettings);

                // For WCF DS Server behavior we need to turn off xml:base processing for V1/V2 back compat.
                this.xmlReader = new BufferingXmlReader(
                    this.baseXmlReader,
                    /*parentXmlReader*/ null,
                    messageReaderSettings.BaseUri,
                    /*disableXmlBase*/ this.UseServerFormatBehavior && this.Version < ODataVersion.V3,
                    messageReaderSettings.MessageQuotas.MaxNestingDepth,
                    messageReaderSettings.ReaderBehavior.ODataNamespace);
            }
            catch (Exception e)
            {
                // Dispose the message stream if we failed to create the input context.
                if (ExceptionUtils.IsCatchableExceptionType(e) && messageStream != null)
                {
                    messageStream.Dispose();
                }

                throw;
            }
        }
Пример #14
0
        /// <summary>
        /// Attempts to read the current element as an annotation element.
        /// </summary>
        /// <param name="annotation">If this method returned true, this is the instance annotation information from the parsed element.</param>
        /// <returns>true if the element was an annotation element, false if it wasn't.</returns>
        /// <remarks>
        /// Pre-Condition:   XmlNodeType.Element    - The element to read.
        /// Post-Condition:  XmlNodeType.EndElement - The end tag of the element (if the element was a non-empty annotation element).
        ///                  XmlNodeType.Element    - The same element as the pre-condition if this method returned false, or an empty annotation element.
        /// </remarks>
        internal bool TryReadAnnotation(out AtomInstanceAnnotation annotation)
        {
            DebugUtils.CheckNoExternalCallers();

            BufferingXmlReader xmlReader = this.inputContext.XmlReader;

            Debug.Assert(xmlReader != null, "xmlReader != null");
            Debug.Assert(xmlReader.NodeType == XmlNodeType.Element, "xmlReader must be positioned on an Element");

            annotation = null;

            if (this.propertyAndValueDeserializer.MessageReaderSettings.ShouldIncludeAnnotation != null &&
                xmlReader.NamespaceEquals(this.odataMetadataNamespace) &&
                xmlReader.LocalNameEquals(this.attributeElementName))
            {
                annotation = AtomInstanceAnnotation.CreateFrom(this.inputContext, this.propertyAndValueDeserializer);
            }

            return(annotation != null);
        }
        /// <summary>Constructor.</summary>
        /// <param name="format">The format for this input context.</param>
        /// <param name="messageStream">The stream to read data from.</param>
        /// <param name="encoding">The encoding to use to read the input.</param>
        /// <param name="messageReaderSettings">Configuration settings of the OData reader.</param>
        /// <param name="version">The OData protocol version to be used for reading the payload.</param>
        /// <param name="readingResponse">true if reading a response message; otherwise false.</param>
        /// <param name="synchronous">true if the input should be read synchronously; false if it should be read asynchronously.</param>
        /// <param name="model">The model to use.</param>
        /// <param name="urlResolver">The optional URL resolver to perform custom URL resolution for URLs read from the payload.</param>
        private ODataMetadataInputContext(
            ODataFormat format,
            Stream messageStream,
            Encoding encoding,
            ODataMessageReaderSettings messageReaderSettings,
            ODataVersion version,
            bool readingResponse,
            bool synchronous,
            IEdmModel model,
            IODataUrlResolver urlResolver)
            : base(format, messageReaderSettings, version, readingResponse, synchronous, model, urlResolver)
        {
            Debug.Assert(messageStream != null, "stream != null");

            ExceptionUtils.CheckArgumentNotNull(format, "format");
            ExceptionUtils.CheckArgumentNotNull(messageReaderSettings, "messageReaderSettings");

            try
            {
                this.baseXmlReader = ODataAtomReaderUtils.CreateXmlReader(messageStream, encoding, messageReaderSettings);

                // We use the buffering reader here only for in-stream error detection (not for buffering).
                this.xmlReader = new BufferingXmlReader(
                    this.baseXmlReader,
                    /*parentXmlReader*/ null,
                    messageReaderSettings.BaseUri,
                    /*disableXmlBase*/ false,
                    messageReaderSettings.MessageQuotas.MaxNestingDepth,
                    messageReaderSettings.ReaderBehavior.ODataNamespace);
            }
            catch (Exception e)
            {
                // Dispose the message stream if we failed to create the input context.
                if (ExceptionUtils.IsCatchableExceptionType(e) && messageStream != null)
                {
                    messageStream.Dispose();
                }

                throw;
            }
        }
Пример #16
0
        /// <summary>
        /// Creates a new ATOM annotation parser.
        /// </summary>
        /// <param name="inputContext">The input context this annotation reader should use to read annotation elements.</param>
        /// <param name="propertyAndValueDeserializer">The property and value deserializer to use to read the value of an annotation element.</param>
        internal ODataAtomAnnotationReader(ODataAtomInputContext inputContext, ODataAtomPropertyAndValueDeserializer propertyAndValueDeserializer)
        {
            DebugUtils.CheckNoExternalCallers();

            this.inputContext = inputContext;
            this.propertyAndValueDeserializer = propertyAndValueDeserializer;
            BufferingXmlReader xmlReader = this.inputContext.XmlReader;

            Debug.Assert(xmlReader != null, "xmlReader != null");
            Debug.Assert(xmlReader.NameTable != null, "xmlReader.NameTable != null");
            xmlReader.NameTable.Add(AtomConstants.ODataAnnotationTargetAttribute);
            xmlReader.NameTable.Add(AtomConstants.ODataAnnotationTermAttribute);
            xmlReader.NameTable.Add(AtomConstants.AtomTypeAttributeName);
            xmlReader.NameTable.Add(AtomConstants.ODataNullAttributeName);
            xmlReader.NameTable.Add(AtomConstants.ODataAnnotationStringAttribute);
            xmlReader.NameTable.Add(AtomConstants.ODataAnnotationBoolAttribute);
            xmlReader.NameTable.Add(AtomConstants.ODataAnnotationDecimalAttribute);
            xmlReader.NameTable.Add(AtomConstants.ODataAnnotationIntAttribute);
            xmlReader.NameTable.Add(AtomConstants.ODataAnnotationFloatAttribute);
            this.odataMetadataNamespace = xmlReader.NameTable.Add(AtomConstants.ODataMetadataNamespace);
            this.attributeElementName   = xmlReader.NameTable.Add(AtomConstants.ODataAnnotationElementName);
        }
Пример #17
0
        /// <summary>
        /// Pops a reader from the top of the customization stack.
        /// </summary>
        /// <returns>The popped reader, the one which was on the top of the stack before the operation.</returns>
        internal BufferingXmlReader PopCustomReader()
        {
            DebugUtils.CheckNoExternalCallers();
            Debug.Assert(this.xmlCustomizationReaders != null, "The reader customization was not initialized.");
            Debug.Assert(
                object.ReferenceEquals(this.xmlCustomizationReaders.Peek(), this.xmlReader),
                "The this.xmlReader must always be the same readers as the top of the XML customization stack.");
            Debug.Assert(this.xmlCustomizationReaders.Count > 1, "To Pop we need the root and the reader to pop on the stack.");

            BufferingXmlReader bufferingCustomXmlReader = this.xmlCustomizationReaders.Pop();
            this.xmlReader = this.xmlCustomizationReaders.Peek();
            return bufferingCustomXmlReader;
        }
Пример #18
0
        /// <summary>Constructor.</summary>
        /// <param name="format">The format for this input context.</param>
        /// <param name="messageStream">The stream to read data from.</param>
        /// <param name="encoding">The encoding to use to read the input.</param>
        /// <param name="messageReaderSettings">Configuration settings of the OData reader.</param>
        /// <param name="version">The OData protocol version to be used for reading the payload.</param>
        /// <param name="readingResponse">true if reading a response message; otherwise false.</param>
        /// <param name="synchronous">true if the input should be read synchronously; false if it should be read asynchronously.</param>
        /// <param name="model">The model to use.</param>
        /// <param name="urlResolver">The optional URL resolver to perform custom URL resolution for URLs read from the payload.</param>
        internal ODataAtomInputContext(
            ODataFormat format,
            Stream messageStream,
            Encoding encoding,
            ODataMessageReaderSettings messageReaderSettings,
            ODataVersion version,
            bool readingResponse,
            bool synchronous,
            IEdmModel model,
            IODataUrlResolver urlResolver)
            : base(format, messageReaderSettings, version, readingResponse, synchronous, model, urlResolver)
        {
            DebugUtils.CheckNoExternalCallers();
            Debug.Assert(messageStream != null, "stream != null");

            ExceptionUtils.CheckArgumentNotNull(format, "format");
            ExceptionUtils.CheckArgumentNotNull(messageReaderSettings, "messageReaderSettings");

            try
            {
                this.baseXmlReader = ODataAtomReaderUtils.CreateXmlReader(messageStream, encoding, messageReaderSettings);

                // For WCF DS Server behavior we need to turn off xml:base processing for V1/V2 back compat.
                this.xmlReader = new BufferingXmlReader(
                    this.baseXmlReader,
                    /*parentXmlReader*/ null,
                    messageReaderSettings.BaseUri,
                    /*disableXmlBase*/ this.UseServerFormatBehavior && this.Version < ODataVersion.V3,
                    messageReaderSettings.MessageQuotas.MaxNestingDepth,
                    messageReaderSettings.ReaderBehavior.ODataNamespace);
            }
            catch (Exception e)
            {
                // Dispose the message stream if we failed to create the input context.
                if (ExceptionUtils.IsCatchableExceptionType(e) && messageStream != null)
                {
                    messageStream.Dispose();
                }

                throw;
            }
        }
        private static ODataInnerError ReadInnerErrorElement(BufferingXmlReader xmlReader, int recursionDepth, int maxInnerErrorDepth)
        {
            ValidationUtils.IncreaseAndValidateRecursionDepth(ref recursionDepth, maxInnerErrorDepth);
            ODataInnerError error = new ODataInnerError();
            DuplicateInnerErrorElementPropertyBitMask none = DuplicateInnerErrorElementPropertyBitMask.None;

            if (xmlReader.IsEmptyElement)
            {
                goto Label_010F;
            }
            xmlReader.Read();
Label_0022:
            switch (xmlReader.NodeType)
            {
            case XmlNodeType.Element:
                string str;
                if (xmlReader.NamespaceEquals(xmlReader.ODataMetadataNamespace) && ((str = xmlReader.LocalName) != null))
                {
                    if (!(str == "message"))
                    {
                        if (str == "type")
                        {
                            VerifyInnerErrorElementNotFound(ref none, DuplicateInnerErrorElementPropertyBitMask.TypeName, "type");
                            error.TypeName = xmlReader.ReadElementValue();
                            goto Label_0102;
                        }
                        if (str == "stacktrace")
                        {
                            VerifyInnerErrorElementNotFound(ref none, DuplicateInnerErrorElementPropertyBitMask.StackTrace, "stacktrace");
                            error.StackTrace = xmlReader.ReadElementValue();
                            goto Label_0102;
                        }
                        if (str == "internalexception")
                        {
                            VerifyInnerErrorElementNotFound(ref none, DuplicateInnerErrorElementPropertyBitMask.InternalException, "internalexception");
                            error.InnerError = ReadInnerErrorElement(xmlReader, recursionDepth, maxInnerErrorDepth);
                            goto Label_0102;
                        }
                    }
                    else
                    {
                        VerifyInnerErrorElementNotFound(ref none, DuplicateInnerErrorElementPropertyBitMask.Message, "message");
                        error.Message = xmlReader.ReadElementValue();
                        goto Label_0102;
                    }
                }
                break;

            case XmlNodeType.EndElement:
                goto Label_0102;
            }
            xmlReader.Skip();
Label_0102:
            if (xmlReader.NodeType != XmlNodeType.EndElement)
            {
                goto Label_0022;
            }
Label_010F:
            xmlReader.Read();
            return(error);
        }
Пример #20
0
        internal void PushCustomReader(XmlReader customXmlReader, Uri xmlBaseUri)
        {
            DebugUtils.CheckNoExternalCallers();
            Debug.Assert(this.xmlCustomizationReaders != null, "The reader customization was not initialized.");
            Debug.Assert(
                object.ReferenceEquals(this.xmlCustomizationReaders.Peek(), this.xmlReader),
                "The this.xmlReader must always be the same reader as the top of the XML customization stack.");
            Debug.Assert(this.xmlCustomizationReaders.Count > 0, "The root must always be on the stack.");

            if (!object.ReferenceEquals(this.xmlReader, customXmlReader))
            {
                Debug.Assert(!this.UseServerFormatBehavior, "Xml reader customizations are not supported on the server.");

                BufferingXmlReader bufferingCustomXmlReader = new BufferingXmlReader(
                    customXmlReader,
                    xmlBaseUri,
                    this.MessageReaderSettings.BaseUri,
                    /*disableXmlBase*/ false,
                    this.MessageReaderSettings.MessageQuotas.MaxNestingDepth,
                    this.MessageReaderSettings.ReaderBehavior.ODataNamespace);
                this.xmlCustomizationReaders.Push(bufferingCustomXmlReader);
                this.xmlReader = bufferingCustomXmlReader;
            }
            else
            {
                // If it's the exact same reader, just push it to the stack so that we know what happened when we pop it.
                this.xmlCustomizationReaders.Push(this.xmlReader);
            }
        }
Пример #21
0
 internal void PushCustomReader(System.Xml.XmlReader customXmlReader, Uri xmlBaseUri)
 {
     if (!object.ReferenceEquals(this.xmlReader, customXmlReader))
     {
         BufferingXmlReader item = new BufferingXmlReader(customXmlReader, xmlBaseUri, base.MessageReaderSettings.BaseUri, false, base.MessageReaderSettings.MessageQuotas.MaxNestingDepth, base.MessageReaderSettings.ReaderBehavior.ODataNamespace);
         this.xmlCustomizationReaders.Push(item);
         this.xmlReader = item;
     }
     else
     {
         this.xmlCustomizationReaders.Push(this.xmlReader);
     }
 }
Пример #22
0
 internal BufferingXmlReader PopCustomReader()
 {
     BufferingXmlReader reader = this.xmlCustomizationReaders.Pop();
     this.xmlReader = this.xmlCustomizationReaders.Peek();
     return reader;
 }
Пример #23
0
        /// <summary>
        /// Reads the content of an inner error element.
        /// </summary>
        /// <param name="xmlReader">The (buffering) Xml reader to read the error payload from.</param>
        /// <param name="recursionDepth">The number of times this function has been called recursively.</param>
        /// <param name="maxInnerErrorDepth">The maximumum number of recursive internalexception elements to allow.</param>
        /// <returns>The <see cref="ODataInnerError"/> representing the inner error.</returns>
        /// <remarks>
        /// Pre-Condition:  XmlNodeType.Element - the m:innererror or m:internalexception element
        /// Post-Condition: Any                 - the node after the m:innererror/m:internalexception end element or the node after the empty m:innererror/m:internalexception element node.
        /// </remarks>
        private static ODataInnerError ReadInnerErrorElement(BufferingXmlReader xmlReader, int recursionDepth, int maxInnerErrorDepth)
        {
            Debug.Assert(xmlReader != null, "this.XmlReader != null");
            Debug.Assert(xmlReader.NodeType == XmlNodeType.Element, "xmlReader.NodeType == XmlNodeType.Element");
            Debug.Assert(
                xmlReader.LocalName == AtomConstants.ODataInnerErrorElementName ||
                xmlReader.LocalName == AtomConstants.ODataInnerErrorInnerErrorElementName,
                "Expected reader to be positioned on 'm:innererror' or 'm:internalexception' element.");
            Debug.Assert(xmlReader.NamespaceEquals(xmlReader.ODataMetadataNamespace), "this.XmlReader.NamespaceEquals(this.ODataMetadataNamespace)");

            ValidationUtils.IncreaseAndValidateRecursionDepth(ref recursionDepth, maxInnerErrorDepth);

            ODataInnerError innerError = new ODataInnerError();
            DuplicateInnerErrorElementPropertyBitMask elementsReadBitmask = DuplicateInnerErrorElementPropertyBitMask.None;

            if (!xmlReader.IsEmptyElement)
            {
                // Move to the first child node of the element.
                xmlReader.Read();

                do
                {
                    switch (xmlReader.NodeType)
                    {
                    case XmlNodeType.EndElement:
                        // end of the <m:innererror> or <m:internalexception> element
                        continue;

                    case XmlNodeType.Element:
                        if (xmlReader.NamespaceEquals(xmlReader.ODataMetadataNamespace))
                        {
                            switch (xmlReader.LocalName)
                            {
                            // <m:message>
                            case AtomConstants.ODataInnerErrorMessageElementName:
                                VerifyInnerErrorElementNotFound(
                                    ref elementsReadBitmask,
                                    DuplicateInnerErrorElementPropertyBitMask.Message,
                                    AtomConstants.ODataInnerErrorMessageElementName);
                                innerError.Message = xmlReader.ReadElementValue();
                                continue;

                            // <m:type>
                            case AtomConstants.ODataInnerErrorTypeElementName:
                                VerifyInnerErrorElementNotFound(
                                    ref elementsReadBitmask,
                                    DuplicateInnerErrorElementPropertyBitMask.TypeName,
                                    AtomConstants.ODataInnerErrorTypeElementName);
                                innerError.TypeName = xmlReader.ReadElementValue();
                                continue;

                            // <m:stacktrace>
                            case AtomConstants.ODataInnerErrorStackTraceElementName:
                                VerifyInnerErrorElementNotFound(
                                    ref elementsReadBitmask,
                                    DuplicateInnerErrorElementPropertyBitMask.StackTrace,
                                    AtomConstants.ODataInnerErrorStackTraceElementName);
                                innerError.StackTrace = xmlReader.ReadElementValue();
                                continue;

                            // <m:internalexception>
                            case AtomConstants.ODataInnerErrorInnerErrorElementName:
                                VerifyInnerErrorElementNotFound(
                                    ref elementsReadBitmask,
                                    DuplicateInnerErrorElementPropertyBitMask.InternalException,
                                    AtomConstants.ODataInnerErrorInnerErrorElementName);
                                innerError.InnerError = ReadInnerErrorElement(xmlReader, recursionDepth, maxInnerErrorDepth);
                                continue;

                            default:
                                break;
                            }
                        }

                        break;

                    default:
                        break;
                    }

                    xmlReader.Skip();
                }while (xmlReader.NodeType != XmlNodeType.EndElement);
            }

            // Read over the end element, or empty start element.
            xmlReader.Read();

            return(innerError);
        }
Пример #24
0
        /// <summary>
        /// Reads the content of an error element.
        /// </summary>
        /// <param name="xmlReader">The Xml reader to read the error payload from.</param>
        /// <param name="maxInnerErrorDepth">The maximumum number of recursive internalexception elements to allow.</param>
        /// <returns>The <see cref="ODataError"/> representing the error.</returns>
        /// <remarks>
        /// This method is used to read top-level errors as well as in-stream errors (from inside the buffering Xml reader).
        /// Pre-Condition:  XmlNodeType.Element   - The m:error start element.
        /// Post-Condition: XmlNodeType.EndElement - The m:error end-element.
        ///                 XmlNodeType.Element    - The empty m:error start element.
        /// </remarks>
        internal static ODataError ReadErrorElement(BufferingXmlReader xmlReader, int maxInnerErrorDepth)
        {
            DebugUtils.CheckNoExternalCallers();
            Debug.Assert(xmlReader != null, "this.XmlReader != null");
            Debug.Assert(xmlReader.NodeType == XmlNodeType.Element, "xmlReader.NodeType == XmlNodeType.Element");
            Debug.Assert(xmlReader.LocalName == AtomConstants.ODataErrorElementName, "Expected reader to be positioned on <m:error> element.");
            Debug.Assert(xmlReader.NamespaceEquals(xmlReader.ODataMetadataNamespace), "this.XmlReader.NamespaceEquals(atomizedMetadataNamespace)");

            ODataError error = new ODataError();
            DuplicateErrorElementPropertyBitMask elementsReadBitmask = DuplicateErrorElementPropertyBitMask.None;

            if (!xmlReader.IsEmptyElement)
            {
                // Move to the first child node of the element.
                xmlReader.Read();

                do
                {
                    switch (xmlReader.NodeType)
                    {
                    case XmlNodeType.EndElement:
                        // end of the <m:error> element
                        continue;

                    case XmlNodeType.Element:
                        if (xmlReader.NamespaceEquals(xmlReader.ODataMetadataNamespace))
                        {
                            switch (xmlReader.LocalName)
                            {
                            // <m:code>
                            case AtomConstants.ODataErrorCodeElementName:
                                VerifyErrorElementNotFound(
                                    ref elementsReadBitmask,
                                    DuplicateErrorElementPropertyBitMask.Code,
                                    AtomConstants.ODataErrorCodeElementName);
                                error.ErrorCode = xmlReader.ReadElementValue();
                                continue;

                            // <m:message lang="...">
                            case AtomConstants.ODataErrorMessageElementName:
                                VerifyErrorElementNotFound(
                                    ref elementsReadBitmask,
                                    DuplicateErrorElementPropertyBitMask.Message,
                                    AtomConstants.ODataErrorMessageElementName);
                                error.MessageLanguage = xmlReader.GetAttribute(xmlReader.XmlLangAttributeName, xmlReader.XmlNamespace);
                                error.Message         = xmlReader.ReadElementValue();
                                continue;

                            // <m:innererror>
                            case AtomConstants.ODataInnerErrorElementName:
                                VerifyErrorElementNotFound(
                                    ref elementsReadBitmask,
                                    DuplicateErrorElementPropertyBitMask.InnerError,
                                    AtomConstants.ODataInnerErrorElementName);
                                error.InnerError = ReadInnerErrorElement(xmlReader, 0 /* recursionDepth */, maxInnerErrorDepth);
                                continue;

                            default:
                                break;
                            }
                        }

                        break;

                    default:
                        break;
                    }

                    xmlReader.Skip();
                }while (xmlReader.NodeType != XmlNodeType.EndElement);
            }

            return(error);
        }
        /// <summary>
        /// Reads the content of an error element.
        /// </summary>
        /// <param name="xmlReader">The Xml reader to read the error payload from.</param>
        /// <param name="maxInnerErrorDepth">The maximumum number of recursive internalexception elements to allow.</param>
        /// <returns>The <see cref="ODataError"/> representing the error.</returns>
        /// <remarks>
        /// This method is used to read top-level errors as well as in-stream errors (from inside the buffering Xml reader).
        /// Pre-Condition:  XmlNodeType.Element   - The m:error start element.
        /// Post-Condition: XmlNodeType.EndElement - The m:error end-element.
        ///                 XmlNodeType.Element    - The empty m:error start element.
        /// </remarks>
        internal static ODataError ReadErrorElement(BufferingXmlReader xmlReader, int maxInnerErrorDepth)
        {
            DebugUtils.CheckNoExternalCallers();
            Debug.Assert(xmlReader != null, "this.XmlReader != null");
            Debug.Assert(xmlReader.NodeType == XmlNodeType.Element, "xmlReader.NodeType == XmlNodeType.Element");
            Debug.Assert(xmlReader.LocalName == AtomConstants.ODataErrorElementName, "Expected reader to be positioned on <m:error> element.");
            Debug.Assert(xmlReader.NamespaceEquals(xmlReader.ODataMetadataNamespace), "this.XmlReader.NamespaceEquals(atomizedMetadataNamespace)");

            ODataError error = new ODataError();
            DuplicateErrorElementPropertyBitMask elementsReadBitmask = DuplicateErrorElementPropertyBitMask.None;

            if (!xmlReader.IsEmptyElement)
            {
                // Move to the first child node of the element.
                xmlReader.Read();

                do
                {
                    switch (xmlReader.NodeType)
                    {
                        case XmlNodeType.EndElement:
                            // end of the <m:error> element
                            continue;

                        case XmlNodeType.Element:
                            if (xmlReader.NamespaceEquals(xmlReader.ODataMetadataNamespace))
                            {
                                switch (xmlReader.LocalName)
                                {
                                    // <m:code>
                                    case AtomConstants.ODataErrorCodeElementName:
                                        VerifyErrorElementNotFound(
                                            ref elementsReadBitmask,
                                            DuplicateErrorElementPropertyBitMask.Code,
                                            AtomConstants.ODataErrorCodeElementName);
                                        error.ErrorCode = xmlReader.ReadElementValue();
                                        continue;

                                    // <m:message lang="...">
                                    case AtomConstants.ODataErrorMessageElementName:
                                        VerifyErrorElementNotFound(
                                            ref elementsReadBitmask,
                                            DuplicateErrorElementPropertyBitMask.Message,
                                            AtomConstants.ODataErrorMessageElementName);
                                        error.MessageLanguage = xmlReader.GetAttribute(xmlReader.XmlLangAttributeName, xmlReader.XmlNamespace);
                                        error.Message = xmlReader.ReadElementValue();
                                        continue;

                                    // <m:innererror>
                                    case AtomConstants.ODataInnerErrorElementName:
                                        VerifyErrorElementNotFound(
                                            ref elementsReadBitmask,
                                            DuplicateErrorElementPropertyBitMask.InnerError,
                                            AtomConstants.ODataInnerErrorElementName);
                                        error.InnerError = ReadInnerErrorElement(xmlReader, 0 /* recursionDepth */, maxInnerErrorDepth);
                                        continue;

                                    default:
                                        break;
                                }
                            }

                            break;
                        default:
                            break;
                    }

                    xmlReader.Skip();
                }
                while (xmlReader.NodeType != XmlNodeType.EndElement);
            }

            return error;
        }
        /// <summary>
        /// Reads the content of an inner error element.
        /// </summary>
        /// <param name="xmlReader">The (buffering) Xml reader to read the error payload from.</param>
        /// <param name="recursionDepth">The number of times this function has been called recursively.</param>
        /// <param name="maxInnerErrorDepth">The maximumum number of recursive internalexception elements to allow.</param>
        /// <returns>The <see cref="ODataInnerError"/> representing the inner error.</returns>
        /// <remarks>
        /// Pre-Condition:  XmlNodeType.Element - the m:innererror or m:internalexception element
        /// Post-Condition: Any                 - the node after the m:innererror/m:internalexception end element or the node after the empty m:innererror/m:internalexception element node.
        /// </remarks>
        private static ODataInnerError ReadInnerErrorElement(BufferingXmlReader xmlReader, int recursionDepth, int maxInnerErrorDepth)
        {
            Debug.Assert(xmlReader != null, "this.XmlReader != null");
            Debug.Assert(xmlReader.NodeType == XmlNodeType.Element, "xmlReader.NodeType == XmlNodeType.Element");
            Debug.Assert(
                xmlReader.LocalName == AtomConstants.ODataInnerErrorElementName || 
                xmlReader.LocalName == AtomConstants.ODataInnerErrorInnerErrorElementName,
                "Expected reader to be positioned on 'm:innererror' or 'm:internalexception' element.");
            Debug.Assert(xmlReader.NamespaceEquals(xmlReader.ODataMetadataNamespace), "this.XmlReader.NamespaceEquals(this.ODataMetadataNamespace)");

            ValidationUtils.IncreaseAndValidateRecursionDepth(ref recursionDepth, maxInnerErrorDepth);

            ODataInnerError innerError = new ODataInnerError();
            DuplicateInnerErrorElementPropertyBitMask elementsReadBitmask = DuplicateInnerErrorElementPropertyBitMask.None;

            if (!xmlReader.IsEmptyElement)
            {
                // Move to the first child node of the element.
                xmlReader.Read();

                do
                {
                    switch (xmlReader.NodeType)
                    {
                        case XmlNodeType.EndElement:
                            // end of the <m:innererror> or <m:internalexception> element
                            continue;

                        case XmlNodeType.Element:
                            if (xmlReader.NamespaceEquals(xmlReader.ODataMetadataNamespace))
                            {
                                switch (xmlReader.LocalName)
                                {
                                    // <m:message>
                                    case AtomConstants.ODataInnerErrorMessageElementName:
                                        VerifyInnerErrorElementNotFound(
                                            ref elementsReadBitmask,
                                            DuplicateInnerErrorElementPropertyBitMask.Message,
                                            AtomConstants.ODataInnerErrorMessageElementName);
                                        innerError.Message = xmlReader.ReadElementValue();
                                        continue;

                                    // <m:type>
                                    case AtomConstants.ODataInnerErrorTypeElementName:
                                        VerifyInnerErrorElementNotFound(
                                            ref elementsReadBitmask,
                                            DuplicateInnerErrorElementPropertyBitMask.TypeName,
                                            AtomConstants.ODataInnerErrorTypeElementName);
                                        innerError.TypeName = xmlReader.ReadElementValue();
                                        continue;

                                    // <m:stacktrace>
                                    case AtomConstants.ODataInnerErrorStackTraceElementName:
                                        VerifyInnerErrorElementNotFound(
                                            ref elementsReadBitmask,
                                            DuplicateInnerErrorElementPropertyBitMask.StackTrace,
                                            AtomConstants.ODataInnerErrorStackTraceElementName);
                                        innerError.StackTrace = xmlReader.ReadElementValue();
                                        continue;

                                    // <m:internalexception>
                                    case AtomConstants.ODataInnerErrorInnerErrorElementName:
                                        VerifyInnerErrorElementNotFound(
                                            ref elementsReadBitmask,
                                            DuplicateInnerErrorElementPropertyBitMask.InternalException,
                                            AtomConstants.ODataInnerErrorInnerErrorElementName);
                                        innerError.InnerError = ReadInnerErrorElement(xmlReader, recursionDepth, maxInnerErrorDepth);
                                        continue;

                                    default:
                                        break;
                                }
                            }

                            break;
                        default:
                            break;
                    }

                    xmlReader.Skip();
                }
                while (xmlReader.NodeType != XmlNodeType.EndElement);
            }

            // Read over the end element, or empty start element.
            xmlReader.Read();

            return innerError;
        }
Пример #27
0
 internal static void AssertNotBuffering(this BufferingXmlReader bufferedXmlReader)
 {
 }