/// <summary> /// Reads an atom:generator element in a feed. /// </summary> /// <param name="atomFeedMetadata">The feed metadata to augment.</param> /// <remarks> /// Pre-Condition: XmlNodeType.Element (atom:generator) - the atom:generator element to read. /// Post-Condition: Any - the node after the atom:generator element which was read. /// </remarks> private void ReadGeneratorElement(AtomFeedMetadata atomFeedMetadata) { this.AssertXmlCondition(XmlNodeType.Element); Debug.Assert( this.XmlReader.LocalName == AtomConstants.AtomGeneratorElementName && this.XmlReader.NamespaceURI == AtomConstants.AtomNamespace, "Only atom:generator elements can be read by this method."); this.VerifyNotPreviouslyDefined(atomFeedMetadata.Generator); AtomGeneratorMetadata generatorMetadata = new AtomGeneratorMetadata(); // Read the attributes. while (this.XmlReader.MoveToNextAttribute()) { if (this.XmlReader.NamespaceEquals(this.EmptyNamespace)) { switch (this.XmlReader.LocalName) { case AtomConstants.AtomGeneratorUriAttributeName: generatorMetadata.Uri = this.ProcessUriFromPayload(this.XmlReader.Value, this.XmlReader.XmlBaseUri); break; case AtomConstants.AtomGeneratorVersionAttributeName: generatorMetadata.Version = this.XmlReader.Value; break; default: // Ignore all other attributes. break; } } } // Read the value of the element as a string and store it as the name of the generator. this.XmlReader.MoveToElement(); if (this.XmlReader.IsEmptyElement) { // Move to the next node after this one. this.XmlReader.Skip(); } else { generatorMetadata.Name = this.XmlReader.ReadElementValue(); } atomFeedMetadata.Generator = generatorMetadata; }
private void ReadGeneratorElement(AtomFeedMetadata atomFeedMetadata) { this.VerifyNotPreviouslyDefined(atomFeedMetadata.Generator); AtomGeneratorMetadata metadata = new AtomGeneratorMetadata(); while (base.XmlReader.MoveToNextAttribute()) { string str; if (base.XmlReader.NamespaceEquals(this.EmptyNamespace) && ((str = base.XmlReader.LocalName) != null)) { if (!(str == "uri")) { if (str == "version") { goto Label_0076; } } else { metadata.Uri = base.ProcessUriFromPayload(base.XmlReader.Value, base.XmlReader.XmlBaseUri); } } continue; Label_0076: metadata.Version = base.XmlReader.Value; } base.XmlReader.MoveToElement(); if (base.XmlReader.IsEmptyElement) { base.XmlReader.Skip(); } else { metadata.Name = base.XmlReader.ReadElementValue(); } atomFeedMetadata.Generator = metadata; }
internal void WriteFeedMetadata(AtomFeedMetadata feedMetadata, ODataFeed feed, string updatedTime, out bool authorWritten) { DebugUtils.CheckNoExternalCallers(); Debug.Assert(feedMetadata != null, "Feed metadata must not be null!"); // <atom:id>text</atom:id> // NOTE: this is the Id of the feed. For a regular feed this is stored on the feed itself; // if used in the context of an <atom:source> element it is stored in metadata Debug.Assert(feed == null || !string.IsNullOrEmpty(feed.Id), "The feed Id should have been validated by now."); string id = feed == null ? feedMetadata.SourceId : feed.Id; this.WriteElementWithTextContent( AtomConstants.AtomNamespacePrefix, AtomConstants.AtomIdElementName, AtomConstants.AtomNamespace, id); // <atom:title>text</atom:title> // NOTE: write an empty element if no title is specified since the element is required this.WriteTextConstruct(AtomConstants.AtomNamespacePrefix, AtomConstants.AtomTitleElementName, AtomConstants.AtomNamespace, feedMetadata.Title); if (feedMetadata.Subtitle != null) { // <atom:subtitle>text</atom:subtitle> this.WriteTextConstruct(AtomConstants.AtomNamespacePrefix, AtomConstants.AtomSubtitleElementName, AtomConstants.AtomNamespace, feedMetadata.Subtitle); } // <atom:updated>date</atom:updated> // NOTE: the <updated> element is required and if not specified we use a single 'default/current' date/time for the whole payload. string updated = feedMetadata.Updated.HasValue ? ODataAtomConvert.ToAtomString(feedMetadata.Updated.Value) : updatedTime; this.WriteElementWithTextContent( AtomConstants.AtomNamespacePrefix, AtomConstants.AtomUpdatedElementName, AtomConstants.AtomNamespace, updated); AtomLinkMetadata selfLinkMetadata = feedMetadata.SelfLink; if (selfLinkMetadata != null) { AtomLinkMetadata mergedSelfLinkMetadata = ODataAtomWriterMetadataUtils.MergeLinkMetadata( selfLinkMetadata, AtomConstants.AtomSelfRelationAttributeValue, null /* href */, null /* title */, null /* media type */); this.WriteAtomLink(mergedSelfLinkMetadata, null /*etag*/); } IEnumerable <AtomLinkMetadata> links = feedMetadata.Links; if (links != null) { foreach (AtomLinkMetadata link in links) { // DeltaLink is written from ODataFeed, so it shouldn't be written again from AtomFeedMetadata. if (link.Relation != AtomConstants.AtomDeltaRelationAttributeValue) { // <atom:link>...</atom:link> this.WriteAtomLink(link, null /* etag */); } } } IEnumerable <AtomCategoryMetadata> categories = feedMetadata.Categories; if (categories != null) { foreach (AtomCategoryMetadata category in categories) { // <atom:category term="..." scheme="..." label="..."></atom:category> this.WriteCategory(category); } } Uri logo = feedMetadata.Logo; if (logo != null) { // <atom:logo>Uri</atom:logo> this.WriteElementWithTextContent( AtomConstants.AtomNamespacePrefix, AtomConstants.AtomLogoElementName, AtomConstants.AtomNamespace, this.UriToUrlAttributeValue(logo)); } if (feedMetadata.Rights != null) { // <atom:rights>rights</atom:rights> this.WriteTextConstruct( AtomConstants.AtomNamespacePrefix, AtomConstants.AtomRightsElementName, AtomConstants.AtomNamespace, feedMetadata.Rights); } IEnumerable <AtomPersonMetadata> contributors = feedMetadata.Contributors; if (contributors != null) { foreach (AtomPersonMetadata contributor in contributors) { // <atom:contributor>contributor data</atom:contributor> this.XmlWriter.WriteStartElement(AtomConstants.AtomNamespacePrefix, AtomConstants.AtomContributorElementName, AtomConstants.AtomNamespace); this.WritePersonMetadata(contributor); this.XmlWriter.WriteEndElement(); } } AtomGeneratorMetadata generator = feedMetadata.Generator; if (generator != null) { // <atom:generator uri="..." version="...">name</atom:generator> this.XmlWriter.WriteStartElement(AtomConstants.AtomNamespacePrefix, AtomConstants.AtomGeneratorElementName, AtomConstants.AtomNamespace); if (generator.Uri != null) { this.XmlWriter.WriteAttributeString(AtomConstants.AtomGeneratorUriAttributeName, this.UriToUrlAttributeValue(generator.Uri)); } if (!string.IsNullOrEmpty(generator.Version)) { this.XmlWriter.WriteAttributeString(AtomConstants.AtomGeneratorVersionAttributeName, generator.Version); } ODataAtomWriterUtils.WriteString(this.XmlWriter, generator.Name); this.XmlWriter.WriteEndElement(); } Uri icon = feedMetadata.Icon; if (icon != null) { // <atom:icon>Uri</atom:icon> this.WriteElementWithTextContent( AtomConstants.AtomNamespacePrefix, AtomConstants.AtomIconElementName, AtomConstants.AtomNamespace, this.UriToUrlAttributeValue(icon)); } IEnumerable <AtomPersonMetadata> authors = feedMetadata.Authors; authorWritten = false; if (authors != null) { foreach (AtomPersonMetadata author in authors) { // <atom:author>author data</atom:author> authorWritten = true; this.XmlWriter.WriteStartElement(AtomConstants.AtomNamespacePrefix, AtomConstants.AtomAuthorElementName, AtomConstants.AtomNamespace); this.WritePersonMetadata(author); this.XmlWriter.WriteEndElement(); } } }
internal void WriteFeedMetadata(AtomFeedMetadata feedMetadata, ODataFeed feed, string updatedTime, out bool authorWritten) { string textContent = (feed == null) ? feedMetadata.SourceId : feed.Id; base.WriteElementWithTextContent("", "id", "http://www.w3.org/2005/Atom", textContent); base.WriteTextConstruct("", "title", "http://www.w3.org/2005/Atom", feedMetadata.Title); if (feedMetadata.Subtitle != null) { base.WriteTextConstruct("", "subtitle", "http://www.w3.org/2005/Atom", feedMetadata.Subtitle); } string str2 = feedMetadata.Updated.HasValue ? ODataAtomConvert.ToAtomString(feedMetadata.Updated.Value) : updatedTime; base.WriteElementWithTextContent("", "updated", "http://www.w3.org/2005/Atom", str2); AtomLinkMetadata selfLink = feedMetadata.SelfLink; if (selfLink != null) { AtomLinkMetadata linkMetadata = ODataAtomWriterMetadataUtils.MergeLinkMetadata(selfLink, "self", null, null, null); base.WriteAtomLink(linkMetadata, null); } IEnumerable <AtomLinkMetadata> links = feedMetadata.Links; if (links != null) { foreach (AtomLinkMetadata metadata3 in links) { base.WriteAtomLink(metadata3, null); } } IEnumerable <AtomCategoryMetadata> categories = feedMetadata.Categories; if (categories != null) { foreach (AtomCategoryMetadata metadata4 in categories) { base.WriteCategory(metadata4); } } Uri logo = feedMetadata.Logo; if (logo != null) { base.WriteElementWithTextContent("", "logo", "http://www.w3.org/2005/Atom", base.UriToUrlAttributeValue(logo)); } if (feedMetadata.Rights != null) { base.WriteTextConstruct("", "rights", "http://www.w3.org/2005/Atom", feedMetadata.Rights); } IEnumerable <AtomPersonMetadata> contributors = feedMetadata.Contributors; if (contributors != null) { foreach (AtomPersonMetadata metadata5 in contributors) { base.XmlWriter.WriteStartElement("", "contributor", "http://www.w3.org/2005/Atom"); base.WritePersonMetadata(metadata5); base.XmlWriter.WriteEndElement(); } } AtomGeneratorMetadata generator = feedMetadata.Generator; if (generator != null) { base.XmlWriter.WriteStartElement("", "generator", "http://www.w3.org/2005/Atom"); if (generator.Uri != null) { base.XmlWriter.WriteAttributeString("uri", base.UriToUrlAttributeValue(generator.Uri)); } if (!string.IsNullOrEmpty(generator.Version)) { base.XmlWriter.WriteAttributeString("version", generator.Version); } ODataAtomWriterUtils.WriteString(base.XmlWriter, generator.Name); base.XmlWriter.WriteEndElement(); } Uri icon = feedMetadata.Icon; if (icon != null) { base.WriteElementWithTextContent("", "icon", "http://www.w3.org/2005/Atom", base.UriToUrlAttributeValue(icon)); } IEnumerable <AtomPersonMetadata> authors = feedMetadata.Authors; authorWritten = false; if (authors != null) { foreach (AtomPersonMetadata metadata7 in authors) { authorWritten = true; base.XmlWriter.WriteStartElement("", "author", "http://www.w3.org/2005/Atom"); base.WritePersonMetadata(metadata7); base.XmlWriter.WriteEndElement(); } } }