private static void VerifyInnerErrorElementNotFound(ref DuplicateInnerErrorElementPropertyBitMask elementsFoundBitField, DuplicateInnerErrorElementPropertyBitMask elementFoundBitMask, string elementName)
 {
     if ((elementsFoundBitField & elementFoundBitMask) == elementFoundBitMask)
     {
         throw new ODataException(Strings.ODataAtomErrorDeserializer_MultipleInnerErrorElementsWithSameName(elementName));
     }
     elementsFoundBitField |= elementFoundBitMask;
 }
        /// <summary>
        /// Verifies that the specified element was not yet found in an inner error element.
        /// </summary>
        /// <param name="elementsFoundBitField">
        /// The bit field which stores which elements of an inner error were found so far.
        /// </param>
        /// <param name="elementFoundBitMask">The bit mask for the element to check.</param>
        /// <param name="elementName">The name of the element to check (used for error reporting).</param>
        private static void VerifyInnerErrorElementNotFound(
            ref DuplicateInnerErrorElementPropertyBitMask elementsFoundBitField,
            DuplicateInnerErrorElementPropertyBitMask elementFoundBitMask,
            string elementName)
        {
            Debug.Assert(((int)elementFoundBitMask & (((int)elementFoundBitMask) - 1)) == 0, "elementFoundBitMask is not a power of 2.");
            Debug.Assert(!string.IsNullOrEmpty(elementName), "!string.IsNullOrEmpty(elementName)");

            if ((elementsFoundBitField & elementFoundBitMask) == elementFoundBitMask)
            {
                throw new ODataException(Strings.ODataAtomErrorDeserializer_MultipleInnerErrorElementsWithSameName(elementName));
            }

            elementsFoundBitField |= elementFoundBitMask;
        }
        /// <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);
        }
        /// <summary>
        /// Verifies that the specified element was not yet found in an inner error element.
        /// </summary>
        /// <param name="elementsFoundBitField">
        /// The bit field which stores which elements of an inner error were found so far.
        /// </param>
        /// <param name="elementFoundBitMask">The bit mask for the element to check.</param>
        /// <param name="elementName">The name of the element to check (used for error reporting).</param>
        private static void VerifyInnerErrorElementNotFound(
            ref DuplicateInnerErrorElementPropertyBitMask elementsFoundBitField,
            DuplicateInnerErrorElementPropertyBitMask elementFoundBitMask,
            string elementName)
        {
            Debug.Assert(((int)elementFoundBitMask & (((int)elementFoundBitMask) - 1)) == 0, "elementFoundBitMask is not a power of 2.");
            Debug.Assert(!string.IsNullOrEmpty(elementName), "!string.IsNullOrEmpty(elementName)");

            if ((elementsFoundBitField & elementFoundBitMask) == elementFoundBitMask)
            {
                throw new ODataException(Strings.ODataAtomErrorDeserializer_MultipleInnerErrorElementsWithSameName(elementName));
            }

            elementsFoundBitField |= elementFoundBitMask;
        }
예제 #5
0
 private static void VerifyInnerErrorElementNotFound(ref DuplicateInnerErrorElementPropertyBitMask elementsFoundBitField, DuplicateInnerErrorElementPropertyBitMask elementFoundBitMask, string elementName)
 {
     if ((elementsFoundBitField & elementFoundBitMask) == elementFoundBitMask)
     {
         throw new ODataException(Strings.ODataAtomErrorDeserializer_MultipleInnerErrorElementsWithSameName(elementName));
     }
     elementsFoundBitField |= elementFoundBitMask;
 }
        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);
        }