2021-09-07 05:15:45 +00:00
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Xml.Linq;
|
2022-06-05 18:44:51 +00:00
|
|
|
|
2021-09-07 05:15:45 +00:00
|
|
|
using NodaTime;
|
2022-06-05 18:44:51 +00:00
|
|
|
|
2022-09-06 05:53:22 +00:00
|
|
|
using static MfGames.Nitride.Feeds.Structure.XmlConstants;
|
2021-09-07 05:15:45 +00:00
|
|
|
|
2022-09-06 05:53:22 +00:00
|
|
|
namespace MfGames.Nitride.Feeds.Structure;
|
2022-06-05 18:44:51 +00:00
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// The type-safe structure for an entry in the Atom feed.
|
|
|
|
/// </summary>
|
|
|
|
[WithProperties]
|
|
|
|
public partial class AtomEntry
|
2021-09-07 05:15:45 +00:00
|
|
|
{
|
|
|
|
/// <summary>
|
2022-06-05 18:44:51 +00:00
|
|
|
/// Gets or sets the author for the feed.
|
2021-09-07 05:15:45 +00:00
|
|
|
/// </summary>
|
2022-06-05 18:44:51 +00:00
|
|
|
public AtomAuthor? Author { get; set; }
|
2021-09-07 05:15:45 +00:00
|
|
|
|
2022-06-05 18:44:51 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Gets or sets the categories associated with this entry.
|
|
|
|
/// </summary>
|
|
|
|
public IEnumerable<AtomCategory>? Categories { get; set; }
|
2021-09-07 05:15:45 +00:00
|
|
|
|
2022-06-05 18:44:51 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Gets or sets the content of the entry.
|
|
|
|
/// </summary>
|
|
|
|
public string? Content { get; set; }
|
2021-09-07 05:15:45 +00:00
|
|
|
|
2022-06-05 18:44:51 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Gets or sets the type of content (text, html) of the content.
|
|
|
|
/// </summary>
|
|
|
|
public string ContentType { get; set; } = "html";
|
2021-09-07 05:15:45 +00:00
|
|
|
|
2022-06-05 18:44:51 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Gets or sets the ID of the feed.
|
|
|
|
/// </summary>
|
|
|
|
public string? Id { get; set; }
|
2021-09-07 05:15:45 +00:00
|
|
|
|
2022-06-05 18:44:51 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Gets or sets the summary of the entry.
|
|
|
|
/// </summary>
|
|
|
|
public string? Summary { get; set; }
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Gets or sets the type of content (text, html) of the summary.
|
|
|
|
/// </summary>
|
|
|
|
public string SummaryType { get; set; } = "html";
|
2021-09-07 05:15:45 +00:00
|
|
|
|
2022-06-05 18:44:51 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Gets or sets the title of the Feed.
|
|
|
|
/// </summary>
|
|
|
|
public string? Title { get; set; }
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Gets or sets the timestamp that the feed was updated.
|
|
|
|
/// </summary>
|
|
|
|
public Instant? Updated { get; set; }
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Gets or sets the URL associated with this feed.
|
|
|
|
/// </summary>
|
|
|
|
public Uri? Url { get; set; }
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Creates an XML element out of the feed along with all items inside
|
|
|
|
/// the feed.
|
|
|
|
/// </summary>
|
|
|
|
/// <returns></returns>
|
|
|
|
public XElement? ToXElement()
|
|
|
|
{
|
|
|
|
var elem = new XElement(AtomNamespace + "entry");
|
|
|
|
|
|
|
|
AtomHelper.AddIfSet(elem, "title", this.Title);
|
|
|
|
|
|
|
|
if (this.Url != null)
|
|
|
|
{
|
|
|
|
elem.Add(
|
|
|
|
new XElement(
|
|
|
|
AtomNamespace + "link",
|
|
|
|
new XAttribute("rel", "alternate"),
|
|
|
|
new XAttribute("href", this.Url.ToString())));
|
|
|
|
}
|
|
|
|
|
|
|
|
AtomHelper.AddIfSet(elem, "updated", this.Updated?.ToString("g", null));
|
|
|
|
AtomHelper.AddIfSet(elem, "id", this.Id);
|
|
|
|
AtomHelper.AddIfSet(elem, this.Author?.ToXElement());
|
|
|
|
|
|
|
|
if (this.Categories != null)
|
|
|
|
{
|
|
|
|
foreach (AtomCategory? category in this.Categories)
|
2021-09-07 05:15:45 +00:00
|
|
|
{
|
2022-06-05 18:44:51 +00:00
|
|
|
elem.Add(category.ToXElement());
|
2021-09-07 05:15:45 +00:00
|
|
|
}
|
2022-06-05 18:44:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(this.Summary))
|
|
|
|
{
|
|
|
|
elem.Add(
|
|
|
|
new XElement(
|
|
|
|
AtomNamespace + "summary",
|
|
|
|
new XAttribute("type", this.SummaryType),
|
|
|
|
new XText(this.Summary)));
|
|
|
|
}
|
2021-09-07 05:15:45 +00:00
|
|
|
|
2022-06-05 18:44:51 +00:00
|
|
|
if (!string.IsNullOrWhiteSpace(this.Content))
|
|
|
|
{
|
|
|
|
elem.Add(
|
|
|
|
new XElement(
|
|
|
|
AtomNamespace + "content",
|
|
|
|
new XAttribute("type", this.ContentType),
|
|
|
|
new XText(this.Content)));
|
2021-09-07 05:15:45 +00:00
|
|
|
}
|
2022-06-05 18:44:51 +00:00
|
|
|
|
|
|
|
return elem;
|
2021-09-07 05:15:45 +00:00
|
|
|
}
|
|
|
|
}
|