本文整理汇总了C#中UmbracoContext类的典型用法代码示例。如果您正苦于以下问题:C# UmbracoContext类的具体用法?C# UmbracoContext怎么用?C# UmbracoContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
UmbracoContext类属于命名空间,在下文中一共展示了UmbracoContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TemplateRenderer
public TemplateRenderer(UmbracoContext umbracoContext, int pageId, int? altTemplateId)
{
if (umbracoContext == null) throw new ArgumentNullException("umbracoContext");
PageId = pageId;
AltTemplate = altTemplateId;
_umbracoContext = umbracoContext;
}
示例2: RenderRouteHandler
/// <summary>
/// Contructor generally used for unit testing
/// </summary>
/// <param name="controllerFactory"></param>
/// <param name="umbracoContext"></param>
internal RenderRouteHandler(IControllerFactory controllerFactory, UmbracoContext umbracoContext)
{
if (controllerFactory == null) throw new ArgumentNullException("controllerFactory");
if (umbracoContext == null) throw new ArgumentNullException("umbracoContext");
_controllerFactory = controllerFactory;
_umbracoContext = umbracoContext;
}
示例3: PublishedContentRequestBuilder
public PublishedContentRequestBuilder(PublishedContentRequest publishedContentRequest)
{
if (publishedContentRequest == null) throw new ArgumentNullException("publishedContentRequest");
_publishedContentRequest = publishedContentRequest;
_umbracoContext = publishedContentRequest.RoutingContext.UmbracoContext;
_routingContext = publishedContentRequest.RoutingContext;
}
示例4: GetOtherUrls
/// <summary>
/// Gets the other urls of a published content.
/// </summary>
/// <param name="umbracoContext">The Umbraco context.</param>
/// <param name="id">The published content id.</param>
/// <param name="current">The current absolute url.</param>
/// <returns>The other urls for the published content.</returns>
/// <remarks>
/// <para>Other urls are those that <c>GetUrl</c> would not return in the current context, but would be valid
/// urls for the node in other contexts (different domain for current request, umbracoUrlAlias...).</para>
/// </remarks>
public IEnumerable<string> GetOtherUrls(UmbracoContext umbracoContext, int id, Uri current)
{
if (!FindByUrlAliasEnabled)
return Enumerable.Empty<string>(); // we have nothing to say
var node = umbracoContext.ContentCache.GetById(id);
string umbracoUrlName = null;
if (node.HasProperty(Constants.Conventions.Content.UrlAlias))
umbracoUrlName = node.GetPropertyValue<string>(Constants.Conventions.Content.UrlAlias);
if (string.IsNullOrWhiteSpace(umbracoUrlName))
return Enumerable.Empty<string>();
var n = node;
var domainUris = DomainHelper.DomainsForNode(n.Id, current, false);
while (domainUris == null && n != null) // n is null at root
{
// move to parent node
n = n.Parent;
domainUris = n == null ? null : DomainHelper.DomainsForNode(n.Id, current, false);
}
var path = "/" + umbracoUrlName;
if (domainUris == null)
{
var uri = new Uri(path, UriKind.Relative);
return new[] { UriUtility.UriFromUmbraco(uri).ToString() };
}
return domainUris
.Select(domainUri => new Uri(CombinePaths(domainUri.Uri.GetLeftPart(UriPartial.Path), path)))
.Select(uri => UriUtility.UriFromUmbraco(uri).ToString());
}
示例5: GetByRoute
public virtual IPublishedContent GetByRoute(UmbracoContext umbracoContext, bool preview, string route, bool? hideTopLevelNode = null)
{
if (route == null) throw new ArgumentNullException("route");
// try to get from cache if not previewing
var contentId = preview ? 0 : _routesCache.GetNodeId(route);
// if found id in cache then get corresponding content
// and clear cache if not found - for whatever reason
IPublishedContent content = null;
if (contentId > 0)
{
content = GetById(umbracoContext, preview, contentId);
if (content == null)
_routesCache.ClearNode(contentId);
}
// still have nothing? actually determine the id
hideTopLevelNode = hideTopLevelNode ?? GlobalSettings.HideTopLevelNodeFromPath; // default = settings
content = content ?? DetermineIdByRoute(umbracoContext, preview, route, hideTopLevelNode.Value);
// cache if we have a content and not previewing
if (content != null && !preview)
{
var domainRootNodeId = route.StartsWith("/") ? -1 : int.Parse(route.Substring(0, route.IndexOf('/')));
var iscanon = !UnitTesting && !DomainHelper.ExistsDomainInPath(DomainHelper.GetAllDomains(false), content.Path, domainRootNodeId);
// and only if this is the canonical url (the one GetUrl would return)
if (iscanon)
_routesCache.Store(contentId, route);
}
return content;
}
示例6: EnsurePublishedContentRequestAttribute
/// <summary>
/// Constructor - can be used for testing
/// </summary>
/// <param name="umbracoContext"></param>
/// <param name="contentId"></param>
/// <param name="culture"></param>
public EnsurePublishedContentRequestAttribute(UmbracoContext umbracoContext, int contentId, string culture = null)
{
if (umbracoContext == null) throw new ArgumentNullException("umbracoContext");
_umbracoContext = umbracoContext;
_contentId = contentId;
_culture = culture;
}
示例7: UmbracoApiController
protected UmbracoApiController(UmbracoContext umbracoContext)
{
if (umbracoContext == null) throw new ArgumentNullException("umbracoContext");
UmbracoContext = umbracoContext;
InstanceId = Guid.NewGuid();
Umbraco = new UmbracoHelper(umbracoContext);
}
示例8: GetUrl
/// <summary>
/// Gets the nice url of a published content.
/// </summary>
/// <param name="umbracoContext">The Umbraco context.</param>
/// <param name="id">The published content id.</param>
/// <param name="current">The current absolute url.</param>
/// <param name="mode">The url mode.</param>
/// <returns>The url for the published content.</returns>
/// <remarks>
/// <para>The url is absolute or relative depending on <c>mode</c> and on <c>current</c>.</para>
/// <para>If the provider is unable to provide a url, it should return <c>null</c>.</para>
/// </remarks>
public virtual string GetUrl(UmbracoContext umbracoContext, int id, Uri current, UrlProviderMode mode)
{
if (!current.IsAbsoluteUri)
throw new ArgumentException("Current url must be absolute.", "current");
// will not use cache if previewing
var route = umbracoContext.ContentCache.GetRouteById(id);
if (string.IsNullOrWhiteSpace(route))
{
LogHelper.Warn<DefaultUrlProvider>(
"Couldn't find any page with nodeId={0}. This is most likely caused by the page not being published.",
() => id);
return null;
}
// extract domainUri and path
// route is /<path> or <domainRootId>/<path>
var pos = route.IndexOf('/');
var path = pos == 0 ? route : route.Substring(pos);
var domainUri = pos == 0 ? null : DomainHelper.DomainForNode(int.Parse(route.Substring(0, pos)), current);
// assemble the url from domainUri (maybe null) and path
return AssembleUrl(domainUri, path, current, mode).ToString();
}
示例9: DetermineIdByRoute
IPublishedContent DetermineIdByRoute(UmbracoContext umbracoContext, bool preview, string route, bool hideTopLevelNode)
{
if (route == null) throw new ArgumentNullException("route");
//the route always needs to be lower case because we only store the urlName attribute in lower case
route = route.ToLowerInvariant();
var pos = route.IndexOf('/');
var path = pos == 0 ? route : route.Substring(pos);
var startNodeId = pos == 0 ? 0 : int.Parse(route.Substring(0, pos));
IEnumerable<XPathVariable> vars;
var xpath = CreateXpathQuery(startNodeId, path, hideTopLevelNode, out vars);
//check if we can find the node in our xml cache
var content = GetSingleByXPath(umbracoContext, preview, xpath, vars == null ? null : vars.ToArray());
// if hideTopLevelNodePath is true then for url /foo we looked for /*/foo
// but maybe that was the url of a non-default top-level node, so we also
// have to look for /foo (see note in ApplyHideTopLevelNodeFromPath).
if (content == null && hideTopLevelNode && path.Length > 1 && path.IndexOf('/', 1) < 0)
{
xpath = CreateXpathQuery(startNodeId, path, false, out vars);
content = GetSingleByXPath(umbracoContext, preview, xpath, vars == null ? null : vars.ToArray());
}
return content;
}
示例10: UrlProvider
/// <summary>
/// Initializes a new instance of the <see cref="UrlProvider"/> class with an Umbraco context and a list of url providers.
/// </summary>
/// <param name="umbracoContext">The Umbraco context.</param>
/// <param name="urlProviders">The list of url providers.</param>
/// <param name="provider"></param>
public UrlProvider(UmbracoContext umbracoContext, IEnumerable<IUrlProvider> urlProviders, UrlProviderMode provider = UrlProviderMode.Auto)
{
if (umbracoContext == null) throw new ArgumentNullException("umbracoContext");
_umbracoContext = umbracoContext;
_urlProviders = urlProviders;
Mode = provider;
}
示例11: RoutingContext
internal RoutingContext(
UmbracoContext umbracoContext,
Lazy<IEnumerable<IContentFinder>> contentFinders,
Lazy<IContentFinder> contentLastChanceFinder,
Lazy<UrlProvider> urlProvider)
{
_publishedContentFinders = contentFinders;
_publishedContentLastChanceFinder = contentLastChanceFinder;
_urlProvider = urlProvider;
}
示例12: RoutingContext
/// <summary>
/// Initializes a new instance of the <see cref="RoutingContext"/> class.
/// </summary>
/// <param name="umbracoContext"> </param>
/// <param name="contentFinders">The document lookups resolver.</param>
/// <param name="contentLastChanceFinder"> </param>
/// <param name="urlProvider">The nice urls provider.</param>
internal RoutingContext(
UmbracoContext umbracoContext,
IEnumerable<IContentFinder> contentFinders,
IContentFinder contentLastChanceFinder,
UrlProvider urlProvider)
{
UmbracoContext = umbracoContext;
PublishedContentFinders = contentFinders;
PublishedContentLastChanceFinder = contentLastChanceFinder;
UrlProvider = urlProvider;
}
示例13: RoutingContext
/// <summary>
/// Initializes a new instance of the <see cref="RoutingContext"/> class.
/// </summary>
/// <param name="umbracoContext"> </param>
/// <param name="documentLookups">The document lookups resolver.</param>
/// <param name="documentLastChanceLookup"> </param>
/// <param name="publishedContentStore">The content store.</param>
/// <param name="niceUrlResolver">The nice urls resolver.</param>
internal RoutingContext(
UmbracoContext umbracoContext,
IEnumerable<IPublishedContentLookup> documentLookups,
IDocumentLastChanceLookup documentLastChanceLookup,
IPublishedContentStore publishedContentStore,
NiceUrlProvider niceUrlResolver)
{
this.UmbracoContext = umbracoContext;
this.DocumentLookups = documentLookups;
DocumentLastChanceLookup = documentLastChanceLookup;
this.PublishedContentStore = publishedContentStore;
this.NiceUrlProvider = niceUrlResolver;
}
示例14: UrlProvider
/// <summary>
/// Initializes a new instance of the <see cref="UrlProvider"/> class with an Umbraco context and a list of url providers.
/// </summary>
/// <param name="umbracoContext">The Umbraco context.</param>
/// <param name="urlProviders">The list of url providers.</param>
internal UrlProvider(UmbracoContext umbracoContext, IEnumerable<IUrlProvider> urlProviders)
{
_umbracoContext = umbracoContext;
_urlProviders = urlProviders;
var provider = UrlProviderMode.Auto;
Mode = provider;
if (Enum<UrlProviderMode>.TryParse(UmbracoConfig.For.UmbracoSettings().WebRouting.UrlProviderMode, out provider))
{
Mode = provider;
}
}
示例15: GetAtRoot
public virtual IEnumerable<IPublishedContent> GetAtRoot(UmbracoContext umbracoContext, bool preview)
{
var rootMedia = global::umbraco.cms.businesslogic.media.Media.GetRootMedias();
var result = new List<IPublishedContent>();
//TODO: need to get a ConvertFromMedia method but we'll just use this for now.
foreach (var media in rootMedia
.Select(m => global::umbraco.library.GetMedia(m.Id, true))
.Where(media => media != null && media.Current != null))
{
media.MoveNext();
result.Add(ConvertFromXPathNavigator(media.Current));
}
return result;
}