/// <summary>
        /// Writes the 'atom:category' element given category metadata.
        /// </summary>
        /// <param name="category">The category information to write.</param>
        internal void WriteCategory(AtomCategoryMetadata category)
        {
            DebugUtils.CheckNoExternalCallers();
            Debug.Assert(category != null, "Category must not be null.");

            this.WriteCategory(AtomConstants.AtomNamespacePrefix, category.Term, category.Scheme, category.Label);
        }
Esempio n. 2
0
        internal static AtomCategoryMetadata MergeCategoryMetadata(AtomCategoryMetadata categoryMetadata, string term, string scheme)
        {
            AtomCategoryMetadata metadata = new AtomCategoryMetadata(categoryMetadata);
            string strB = metadata.Term;

            if (strB != null)
            {
                if (string.CompareOrdinal(term, strB) != 0)
                {
                    throw new ODataException(Strings.ODataAtomWriterMetadataUtils_CategoryTermsMustMatch(term, strB));
                }
            }
            else
            {
                metadata.Term = term;
            }
            string str2 = metadata.Scheme;

            if (str2 == null)
            {
                metadata.Scheme = scheme;
                return(metadata);
            }
            if (string.CompareOrdinal(scheme, str2) != 0)
            {
                throw new ODataException(Strings.ODataAtomWriterMetadataUtils_CategorySchemesMustMatch(scheme, str2));
            }
            return(metadata);
        }
Esempio n. 3
0
        /// <summary>
        /// Reads an "atom:category" element and returns the data as an <seealso cref="AtomCategoryMetadata"/> object.
        /// </summary>
        /// <returns>An <seealso cref="AtomCategoryMetadata"/> object with its properties filled in according to what was found in the XML.</returns>
        /// <remarks>
        /// Pre-Condition:  XmlNodeType.Element - The start of the atom:category element.
        /// Post-Condition: Any                 - The next node after the atom:category element.
        /// </remarks>
        private AtomCategoryMetadata ReadCategoryElementInCollection()
        {
            this.AssertXmlCondition(XmlNodeType.Element);
            Debug.Assert(this.XmlReader.LocalName == AtomConstants.AtomCategoryElementName, "Expected element named 'category'.");
            Debug.Assert(this.XmlReader.NamespaceURI == AtomConstants.AtomNamespace, "Element 'category' should be in the atom namespace.");

            AtomCategoryMetadata categoryMetadata = new AtomCategoryMetadata();

            while (this.XmlReader.MoveToNextAttribute())
            {
                string attributeValue = this.XmlReader.Value;

                if (this.XmlReader.NamespaceEquals(this.EmptyNamespace))
                {
                    if (this.XmlReader.LocalNameEquals(this.AtomCategoryTermAttributeName))
                    {
                        categoryMetadata.Term = attributeValue;
                    }
                    else if (this.XmlReader.LocalNameEquals(this.AtomCategorySchemeAttributeName))
                    {
                        categoryMetadata.Scheme = attributeValue;
                    }
                    else if (this.XmlReader.LocalNameEquals(this.AtomCategoryLabelAttributeName))
                    {
                        categoryMetadata.Label = attributeValue;
                    }
                }
            }

            return(categoryMetadata);
        }
        private void ReadCategoryElement(AtomFeedMetadata atomFeedMetadata)
        {
            AtomCategoryMetadata categoryMetadata = new AtomCategoryMetadata();

            while (base.XmlReader.MoveToNextAttribute())
            {
                string str;
                if (base.XmlReader.NamespaceEquals(this.EmptyNamespace) && ((str = base.XmlReader.LocalName) != null))
                {
                    if (!(str == "scheme"))
                    {
                        if (str == "term")
                        {
                            goto Label_0069;
                        }
                        if (str == "label")
                        {
                            goto Label_007C;
                        }
                    }
                    else
                    {
                        categoryMetadata.Scheme = base.XmlReader.Value;
                    }
                }
                continue;
Label_0069:
                categoryMetadata.Term = base.XmlReader.Value;
                continue;
Label_007C:
                categoryMetadata.Label = base.XmlReader.Value;
            }
            AtomMetadataReaderUtils.AddCategoryToFeedMetadata(atomFeedMetadata, categoryMetadata);
            base.XmlReader.Skip();
        }
        private AtomCategoryMetadata ReadCategoryElementInCollection()
        {
            AtomCategoryMetadata metadata = new AtomCategoryMetadata();

            while (base.XmlReader.MoveToNextAttribute())
            {
                string str = base.XmlReader.Value;
                if (base.XmlReader.NamespaceEquals(this.EmptyNamespace))
                {
                    if (base.XmlReader.LocalNameEquals(this.AtomCategoryTermAttributeName))
                    {
                        metadata.Term = str;
                    }
                    else
                    {
                        if (base.XmlReader.LocalNameEquals(this.AtomCategorySchemeAttributeName))
                        {
                            metadata.Scheme = str;
                            continue;
                        }
                        if (base.XmlReader.LocalNameEquals(this.AtomCategoryLabelAttributeName))
                        {
                            metadata.Label = str;
                        }
                    }
                }
            }
            return(metadata);
        }
        /// <summary>
        /// Writes the 'atom:category' element given category metadata.
        /// </summary>
        /// <param name="category">The category information to write.</param>
        internal void WriteCategory(AtomCategoryMetadata category)
        {
            DebugUtils.CheckNoExternalCallers();
            Debug.Assert(category != null, "Category must not be null.");

            this.WriteCategory(AtomConstants.AtomNamespacePrefix, category.Term, category.Scheme, category.Label);
        }
 internal static AtomCategoryMetadata MergeCategoryMetadata(AtomCategoryMetadata categoryMetadata, string term, string scheme)
 {
     AtomCategoryMetadata metadata = new AtomCategoryMetadata(categoryMetadata);
     string strB = metadata.Term;
     if (strB != null)
     {
         if (string.CompareOrdinal(term, strB) != 0)
         {
             throw new ODataException(Strings.ODataAtomWriterMetadataUtils_CategoryTermsMustMatch(term, strB));
         }
     }
     else
     {
         metadata.Term = term;
     }
     string str2 = metadata.Scheme;
     if (str2 == null)
     {
         metadata.Scheme = scheme;
         return metadata;
     }
     if (string.CompareOrdinal(scheme, str2) != 0)
     {
         throw new ODataException(Strings.ODataAtomWriterMetadataUtils_CategorySchemesMustMatch(scheme, str2));
     }
     return metadata;
 }
Esempio n. 8
0
        internal AtomCategoryMetadata ReadAtomCategoryElement()
        {
            AtomCategoryMetadata metadata = new AtomCategoryMetadata();

            while (base.XmlReader.MoveToNextAttribute())
            {
                string str2;
                if (!base.XmlReader.NamespaceEquals(this.EmptyNamespace))
                {
                    goto Label_00AF;
                }
                string localName = base.XmlReader.LocalName;
                if (localName != null)
                {
                    if (!(localName == "scheme"))
                    {
                        if (localName == "term")
                        {
                            goto Label_007F;
                        }
                        if (localName == "label")
                        {
                            goto Label_009C;
                        }
                    }
                    else
                    {
                        metadata.Scheme = metadata.Scheme ?? base.XmlReader.Value;
                    }
                }
                continue;
                Label_007F :;
                metadata.Term = metadata.Term ?? base.XmlReader.Value;
                continue;
Label_009C:
                metadata.Label = base.XmlReader.Value;
                continue;
Label_00AF:
                if ((base.UseClientFormatBehavior && base.XmlReader.NamespaceEquals(this.AtomNamespace)) && ((str2 = base.XmlReader.LocalName) != null))
                {
                    if (!(str2 == "scheme"))
                    {
                        if (str2 == "term")
                        {
                            goto Label_0108;
                        }
                    }
                    else
                    {
                        metadata.Scheme = base.XmlReader.Value;
                    }
                }
                continue;
Label_0108:
                metadata.Term = base.XmlReader.Value;
            }
            base.XmlReader.Skip();
            return(metadata);
        }
Esempio n. 9
0
 internal static void AddCategoryToFeedMetadata(AtomFeedMetadata feedMetadata, AtomCategoryMetadata categoryMetadata)
 {
     if (object.ReferenceEquals(feedMetadata.Categories, EmptyCategoriesList))
     {
         feedMetadata.Categories = new ReadOnlyEnumerable<AtomCategoryMetadata>();
     }
     ReaderUtils.GetSourceListOfEnumerable<AtomCategoryMetadata>(feedMetadata.Categories, "Categories").Add(categoryMetadata);
 }
Esempio n. 10
0
 internal void WriteEntryTypeName(string typeName, AtomEntryMetadata entryMetadata)
 {
     if (typeName != null)
     {
         AtomCategoryMetadata category = ODataAtomWriterMetadataUtils.MergeCategoryMetadata((entryMetadata == null) ? null : entryMetadata.CategoryWithTypeName, typeName, base.MessageWriterSettings.WriterBehavior.ODataTypeScheme);
         this.atomEntryMetadataSerializer.WriteCategory(category);
     }
 }
 internal AtomCategoryMetadata ReadAtomCategoryElement()
 {
     AtomCategoryMetadata metadata = new AtomCategoryMetadata();
     while (base.XmlReader.MoveToNextAttribute())
     {
         string str2;
         if (!base.XmlReader.NamespaceEquals(this.EmptyNamespace))
         {
             goto Label_00AF;
         }
         string localName = base.XmlReader.LocalName;
         if (localName != null)
         {
             if (!(localName == "scheme"))
             {
                 if (localName == "term")
                 {
                     goto Label_007F;
                 }
                 if (localName == "label")
                 {
                     goto Label_009C;
                 }
             }
             else
             {
                 metadata.Scheme = metadata.Scheme ?? base.XmlReader.Value;
             }
         }
         continue;
     Label_007F:;
         metadata.Term = metadata.Term ?? base.XmlReader.Value;
         continue;
     Label_009C:
         metadata.Label = base.XmlReader.Value;
         continue;
     Label_00AF:
         if ((base.UseClientFormatBehavior && base.XmlReader.NamespaceEquals(this.AtomNamespace)) && ((str2 = base.XmlReader.LocalName) != null))
         {
             if (!(str2 == "scheme"))
             {
                 if (str2 == "term")
                 {
                     goto Label_0108;
                 }
             }
             else
             {
                 metadata.Scheme = base.XmlReader.Value;
             }
         }
         continue;
     Label_0108:
         metadata.Term = base.XmlReader.Value;
     }
     base.XmlReader.Skip();
     return metadata;
 }
        /// <summary>
        /// Reads the atom:category element.
        /// </summary>
        /// <returns>The ATOM category metadata read.</returns>
        /// <remarks>
        /// Pre-Condition:  XmlNodeType.Element (atom:category) - the atom:category element to read.
        /// Post-Condition: Any                                 - the node after the atom:category which was read.
        /// </remarks>
        internal AtomCategoryMetadata ReadAtomCategoryElement()
        {
            DebugUtils.CheckNoExternalCallers();
            this.AssertXmlCondition(XmlNodeType.Element);
            Debug.Assert(
                this.XmlReader.NamespaceURI == AtomConstants.AtomNamespace && this.XmlReader.LocalName == AtomConstants.AtomCategoryElementName,
                "Only atom:category element can be read by this method.");

            AtomCategoryMetadata categoryMetadata = new AtomCategoryMetadata();

            // Read the attributes
            while (this.XmlReader.MoveToNextAttribute())
            {
                if (this.XmlReader.NamespaceEquals(this.EmptyNamespace))
                {
                    switch (this.XmlReader.LocalName)
                    {
                    case AtomConstants.AtomCategorySchemeAttributeName:
                        categoryMetadata.Scheme = categoryMetadata.Scheme ?? this.XmlReader.Value;
                        break;

                    case AtomConstants.AtomCategoryTermAttributeName:
                        categoryMetadata.Term = categoryMetadata.Term ?? this.XmlReader.Value;
                        break;

                    case AtomConstants.AtomCategoryLabelAttributeName:
                        categoryMetadata.Label = this.XmlReader.Value;
                        break;

                    default:
                        // Ignore all other attributes.
                        break;
                    }
                }
                else if (this.UseClientFormatBehavior && this.XmlReader.NamespaceEquals(this.AtomNamespace))
                {
                    switch (this.XmlReader.LocalName)
                    {
                    case AtomConstants.AtomCategorySchemeAttributeName:
                        categoryMetadata.Scheme = this.XmlReader.Value;
                        break;

                    case AtomConstants.AtomCategoryTermAttributeName:
                        categoryMetadata.Term = this.XmlReader.Value;
                        break;

                    default:
                        // Ignore all other attributes.
                        break;
                    }
                }
            }

            // Skip the element in any case (we only ever consume attributes on it anyway).
            this.XmlReader.Skip();

            return(categoryMetadata);
        }
Esempio n. 13
0
 internal AtomCategoryMetadata(AtomCategoryMetadata other)
 {
     if (other != null)
     {
         this.Term   = other.Term;
         this.Scheme = other.Scheme;
         this.Label  = other.Label;
     }
 }
Esempio n. 14
0
 internal AtomCategoryMetadata(AtomCategoryMetadata other)
 {
     if (other != null)
     {
         this.Term = other.Term;
         this.Scheme = other.Scheme;
         this.Label = other.Label;
     }
 }
Esempio n. 15
0
        /// <summary>
        /// Writes the type name category element for the entry.
        /// </summary>
        /// <param name="typeName">The type name to write.</param>
        /// <param name="entryMetadata">The entry metadata if available.</param>
        internal void WriteEntryTypeName(string typeName, AtomEntryMetadata entryMetadata)
        {
            DebugUtils.CheckNoExternalCallers();

            if (typeName != null)
            {
                AtomCategoryMetadata mergedCategoryMetadata = ODataAtomWriterMetadataUtils.MergeCategoryMetadata(
                    entryMetadata == null ? null : entryMetadata.CategoryWithTypeName,
                    typeName,
                    this.MessageWriterSettings.WriterBehavior.ODataTypeScheme);
                this.atomEntryMetadataSerializer.WriteCategory(mergedCategoryMetadata);
            }
        }
Esempio n. 16
0
        /// <summary>
        /// Creates a new <see cref="AtomCategoryMetadata"/> instance by merging the given
        /// <paramref name="categoryMetadata"/> (if any) with the specified <paramref name="term"/> and <paramref name="scheme"/>.
        /// </summary>
        /// <param name="categoryMetadata">The metadata to merge with the <paramref name="term"/> and <paramref name="scheme"/>.</param>
        /// <param name="term">The term to use in the merged metadata.</param>
        /// <param name="scheme">The scheme to use in the merged metadata.</param>
        /// <returns>A new <see cref="AtomCategoryMetadata"/> instance created by merging all the arguments.</returns>
        /// <remarks>
        /// If the <paramref name="categoryMetadata"/> already holds values for <paramref name="term"/> or <paramref name="scheme"/>
        /// this method validates that they are the same as the ones specified in the method arguments.
        /// </remarks>
        internal static AtomCategoryMetadata MergeCategoryMetadata(AtomCategoryMetadata categoryMetadata, string term, string scheme)
        {
            DebugUtils.CheckNoExternalCallers();
            Debug.Assert(term != null, "term != null");
            Debug.Assert(scheme != null, "scheme != null");

            AtomCategoryMetadata mergedCategoryMetadata = new AtomCategoryMetadata(categoryMetadata);

            // Set the term.
            string metadataTerm = mergedCategoryMetadata.Term;

            if (metadataTerm != null)
            {
                // Validate that terms are the same.
                if (string.CompareOrdinal(term, metadataTerm) != 0)
                {
                    throw new ODataException(Strings.ODataAtomWriterMetadataUtils_CategoryTermsMustMatch(term, metadataTerm));
                }
            }
            else
            {
                mergedCategoryMetadata.Term = term;
            }

            // Set the scheme.
            string metadataScheme = mergedCategoryMetadata.Scheme;

            if (metadataScheme != null)
            {
                // Validate that schemes are the same.
                if (string.CompareOrdinal(scheme, metadataScheme) != 0)
                {
                    throw new ODataException(Strings.ODataAtomWriterMetadataUtils_CategorySchemesMustMatch(scheme, metadataScheme));
                }
            }
            else
            {
                mergedCategoryMetadata.Scheme = scheme;
            }

            return(mergedCategoryMetadata);
        }
Esempio n. 17
0
        /// <summary>
        /// Reads an atom:category element in a feed.
        /// </summary>
        /// <param name="atomFeedMetadata">The feed metadata to augment.</param>
        /// <remarks>
        /// Pre-Condition:  XmlNodeType.Element (atom:category) - the atom:category element to read.
        /// Post-Condition: Any                                 - the node after the atom:category which was read.
        /// </remarks>
        private void ReadCategoryElement(AtomFeedMetadata atomFeedMetadata)
        {
            DebugUtils.CheckNoExternalCallers();
            this.AssertXmlCondition(XmlNodeType.Element);
            Debug.Assert(
                this.XmlReader.NamespaceURI == AtomConstants.AtomNamespace && this.XmlReader.LocalName == AtomConstants.AtomCategoryElementName,
                "Only atom:category element can be read by this method.");

            AtomCategoryMetadata categoryMetadata = new AtomCategoryMetadata();

            // Read the attributes
            while (this.XmlReader.MoveToNextAttribute())
            {
                if (this.XmlReader.NamespaceEquals(this.EmptyNamespace))
                {
                    switch (this.XmlReader.LocalName)
                    {
                    case AtomConstants.AtomCategorySchemeAttributeName:
                        categoryMetadata.Scheme = this.XmlReader.Value;
                        break;

                    case AtomConstants.AtomCategoryTermAttributeName:
                        categoryMetadata.Term = this.XmlReader.Value;
                        break;

                    case AtomConstants.AtomCategoryLabelAttributeName:
                        categoryMetadata.Label = this.XmlReader.Value;
                        break;

                    default:
                        // Ignore all other attributes.
                        break;
                    }
                }
            }

            atomFeedMetadata.AddCategory(categoryMetadata);

            // Skip the rest of the category element.
            this.XmlReader.Skip();
        }
        /// <summary>
        /// Reads the atom:category element in the entry content.
        /// </summary>
        /// <param name="entryState">The reader entry state for the entry being read.</param>
        /// <remarks>
        /// Pre-Condition:  XmlNodeType.Element (atom:category) - the atom:category element to read.
        /// Post-Condition: Any                                 - the node after the atom:category which was read.
        /// </remarks>
        internal void ReadAtomCategoryElementInEntryContent(IODataAtomReaderEntryState entryState)
        {
            DebugUtils.CheckNoExternalCallers();
            Debug.Assert(entryState != null, "entryState != null");
            this.AssertXmlCondition(XmlNodeType.Element);
            Debug.Assert(
                this.XmlReader.NamespaceURI == AtomConstants.AtomNamespace && this.XmlReader.LocalName == AtomConstants.AtomCategoryElementName,
                "Only atom:category element can be read by this method.");

            ODataEntityPropertyMappingCache cachedEpm            = entryState.CachedEpm;
            EpmTargetPathSegment            epmTargetPathSegment = null;

            if (cachedEpm != null)
            {
                epmTargetPathSegment = cachedEpm.EpmTargetTree.SyndicationRoot;
            }

            // Rough estimate if we will need the category for EPM - we can't tell for sure since we don't know the scheme value yet.
            bool hasCategoryEpm = epmTargetPathSegment != null && epmTargetPathSegment.SubSegments.Any(segment =>
                                                                                                       string.CompareOrdinal(segment.SegmentName, AtomConstants.AtomCategoryElementName) == 0);

            // Read the attributes and create the category metadata regardless if we will need it or not.
            // We can do this since there's no validation done on any of the values and thus this operation will never fail.
            // If we then decide we don't need it, we can safely throw it away.
            if (this.ReadAtomMetadata || hasCategoryEpm)
            {
                AtomCategoryMetadata categoryMetadata = this.ReadAtomCategoryElement();

                // No point in trying to figure out if we will need the category for EPM or not here.
                // Our EPM syndication reader must handle unneeded categories anyway (if ATOM metadata reading is on)
                // So instead of burning the cycles to compute if we need it, just store it anyway.
                AtomMetadataReaderUtils.AddCategoryToEntryMetadata(entryState.AtomEntryMetadata, categoryMetadata);
            }
            else
            {
                // Skip the element in any case (we only ever consume attributes on it anyway).
                this.XmlReader.Skip();
            }
        }
Esempio n. 19
0
        internal void ReadAtomCategoryElementInEntryContent(IODataAtomReaderEntryState entryState)
        {
            ODataEntityPropertyMappingCache cachedEpm       = entryState.CachedEpm;
            EpmTargetPathSegment            syndicationRoot = null;

            if (cachedEpm != null)
            {
                syndicationRoot = cachedEpm.EpmTargetTree.SyndicationRoot;
            }
            if (syndicationRoot == null)
            {
            }
            bool flag = syndicationRoot.SubSegments.Any <EpmTargetPathSegment>();

            if (base.ReadAtomMetadata || flag)
            {
                AtomCategoryMetadata categoryMetadata = this.ReadAtomCategoryElement();
                AtomMetadataReaderUtils.AddCategoryToEntryMetadata(entryState.AtomEntryMetadata, categoryMetadata);
            }
            else
            {
                base.XmlReader.Skip();
            }
        }
        /// <summary>
        /// Reads an atom:category element in a feed.
        /// </summary>
        /// <param name="atomFeedMetadata">The feed metadata to augment.</param>
        /// <remarks>
        /// Pre-Condition:  XmlNodeType.Element (atom:category) - the atom:category element to read.
        /// Post-Condition: Any                                 - the node after the atom:category which was read.
        /// </remarks>
        private void ReadCategoryElement(AtomFeedMetadata atomFeedMetadata)
        {
            DebugUtils.CheckNoExternalCallers();
            this.AssertXmlCondition(XmlNodeType.Element);
            Debug.Assert(
                this.XmlReader.NamespaceURI == AtomConstants.AtomNamespace && this.XmlReader.LocalName == AtomConstants.AtomCategoryElementName,
                "Only atom:category element can be read by this method.");

            AtomCategoryMetadata categoryMetadata = new AtomCategoryMetadata();

            // Read the attributes
            while (this.XmlReader.MoveToNextAttribute())
            {
                if (this.XmlReader.NamespaceEquals(this.EmptyNamespace))
                {
                    switch (this.XmlReader.LocalName)
                    {
                        case AtomConstants.AtomCategorySchemeAttributeName:
                            categoryMetadata.Scheme = this.XmlReader.Value;
                            break;
                        case AtomConstants.AtomCategoryTermAttributeName:
                            categoryMetadata.Term = this.XmlReader.Value;
                            break;
                        case AtomConstants.AtomCategoryLabelAttributeName:
                            categoryMetadata.Label = this.XmlReader.Value;
                            break;
                        default:
                            // Ignore all other attributes.
                            break;
                    }
                }
            }

            AtomMetadataReaderUtils.AddCategoryToFeedMetadata(atomFeedMetadata, categoryMetadata);

            // Skip the rest of the category element.
            this.XmlReader.Skip();
        }
 private AtomCategoryMetadata ReadCategoryElementInCollection()
 {
     AtomCategoryMetadata metadata = new AtomCategoryMetadata();
     while (base.XmlReader.MoveToNextAttribute())
     {
         string str = base.XmlReader.Value;
         if (base.XmlReader.NamespaceEquals(this.EmptyNamespace))
         {
             if (base.XmlReader.LocalNameEquals(this.AtomCategoryTermAttributeName))
             {
                 metadata.Term = str;
             }
             else
             {
                 if (base.XmlReader.LocalNameEquals(this.AtomCategorySchemeAttributeName))
                 {
                     metadata.Scheme = str;
                     continue;
                 }
                 if (base.XmlReader.LocalNameEquals(this.AtomCategoryLabelAttributeName))
                 {
                     metadata.Label = str;
                 }
             }
         }
     }
     return metadata;
 }
        /// <summary>
        /// Creates a new <see cref="AtomCategoryMetadata"/> instance by merging the given
        /// <paramref name="categoryMetadata"/> (if any) with the specified <paramref name="term"/> and <paramref name="scheme"/>.
        /// </summary>
        /// <param name="categoryMetadata">The metadata to merge with the <paramref name="term"/> and <paramref name="scheme"/>.</param>
        /// <param name="term">The term to use in the merged metadata.</param>
        /// <param name="scheme">The scheme to use in the merged metadata.</param>
        /// <returns>A new <see cref="AtomCategoryMetadata"/> instance created by merging all the arguments.</returns>
        /// <remarks>
        /// If the <paramref name="categoryMetadata"/> already holds values for <paramref name="term"/> or <paramref name="scheme"/>
        /// this method validates that they are the same as the ones specified in the method arguments.
        /// </remarks>
        internal static AtomCategoryMetadata MergeCategoryMetadata(AtomCategoryMetadata categoryMetadata, string term, string scheme)
        {
            DebugUtils.CheckNoExternalCallers();
            Debug.Assert(term != null, "term != null");
            Debug.Assert(scheme != null, "scheme != null");

            AtomCategoryMetadata mergedCategoryMetadata = new AtomCategoryMetadata(categoryMetadata);

            // Set the term.
            string metadataTerm = mergedCategoryMetadata.Term;
            if (metadataTerm != null)
            {
                // Validate that terms are the same.
                if (string.CompareOrdinal(term, metadataTerm) != 0)
                {
                    throw new ODataException(Strings.ODataAtomWriterMetadataUtils_CategoryTermsMustMatch(term, metadataTerm));
                }
            }
            else
            {
                mergedCategoryMetadata.Term = term;
            }

            // Set the scheme.
            string metadataScheme = mergedCategoryMetadata.Scheme;
            if (metadataScheme != null)
            {
                // Validate that schemes are the same.
                if (string.CompareOrdinal(scheme, metadataScheme) != 0)
                {
                    throw new ODataException(Strings.ODataAtomWriterMetadataUtils_CategorySchemesMustMatch(scheme, metadataScheme));
                }
            }
            else
            {
                mergedCategoryMetadata.Scheme = scheme;
            }

            return mergedCategoryMetadata;
        }
        /// <summary>
        /// Reads an "atom:category" element and returns the data as an <seealso cref="AtomCategoryMetadata"/> object.
        /// </summary>
        /// <returns>An <seealso cref="AtomCategoryMetadata"/> object with its properties filled in according to what was found in the XML.</returns>
        /// <remarks>
        /// Pre-Condition:  XmlNodeType.Element - The start of the atom:category element.
        /// Post-Condition: Any                 - The next node after the atom:category element.
        /// </remarks>
        private AtomCategoryMetadata ReadCategoryElementInCollection()
        {
            this.AssertXmlCondition(XmlNodeType.Element);
            Debug.Assert(this.XmlReader.LocalName == AtomConstants.AtomCategoryElementName, "Expected element named 'category'.");
            Debug.Assert(this.XmlReader.NamespaceURI == AtomConstants.AtomNamespace, "Element 'category' should be in the atom namespace.");

            AtomCategoryMetadata categoryMetadata = new AtomCategoryMetadata();

            while (this.XmlReader.MoveToNextAttribute())
            {
                string attributeValue = this.XmlReader.Value;

                if (this.XmlReader.NamespaceEquals(this.EmptyNamespace))
                {
                    if (this.XmlReader.LocalNameEquals(this.AtomCategoryTermAttributeName))
                    {
                        categoryMetadata.Term = attributeValue;
                    }
                    else if (this.XmlReader.LocalNameEquals(this.AtomCategorySchemeAttributeName))
                    {
                        categoryMetadata.Scheme = attributeValue;
                    }
                    else if (this.XmlReader.LocalNameEquals(this.AtomCategoryLabelAttributeName))
                    {
                        categoryMetadata.Label = attributeValue;
                    }
                }
            }

            return categoryMetadata;
        }
Esempio n. 24
0
 internal void WriteCategory(AtomCategoryMetadata category)
 {
     this.WriteCategory("", category.Term, category.Scheme, category.Label);
 }
 internal void WriteCategory(AtomCategoryMetadata category)
 {
     this.WriteCategory("", category.Term, category.Scheme, category.Label);
 }
        /// <summary>
        /// Adds a new category to feed metadata.
        /// </summary>
        /// <param name="feedMetadata">The feed metadata to add the category to.</param>
        /// <param name="categoryMetadata">The category metadata to add.</param>
        internal static void AddCategoryToFeedMetadata(AtomFeedMetadata feedMetadata, AtomCategoryMetadata categoryMetadata)
        {
            DebugUtils.CheckNoExternalCallers();
            Debug.Assert(feedMetadata != null, "feedMetadata != null");
            Debug.Assert(categoryMetadata != null, "categoryMetadata != null");

            if (object.ReferenceEquals(feedMetadata.Categories, EmptyCategoriesList))
            {
                feedMetadata.Categories = new ReadOnlyEnumerable<AtomCategoryMetadata>();
            }

            ReaderUtils.GetSourceListOfEnumerable(feedMetadata.Categories, "Categories").Add(categoryMetadata);
        }
 private void ReadCategoryElement(AtomFeedMetadata atomFeedMetadata)
 {
     AtomCategoryMetadata categoryMetadata = new AtomCategoryMetadata();
     while (base.XmlReader.MoveToNextAttribute())
     {
         string str;
         if (base.XmlReader.NamespaceEquals(this.EmptyNamespace) && ((str = base.XmlReader.LocalName) != null))
         {
             if (!(str == "scheme"))
             {
                 if (str == "term")
                 {
                     goto Label_0069;
                 }
                 if (str == "label")
                 {
                     goto Label_007C;
                 }
             }
             else
             {
                 categoryMetadata.Scheme = base.XmlReader.Value;
             }
         }
         continue;
     Label_0069:
         categoryMetadata.Term = base.XmlReader.Value;
         continue;
     Label_007C:
         categoryMetadata.Label = base.XmlReader.Value;
     }
     AtomMetadataReaderUtils.AddCategoryToFeedMetadata(atomFeedMetadata, categoryMetadata);
     base.XmlReader.Skip();
 }
        /// <summary>
        /// Reads the atom:category element.
        /// </summary>
        /// <returns>The ATOM category metadata read.</returns>
        /// <remarks>
        /// Pre-Condition:  XmlNodeType.Element (atom:category) - the atom:category element to read.
        /// Post-Condition: Any                                 - the node after the atom:category which was read.
        /// </remarks>
        internal AtomCategoryMetadata ReadAtomCategoryElement()
        {
            DebugUtils.CheckNoExternalCallers();
            this.AssertXmlCondition(XmlNodeType.Element);
            Debug.Assert(
                this.XmlReader.NamespaceURI == AtomConstants.AtomNamespace && this.XmlReader.LocalName == AtomConstants.AtomCategoryElementName,
                "Only atom:category element can be read by this method.");

            AtomCategoryMetadata categoryMetadata = new AtomCategoryMetadata();

            // Read the attributes
            while (this.XmlReader.MoveToNextAttribute())
            {
                if (this.XmlReader.NamespaceEquals(this.EmptyNamespace))
                {
                    switch (this.XmlReader.LocalName)
                    {
                        case AtomConstants.AtomCategorySchemeAttributeName:
                            categoryMetadata.Scheme = categoryMetadata.Scheme ?? this.XmlReader.Value;
                            break;
                        case AtomConstants.AtomCategoryTermAttributeName:
                            categoryMetadata.Term = categoryMetadata.Term ?? this.XmlReader.Value;
                            break;
                        case AtomConstants.AtomCategoryLabelAttributeName:
                            categoryMetadata.Label = this.XmlReader.Value;
                            break;
                        default:
                            // Ignore all other attributes.
                            break;
                    }
                }
                else if (this.UseClientFormatBehavior && this.XmlReader.NamespaceEquals(this.AtomNamespace))
                {
                    switch (this.XmlReader.LocalName)
                    {
                        case AtomConstants.AtomCategorySchemeAttributeName:
                            categoryMetadata.Scheme = this.XmlReader.Value;
                            break;
                        case AtomConstants.AtomCategoryTermAttributeName:
                            categoryMetadata.Term = this.XmlReader.Value;
                            break;
                        default:
                            // Ignore all other attributes.
                            break;
                    }
                }
            }

            // Skip the element in any case (we only ever consume attributes on it anyway).
            this.XmlReader.Skip();

            return categoryMetadata;
        }