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);
        }
Exemplo n.º 2
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;
        }
        /// <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;
        }
Exemplo n.º 5
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;
        }
Exemplo n.º 6
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);
        }
Exemplo n.º 7
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);
        }
        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);
        }