本文整理汇总了C#中IPublishable.OnServing方法的典型用法代码示例。如果您正苦于以下问题:C# IPublishable.OnServing方法的具体用法?C# IPublishable.OnServing怎么用?C# IPublishable.OnServing使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IPublishable
的用法示例。
在下文中一共展示了IPublishable.OnServing方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WriteRssItem
/// <summary>
/// Writes the RSS channel item element information to the specified <see cref="XmlWriter"/> using the supplied <see cref="Page"/>.
/// </summary>
/// <param name="writer">
/// The <see cref="XmlWriter"/> to write channel item element information to.
/// </param>
/// <param name="publishable">
/// The <see cref="IPublishable"/> used to generate channel item content.
/// </param>
private static void WriteRssItem(XmlWriter writer, IPublishable publishable)
{
// ------------------------------------------------------------
// Cast IPublishable as Post to support comments/trackback
// ------------------------------------------------------------
var post = publishable as Post;
var comment = publishable as Comment;
// ------------------------------------------------------------
// Raise serving event
// ------------------------------------------------------------
var arg = new ServingEventArgs(publishable.Content, ServingLocation.Feed);
publishable.OnServing(arg);
if (arg.Cancel)
{
return;
}
// ------------------------------------------------------------
// Modify post content to make references absolute
// ------------------------------------------------------------
var content = Utils.ConvertPublishablePathsToAbsolute(arg.Body, publishable);
if (comment != null)
{
content = content.Replace(Environment.NewLine, "<br />");
}
writer.WriteStartElement("item");
// ------------------------------------------------------------
// Write required channel item elements
// ------------------------------------------------------------
if (comment != null)
{
writer.WriteElementString("title", publishable.Author + " on " + comment.Parent.Title);
}
else
{
writer.WriteElementString("title", publishable.Title);
}
writer.WriteElementString("description", content);
writer.WriteElementString("link", publishable.AbsoluteLink.ToString());
// ------------------------------------------------------------
// Write enclosure tag for podcasting support
// ------------------------------------------------------------
if (BlogSettings.Instance.EnableEnclosures)
{
var encloser = GetEnclosure(content, publishable);
if (!string.IsNullOrEmpty(encloser))
{
writer.WriteRaw(encloser);
}
}
// ------------------------------------------------------------
// Write optional channel item elements
// ------------------------------------------------------------
if (!string.IsNullOrEmpty(BlogSettings.Instance.FeedAuthor))
{
writer.WriteElementString("author", BlogSettings.Instance.FeedAuthor);
}
if (post != null)
{
writer.WriteElementString(
"comments", String.Concat(publishable.AbsoluteLink.ToString(),
BlogSettings.Instance.ModerationType == BlogSettings.Moderation.Disqus ? "#disqus_thread" : "#comment"));
}
writer.WriteElementString("guid", GetPermaLink(publishable).ToString());
writer.WriteElementString("pubDate", ToRfc822DateTime(publishable.DateCreated));
// ------------------------------------------------------------
// Write channel item category elements
// ------------------------------------------------------------
if (publishable.Categories != null)
{
foreach (var category in publishable.Categories)
{
writer.WriteElementString("category", category.Title);
}
}
// ------------------------------------------------------------
// Write Dublin Core syndication extension elements
// ------------------------------------------------------------
if (!String.IsNullOrEmpty(publishable.Author))
{
writer.WriteElementString("dc", "publisher", "http://purl.org/dc/elements/1.1/", publishable.Author);
//.........这里部分代码省略.........
示例2: WriteAtomEntry
/// <summary>
/// Writes the Atom feed entry element information to the specified <see cref="XmlWriter"/> using the supplied <see cref="Page"/>.
/// </summary>
/// <param name="writer">
/// The <see cref="XmlWriter"/> to write feed entry element information to.
/// </param>
/// <param name="publishable">
/// The <see cref="IPublishable"/> used to generate feed entry content.
/// </param>
private static void WriteAtomEntry(XmlWriter writer, IPublishable publishable)
{
var post = publishable as Post;
// var comment = publishable as Comment;
// ------------------------------------------------------------
// Raise serving event
// ------------------------------------------------------------
var arg = new ServingEventArgs(publishable.Content, ServingLocation.Feed);
publishable.OnServing(arg);
if (arg.Cancel)
{
return;
}
// ------------------------------------------------------------
// Modify publishable content to make references absolute
// ------------------------------------------------------------
var content = Utils.ConvertPublishablePathsToAbsolute(arg.Body, publishable);
writer.WriteStartElement("entry");
// ------------------------------------------------------------
// Write required entry elements
// ------------------------------------------------------------
writer.WriteElementString("id", publishable.AbsoluteLink.ToString());
writer.WriteElementString("title", publishable.Title);
writer.WriteElementString("updated", ToW3CDateTime(publishable.DateCreated.ToUniversalTime()));
// ------------------------------------------------------------
// Write recommended entry elements
// ------------------------------------------------------------
writer.WriteStartElement("link");
writer.WriteAttributeString("rel", "self");
writer.WriteAttributeString("href", GetPermaLink(publishable).ToString());
writer.WriteEndElement();
writer.WriteStartElement("link");
writer.WriteAttributeString("href", publishable.AbsoluteLink.ToString());
writer.WriteEndElement();
writer.WriteStartElement("author");
writer.WriteElementString("name", publishable.Author);
writer.WriteEndElement();
writer.WriteStartElement("summary");
writer.WriteAttributeString("type", "html");
writer.WriteString(content);
writer.WriteEndElement();
// ------------------------------------------------------------
// Write optional entry elements
// ------------------------------------------------------------
writer.WriteElementString("published", ToW3CDateTime(publishable.DateCreated.ToUniversalTime()));
writer.WriteStartElement("link");
writer.WriteAttributeString("rel", "related");
writer.WriteAttributeString("href", String.Concat(publishable.AbsoluteLink.ToString(),
BlogSettings.Instance.ModerationType == BlogSettings.Moderation.Disqus ? "#disqus_thread" : "#comment"));
writer.WriteEndElement();
// ------------------------------------------------------------
// Write enclosure tag for podcasting support
// ------------------------------------------------------------
if (BlogSettings.Instance.EnableEnclosures)
{
var encloser = GetEnclosure(content, publishable);
if (!string.IsNullOrEmpty(encloser))
{
writer.WriteRaw(encloser);
}
}
// ------------------------------------------------------------
// Write entry category elements
// ------------------------------------------------------------
if (publishable.Categories != null)
{
foreach (var category in publishable.Categories)
{
writer.WriteStartElement("category");
writer.WriteAttributeString("term", category.Title);
writer.WriteEndElement();
}
}
// ------------------------------------------------------------
// Write Dublin Core syndication extension elements
// ------------------------------------------------------------
if (!String.IsNullOrEmpty(publishable.Author))
//.........这里部分代码省略.........