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);
        }
        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;
        }
Beispiel #4
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);
        }