internal AtomFeedMetadata ReadAtomSourceInEntryContent() { AtomFeedMetadata atomFeedMetadata = AtomMetadataReaderUtils.CreateNewAtomFeedMetadata(); if (base.XmlReader.IsEmptyElement) { base.XmlReader.Read(); return(atomFeedMetadata); } base.XmlReader.Read(); while (base.XmlReader.NodeType != XmlNodeType.EndElement) { if (base.XmlReader.NodeType != XmlNodeType.Element) { base.XmlReader.Skip(); } else { if (base.XmlReader.NamespaceEquals(this.AtomNamespace)) { this.SourceMetadataDeserializer.ReadAtomElementAsFeedMetadata(atomFeedMetadata); continue; } base.XmlReader.Skip(); } } base.XmlReader.Read(); return(atomFeedMetadata); }
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(); }
internal void ReadAtomElementAsFeedMetadata(AtomFeedMetadata atomFeedMetadata) { switch (base.XmlReader.LocalName) { case "author": this.ReadAuthorElement(atomFeedMetadata); return; case "category": this.ReadCategoryElement(atomFeedMetadata); return; case "contributor": this.ReadContributorElement(atomFeedMetadata); return; case "generator": this.ReadGeneratorElement(atomFeedMetadata); return; case "icon": this.ReadIconElement(atomFeedMetadata); return; case "id": if (!this.InSourceElement) { base.XmlReader.Skip(); return; } this.ReadIdElementAsSourceId(atomFeedMetadata); return; case "link": this.ReadLinkElementIntoLinksCollection(atomFeedMetadata); return; case "logo": this.ReadLogoElement(atomFeedMetadata); return; case "rights": this.ReadRightsElement(atomFeedMetadata); return; case "subtitle": this.ReadSubtitleElement(atomFeedMetadata); return; case "title": this.ReadTitleElement(atomFeedMetadata); return; case "updated": this.ReadUpdatedElement(atomFeedMetadata); return; } base.XmlReader.Skip(); }
/// <summary> /// Reads an element in the ATOM namespace in feed or source content. /// </summary> /// <param name="atomFeedMetadata">The atom feed metadata object to store metadata details in.</param> /// <remarks> /// Pre-Condition: XmlNodeType.Element (atom:*) - the ATOM element to read. /// Post-Condition: Any - the node after the ATOM element which was read. /// /// If the the property InSourceElement is true (i.e., we're reading within source content), then the value /// of the atom:id element will be stored in the feed metadata as SourceId, otherwise it will be ignored. /// </remarks> internal void ReadAtomElementAsFeedMetadata(AtomFeedMetadata atomFeedMetadata) { DebugUtils.CheckNoExternalCallers(); this.AssertXmlCondition(XmlNodeType.Element); Debug.Assert(this.XmlReader.NamespaceURI == AtomConstants.AtomNamespace, "Only atom:* elements can be read by this method."); switch (this.XmlReader.LocalName) { case AtomConstants.AtomAuthorElementName: this.ReadAuthorElement(atomFeedMetadata); break; case AtomConstants.AtomCategoryElementName: this.ReadCategoryElement(atomFeedMetadata); break; case AtomConstants.AtomContributorElementName: this.ReadContributorElement(atomFeedMetadata); break; case AtomConstants.AtomGeneratorElementName: this.ReadGeneratorElement(atomFeedMetadata); break; case AtomConstants.AtomIconElementName: this.ReadIconElement(atomFeedMetadata); break; case AtomConstants.AtomIdElementName: // Only store the ID as ATOM metadata if we're within an atom:source element. if (this.InSourceElement) { this.ReadIdElementAsSourceId(atomFeedMetadata); } else { this.XmlReader.Skip(); } break; case AtomConstants.AtomLinkElementName: this.ReadLinkElementIntoLinksCollection(atomFeedMetadata); break; case AtomConstants.AtomLogoElementName: this.ReadLogoElement(atomFeedMetadata); break; case AtomConstants.AtomRightsElementName: this.ReadRightsElement(atomFeedMetadata); break; case AtomConstants.AtomSubtitleElementName: this.ReadSubtitleElement(atomFeedMetadata); break; case AtomConstants.AtomTitleElementName: this.ReadTitleElement(atomFeedMetadata); break; case AtomConstants.AtomUpdatedElementName: this.ReadUpdatedElement(atomFeedMetadata); break; default: // Not something we recognize, so just ignore it. this.XmlReader.Skip(); break; } }
internal static void AddContributorToFeedMetadata(AtomFeedMetadata feedMetadata, AtomPersonMetadata contributorMetadata) { if (object.ReferenceEquals(feedMetadata.Contributors, EmptyPersonsList)) { feedMetadata.Contributors = new ReadOnlyEnumerable<AtomPersonMetadata>(); } ReaderUtils.GetSourceListOfEnumerable<AtomPersonMetadata>(feedMetadata.Contributors, "Contributors").Add(contributorMetadata); }
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); }
internal static void AddLinkToFeedMetadata(AtomFeedMetadata feedMetadata, AtomLinkMetadata linkMetadata) { if (object.ReferenceEquals(feedMetadata.Links, EmptyLinksList)) { feedMetadata.Links = new ReadOnlyEnumerable<AtomLinkMetadata>(); } ReaderUtils.GetSourceListOfEnumerable<AtomLinkMetadata>(feedMetadata.Links, "Links").Add(linkMetadata); }
/// <summary> /// Reads an atom:contributor element in a feed. /// </summary> /// <param name="atomFeedMetadata">The feed metadata to augment.</param> /// <remarks> /// Pre-Condition: XmlNodeType.Element (atom:contributor) - the atom:contributor element to read. /// Post-Condition: Any - the node after the atom:contributor element which was read. /// </remarks> private void ReadContributorElement(AtomFeedMetadata atomFeedMetadata) { this.AssertXmlCondition(XmlNodeType.Element); Debug.Assert( this.XmlReader.LocalName == AtomConstants.AtomContributorElementName && this.XmlReader.NamespaceURI == AtomConstants.AtomNamespace, "Only atom:contributor elements can be read by this method."); atomFeedMetadata.AddContributor(this.ReadAtomPersonConstruct(null)); }
/// <summary> /// Reads an atom:id element in a source element. /// </summary> /// <param name="atomFeedMetadata">The feed metadata to augment.</param> /// <remarks> /// Pre-Condition: XmlNodeType.Element (atom:icon) - the atom:icon element to read. /// Post-Condition: Any - the node after the atom:icon element which was read. /// </remarks> private void ReadIdElementAsSourceId(AtomFeedMetadata atomFeedMetadata) { this.AssertXmlCondition(XmlNodeType.Element); Debug.Assert( this.XmlReader.LocalName == AtomConstants.AtomIdElementName && this.XmlReader.NamespaceURI == AtomConstants.AtomNamespace, "Only atom:id elements can be read by this method."); this.VerifyNotPreviouslyDefined(atomFeedMetadata.SourceId); atomFeedMetadata.SourceId = this.XmlReader.ReadElementValue(); }
/// <summary> /// Reads an atom:logo element in a feed. /// </summary> /// <param name="atomFeedMetadata">The feed metadata to augment.</param> /// <remarks> /// Pre-Condition: XmlNodeType.Element (atom:logo) - the atom:logo element to read. /// Post-Condition: Any - the node after the atom:logo element which was read. /// </remarks> private void ReadLogoElement(AtomFeedMetadata atomFeedMetadata) { this.AssertXmlCondition(XmlNodeType.Element); Debug.Assert( this.XmlReader.LocalName == AtomConstants.AtomLogoElementName && this.XmlReader.NamespaceURI == AtomConstants.AtomNamespace, "Only atom:logo elements can be read by this method."); this.VerifyNotPreviouslyDefined(atomFeedMetadata.Logo); atomFeedMetadata.Logo = this.ReadUriValuedElement(); }
/// <summary> /// Reads an atom:updated element in a feed. /// </summary> /// <param name="atomFeedMetadata">The feed metadata to augment.</param> /// <remarks> /// Pre-Condition: XmlNodeType.Element (atom:updated) - the atom:updated element to read. /// Post-Condition: Any - the node after the atom:updated element which was read. /// </remarks> private void ReadUpdatedElement(AtomFeedMetadata atomFeedMetadata) { this.AssertXmlCondition(XmlNodeType.Element); Debug.Assert( this.XmlReader.LocalName == AtomConstants.AtomUpdatedElementName && this.XmlReader.NamespaceURI == AtomConstants.AtomNamespace, "Only atom:updated elements can be read by this method."); this.VerifyNotPreviouslyDefined(atomFeedMetadata.Updated); atomFeedMetadata.Updated = this.ReadAtomDateConstruct(); }
internal void WriteFeedNextPageLink(ODataFeed feed) { Uri nextPageLink = feed.NextPageLink; if (nextPageLink != null) { AtomFeedMetadata annotation = feed.GetAnnotation <AtomFeedMetadata>(); AtomLinkMetadata linkMetadata = ODataAtomWriterMetadataUtils.MergeLinkMetadata((annotation == null) ? null : annotation.NextPageLink, "next", nextPageLink, null, null); this.atomFeedMetadataSerializer.WriteAtomLink(linkMetadata, null); } }
/// <summary> /// Reads an atom:author element in a feed. /// </summary> /// <param name="atomFeedMetadata">The feed metadata to augment.</param> /// <remarks> /// Pre-Condition: XmlNodeType.Element (atom:author) - the atom:author element to read. /// Post-Condition: Any - the node after the atom:author element which was read. /// </remarks> private void ReadAuthorElement(AtomFeedMetadata atomFeedMetadata) { this.AssertXmlCondition(XmlNodeType.Element); Debug.Assert( this.XmlReader.LocalName == AtomConstants.AtomAuthorElementName && this.XmlReader.NamespaceURI == AtomConstants.AtomNamespace, "Only atom:author elements can be read by this method."); AtomMetadataReaderUtils.AddAuthorToFeedMetadata( atomFeedMetadata, this.ReadAtomPersonConstruct(null)); }
public static AtomFeedMetadata Atom(this ODataFeed feed) { ExceptionUtils.CheckArgumentNotNull<ODataFeed>(feed, "feed"); AtomFeedMetadata annotation = feed.GetAnnotation<AtomFeedMetadata>(); if (annotation == null) { annotation = new AtomFeedMetadata(); feed.SetAnnotation<AtomFeedMetadata>(annotation); } return annotation; }
/// <summary> /// Reads an atom:link element into the Links collection of feed metadata (i.e., links that are not special to the OData protocol). /// </summary> /// <param name="atomFeedMetadata">The feed metadata to augment.</param> /// <remarks> /// Pre-Condition: XmlNodeType.Element (atom:link) - the atom:link element to read. /// Post-Condition: Any - the node after the atom:link element which was read. /// </remarks> private void ReadLinkElementIntoLinksCollection(AtomFeedMetadata atomFeedMetadata) { this.AssertXmlCondition(XmlNodeType.Element); Debug.Assert( this.XmlReader.LocalName == AtomConstants.AtomLinkElementName && this.XmlReader.NamespaceURI == AtomConstants.AtomNamespace, "Only atom:link elements can be read by this method."); // By sending nulls to ReadAtomLinkElementInFeed(), the method will read and store values for href and rel from the wire (inside of using parameter overrides). AtomLinkMetadata linkMetadata = this.ReadAtomLinkElementInFeed(null, null); atomFeedMetadata.AddLink(linkMetadata); }
public static AtomFeedMetadata Atom(this ODataFeed feed) { ExceptionUtils.CheckArgumentNotNull <ODataFeed>(feed, "feed"); AtomFeedMetadata annotation = feed.GetAnnotation <AtomFeedMetadata>(); if (annotation == null) { annotation = new AtomFeedMetadata(); feed.SetAnnotation <AtomFeedMetadata>(annotation); } return(annotation); }
/// <summary> /// Writes a feed link. /// </summary> /// <param name="feed">The feed that contains the link.</param> /// <param name="relation">Relation attribute of the link.</param> /// <param name="href">href attribute of the link.</param> /// <param name="getLinkMetadata">Function to get the AtomLinkMetadata for the feed link.</param> internal void WriteFeedLink(ODataFeed feed, string relation, Uri href, Func <AtomFeedMetadata, AtomLinkMetadata> getLinkMetadata) { DebugUtils.CheckNoExternalCallers(); AtomFeedMetadata feedMetadata = feed.GetAnnotation <AtomFeedMetadata>(); AtomLinkMetadata mergedLink = ODataAtomWriterMetadataUtils.MergeLinkMetadata( getLinkMetadata(feedMetadata), relation, href, null, /*title*/ null /*mediaType*/); this.atomFeedMetadataSerializer.WriteAtomLink(mergedLink, null); }
public static AtomFeedMetadata Atom(this ODataFeed feed) { ExceptionUtils.CheckArgumentNotNull(feed, "feed"); AtomFeedMetadata feedMetadata = feed.GetAnnotation<AtomFeedMetadata>(); if (feedMetadata == null) { feedMetadata = new AtomFeedMetadata(); feed.SetAnnotation(feedMetadata); } return feedMetadata; }
public static AtomFeedMetadata Atom(this ODataFeed feed) { ExceptionUtils.CheckArgumentNotNull(feed, "feed"); AtomFeedMetadata feedMetadata = feed.GetAnnotation <AtomFeedMetadata>(); if (feedMetadata == null) { feedMetadata = new AtomFeedMetadata(); feed.SetAnnotation(feedMetadata); } return(feedMetadata); }
/// <summary> /// Reads the atom:source element in the entry content. /// </summary> /// <returns>The information in the source element as <see cref="AtomFeedMetadata"/>.</returns> /// <remarks> /// Pre-Condition: XmlNodeType.Element (atom:source) - the atom:source element to read. /// Post-Condition: Any - the node after the atom:source which was read. /// </remarks> internal AtomFeedMetadata ReadAtomSourceInEntryContent() { DebugUtils.CheckNoExternalCallers(); this.AssertXmlCondition(XmlNodeType.Element); Debug.Assert( this.XmlReader.NamespaceURI == AtomConstants.AtomNamespace && this.XmlReader.LocalName == AtomConstants.AtomSourceElementName, "Only atom:source element can be read by this method."); AtomFeedMetadata atomFeedMetadata = AtomMetadataReaderUtils.CreateNewAtomFeedMetadata(); if (this.XmlReader.IsEmptyElement) { // Advance reader past this element. this.XmlReader.Read(); return(atomFeedMetadata); } // Read the start tag of the source element. this.XmlReader.Read(); while (this.XmlReader.NodeType != XmlNodeType.EndElement) { if (this.XmlReader.NodeType != XmlNodeType.Element) { Debug.Assert(this.XmlReader.NodeType != XmlNodeType.EndElement, "EndElement should have been handled already."); // Skip everything but elements, including insignificant nodes, text nodes and CDATA nodes. this.XmlReader.Skip(); continue; } if (this.XmlReader.NamespaceEquals(this.AtomNamespace)) { // Use a feed metadata deserializer to process this element and modify atomFeedMetadata appropriately. this.SourceMetadataDeserializer.ReadAtomElementAsFeedMetadata(atomFeedMetadata); } else { // Skip all elements not in the ATOM namespace. this.XmlReader.Skip(); } } // Advance the reader past the end tag of the source element. this.XmlReader.Read(); return(atomFeedMetadata); }
internal void WriteFeedMetadata(ODataFeed feed, string updatedTime, out bool authorWritten) { AtomFeedMetadata annotation = feed.GetAnnotation <AtomFeedMetadata>(); if (annotation == null) { base.WriteElementWithTextContent("", "id", "http://www.w3.org/2005/Atom", feed.Id); base.WriteEmptyElement("", "title", "http://www.w3.org/2005/Atom"); base.WriteElementWithTextContent("", "updated", "http://www.w3.org/2005/Atom", updatedTime); authorWritten = false; } else { this.atomFeedMetadataSerializer.WriteFeedMetadata(annotation, feed, updatedTime, out authorWritten); } }
/// <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; }
/// <summary> /// Write the given feed metadata in atom format /// </summary> /// <param name="feed">The feed for which to write the meadata or null if it is the metadata of an atom:source element.</param> /// <param name="updatedTime">Value for the atom:updated element.</param> /// <param name="authorWritten">Set to true if the author element was written, false otherwise.</param> internal void WriteFeedMetadata(ODataFeed feed, string updatedTime, out bool authorWritten) { DebugUtils.CheckNoExternalCallers(); Debug.Assert(feed != null, "feed != null"); Debug.Assert(!string.IsNullOrEmpty(updatedTime), "!string.IsNullOrEmpty(updatedTime)"); #if DEBUG DateTimeOffset tempDateTimeOffset; Debug.Assert(DateTimeOffset.TryParse(updatedTime, out tempDateTimeOffset), "DateTimeOffset.TryParse(updatedTime, out tempDateTimeOffset)"); #endif AtomFeedMetadata feedMetadata = feed.GetAnnotation <AtomFeedMetadata>(); if (feedMetadata == null) { // create the required metadata elements with default values. // <atom:id>idValue</atom:id> Debug.Assert(!string.IsNullOrEmpty(feed.Id), "The feed Id should have been validated by now."); this.WriteElementWithTextContent( AtomConstants.AtomNamespacePrefix, AtomConstants.AtomIdElementName, AtomConstants.AtomNamespace, feed.Id); // <atom:title></atom:title> this.WriteEmptyElement( AtomConstants.AtomNamespacePrefix, AtomConstants.AtomTitleElementName, AtomConstants.AtomNamespace); // <atom:updated>dateTimeOffset</atom:updated> this.WriteElementWithTextContent( AtomConstants.AtomNamespacePrefix, AtomConstants.AtomUpdatedElementName, AtomConstants.AtomNamespace, updatedTime); authorWritten = false; } else { this.atomFeedMetadataSerializer.WriteFeedMetadata(feedMetadata, feed, updatedTime, out authorWritten); } }
/// <summary> /// Writes the next page link for a feed. /// </summary> /// <param name="feed">The feed to write the next page link for.</param> internal void WriteFeedNextPageLink(ODataFeed feed) { DebugUtils.CheckNoExternalCallers(); Debug.Assert(feed != null, "feed != null"); Uri nextPageLink = feed.NextPageLink; if (nextPageLink != null) { // <atom:link rel="next" href="next-page-link" /> AtomFeedMetadata feedMetadata = feed.GetAnnotation <AtomFeedMetadata>(); AtomLinkMetadata mergedLink = ODataAtomWriterMetadataUtils.MergeLinkMetadata( feedMetadata == null ? null : feedMetadata.NextPageLink, AtomConstants.AtomNextRelationAttributeValue, nextPageLink, null, /*title*/ null /*mediaType*/); this.atomFeedMetadataSerializer.WriteAtomLink(mergedLink, null); } }
/// <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(); }
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) { 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(); } } }
private void ReadTitleElement(AtomFeedMetadata atomFeedMetadata) { this.VerifyNotPreviouslyDefined(atomFeedMetadata.Title); atomFeedMetadata.Title = base.ReadAtomTextConstruct(); }
private void ReadUpdatedElement(AtomFeedMetadata atomFeedMetadata) { this.VerifyNotPreviouslyDefined(atomFeedMetadata.Updated); atomFeedMetadata.Updated = base.ReadAtomDateConstruct(); }
private void ReadRightsElement(AtomFeedMetadata atomFeedMetadata) { this.VerifyNotPreviouslyDefined(atomFeedMetadata.Rights); atomFeedMetadata.Rights = base.ReadAtomTextConstruct(); }
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) { // <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(); } } }
private void ReadIdElementAsSourceId(AtomFeedMetadata atomFeedMetadata) { this.VerifyNotPreviouslyDefined(atomFeedMetadata.SourceId); atomFeedMetadata.SourceId = base.XmlReader.ReadElementValue(); }
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(); } } }
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(); } } }
/// <summary> /// Reads an atom:contributor element in a feed. /// </summary> /// <param name="atomFeedMetadata">The feed metadata to augment.</param> /// <remarks> /// Pre-Condition: XmlNodeType.Element (atom:contributor) - the atom:contributor element to read. /// Post-Condition: Any - the node after the atom:contributor element which was read. /// </remarks> private void ReadContributorElement(AtomFeedMetadata atomFeedMetadata) { this.AssertXmlCondition(XmlNodeType.Element); Debug.Assert( this.XmlReader.LocalName == AtomConstants.AtomContributorElementName && this.XmlReader.NamespaceURI == AtomConstants.AtomNamespace, "Only atom:contributor elements can be read by this method."); AtomMetadataReaderUtils.AddContributorToFeedMetadata( atomFeedMetadata, this.ReadAtomPersonConstruct(null)); }
/// <summary> /// Reads an atom:link element into the Links collection of feed metadata (i.e., links that are not special to the OData protocol). /// </summary> /// <param name="atomFeedMetadata">The feed metadata to augment.</param> /// <remarks> /// Pre-Condition: XmlNodeType.Element (atom:link) - the atom:link element to read. /// Post-Condition: Any - the node after the atom:link element which was read. /// </remarks> private void ReadLinkElementIntoLinksCollection(AtomFeedMetadata atomFeedMetadata) { this.AssertXmlCondition(XmlNodeType.Element); Debug.Assert( this.XmlReader.LocalName == AtomConstants.AtomLinkElementName && this.XmlReader.NamespaceURI == AtomConstants.AtomNamespace, "Only atom:link elements can be read by this method."); // By sending nulls to ReadAtomLinkElementInFeed(), the method will read and store values for href and rel from the wire (inside of using parameter overrides). AtomLinkMetadata linkMetadata = this.ReadAtomLinkElementInFeed(null, null); AtomMetadataReaderUtils.AddLinkToFeedMetadata(atomFeedMetadata, linkMetadata); }
/// <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 void ReadLogoElement(AtomFeedMetadata atomFeedMetadata) { this.VerifyNotPreviouslyDefined(atomFeedMetadata.Logo); atomFeedMetadata.Logo = this.ReadUriValuedElement(); }
private void ReadIconElement(AtomFeedMetadata atomFeedMetadata) { this.VerifyNotPreviouslyDefined(atomFeedMetadata.Icon); atomFeedMetadata.Icon = this.ReadUriValuedElement(); }
private void ReadContributorElement(AtomFeedMetadata atomFeedMetadata) { AtomMetadataReaderUtils.AddContributorToFeedMetadata(atomFeedMetadata, base.ReadAtomPersonConstruct(null)); }
private void ReadLinkElementIntoLinksCollection(AtomFeedMetadata atomFeedMetadata) { AtomLinkMetadata linkMetadata = this.ReadAtomLinkElementInFeed(null, null); AtomMetadataReaderUtils.AddLinkToFeedMetadata(atomFeedMetadata, linkMetadata); }
/// <summary> /// Adds a new link to feed metadata. /// </summary> /// <param name="feedMetadata">The feed metadata to add the link to.</param> /// <param name="linkMetadata">The link metadata to add.</param> internal static void AddLinkToFeedMetadata(AtomFeedMetadata feedMetadata, AtomLinkMetadata linkMetadata) { DebugUtils.CheckNoExternalCallers(); Debug.Assert(feedMetadata != null, "feedMetadata != null"); Debug.Assert(linkMetadata != null, "linkMetadata != null"); if (object.ReferenceEquals(feedMetadata.Links, EmptyLinksList)) { feedMetadata.Links = new ReadOnlyEnumerable<AtomLinkMetadata>(); } ReaderUtils.GetSourceListOfEnumerable(feedMetadata.Links, "Links").Add(linkMetadata); }
/// <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); }
/// <summary> /// Adds a new contributor to feed metadata. /// </summary> /// <param name="feedMetadata">The feed metadata to add the contributor to.</param> /// <param name="contributorMetadata">The author metadata to add.</param> internal static void AddContributorToFeedMetadata(AtomFeedMetadata feedMetadata, AtomPersonMetadata contributorMetadata) { DebugUtils.CheckNoExternalCallers(); Debug.Assert(feedMetadata != null, "feedMetadata != null"); Debug.Assert(contributorMetadata != null, "contributorMetadata != null"); if (object.ReferenceEquals(feedMetadata.Contributors, EmptyPersonsList)) { feedMetadata.Contributors = new ReadOnlyEnumerable<AtomPersonMetadata>(); } ReaderUtils.GetSourceListOfEnumerable(feedMetadata.Contributors, "Contributors").Add(contributorMetadata); }
internal void WriteEntryMetadata(AtomEntryMetadata entryMetadata, AtomEntryMetadata epmEntryMetadata, string updatedTime) { DebugUtils.CheckNoExternalCallers(); Debug.Assert(!string.IsNullOrEmpty(updatedTime), "!string.IsNullOrEmpty(updatedTime)"); #if DEBUG DateTimeOffset tempDateTimeOffset; Debug.Assert(DateTimeOffset.TryParse(updatedTime, out tempDateTimeOffset), "DateTimeOffset.TryParse(updatedTime, out tempDateTimeOffset)"); #endif // TODO: implement the rule around authors (an entry has to have an author directly or in the <entry:source> unless the feed has an author). // currently we make all entries have an author. AtomEntryMetadata mergedEntryMetadata = ODataAtomWriterMetadataEpmMergeUtils.MergeCustomAndEpmEntryMetadata(entryMetadata, epmEntryMetadata, this.MessageWriterSettings.WriterBehavior); if (mergedEntryMetadata == null) { // write all required metadata elements with default content // <atom:title></atom:title> this.WriteEmptyElement( AtomConstants.AtomNamespacePrefix, AtomConstants.AtomTitleElementName, AtomConstants.AtomNamespace); // <atom:updated>dateTimeOffset</atom:updated> // NOTE: the <updated> element is required and if not specified we use a single 'default/current' date/time for the whole payload. this.WriteElementWithTextContent( AtomConstants.AtomNamespacePrefix, AtomConstants.AtomUpdatedElementName, AtomConstants.AtomNamespace, updatedTime); this.WriteEmptyAuthor(); } else { // <atom:title>text</atom:title> // NOTE: writes an empty element even if no title was specified since the title is required this.WriteTextConstruct(AtomConstants.AtomNamespacePrefix, AtomConstants.AtomTitleElementName, AtomConstants.AtomNamespace, mergedEntryMetadata.Title); AtomTextConstruct summary = mergedEntryMetadata.Summary; if (summary != null) { // <atom:summary>text</atom:summary> this.WriteTextConstruct(AtomConstants.AtomNamespacePrefix, AtomConstants.AtomSummaryElementName, AtomConstants.AtomNamespace, summary); } string published = this.UseClientFormatBehavior ? mergedEntryMetadata.PublishedString : mergedEntryMetadata.Published.HasValue ? ODataAtomConvert.ToAtomString(mergedEntryMetadata.Published.Value) : null; if (published != null) { // <atom:published>dateTimeOffset</atom:published> this.WriteElementWithTextContent( AtomConstants.AtomNamespacePrefix, AtomConstants.AtomPublishedElementName, AtomConstants.AtomNamespace, published); } // <atom:updated>date</atom:updated> string updated = this.UseClientFormatBehavior ? mergedEntryMetadata.UpdatedString : mergedEntryMetadata.Updated.HasValue ? ODataAtomConvert.ToAtomString(mergedEntryMetadata.Updated.Value) : null; // NOTE: the <updated> element is required and if not specified we use a single 'default/current' date/time for the whole payload. updated = updated ?? updatedTime; this.WriteElementWithTextContent( AtomConstants.AtomNamespacePrefix, AtomConstants.AtomUpdatedElementName, AtomConstants.AtomNamespace, updated); bool wroteAuthor = false; IEnumerable <AtomPersonMetadata> authors = mergedEntryMetadata.Authors; if (authors != null) { foreach (AtomPersonMetadata author in authors) { if (author == null) { throw new ODataException(ODataErrorStrings.ODataAtomWriterMetadataUtils_AuthorMetadataMustNotContainNull); } // <atom:author>author data</atom:author> this.XmlWriter.WriteStartElement(AtomConstants.AtomNamespacePrefix, AtomConstants.AtomAuthorElementName, AtomConstants.AtomNamespace); this.WritePersonMetadata(author); this.XmlWriter.WriteEndElement(); wroteAuthor = true; } } if (!wroteAuthor) { // write empty authors since they are required this.WriteEmptyAuthor(); } IEnumerable <AtomPersonMetadata> contributors = mergedEntryMetadata.Contributors; if (contributors != null) { foreach (AtomPersonMetadata contributor in contributors) { if (contributor == null) { throw new ODataException(ODataErrorStrings.ODataAtomWriterMetadataUtils_ContributorMetadataMustNotContainNull); } // <atom:contributor>contributor data</atom:contributor> this.XmlWriter.WriteStartElement(AtomConstants.AtomNamespacePrefix, AtomConstants.AtomContributorElementName, AtomConstants.AtomNamespace); this.WritePersonMetadata(contributor); this.XmlWriter.WriteEndElement(); } } IEnumerable <AtomLinkMetadata> links = mergedEntryMetadata.Links; if (links != null) { foreach (AtomLinkMetadata link in links) { if (link == null) { throw new ODataException(ODataErrorStrings.ODataAtomWriterMetadataUtils_LinkMetadataMustNotContainNull); } // <atom:link>...</atom:link> this.WriteAtomLink(link, null /*edit-link-etag*/); } } IEnumerable <AtomCategoryMetadata> categories = mergedEntryMetadata.Categories; if (categories != null) { foreach (AtomCategoryMetadata category in categories) { if (category == null) { throw new ODataException(ODataErrorStrings.ODataAtomWriterMetadataUtils_CategoryMetadataMustNotContainNull); } // <atom:category term="..." scheme="..." label="..."></atom:category> this.WriteCategory(category); } } if (mergedEntryMetadata.Rights != null) { // <atom:rights>rights</atom:rights> this.WriteTextConstruct( AtomConstants.AtomNamespacePrefix, AtomConstants.AtomRightsElementName, AtomConstants.AtomNamespace, mergedEntryMetadata.Rights); } AtomFeedMetadata source = mergedEntryMetadata.Source; if (source != null) { // <atom:source> this.XmlWriter.WriteStartElement(AtomConstants.AtomNamespacePrefix, AtomConstants.AtomSourceElementName, AtomConstants.AtomNamespace); bool authorWritten; this.SourceMetadataSerializer.WriteFeedMetadata(source, null /* feed */, updatedTime, out authorWritten); // </atom:source> this.XmlWriter.WriteEndElement(); } } }
private void WriteFeedElements(IExpandedResult expanded, IEnumerator elements, ResourceType expectedType, string title, Uri relativeUri, Uri absoluteUri, bool hasMoved, bool topLevel) { ODataFeed feed = new ODataFeed { Id = absoluteUri.AbsoluteUri }; AtomFeedMetadata annotation = new AtomFeedMetadata(); feed.SetAnnotation<AtomFeedMetadata>(annotation); AtomTextConstruct construct = new AtomTextConstruct { Text = title }; annotation.Title = construct; AtomLinkMetadata metadata2 = new AtomLinkMetadata { Href = relativeUri, Title = title }; annotation.SelfLink = metadata2; bool flag = false; if (topLevel && (base.RequestDescription.CountOption == RequestQueryCountOption.Inline)) { flag = this.contentFormat == ODataFormat.VerboseJson; if (!flag) { feed.Count = new long?(base.RequestDescription.CountValue); } } this.odataWriter.WriteStart(feed); try { object lastObject = null; IExpandedResult skipTokenExpandedResult = null; while (hasMoved) { object current = elements.Current; IExpandedResult skipToken = base.GetSkipToken(expanded); if (current != null) { IExpandedResult result3 = current as IExpandedResult; if (result3 != null) { expanded = result3; current = Serializer.GetExpandedElement(expanded); skipToken = base.GetSkipToken(expanded); } this.WriteEntry(expanded, current, true, expectedType); } hasMoved = elements.MoveNext(); lastObject = current; skipTokenExpandedResult = skipToken; } if (flag) { feed.Count = new long?(base.RequestDescription.CountValue); } if (base.NeedNextPageLink(elements)) { feed.NextPageLink = base.GetNextLinkUri(lastObject, skipTokenExpandedResult, absoluteUri); } } finally { if (!topLevel) { WebUtil.Dispose(elements); } } this.odataWriter.WriteEnd(); }