本文整理汇总了C#中TypedEntity.AsEnumerableOfOne方法的典型用法代码示例。如果您正苦于以下问题:C# TypedEntity.AsEnumerableOfOne方法的具体用法?C# TypedEntity.AsEnumerableOfOne怎么用?C# TypedEntity.AsEnumerableOfOne使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TypedEntity
的用法示例。
在下文中一共展示了TypedEntity.AsEnumerableOfOne方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetContentUrl
/// <summary>
/// Gets the content URL.
/// </summary>
/// <param name="entity">The entity.</param>
/// <returns></returns>
/// <remarks>
/// This takes into account the current host name in the request. If the current host name matches a host name
/// defined in the domain list for the entity being looked up, then the hostname of the current request will
/// be used, otherwise the primary (first ordinal) domain will be used for the url.
/// </remarks>
protected UrlResolutionResult GetContentUrl(TypedEntity entity)
{
Mandate.ParameterNotNull(entity, "entity");
//the cache key must include the host since it must be unique depending on what the current host/port is
var cacheKey = ContentUrlKey + entity.Id + _httpContext.Request.Url.Authority;
//return from cache if its there, otherwise go get it
return ApplicationContext.FrameworkContext.ApplicationCache
.GetOrCreate(cacheKey, () =>
{
using (var uow = ApplicationContext.Hive.OpenReader<IContentStore>())
{
//need to check if this node is in a branch with an assigned domain
// get the ancestor ids except system ones
var allAncestorIds = uow.Repositories.GetAncestorIds(entity.Id, FixedRelationTypes.DefaultRelationType).ToArray();
var ancestorIds = allAncestorIds
.Where(x => !x.IsSystem())
.ToArray();
// load the published ancestors
var ancestors = uow.Repositories
.OfRevisionType(FixedStatusTypes.Published)
.InIds(ancestorIds)
.ToArray();
// add current one to mimic "ancestors or self" but without reloading it
ancestors = entity.AsEnumerableOfOne().Concat(ancestors).ToArray();
// (APN Oct 2011) In latest codebase ancestors are returned in reverse document order, same as Xml
var reverse = ancestors.Reverse();
var nonDomainUrl = GetNonDomainUrl(reverse);
if (nonDomainUrl != null && nonDomainUrl.Status != UrlResolutionStatus.OnlyDomainUrlsValid)
{
return new HttpRuntimeCacheParameters<UrlResolutionResult>(nonDomainUrl);
}
//this is a branch that has a hostname assigned, so need to route by that
var domainUrls = GetDomainUrls(reverse);
if (domainUrls == null || !domainUrls.Any())
{
return new HttpRuntimeCacheParameters<UrlResolutionResult>(new UrlResolutionResult(string.Empty, UrlResolutionStatus.FailedRequiresHostname));
}
//now we need to determine what the current authority is, and if it matches one of the domain URLs, then we can remove the authority since
//we'll be returning a relative URL to the current request
var relativeHostUrl = domainUrls.Where(x => x.Url.StartsWith(_httpContext.Request.Url.Authority)).FirstOrDefault();
if (relativeHostUrl != null)
{
//return a relative URL for the current request authority
//var url = relativeHostUrl.Url.Substring(0, _httpContext.Request.Url.Authority.Length);
var url = relativeHostUrl.Url.Substring(_httpContext.Request.Url.Authority.Length, relativeHostUrl.Url.Length - _httpContext.Request.Url.Authority.Length);
return new HttpRuntimeCacheParameters<UrlResolutionResult>(new UrlResolutionResult(url, UrlResolutionStatus.SuccessWithoutHostname));
}
//if the request has come in on a domain that isn't in this entity's domain urls, then return the first domain url assigned to it
return new HttpRuntimeCacheParameters<UrlResolutionResult>(domainUrls.First());
}
});
}