/// <summary> /// Extracts syndication feed items. /// </summary> /// <param name="localization">The context <see cref="Localization"/>.</param> /// <returns>A single syndication feed item containing information extracted from this <see cref="Teaser"/>.</returns> public IEnumerable<SyndicationItem> ExtractSyndicationFeedItems(Localization localization) { Link link = Link; if (link == null && Media != null) { // If the Teaser doesn't have a Link, but does have Media, create a Link from its Media. link = new Link { Url = Media.Url }; } return new[] { CreateSyndicationItem(Headline, Text, link, Date, localization) }; }
/// <summary> /// Extracts syndication feed items. /// </summary> /// <param name="localization">The context <see cref="Localization"/>.</param> /// <returns>A single syndication feed item containing information extracted from this <see cref="Teaser"/>.</returns> public IEnumerable<SyndicationItem> ExtractSyndicationFeedItems(Localization localization) { Link downloadLink = new Link {Url = Url}; return new[] { CreateSyndicationItem(FileName, Description, downloadLink, null, localization) }; }
/// <summary> /// Creates a syndication item link from a given <see cref="Link"/> instance. /// </summary> /// <param name="link">The <see cref="Link"/> instance.</param> /// <param name="localization">The context <see cref="Localization"/>.</param> /// <returns>The syndication item link or <c>null</c> if <paramref name="link"/> is <c>null</c> or an empty link.</returns> protected SyndicationLink CreateSyndicationLink(Link link, Localization localization) { if (link == null || string.IsNullOrEmpty(link.Url)) { return null; } string absoluteUrl = SiteConfiguration.MakeFullUrl(link.Url, localization); return new SyndicationLink(new Uri(absoluteUrl)); }
/// <summary> /// Creates a syndication feed item based on essential data. /// </summary> /// <param name="title">The title.</param> /// <param name="summary">The summary. Can be a string or a <see cref="RichText"/> instance.</param> /// <param name="link">The link.</param> /// <param name="publishDate">The date/time this item was published/created. If <c>null</c>, publish date is not included in the feed.</param> /// <param name="localization">The context <see cref="Localization"/>.</param> /// <returns>The syndication feed item.</returns> protected SyndicationItem CreateSyndicationItem(string title, object summary, Link link, DateTime? publishDate, Localization localization) { SyndicationItem result = new SyndicationItem { Title = new TextSyndicationContent(title), }; if (summary != null) { TextSyndicationContentKind textKind = (summary is RichText) ? TextSyndicationContentKind.Html : TextSyndicationContentKind.Plaintext; result.Summary = new TextSyndicationContent(summary.ToString(), textKind); } SyndicationLink syndicationLink = CreateSyndicationLink(link, localization); if (syndicationLink != null) { result.Links.Add(syndicationLink); } if (publishDate.HasValue) { result.PublishDate = publishDate.Value; } return result; }