Example #1
0
 protected SyndicationCategory(SyndicationCategory source)
 {
     if (source == null)
     {
         throw new ArgumentNullException(nameof(source));
     }
     _label      = source._label;
     _name       = source._name;
     _scheme     = source._scheme;
     _extensions = source._extensions.Clone();
 }
        private static async Task ReadInlineCategoriesAsync(XmlReaderWrapper reader, InlineCategoriesDocument inlineCategories, Uri baseUri, string version, bool preserveElementExtensions, bool preserveAttributeExtensions, int _maxExtensionSize)
        {
            inlineCategories.BaseUri = baseUri;
            if (reader.HasAttributes)
            {
                while (reader.MoveToNextAttribute())
                {
                    if (reader.LocalName == "base" && reader.NamespaceURI == Atom10FeedFormatter.XmlNs)
                    {
                        inlineCategories.BaseUri = FeedUtils.CombineXmlBase(inlineCategories.BaseUri, await reader.GetValueAsync());
                    }
                    else if (reader.LocalName == "lang" && reader.NamespaceURI == Atom10FeedFormatter.XmlNs)
                    {
                        inlineCategories.Language = await reader.GetValueAsync();
                    }
                    else if (reader.LocalName == App10Constants.Fixed && reader.NamespaceURI == string.Empty)
                    {
                        inlineCategories.IsFixed = (reader.Value == "yes");
                    }
                    else if (reader.LocalName == Atom10Constants.SchemeTag && reader.NamespaceURI == string.Empty)
                    {
                        inlineCategories.Scheme = await reader.GetValueAsync();
                    }
                    else
                    {
                        string ns   = reader.NamespaceURI;
                        string name = reader.LocalName;
                        if (FeedUtils.IsXmlns(name, ns) || FeedUtils.IsXmlSchemaType(name, ns))
                        {
                            continue;
                        }
                        string val = await reader.GetValueAsync();

                        if (!TryParseAttribute(name, ns, val, inlineCategories, version))
                        {
                            if (preserveAttributeExtensions)
                            {
                                inlineCategories.AttributeExtensions.Add(new XmlQualifiedName(reader.LocalName, reader.NamespaceURI), await reader.GetValueAsync());
                            }
                        }
                    }
                }
            }

            await SyndicationFeedFormatter.MoveToStartElementAsync(reader);

            bool isEmptyElement = reader.IsEmptyElement;
            await reader.ReadStartElementAsync();

            if (!isEmptyElement)
            {
                XmlBuffer           buffer    = null;
                XmlDictionaryWriter extWriter = null;
                try
                {
                    while (await reader.IsStartElementAsync())
                    {
                        if (await reader.IsStartElementAsync(Atom10Constants.CategoryTag, Atom10Constants.Atom10Namespace))
                        {
                            SyndicationCategory category = CreateCategory(inlineCategories);
                            await Atom10FeedFormatter.ReadCategoryAsync(reader, category, version, preserveAttributeExtensions, preserveElementExtensions, _maxExtensionSize);

                            if (category.Scheme == null)
                            {
                                category.Scheme = inlineCategories.Scheme;
                            }

                            inlineCategories.Categories.Add(category);
                        }
                        else if (!TryParseElement(reader, inlineCategories, version))
                        {
                            if (preserveElementExtensions)
                            {
                                var tuple = await SyndicationFeedFormatter.CreateBufferIfRequiredAndWriteNodeAsync(buffer, extWriter, reader, _maxExtensionSize);

                                buffer    = tuple.Item1;
                                extWriter = tuple.Item2;
                            }
                            else
                            {
                                await reader.SkipAsync();
                            }
                        }
                    }
                    LoadElementExtensions(buffer, extWriter, inlineCategories);
                }
                finally
                {
                    if (extWriter != null)
                    {
                        extWriter.Close();
                    }
                }

                await reader.ReadEndElementAsync();
            }
        }
 protected Task WriteElementExtensionsAsync(XmlWriter writer, SyndicationCategory category, string version)
 {
     return(SyndicationFeedFormatter.WriteElementExtensionsAsync(writer, category, version));
 }
 internal static void LoadElementExtensions(XmlBuffer buffer, XmlDictionaryWriter writer, SyndicationCategory category)
 {
     SyndicationFeedFormatter.LoadElementExtensions(buffer, writer, category);
 }
 protected static bool TryParseElement(XmlReader reader, SyndicationCategory category, string version)
 {
     return(SyndicationFeedFormatter.TryParseElement(reader, category, version));
 }
 protected static async Task WriteAttributeExtensionsAsync(XmlWriter writer, SyndicationCategory category, string version)
 {
     await SyndicationFeedFormatter.WriteAttributeExtensionsAsync(writer, category, version);
 }
 protected static bool TryParseAttribute(string name, string ns, string value, SyndicationCategory category, string version)
 {
     return(SyndicationFeedFormatter.TryParseAttribute(name, ns, value, category, version));
 }
 protected static void LoadElementExtensions(XmlReader reader, SyndicationCategory category, int maxExtensionSize)
 {
     SyndicationFeedFormatter.LoadElementExtensions(reader, category, maxExtensionSize);
 }
        internal static void LoadElementExtensions(XmlBuffer buffer, XmlDictionaryWriter writer, SyndicationCategory category)
        {
            if (category == null)
            {
                throw new ArgumentNullException(nameof(category));
            }

            CloseBuffer(buffer, writer);
            category.LoadElementExtensions(buffer);
        }
 internal static protected Task WriteAttributeExtensionsAsync(XmlWriter writer, SyndicationCategory category, string version)
 {
     if (category == null)
     {
         throw new ArgumentNullException(nameof(category));
     }
     return(category.WriteAttributeExtensionsAsync(writer, version));
 }
 internal static protected bool TryParseAttribute(string name, string ns, string value, SyndicationCategory category, string version)
 {
     if (category == null)
     {
         throw new ArgumentNullException(nameof(category));
     }
     if (FeedUtils.IsXmlns(name, ns))
     {
         return(true);
     }
     return(category.TryParseAttribute(name, ns, value, version));
 }