Пример #1
0
        public async Task WriteToAsync(XmlWriter writer, string outerElementName, string outerElementNamespace)
        {
            if (writer == null)
            {
                throw new ArgumentNullException(nameof(writer));
            }
            if (string.IsNullOrEmpty(outerElementName))
            {
                throw new ArgumentException(SR.OuterElementNameNotSpecified);
            }

            writer = XmlWriterWrapper.CreateFromWriter(writer);

            await writer.WriteStartElementAsync(outerElementName, outerElementNamespace);

            await writer.WriteAttributeStringAsync(Atom10Constants.TypeTag, string.Empty, this.Type);

            if (_attributeExtensions != null)
            {
                foreach (XmlQualifiedName key in _attributeExtensions.Keys)
                {
                    if (key.Name == Atom10Constants.TypeTag && key.Namespace == string.Empty)
                    {
                        continue;
                    }
                    string attrValue;
                    if (_attributeExtensions.TryGetValue(key, out attrValue))
                    {
                        await writer.WriteAttributeStringAsync(key.Name, key.Namespace, attrValue);
                    }
                }
            }
            WriteContentsTo(writer);
            await writer.WriteEndElementAsync();
        }
        Task WriteXml(XmlWriter writer)
        {
            if (writer == null)
            {
                throw new ArgumentNullException(nameof(writer));
            }

            if (this.Document == null)
            {
                throw new InvalidOperationException(SR.DocumentFormatterDoesNotHaveDocument);
            }

            return(WriteDocumentAsync(XmlWriterWrapper.CreateFromWriter(writer)));
        }
Пример #3
0
        public override async Task WriteToAsync(XmlWriter writer)
        {
            if (writer == null)
            {
                throw new ArgumentNullException(nameof(writer));
            }

            writer = XmlWriterWrapper.CreateFromWriter(writer);

            await writer.WriteStartElementAsync(Atom10Constants.EntryTag, Atom10Constants.Atom10Namespace);

            await WriteItemAsync(writer);

            await writer.WriteEndElementAsync();
        }
Пример #4
0
        internal async Task WriteAttributeExtensionsAsync(XmlWriter writer)
        {
            if (writer == null)
            {
                throw new ArgumentNullException(nameof(writer));
            }

            writer = XmlWriterWrapper.CreateFromWriter(writer);

            if (_attributeExtensions != null)
            {
                foreach (XmlQualifiedName qname in _attributeExtensions.Keys)
                {
                    string value = _attributeExtensions[qname];
                    await writer.WriteAttributeStringAsync(qname.Name, qname.Namespace, value);
                }
            }
        }
Пример #5
0
        //public Task<XmlReader> GetReader()
        //{
        //    return GetReaderAsync();
        //}

        public async Task WriteToAsync(XmlWriter writer)
        {
            if (writer == null)
            {
                throw new ArgumentNullException(nameof(writer));
            }
            if (_extensionDataWriter != null)
            {
                _extensionDataWriter.WriteToAsync(writer);
            }
            else
            {
                writer = XmlWriterWrapper.CreateFromWriter(writer);
                using (XmlReader reader = await GetReaderAsync())
                {
                    await writer.WriteNodeAsync(reader, false);
                }
            }
        }
        public override async Task WriteToAsync(XmlWriter writer)
        {
            if (writer == null)
            {
                throw new ArgumentNullException(nameof(writer));
            }

            if (this.Document == null)
            {
                throw new InvalidOperationException(SR.DocumentFormatterDoesNotHaveDocument);
            }

            writer = XmlWriterWrapper.CreateFromWriter(writer);

            await writer.WriteStartElementAsync(App10Constants.Prefix, App10Constants.Service, App10Constants.Namespace);

            await WriteDocumentAsync(writer);

            await writer.WriteEndElementAsync();
        }
        private static async Task WriteInlineCategoriesContentAsync(XmlWriter writer, InlineCategoriesDocument categories, string version)
        {
            writer = XmlWriterWrapper.CreateFromWriter(writer);
            if (!string.IsNullOrEmpty(categories.Scheme))
            {
                await writer.WriteAttributeStringAsync(Atom10Constants.SchemeTag, categories.Scheme);
            }
            // by default, categories are not fixed
            if (categories.IsFixed)
            {
                await writer.WriteAttributeStringAsync(App10Constants.Fixed, "yes");
            }

            await WriteAttributeExtensionsAsync(writer, categories, version);

            for (int i = 0; i < categories.Categories.Count; ++i)
            {
                await Atom10FeedFormatter.WriteCategoryAsync(writer, categories.Categories[i], version);
            }

            await WriteElementExtensionsAsync(writer, categories, version);
        }
        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);
            }
            else
            {
                WriteReferencedCategoriesContent(writer, (ReferencedCategoriesDocument)categories, version);
            }
        }
Пример #9
0
 public void WriteToAsync(XmlWriter writer)
 {
     if (_xmlSerializer != null)
     {
         Debug.Assert((_dataContractSerializer == null && _outerName == null && _outerNamespace == null), "Xml serializer cannot have outer name, ns");
         _xmlSerializer.Serialize(writer, _extensionData);
     }
     else
     {
         Debug.Assert(_xmlSerializer == null, "Xml serializer cannot be configured");
         writer = XmlWriterWrapper.CreateFromWriter(writer);
         if (_outerName != null)
         {
             writer.WriteStartElementAsync(_outerName, _outerNamespace);
             _dataContractSerializer.WriteObjectContent(writer, _extensionData);
             writer.WriteEndElementAsync();
         }
         else
         {
             _dataContractSerializer.WriteObject(writer, _extensionData);
         }
     }
 }