示例#1
0
        internal static void WriteCategoriesInnerXml(XmlWriter writer, CategoriesDocument categories, Uri baseUri, string version)
        {
            Uri baseUriToWrite = FeedUtils.GetBaseUriToWrite(baseUri, categories.BaseUri);

            if (baseUriToWrite != null)
            {
                WriteXmlBase(writer, baseUriToWrite);
            }
            if (!string.IsNullOrEmpty(categories.Language))
            {
                WriteXmlLang(writer, categories.Language);
            }
            if (categories.IsInline)
            {
                WriteInlineCategoriesContent(writer, (InlineCategoriesDocument)categories, version);
            }
            else
            {
                WriteReferencedCategoriesContent(writer, (ReferencedCategoriesDocument)categories, version);
            }
        }
示例#2
0
        protected SyndicationFeed(SyndicationFeed source, bool cloneItems)
        {
            if (source is null)
            {
                throw new ArgumentNullException(nameof(source));
            }

            _authors         = FeedUtils.ClonePersons(source._authors);
            _categories      = FeedUtils.CloneCategories(source._categories);
            _contributors    = FeedUtils.ClonePersons(source._contributors);
            Copyright        = FeedUtils.CloneTextContent(source.Copyright);
            Description      = FeedUtils.CloneTextContent(source.Description);
            _extensions      = source._extensions.Clone();
            Generator        = source.Generator;
            Id               = source.Id;
            ImageUrl         = source.ImageUrl;
            Language         = source.Language;
            _lastUpdatedTime = source._lastUpdatedTime;
            _links           = FeedUtils.CloneLinks(source._links);
            Title            = FeedUtils.CloneTextContent(source.Title);
            BaseUri          = source.BaseUri;
            if (source._items is IList <SyndicationItem> srcList)
            {
                Collection <SyndicationItem> tmp = new NullNotAllowedCollection <SyndicationItem>();
                for (int i = 0; i < srcList.Count; ++i)
                {
                    tmp.Add((cloneItems) ? srcList[i].Clone() : srcList[i]);
                }
                _items = tmp;
            }
            else
            {
                if (cloneItems)
                {
                    throw new InvalidOperationException(SR.UnbufferedItemsCannotBeCloned);
                }

                _items = source._items;
            }
        }
示例#3
0
        protected SyndicationFeed(SyndicationFeed source, bool cloneItems)
        {
            if (source == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("source");
            }
            _authors         = FeedUtils.ClonePersons(source._authors);
            _categories      = FeedUtils.CloneCategories(source._categories);
            _contributors    = FeedUtils.ClonePersons(source._contributors);
            _copyright       = FeedUtils.CloneTextContent(source._copyright);
            _description     = FeedUtils.CloneTextContent(source._description);
            _extensions      = source._extensions.Clone();
            _generator       = source._generator;
            _id              = source._id;
            _imageUrl        = source._imageUrl;
            _language        = source._language;
            _lastUpdatedTime = source._lastUpdatedTime;
            _links           = FeedUtils.CloneLinks(source._links);
            _title           = FeedUtils.CloneTextContent(source._title);
            _baseUri         = source._baseUri;
            IList <SyndicationItem> srcList = source._items as IList <SyndicationItem>;

            if (srcList != null)
            {
                Collection <SyndicationItem> tmp = new NullNotAllowedCollection <SyndicationItem>();
                for (int i = 0; i < srcList.Count; ++i)
                {
                    tmp.Add((cloneItems) ? srcList[i].Clone() : srcList[i]);
                }
                _items = tmp;
            }
            else
            {
                if (cloneItems)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.Format(SR.UnbufferedItemsCannotBeCloned)));
                }
                _items = source._items;
            }
        }
        private void WriteWorkspace(XmlWriter writer, Workspace workspace, Uri baseUri)
        {
            writer.WriteStartElement(App10Constants.Prefix, App10Constants.Workspace, App10Constants.Namespace);
            Uri baseUriToWrite = FeedUtils.GetBaseUriToWrite(baseUri, workspace.BaseUri);

            if (baseUriToWrite != null)
            {
                baseUri = workspace.BaseUri;
                WriteXmlBase(writer, baseUriToWrite);
            }
            WriteAttributeExtensions(writer, workspace, Version);
            if (workspace.Title != null)
            {
                workspace.Title.WriteTo(writer, Atom10Constants.TitleTag, Atom10Constants.Atom10Namespace);
            }
            for (int i = 0; i < workspace.Collections.Count; ++i)
            {
                WriteCollection(writer, workspace.Collections[i], baseUri);
            }
            WriteElementExtensions(writer, workspace, Version);
            writer.WriteEndElement();
        }
        private void WriteWorkspace(XmlWriter writer, Workspace workspace, Uri baseUri)
        {
            writer.WriteStartElement("app", "workspace", "http://www.w3.org/2007/app");
            Uri baseUriToWrite = FeedUtils.GetBaseUriToWrite(baseUri, workspace.BaseUri);

            if (baseUriToWrite != null)
            {
                baseUri = workspace.BaseUri;
                WriteXmlBase(writer, baseUriToWrite);
            }
            ServiceDocumentFormatter.WriteAttributeExtensions(writer, workspace, this.Version);
            if (workspace.Title != null)
            {
                workspace.Title.WriteTo(writer, "title", "http://www.w3.org/2005/Atom");
            }
            for (int i = 0; i < workspace.Collections.Count; i++)
            {
                this.WriteCollection(writer, workspace.Collections[i], baseUri);
            }
            ServiceDocumentFormatter.WriteElementExtensions(writer, workspace, this.Version);
            writer.WriteEndElement();
        }
        private async Task WriteCollectionAsync(XmlWriter writer, ResourceCollectionInfo collection, Uri baseUri)
        {
            await writer.WriteStartElementAsync(App10Constants.Prefix, App10Constants.Collection, App10Constants.Namespace);

            Uri baseUriToWrite = FeedUtils.GetBaseUriToWrite(baseUri, collection.BaseUri);

            if (baseUriToWrite != null)
            {
                baseUri = collection.BaseUri;
                WriteXmlBase(writer, baseUriToWrite);
            }

            if (collection.Link != null)
            {
                await writer.WriteAttributeStringAsync(App10Constants.Href, FeedUtils.GetUriString(collection.Link));
            }

            await WriteAttributeExtensionsAsync(writer, collection, this.Version);

            if (collection.Title != null)
            {
                await collection.Title.WriteToAsync(writer, Atom10Constants.TitleTag, Atom10Constants.Atom10Namespace);
            }

            for (int i = 0; i < collection.Accepts.Count; ++i)
            {
                await writer.WriteElementStringAsync(App10Constants.Prefix, App10Constants.Accept, App10Constants.Namespace, collection.Accepts[i]);
            }

            for (int i = 0; i < collection.Categories.Count; ++i)
            {
                await WriteCategoriesAsync(writer, collection.Categories[i], baseUri, this.Version);
            }

            await WriteElementExtensionsAsync(writer, collection, this.Version);

            await writer.WriteEndElementAsync();
        }
示例#7
0
        internal static async Task WriteCategoriesInnerXml(XmlWriter writer, CategoriesDocument categories, Uri baseUri, string version)
        {
            Uri baseUriToWrite = FeedUtils.GetBaseUriToWrite(baseUri, categories.BaseUri);

            if (baseUriToWrite != null)
            {
                WriteXmlBase(writer, baseUriToWrite);
            }

            if (!string.IsNullOrEmpty(categories.Language))
            {
                WriteXmlLang(writer, categories.Language);
            }

            if (categories.IsInline)
            {
                await WriteInlineCategoriesContentAsync(XmlWriterWrapper.CreateFromWriter(writer), (InlineCategoriesDocument)categories, version).ConfigureAwait(false);
            }
            else
            {
                WriteReferencedCategoriesContent(writer, (ReferencedCategoriesDocument)categories, version);
            }
        }
        internal DateTimeOffset DateFromString(string dateTimeString, XmlReader reader)
        {
            try
            {
                DateTimeOffset dateTimeOffset       = default;
                var            elementQualifiedName = new XmlQualifiedName(reader.LocalName, reader.NamespaceURI);
                var            xmlDateTimeData      = new XmlDateTimeData(dateTimeString, elementQualifiedName);
                object[]       args = new object[] { xmlDateTimeData, dateTimeOffset };
                foreach (Delegate dateTimeParser in DateTimeParser.GetInvocationList())
                {
                    if ((bool)dateTimeParser.Method.Invoke(dateTimeParser.Target, args))
                    {
                        dateTimeOffset = (DateTimeOffset)args[args.Length - 1];
                        return(dateTimeOffset);
                    }
                }
            }
            catch (Exception e)
            {
                throw new XmlException(FeedUtils.AddLineInfo(reader, SR.ErrorParsingDateTime), e);
            }

            throw new XmlException(FeedUtils.AddLineInfo(reader, SR.ErrorParsingDateTime));
        }
        private Workspace ReadWorkspace(XmlReader reader, ServiceDocument document)
        {
            Workspace result = CreateWorkspace(document);

            result.BaseUri = document.BaseUri;
            if (reader.HasAttributes)
            {
                while (reader.MoveToNextAttribute())
                {
                    if (reader.LocalName == "base" && reader.NamespaceURI == Atom10FeedFormatter.XmlNs)
                    {
                        result.BaseUri = FeedUtils.CombineXmlBase(result.BaseUri, reader.Value);
                    }
                    else
                    {
                        string ns   = reader.NamespaceURI;
                        string name = reader.LocalName;
                        if (FeedUtils.IsXmlns(name, ns) || FeedUtils.IsXmlSchemaType(name, ns))
                        {
                            continue;
                        }

                        string val = reader.Value;
                        if (!TryParseAttribute(name, ns, val, result, Version))
                        {
                            result.AttributeExtensions.Add(new XmlQualifiedName(reader.LocalName, reader.NamespaceURI), reader.Value);
                        }
                    }
                }
            }

            XmlBuffer           buffer    = null;
            XmlDictionaryWriter extWriter = null;

            reader.ReadStartElement();
            try
            {
                while (reader.IsStartElement())
                {
                    if (reader.IsStartElement(Atom10Constants.TitleTag, Atom10Constants.Atom10Namespace))
                    {
                        result.Title = Atom10FeedFormatter.ReadTextContentFrom(reader, "//app:service/app:workspace/atom:title[@type]", preserveAttributeExtensions: true);
                    }
                    else if (reader.IsStartElement(App10Constants.Collection, App10Constants.Namespace))
                    {
                        result.Collections.Add(ReadCollection(reader, result));
                    }
                    else if (!TryParseElement(reader, result, Version))
                    {
                        SyndicationFeedFormatter.CreateBufferIfRequiredAndWriteNode(ref buffer, ref extWriter, reader, _maxExtensionSize);
                    }
                }
                LoadElementExtensions(buffer, extWriter, result);
            }
            finally
            {
                extWriter?.Close();
            }

            reader.ReadEndElement();
            return(result);
        }
        private ResourceCollectionInfo ReadCollection(XmlReader reader, Workspace workspace)
        {
            ResourceCollectionInfo result = CreateCollection(workspace);

            result.BaseUri = workspace.BaseUri;
            if (reader.HasAttributes)
            {
                while (reader.MoveToNextAttribute())
                {
                    if (reader.LocalName == "base" && reader.NamespaceURI == Atom10FeedFormatter.XmlNs)
                    {
                        result.BaseUri = FeedUtils.CombineXmlBase(result.BaseUri, reader.Value);
                    }
                    else if (reader.LocalName == App10Constants.Href && reader.NamespaceURI == string.Empty)
                    {
                        result.Link = new Uri(reader.Value, UriKind.RelativeOrAbsolute);
                    }
                    else
                    {
                        string ns   = reader.NamespaceURI;
                        string name = reader.LocalName;
                        if (FeedUtils.IsXmlns(name, ns) || FeedUtils.IsXmlSchemaType(name, ns))
                        {
                            continue;
                        }

                        string val = reader.Value;
                        if (!TryParseAttribute(name, ns, val, result, Version))
                        {
                            result.AttributeExtensions.Add(new XmlQualifiedName(reader.LocalName, reader.NamespaceURI), reader.Value);
                        }
                    }
                }
            }

            XmlBuffer           buffer    = null;
            XmlDictionaryWriter extWriter = null;

            reader.ReadStartElement();
            try
            {
                while (reader.IsStartElement())
                {
                    if (reader.IsStartElement(Atom10Constants.TitleTag, Atom10Constants.Atom10Namespace))
                    {
                        result.Title = Atom10FeedFormatter.ReadTextContentFrom(reader, "//app:service/app:workspace/app:collection/atom:title[@type]", preserveAttributeExtensions: true);
                    }
                    else if (reader.IsStartElement(App10Constants.Categories, App10Constants.Namespace))
                    {
                        result.Categories.Add(ReadCategories(reader,
                                                             result.BaseUri,
                                                             () => CreateInlineCategories(result),
                                                             () => CreateReferencedCategories(result),
                                                             Version,
                                                             _maxExtensionSize));
                    }
                    else if (reader.IsStartElement(App10Constants.Accept, App10Constants.Namespace))
                    {
                        result.Accepts.Add(reader.ReadElementString());
                    }
                    else if (!TryParseElement(reader, result, Version))
                    {
                        SyndicationFeedFormatter.CreateBufferIfRequiredAndWriteNode(ref buffer, ref extWriter, reader, _maxExtensionSize);
                    }
                }
                LoadElementExtensions(buffer, extWriter, result);
            }
            finally
            {
                extWriter?.Close();
            }

            reader.ReadEndElement();
            return(result);
        }
        private void ReadDocument(XmlReader reader)
        {
            ServiceDocument result = CreateDocumentInstance();

            try
            {
                SyndicationFeedFormatter.MoveToStartElement(reader);
                bool elementIsEmpty = reader.IsEmptyElement;
                if (reader.HasAttributes)
                {
                    while (reader.MoveToNextAttribute())
                    {
                        if (reader.LocalName == "lang" && reader.NamespaceURI == Atom10FeedFormatter.XmlNs)
                        {
                            result.Language = reader.Value;
                        }
                        else if (reader.LocalName == "base" && reader.NamespaceURI == Atom10FeedFormatter.XmlNs)
                        {
                            result.BaseUri = new Uri(reader.Value, UriKind.RelativeOrAbsolute);
                        }
                        else
                        {
                            string ns   = reader.NamespaceURI;
                            string name = reader.LocalName;
                            if (FeedUtils.IsXmlns(name, ns) || FeedUtils.IsXmlSchemaType(name, ns))
                            {
                                continue;
                            }

                            string val = reader.Value;
                            if (!TryParseAttribute(name, ns, val, result, Version))
                            {
                                result.AttributeExtensions.Add(new XmlQualifiedName(reader.LocalName, reader.NamespaceURI), reader.Value);
                            }
                        }
                    }
                }
                XmlBuffer           buffer    = null;
                XmlDictionaryWriter extWriter = null;

                reader.ReadStartElement();
                if (!elementIsEmpty)
                {
                    try
                    {
                        while (reader.IsStartElement())
                        {
                            if (reader.IsStartElement(App10Constants.Workspace, App10Constants.Namespace))
                            {
                                result.Workspaces.Add(ReadWorkspace(reader, result));
                            }
                            else if (!TryParseElement(reader, result, Version))
                            {
                                SyndicationFeedFormatter.CreateBufferIfRequiredAndWriteNode(ref buffer, ref extWriter, reader, _maxExtensionSize);
                            }
                        }
                        LoadElementExtensions(buffer, extWriter, result);
                    }
                    finally
                    {
                        extWriter?.Close();
                    }
                }

                reader.ReadEndElement();
            }
            catch (FormatException e)
            {
                throw new XmlException(FeedUtils.AddLineInfo(reader, SR.ErrorParsingDocument), e);
            }
            catch (ArgumentException e)
            {
                throw new XmlException(FeedUtils.AddLineInfo(reader, SR.ErrorParsingDocument), e);
            }

            SetDocument(result);
        }
        private static void ReadReferencedCategories(XmlReader reader, ReferencedCategoriesDocument referencedCategories, Uri baseUri, Uri link, string version, int maxExtensionSize)
        {
            referencedCategories.BaseUri = baseUri;
            referencedCategories.Link    = link;
            if (reader.HasAttributes)
            {
                while (reader.MoveToNextAttribute())
                {
                    if (reader.LocalName == "base" && reader.NamespaceURI == Atom10FeedFormatter.XmlNs)
                    {
                        referencedCategories.BaseUri = FeedUtils.CombineXmlBase(referencedCategories.BaseUri, reader.Value);
                    }
                    else if (reader.LocalName == "lang" && reader.NamespaceURI == Atom10FeedFormatter.XmlNs)
                    {
                        referencedCategories.Language = reader.Value;
                    }
                    else if (reader.LocalName == App10Constants.Href && reader.NamespaceURI == string.Empty)
                    {
                        continue;
                    }
                    else
                    {
                        string ns   = reader.NamespaceURI;
                        string name = reader.LocalName;
                        if (FeedUtils.IsXmlns(name, ns) || FeedUtils.IsXmlSchemaType(name, ns))
                        {
                            continue;
                        }

                        string val = reader.Value;
                        if (!TryParseAttribute(name, ns, val, referencedCategories, version))
                        {
                            referencedCategories.AttributeExtensions.Add(new XmlQualifiedName(reader.LocalName, reader.NamespaceURI), reader.Value);
                        }
                    }
                }
            }

            reader.MoveToElement();
            bool isEmptyElement = reader.IsEmptyElement;

            reader.ReadStartElement();
            if (!isEmptyElement)
            {
                XmlBuffer           buffer    = null;
                XmlDictionaryWriter extWriter = null;
                try
                {
                    while (reader.IsStartElement())
                    {
                        if (!TryParseElement(reader, referencedCategories, version))
                        {
                            SyndicationFeedFormatter.CreateBufferIfRequiredAndWriteNode(ref buffer, ref extWriter, reader, maxExtensionSize);
                        }
                    }
                    LoadElementExtensions(buffer, extWriter, referencedCategories);
                }
                finally
                {
                    extWriter?.Close();
                }
                reader.ReadEndElement();
            }
        }
 private static void WriteXmlBase(XmlWriter writer, Uri baseUri)
 {
     writer.WriteAttributeString("xml", "base", Atom10FeedFormatter.XmlNs, FeedUtils.GetUriString(baseUri));
 }
 private static void WriteXmlBase(XmlWriter writer, Uri baseUri)
 {
     writer.WriteAttributeString("xml", "base", "http://www.w3.org/XML/1998/namespace", FeedUtils.GetUriString(baseUri));
 }
        private static void ReadInlineCategories(XmlReader reader, InlineCategoriesDocument inlineCategories, Uri baseUri, string version, 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, reader.Value);
                    }
                    else if (reader.LocalName == "lang" && reader.NamespaceURI == Atom10FeedFormatter.XmlNs)
                    {
                        inlineCategories.Language = reader.Value;
                    }
                    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 = reader.Value;
                    }
                    else
                    {
                        string ns   = reader.NamespaceURI;
                        string name = reader.LocalName;
                        if (FeedUtils.IsXmlns(name, ns) || FeedUtils.IsXmlSchemaType(name, ns))
                        {
                            continue;
                        }

                        string val = reader.Value;
                        if (!TryParseAttribute(name, ns, val, inlineCategories, version))
                        {
                            inlineCategories.AttributeExtensions.Add(new XmlQualifiedName(reader.LocalName, reader.NamespaceURI), reader.Value);
                        }
                    }
                }
            }
            SyndicationFeedFormatter.MoveToStartElement(reader);
            bool isEmptyElement = reader.IsEmptyElement;

            reader.ReadStartElement();
            if (!isEmptyElement)
            {
                XmlBuffer           buffer    = null;
                XmlDictionaryWriter extWriter = null;
                try
                {
                    while (reader.IsStartElement())
                    {
                        if (reader.IsStartElement(Atom10Constants.CategoryTag, Atom10Constants.Atom10Namespace))
                        {
                            SyndicationCategory category = CreateCategory(inlineCategories);
                            Atom10FeedFormatter.ReadCategory(reader, category, version, preserveAttributeExtensions: true, preserveElementExtensions: true, maxExtensionSize);
                            if (category.Scheme == null)
                            {
                                category.Scheme = inlineCategories.Scheme;
                            }
                            inlineCategories.Categories.Add(category);
                        }
                        else if (!TryParseElement(reader, inlineCategories, version))
                        {
                            SyndicationFeedFormatter.CreateBufferIfRequiredAndWriteNode(ref buffer, ref extWriter, reader, maxExtensionSize);
                        }
                    }
                    LoadElementExtensions(buffer, extWriter, inlineCategories);
                }
                finally
                {
                    extWriter?.Close();
                }
                reader.ReadEndElement();
            }
        }
        private void ReadDocument(XmlReader reader)
        {
            ServiceDocument document = this.CreateDocumentInstance();

            try
            {
                SyndicationFeedFormatter.MoveToStartElement(reader);
                bool isEmptyElement = reader.IsEmptyElement;
                if (reader.HasAttributes)
                {
                    while (reader.MoveToNextAttribute())
                    {
                        if ((reader.LocalName == "lang") && (reader.NamespaceURI == "http://www.w3.org/XML/1998/namespace"))
                        {
                            document.Language = reader.Value;
                        }
                        else
                        {
                            if ((reader.LocalName == "base") && (reader.NamespaceURI == "http://www.w3.org/XML/1998/namespace"))
                            {
                                document.BaseUri = new Uri(reader.Value, UriKind.RelativeOrAbsolute);
                                continue;
                            }
                            string namespaceURI = reader.NamespaceURI;
                            string localName    = reader.LocalName;
                            if (!FeedUtils.IsXmlns(localName, namespaceURI) && !FeedUtils.IsXmlSchemaType(localName, namespaceURI))
                            {
                                string str3 = reader.Value;
                                if (!ServiceDocumentFormatter.TryParseAttribute(localName, namespaceURI, str3, document, this.Version))
                                {
                                    if (this.preserveAttributeExtensions)
                                    {
                                        document.AttributeExtensions.Add(new XmlQualifiedName(reader.LocalName, reader.NamespaceURI), reader.Value);
                                        continue;
                                    }
                                    SyndicationFeedFormatter.TraceSyndicationElementIgnoredOnRead(reader);
                                }
                            }
                        }
                    }
                }
                XmlBuffer           buffer    = null;
                XmlDictionaryWriter extWriter = null;
                reader.ReadStartElement();
                if (!isEmptyElement)
                {
                    try
                    {
                        while (reader.IsStartElement())
                        {
                            if (reader.IsStartElement("workspace", "http://www.w3.org/2007/app"))
                            {
                                document.Workspaces.Add(this.ReadWorkspace(reader, document));
                            }
                            else if (!ServiceDocumentFormatter.TryParseElement(reader, document, this.Version))
                            {
                                if (this.preserveElementExtensions)
                                {
                                    SyndicationFeedFormatter.CreateBufferIfRequiredAndWriteNode(ref buffer, ref extWriter, reader, this.maxExtensionSize);
                                    continue;
                                }
                                SyndicationFeedFormatter.TraceSyndicationElementIgnoredOnRead(reader);
                                reader.Skip();
                            }
                        }
                        ServiceDocumentFormatter.LoadElementExtensions(buffer, extWriter, document);
                    }
                    finally
                    {
                        if (extWriter != null)
                        {
                            extWriter.Close();
                        }
                    }
                }
                reader.ReadEndElement();
            }
            catch (FormatException exception)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(FeedUtils.AddLineInfo(reader, "ErrorParsingDocument"), exception));
            }
            catch (ArgumentException exception2)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(FeedUtils.AddLineInfo(reader, "ErrorParsingDocument"), exception2));
            }
            this.SetDocument(document);
        }
示例#17
0
        private void ReadDocument(XmlReader reader)
        {
            try
            {
                SyndicationFeedFormatter.MoveToStartElement(reader);
                SetDocument(AtomPub10ServiceDocumentFormatter.ReadCategories(reader, null,
                                                                             delegate()
                {
                    return(this.CreateInlineCategoriesDocument());
                },

                                                                             delegate()
                {
                    return(this.CreateReferencedCategoriesDocument());
                },
                                                                             this.Version,
                                                                             _preserveElementExtensions,
                                                                             _preserveAttributeExtensions,
                                                                             _maxExtensionSize));
            }
            catch (FormatException e)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(FeedUtils.AddLineInfo(reader, SR.ErrorParsingDocument), e));
            }
            catch (ArgumentException e)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(FeedUtils.AddLineInfo(reader, SR.ErrorParsingDocument), e));
            }
        }
        private static void ReadReferencedCategories(XmlReader reader, ReferencedCategoriesDocument referencedCategories, Uri baseUri, Uri link, string version, bool preserveElementExtensions, bool preserveAttributeExtensions, int maxExtensionSize)
        {
            referencedCategories.BaseUri = baseUri;
            referencedCategories.Link    = link;
            if (reader.HasAttributes)
            {
                while (reader.MoveToNextAttribute())
                {
                    if ((reader.LocalName == "base") && (reader.NamespaceURI == "http://www.w3.org/XML/1998/namespace"))
                    {
                        referencedCategories.BaseUri = FeedUtils.CombineXmlBase(referencedCategories.BaseUri, reader.Value);
                    }
                    else
                    {
                        if ((reader.LocalName == "lang") && (reader.NamespaceURI == "http://www.w3.org/XML/1998/namespace"))
                        {
                            referencedCategories.Language = reader.Value;
                            continue;
                        }
                        if ((reader.LocalName != "href") || (reader.NamespaceURI != string.Empty))
                        {
                            string namespaceURI = reader.NamespaceURI;
                            string localName    = reader.LocalName;
                            if (!FeedUtils.IsXmlns(localName, namespaceURI) && !FeedUtils.IsXmlSchemaType(localName, namespaceURI))
                            {
                                string str3 = reader.Value;
                                if (!ServiceDocumentFormatter.TryParseAttribute(localName, namespaceURI, str3, referencedCategories, version))
                                {
                                    if (preserveAttributeExtensions)
                                    {
                                        referencedCategories.AttributeExtensions.Add(new XmlQualifiedName(reader.LocalName, reader.NamespaceURI), reader.Value);
                                        continue;
                                    }
                                    SyndicationFeedFormatter.TraceSyndicationElementIgnoredOnRead(reader);
                                }
                            }
                        }
                    }
                }
            }
            reader.MoveToElement();
            bool isEmptyElement = reader.IsEmptyElement;

            reader.ReadStartElement();
            if (!isEmptyElement)
            {
                XmlBuffer           buffer    = null;
                XmlDictionaryWriter extWriter = null;
                try
                {
                    while (reader.IsStartElement())
                    {
                        if (!ServiceDocumentFormatter.TryParseElement(reader, referencedCategories, version))
                        {
                            if (preserveElementExtensions)
                            {
                                SyndicationFeedFormatter.CreateBufferIfRequiredAndWriteNode(ref buffer, ref extWriter, reader, maxExtensionSize);
                            }
                            else
                            {
                                SyndicationFeedFormatter.TraceSyndicationElementIgnoredOnRead(reader);
                                reader.Skip();
                            }
                        }
                    }
                    ServiceDocumentFormatter.LoadElementExtensions(buffer, extWriter, referencedCategories);
                }
                finally
                {
                    if (extWriter != null)
                    {
                        extWriter.Close();
                    }
                }
                reader.ReadEndElement();
            }
        }
        private void ReadDocument(XmlReader reader)
        {
            CreateInlineCategoriesDelegate     inlineCategoriesFactory     = null;
            CreateReferencedCategoriesDelegate referencedCategoriesFactory = null;

            try
            {
                SyndicationFeedFormatter.MoveToStartElement(reader);
                if (inlineCategoriesFactory == null)
                {
                    inlineCategoriesFactory = () => this.CreateInlineCategoriesDocument();
                }
                if (referencedCategoriesFactory == null)
                {
                    referencedCategoriesFactory = () => this.CreateReferencedCategoriesDocument();
                }
                this.SetDocument(AtomPub10ServiceDocumentFormatter.ReadCategories(reader, null, inlineCategoriesFactory, referencedCategoriesFactory, this.Version, this.preserveElementExtensions, this.preserveAttributeExtensions, this.maxExtensionSize));
            }
            catch (FormatException exception)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(FeedUtils.AddLineInfo(reader, "ErrorParsingDocument"), exception));
            }
            catch (ArgumentException exception2)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(FeedUtils.AddLineInfo(reader, "ErrorParsingDocument"), exception2));
            }
        }
        private async Task <ResourceCollectionInfo> ReadCollection(XmlReaderWrapper reader, Workspace workspace)
        {
            ResourceCollectionInfo result = CreateCollection(workspace);

            result.BaseUri = workspace.BaseUri;
            if (reader.HasAttributes)
            {
                while (reader.MoveToNextAttribute())
                {
                    if (reader.LocalName == "base" && reader.NamespaceURI == Atom10FeedFormatter.XmlNs)
                    {
                        result.BaseUri = FeedUtils.CombineXmlBase(result.BaseUri, await reader.GetValueAsync());
                    }
                    else if (reader.LocalName == App10Constants.Href && reader.NamespaceURI == string.Empty)
                    {
                        result.Link = new Uri(await reader.GetValueAsync(), UriKind.RelativeOrAbsolute);
                    }
                    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, result, this.Version))
                        {
                            if (_preserveAttributeExtensions)
                            {
                                result.AttributeExtensions.Add(new XmlQualifiedName(reader.LocalName, reader.NamespaceURI), val);
                            }
                        }
                    }
                }
            }

            XmlBuffer           buffer    = null;
            XmlDictionaryWriter extWriter = null;

            reader.ReadStartElement();
            try
            {
                while (await reader.IsStartElementAsync())
                {
                    if (await reader.IsStartElementAsync(Atom10Constants.TitleTag, Atom10Constants.Atom10Namespace))
                    {
                        result.Title = await new Atom10FeedFormatter().ReadTextContentFromAsync(reader, "//app:service/app:workspace/app:collection/atom:title[@type]", _preserveAttributeExtensions);
                    }
                    else if (await reader.IsStartElementAsync(App10Constants.Categories, App10Constants.Namespace))
                    {
                        result.Categories.Add(await ReadCategories(reader,
                                                                   result.BaseUri,
                                                                   delegate()
                        {
                            return(CreateInlineCategories(result));
                        },

                                                                   delegate()
                        {
                            return(CreateReferencedCategories(result));
                        },
                                                                   this.Version,
                                                                   _preserveElementExtensions,
                                                                   _preserveAttributeExtensions,
                                                                   _maxExtensionSize));
                    }
                    else if (await reader.IsStartElementAsync(App10Constants.Accept, App10Constants.Namespace))
                    {
                        result.Accepts.Add(reader.ReadElementString());
                    }
                    else if (!TryParseElement(reader, result, this.Version))
                    {
                        if (_preserveElementExtensions)
                        {
                            if (buffer == null)
                            {
                                buffer    = new XmlBuffer(_maxExtensionSize);
                                extWriter = buffer.OpenSection(XmlDictionaryReaderQuotas.Max);
                                extWriter.WriteStartElement(Rss20Constants.ExtensionWrapperTag);
                            }

                            await XmlReaderWrapper.WriteNodeAsync(extWriter, reader, false);
                        }
                        else
                        {
                            reader.Skip();
                        }
                    }
                }

                LoadElementExtensions(buffer, extWriter, result);
            }
            finally
            {
                if (extWriter != null)
                {
                    extWriter.Close();
                }
            }

            reader.ReadEndElement();
            return(result);
        }
        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();
            }
        }
        private ResourceCollectionInfo ReadCollection(XmlReader reader, Workspace workspace)
        {
            CreateInlineCategoriesDelegate     inlineCategoriesFactory     = null;
            CreateReferencedCategoriesDelegate referencedCategoriesFactory = null;
            ResourceCollectionInfo             result = ServiceDocumentFormatter.CreateCollection(workspace);

            result.BaseUri = workspace.BaseUri;
            if (reader.HasAttributes)
            {
                while (reader.MoveToNextAttribute())
                {
                    if ((reader.LocalName == "base") && (reader.NamespaceURI == "http://www.w3.org/XML/1998/namespace"))
                    {
                        result.BaseUri = FeedUtils.CombineXmlBase(result.BaseUri, reader.Value);
                    }
                    else
                    {
                        if ((reader.LocalName == "href") && (reader.NamespaceURI == string.Empty))
                        {
                            result.Link = new Uri(reader.Value, UriKind.RelativeOrAbsolute);
                            continue;
                        }
                        string namespaceURI = reader.NamespaceURI;
                        string localName    = reader.LocalName;
                        if (!FeedUtils.IsXmlns(localName, namespaceURI) && !FeedUtils.IsXmlSchemaType(localName, namespaceURI))
                        {
                            string str3 = reader.Value;
                            if (!ServiceDocumentFormatter.TryParseAttribute(localName, namespaceURI, str3, result, this.Version))
                            {
                                if (this.preserveAttributeExtensions)
                                {
                                    result.AttributeExtensions.Add(new XmlQualifiedName(reader.LocalName, reader.NamespaceURI), reader.Value);
                                    continue;
                                }
                                SyndicationFeedFormatter.TraceSyndicationElementIgnoredOnRead(reader);
                            }
                        }
                    }
                }
            }
            XmlBuffer           buffer    = null;
            XmlDictionaryWriter extWriter = null;

            reader.ReadStartElement();
            try
            {
                while (reader.IsStartElement())
                {
                    if (reader.IsStartElement("title", "http://www.w3.org/2005/Atom"))
                    {
                        result.Title = Atom10FeedFormatter.ReadTextContentFrom(reader, "//app:service/app:workspace/app:collection/atom:title[@type]", this.preserveAttributeExtensions);
                    }
                    else
                    {
                        if (reader.IsStartElement("categories", "http://www.w3.org/2007/app"))
                        {
                            if (inlineCategoriesFactory == null)
                            {
                                inlineCategoriesFactory = () => ServiceDocumentFormatter.CreateInlineCategories(result);
                            }
                            if (referencedCategoriesFactory == null)
                            {
                                referencedCategoriesFactory = () => ServiceDocumentFormatter.CreateReferencedCategories(result);
                            }
                            result.Categories.Add(ReadCategories(reader, result.BaseUri, inlineCategoriesFactory, referencedCategoriesFactory, this.Version, this.preserveElementExtensions, this.preserveAttributeExtensions, this.maxExtensionSize));
                            continue;
                        }
                        if (reader.IsStartElement("accept", "http://www.w3.org/2007/app"))
                        {
                            result.Accepts.Add(reader.ReadElementString());
                        }
                        else if (!ServiceDocumentFormatter.TryParseElement(reader, result, this.Version))
                        {
                            if (this.preserveElementExtensions)
                            {
                                SyndicationFeedFormatter.CreateBufferIfRequiredAndWriteNode(ref buffer, ref extWriter, reader, this.maxExtensionSize);
                                continue;
                            }
                            SyndicationFeedFormatter.TraceSyndicationElementIgnoredOnRead(reader);
                            reader.Skip();
                        }
                    }
                }
                ServiceDocumentFormatter.LoadElementExtensions(buffer, extWriter, result);
            }
            finally
            {
                if (extWriter != null)
                {
                    extWriter.Close();
                }
            }
            reader.ReadEndElement();
            return(result);
        }
示例#23
0
 protected override void WriteContentsTo(XmlWriter writer)
 {
     writer.WriteAttributeString(Atom10Constants.SourceTag, string.Empty, FeedUtils.GetUriString(Url));
 }
示例#24
0
        private static async Task ReadReferencedCategoriesAsync(XmlReader reader, ReferencedCategoriesDocument referencedCategories, Uri baseUri, Uri link, string version, bool preserveElementExtensions, bool preserveAttributeExtensions, int maxExtensionSize)
        {
            referencedCategories.BaseUri = baseUri;
            referencedCategories.Link    = link;
            if (reader.HasAttributes)
            {
                while (reader.MoveToNextAttribute())
                {
                    if (reader.LocalName == "base" && reader.NamespaceURI == Atom10FeedFormatter.XmlNs)
                    {
                        referencedCategories.BaseUri = FeedUtils.CombineXmlBase(referencedCategories.BaseUri, await reader.GetValueAsync().ConfigureAwait(false));
                    }
                    else if (reader.LocalName == "lang" && reader.NamespaceURI == Atom10FeedFormatter.XmlNs)
                    {
                        referencedCategories.Language = await reader.GetValueAsync().ConfigureAwait(false);
                    }
                    else if (reader.LocalName == App10Constants.Href && reader.NamespaceURI == string.Empty)
                    {
                        continue;
                    }
                    else
                    {
                        string ns   = reader.NamespaceURI;
                        string name = reader.LocalName;
                        if (FeedUtils.IsXmlns(name, ns) || FeedUtils.IsXmlSchemaType(name, ns))
                        {
                            continue;
                        }

                        string val = await reader.GetValueAsync().ConfigureAwait(false);

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

            reader.MoveToElement();
            bool isEmptyElement = reader.IsEmptyElement;
            await reader.ReadStartElementAsync().ConfigureAwait(false);

            if (!isEmptyElement)
            {
                XmlBuffer           buffer    = null;
                XmlDictionaryWriter extWriter = null;
                try
                {
                    while (await reader.IsStartElementAsync().ConfigureAwait(false))
                    {
                        if (!TryParseElement(reader, referencedCategories, version))
                        {
                            if (preserveElementExtensions)
                            {
                                var tuple = await SyndicationFeedFormatter.CreateBufferIfRequiredAndWriteNodeAsync(buffer, extWriter, reader, maxExtensionSize).ConfigureAwait(false);

                                buffer    = tuple.Item1;
                                extWriter = tuple.Item2;
                            }
                        }
                    }

                    LoadElementExtensions(buffer, extWriter, referencedCategories);
                }
                finally
                {
                    if (extWriter != null)
                    {
                        extWriter.Close();
                    }
                }

                await reader.ReadEndElementAsync().ConfigureAwait(false);
            }
        }
        private async Task ReadDocumentAsync(XmlReaderWrapper reader)
        {
            ServiceDocument result = CreateDocumentInstance();

            try
            {
                await SyndicationFeedFormatter.MoveToStartElementAsync(reader);

                bool elementIsEmpty = reader.IsEmptyElement;
                if (reader.HasAttributes)
                {
                    while (reader.MoveToNextAttribute())
                    {
                        if (reader.LocalName == "lang" && reader.NamespaceURI == Atom10FeedFormatter.XmlNs)
                        {
                            result.Language = await reader.GetValueAsync();
                        }
                        else if (reader.LocalName == "base" && reader.NamespaceURI == Atom10FeedFormatter.XmlNs)
                        {
                            result.BaseUri = new Uri(await reader.GetValueAsync(), UriKind.RelativeOrAbsolute);
                        }
                        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, result, this.Version))
                            {
                                if (_preserveAttributeExtensions)
                                {
                                    result.AttributeExtensions.Add(new XmlQualifiedName(reader.LocalName, reader.NamespaceURI), val);
                                }
                            }
                        }
                    }
                }
                XmlBuffer           buffer    = null;
                XmlDictionaryWriter extWriter = null;

                await reader.ReadStartElementAsync();

                if (!elementIsEmpty)
                {
                    try
                    {
                        while (await reader.IsStartElementAsync())
                        {
                            if (await reader.IsStartElementAsync(App10Constants.Workspace, App10Constants.Namespace))
                            {
                                result.Workspaces.Add(ReadWorkspace(reader, result).Result);
                            }
                            else if (!TryParseElement(reader, result, this.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, result);
                    }
                    finally
                    {
                        if (extWriter != null)
                        {
                            extWriter.Close();
                        }
                    }
                }

                await reader.ReadEndElementAsync();
            }
            catch (FormatException e)
            {
                throw new XmlException(FeedUtils.AddLineInfo(reader, SR.ErrorParsingDocument), e);
            }
            catch (ArgumentException e)
            {
                new XmlException(FeedUtils.AddLineInfo(reader, SR.ErrorParsingDocument), e);
            }

            SetDocument(result);
        }
        private Workspace ReadWorkspace(XmlReader reader, ServiceDocument document)
        {
            Workspace workspace = ServiceDocumentFormatter.CreateWorkspace(document);

            workspace.BaseUri = document.BaseUri;
            if (reader.HasAttributes)
            {
                while (reader.MoveToNextAttribute())
                {
                    if ((reader.LocalName == "base") && (reader.NamespaceURI == "http://www.w3.org/XML/1998/namespace"))
                    {
                        workspace.BaseUri = FeedUtils.CombineXmlBase(workspace.BaseUri, reader.Value);
                    }
                    else
                    {
                        string namespaceURI = reader.NamespaceURI;
                        string localName    = reader.LocalName;
                        if (!FeedUtils.IsXmlns(localName, namespaceURI) && !FeedUtils.IsXmlSchemaType(localName, namespaceURI))
                        {
                            string str3 = reader.Value;
                            if (!ServiceDocumentFormatter.TryParseAttribute(localName, namespaceURI, str3, workspace, this.Version))
                            {
                                if (this.preserveAttributeExtensions)
                                {
                                    workspace.AttributeExtensions.Add(new XmlQualifiedName(reader.LocalName, reader.NamespaceURI), reader.Value);
                                    continue;
                                }
                                SyndicationFeedFormatter.TraceSyndicationElementIgnoredOnRead(reader);
                            }
                        }
                    }
                }
            }
            XmlBuffer           buffer    = null;
            XmlDictionaryWriter extWriter = null;

            reader.ReadStartElement();
            try
            {
                while (reader.IsStartElement())
                {
                    if (reader.IsStartElement("title", "http://www.w3.org/2005/Atom"))
                    {
                        workspace.Title = Atom10FeedFormatter.ReadTextContentFrom(reader, "//app:service/app:workspace/atom:title[@type]", this.preserveAttributeExtensions);
                    }
                    else
                    {
                        if (reader.IsStartElement("collection", "http://www.w3.org/2007/app"))
                        {
                            workspace.Collections.Add(this.ReadCollection(reader, workspace));
                            continue;
                        }
                        if (!ServiceDocumentFormatter.TryParseElement(reader, workspace, this.Version))
                        {
                            if (this.preserveElementExtensions)
                            {
                                SyndicationFeedFormatter.CreateBufferIfRequiredAndWriteNode(ref buffer, ref extWriter, reader, this.maxExtensionSize);
                                continue;
                            }
                            SyndicationFeedFormatter.TraceSyndicationElementIgnoredOnRead(reader);
                            reader.Skip();
                        }
                    }
                }
                ServiceDocumentFormatter.LoadElementExtensions(buffer, extWriter, workspace);
            }
            finally
            {
                if (extWriter != null)
                {
                    extWriter.Close();
                }
            }
            reader.ReadEndElement();
            return(workspace);
        }
        private async Task <Workspace> ReadWorkspace(XmlReaderWrapper reader, ServiceDocument document)
        {
            Workspace result = CreateWorkspace(document);

            result.BaseUri = document.BaseUri;
            if (reader.HasAttributes)
            {
                while (reader.MoveToNextAttribute())
                {
                    if (reader.LocalName == "base" && reader.NamespaceURI == Atom10FeedFormatter.XmlNs)
                    {
                        result.BaseUri = FeedUtils.CombineXmlBase(result.BaseUri, 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, result, this.Version))
                        {
                            if (_preserveAttributeExtensions)
                            {
                                result.AttributeExtensions.Add(new XmlQualifiedName(reader.LocalName, reader.NamespaceURI), val);
                            }
                        }
                    }
                }
            }

            XmlBuffer           buffer    = null;
            XmlDictionaryWriter extWriter = null;
            await reader.ReadStartElementAsync();

            try
            {
                while (await reader.IsStartElementAsync())
                {
                    if (await reader.IsStartElementAsync(Atom10Constants.TitleTag, Atom10Constants.Atom10Namespace))
                    {
                        result.Title = await new Atom10FeedFormatter().ReadTextContentFromAsync(reader, "//app:service/app:workspace/atom:title[@type]", _preserveAttributeExtensions);
                    }
                    else if (await reader.IsStartElementAsync(App10Constants.Collection, App10Constants.Namespace))
                    {
                        result.Collections.Add(ReadCollection(reader, result).Result);
                    }
                    else if (!TryParseElement(reader, result, this.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, result);
            }
            finally
            {
                if (extWriter != null)
                {
                    extWriter.Close();
                }
            }

            await reader.ReadEndElementAsync();

            return(result);
        }
 protected override void WriteContentsTo(XmlWriter writer)
 {
     writer.WriteAttributeString("src", string.Empty, FeedUtils.GetUriString(this.url));
 }