private static void VerifyEntityReferenceLinksElementNotFound(ref DuplicateEntityReferenceLinksElementBitMask elementsFoundBitField, DuplicateEntityReferenceLinksElementBitMask elementFoundBitMask, string elementNamespace, string elementName)
 {
     if ((elementsFoundBitField & elementFoundBitMask) == elementFoundBitMask)
     {
         throw new ODataException(Strings.ODataAtomEntityReferenceLinkDeserializer_MultipleEntityReferenceLinksElementsWithSameName(elementNamespace, elementName));
     }
     elementsFoundBitField |= elementFoundBitMask;
 }
        private ODataEntityReferenceLinks ReadLinksElement()
        {
            ODataEntityReferenceLinks                   links      = new ODataEntityReferenceLinks();
            List <ODataEntityReferenceLink>             sourceList = new List <ODataEntityReferenceLink>();
            DuplicateEntityReferenceLinksElementBitMask none       = DuplicateEntityReferenceLinksElementBitMask.None;

            if (base.XmlReader.IsEmptyElement)
            {
                goto Label_018C;
            }
            base.XmlReader.Read();
Label_002A:
            switch (base.XmlReader.NodeType)
            {
            case XmlNodeType.Element:
                if ((base.XmlReader.NamespaceEquals(base.XmlReader.ODataMetadataNamespace) && base.XmlReader.LocalNameEquals(this.ODataCountElementName)) && (base.Version >= ODataVersion.V2))
                {
                    VerifyEntityReferenceLinksElementNotFound(ref none, DuplicateEntityReferenceLinksElementBitMask.Count, base.XmlReader.ODataMetadataNamespace, "count");
                    long num = (long)AtomValueUtils.ReadPrimitiveValue(base.XmlReader, EdmCoreModel.Instance.GetInt64(false));
                    links.Count = new long?(num);
                    base.XmlReader.Read();
                    goto Label_017A;
                }
                if (base.XmlReader.NamespaceEquals(base.XmlReader.ODataNamespace))
                {
                    if (base.XmlReader.LocalNameEquals(this.ODataUriElementName))
                    {
                        ODataEntityReferenceLink item = this.ReadUriElement();
                        sourceList.Add(item);
                        goto Label_017A;
                    }
                    if (base.XmlReader.LocalNameEquals(this.ODataNextElementName) && (base.Version >= ODataVersion.V2))
                    {
                        VerifyEntityReferenceLinksElementNotFound(ref none, DuplicateEntityReferenceLinksElementBitMask.NextLink, base.XmlReader.ODataNamespace, "next");
                        Uri    xmlBaseUri     = base.XmlReader.XmlBaseUri;
                        string uriFromPayload = base.XmlReader.ReadElementValue();
                        links.NextPageLink = base.ProcessUriFromPayload(uriFromPayload, xmlBaseUri);
                        goto Label_017A;
                    }
                }
                break;

            case XmlNodeType.EndElement:
                goto Label_017A;
            }
            base.XmlReader.Skip();
Label_017A:
            if (base.XmlReader.NodeType != XmlNodeType.EndElement)
            {
                goto Label_002A;
            }
Label_018C:
            base.XmlReader.Read();
            links.Links = new ReadOnlyEnumerable <ODataEntityReferenceLink>(sourceList);
            return(links);
        }
Esempio n. 3
0
        /// <summary>
        /// Verifies that the specified element was not yet found in the entity reference links 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="elementNamespace">The namespace name of the element ot check (used for error reporting).</param>
        /// <param name="elementName">The name of the element to check (used for error reporting).</param>
        private static void VerifyEntityReferenceLinksElementNotFound(
            ref DuplicateEntityReferenceLinksElementBitMask elementsFoundBitField,
            DuplicateEntityReferenceLinksElementBitMask elementFoundBitMask,
            string elementNamespace,
            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.ODataAtomEntityReferenceLinkDeserializer_MultipleEntityReferenceLinksElementsWithSameName(elementNamespace, elementName));
            }

            elementsFoundBitField |= elementFoundBitMask;
        }
        /// <summary>
        /// Verifies that the specified element was not yet found in the entity reference links 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="elementNamespace">The namespace name of the element ot check (used for error reporting).</param>
        /// <param name="elementName">The name of the element to check (used for error reporting).</param>
        private static void VerifyEntityReferenceLinksElementNotFound(
            ref DuplicateEntityReferenceLinksElementBitMask elementsFoundBitField,
            DuplicateEntityReferenceLinksElementBitMask elementFoundBitMask,
            string elementNamespace,
            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.ODataAtomEntityReferenceLinkDeserializer_MultipleEntityReferenceLinksElementsWithSameName(elementNamespace, elementName));
            }

            elementsFoundBitField |= elementFoundBitMask;
        }
Esempio n. 5
0
        /// <summary>
        /// Reads all top-level entity reference links and the (optional) inline count and next link elements.
        /// </summary>
        /// <returns>An <see cref="ODataEntityReferenceLinks"/> instance representing the read entity reference links.</returns>
        /// <remarks>
        /// Pre-Condition:  XmlNodeType.Element - The 'd:links' element.
        /// Post-Condtion:  any                 - The node after the 'd:links' end element (or empty 'd:links' element).
        /// </remarks>
        private ODataEntityReferenceLinks ReadLinksElement()
        {
            Debug.Assert(this.XmlReader != null, "this.XmlReader != null");
            this.AssertXmlCondition(XmlNodeType.Element);
            Debug.Assert(this.XmlReader.NamespaceURI == this.XmlReader.ODataNamespace, "this.XmlReader.NamespaceURI == this.XmlReader.ODataNamespace");
            Debug.Assert(this.XmlReader.LocalName == AtomConstants.ODataLinksElementName, "this.XmlReader.LocalName == AtomConstants.ODataLinksElementName");

            ODataEntityReferenceLinks                   links               = new ODataEntityReferenceLinks();
            List <ODataEntityReferenceLink>             linkList            = new List <ODataEntityReferenceLink>();
            DuplicateEntityReferenceLinksElementBitMask elementsReadBitmask = DuplicateEntityReferenceLinksElementBitMask.None;

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

                do
                {
                    switch (this.XmlReader.NodeType)
                    {
                    case XmlNodeType.EndElement:
                        // end of the <links> element
                        continue;

                    case XmlNodeType.Element:
                        // <m:count>
                        if (this.XmlReader.NamespaceEquals(this.XmlReader.ODataMetadataNamespace) &&
                            this.XmlReader.LocalNameEquals(this.ODataCountElementName) &&
                            this.Version >= ODataVersion.V2)
                        {
                            VerifyEntityReferenceLinksElementNotFound(
                                ref elementsReadBitmask,
                                DuplicateEntityReferenceLinksElementBitMask.Count,
                                this.XmlReader.ODataMetadataNamespace,
                                AtomConstants.ODataCountElementName);

                            // Note that we allow negative values to be read.
                            long countValue = (long)AtomValueUtils.ReadPrimitiveValue(this.XmlReader, EdmCoreModel.Instance.GetInt64(false));
                            links.Count = countValue;

                            // Read over the end element of the <m:count> element
                            this.XmlReader.Read();

                            continue;
                        }

                        if (this.XmlReader.NamespaceEquals(this.XmlReader.ODataNamespace))
                        {
                            // <d:uri>
                            if (this.XmlReader.LocalNameEquals(this.ODataUriElementName))
                            {
                                ODataEntityReferenceLink link = this.ReadUriElement();
                                linkList.Add(link);

                                continue;
                            }

                            // <d:next>
                            if (this.XmlReader.LocalNameEquals(this.ODataNextElementName) && this.Version >= ODataVersion.V2)
                            {
                                VerifyEntityReferenceLinksElementNotFound(
                                    ref elementsReadBitmask,
                                    DuplicateEntityReferenceLinksElementBitMask.NextLink,
                                    this.XmlReader.ODataNamespace,
                                    AtomConstants.ODataNextLinkElementName);

                                // NOTE: get the base URI here before we read the content as string; reading the content as string will move the
                                //       reader to the end element and thus we lose the xml:base definition on the element.
                                Uri    xmlBaseUri = this.XmlReader.XmlBaseUri;
                                string uriString  = this.XmlReader.ReadElementValue();
                                links.NextPageLink = this.ProcessUriFromPayload(uriString, xmlBaseUri);

                                continue;
                            }
                        }

                        break;

                    default:
                        break;
                    }

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

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

            links.Links = new ReadOnlyEnumerable <ODataEntityReferenceLink>(linkList);
            return(links);
        }
 private static void VerifyEntityReferenceLinksElementNotFound(ref DuplicateEntityReferenceLinksElementBitMask elementsFoundBitField, DuplicateEntityReferenceLinksElementBitMask elementFoundBitMask, string elementNamespace, string elementName)
 {
     if ((elementsFoundBitField & elementFoundBitMask) == elementFoundBitMask)
     {
         throw new ODataException(Strings.ODataAtomEntityReferenceLinkDeserializer_MultipleEntityReferenceLinksElementsWithSameName(elementNamespace, elementName));
     }
     elementsFoundBitField |= elementFoundBitMask;
 }