本文整理汇总了C#中IExecutionContext.GetLink方法的典型用法代码示例。如果您正苦于以下问题:C# IExecutionContext.GetLink方法的具体用法?C# IExecutionContext.GetLink怎么用?C# IExecutionContext.GetLink使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IExecutionContext
的用法示例。
在下文中一共展示了IExecutionContext.GetLink方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Execute
public IEnumerable<IDocument> Execute(IReadOnlyList<IDocument> inputs, IExecutionContext context)
{
StringBuilder sb = new StringBuilder();
sb.Append("<?xml version=\"1.0\" encoding=\"UTF-8\"?><urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">");
foreach (IDocument input in inputs)
{
// Try to get a SitemapItem
object delegateResult = _sitemapItemOrLocation(input, context);
SitemapItem sitemapItem = delegateResult as SitemapItem;
if (sitemapItem == null)
{
string locationDelegateResult = delegateResult as string;
if (!string.IsNullOrWhiteSpace(locationDelegateResult))
{
sitemapItem = new SitemapItem(locationDelegateResult);
}
}
// Add a sitemap entry if we got an item and valid location
if (!string.IsNullOrWhiteSpace(sitemapItem?.Location))
{
string location = sitemapItem.Location;
// Apply the location formatter if there is one
if (_locationFormatter != null)
{
location = _locationFormatter(location);
}
// Apply the hostname if defined (and the location formatter didn't already set a hostname)
if (!string.IsNullOrWhiteSpace(location))
{
if (!location.StartsWith("http://", StringComparison.InvariantCultureIgnoreCase))
{
location = context.GetLink(new FilePath(location), true);
}
}
// Location being null signals that this document should not be included in the sitemap
if (!string.IsNullOrWhiteSpace(location))
{
sb.Append("<url>");
sb.AppendFormat("<loc>{0}</loc>", location);
if (sitemapItem.LastModUtc.HasValue)
{
sb.AppendFormat("<lastmod>{0}</lastmod>", sitemapItem.LastModUtc.Value.ToString("yyyy-MM-ddTHH:mm:ssZ"));
}
if (sitemapItem.ChangeFrequency.HasValue)
{
sb.AppendFormat("<changefreq>{0}</changefreq>", ChangeFrequencies[(int)sitemapItem.ChangeFrequency.Value]);
}
if (sitemapItem.Priority.HasValue)
{
sb.AppendFormat(CultureInfo.InvariantCulture, "<priority>{0}</priority>", sitemapItem.Priority.Value);
}
sb.Append("</url>");
}
}
}
// Always output the sitemap document, even if it's empty
sb.Append("</urlset>");
return new[] { context.GetDocument(sb.ToString()) };
}
示例2: BuildSearchIndex
private string BuildSearchIndex(IList<SearchIndexItem> searchIndexItems, string[] stopwords, IExecutionContext context)
{
StringBuilder sb = new StringBuilder();
for (int i = 0; i < searchIndexItems.Count(); ++i)
{
SearchIndexItem itm = searchIndexItems.ElementAt(i);
sb.AppendLine([email protected]"a({{
id:{i},
title:{CleanString(itm.Title, stopwords)},
content:{CleanString(itm.Content, stopwords)},
description:{CleanString(itm.Description, stopwords)},
tags:'{itm.Tags}'
}});");
}
foreach (SearchIndexItem itm in searchIndexItems)
{
sb.AppendLine([email protected]"y({{
url:'{context.GetLink(new FilePath(itm.Url), true)}',
title:{ToJsonString(itm.Title)},
description:{ToJsonString(itm.Description)}
}});");
}
return CreateJs(sb.ToString());
}