• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# UmbracoContext类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中UmbracoContext的典型用法代码示例。如果您正苦于以下问题:C# UmbracoContext类的具体用法?C# UmbracoContext怎么用?C# UmbracoContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



UmbracoContext类属于命名空间,在下文中一共展示了UmbracoContext类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: TemplateRenderer

		public TemplateRenderer(UmbracoContext umbracoContext, int pageId, int? altTemplateId)
		{
			if (umbracoContext == null) throw new ArgumentNullException("umbracoContext");
			PageId = pageId;
			AltTemplate = altTemplateId;
			_umbracoContext = umbracoContext;
		}
开发者ID:Jeavon,项目名称:Umbraco-CMS,代码行数:7,代码来源:TemplateRenderer.cs


示例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;
		}
开发者ID:Jeavon,项目名称:Umbraco-CMS,代码行数:12,代码来源:RenderRouteHandler.cs


示例3: PublishedContentRequestBuilder

		public PublishedContentRequestBuilder(PublishedContentRequest publishedContentRequest)
		{
			if (publishedContentRequest == null) throw new ArgumentNullException("publishedContentRequest");
			_publishedContentRequest = publishedContentRequest;
			_umbracoContext = publishedContentRequest.RoutingContext.UmbracoContext;
			_routingContext = publishedContentRequest.RoutingContext;
		}
开发者ID:phaniarveti,项目名称:Experiments,代码行数:7,代码来源:PublishedContentRequestBuilder.cs


示例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());
        }
开发者ID:nlorusso,项目名称:Umbraco-CMS,代码行数:44,代码来源:AliasUrlProvider.cs


示例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;
        }
开发者ID:phaniarveti,项目名称:Experiments,代码行数:33,代码来源:PublishedContentCache.cs


示例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;
 }
开发者ID:phaniarveti,项目名称:Experiments,代码行数:13,代码来源:EnsurePublishedContentRequestAttribute.cs


示例7: UmbracoApiController

 protected UmbracoApiController(UmbracoContext umbracoContext)
 {
     if (umbracoContext == null) throw new ArgumentNullException("umbracoContext");
     UmbracoContext = umbracoContext;
     InstanceId = Guid.NewGuid();
     Umbraco = new UmbracoHelper(umbracoContext);
 }
开发者ID:saciervo,项目名称:Umbraco-CMS,代码行数:7,代码来源:UmbracoApiController.cs


示例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();
        }
开发者ID:phaniarveti,项目名称:Experiments,代码行数:37,代码来源:DefaultUrlProvider.cs


示例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;
        }
开发者ID:CarlSargunar,项目名称:Umbraco-CMS,代码行数:28,代码来源:PublishedContentCache.cs


示例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;
        }
开发者ID:vnbaaij,项目名称:Umbraco9,代码行数:15,代码来源:UrlProvider.cs


示例11: RoutingContext

 internal RoutingContext(
     UmbracoContext umbracoContext,
     Lazy<IEnumerable<IContentFinder>> contentFinders,
     Lazy<IContentFinder> contentLastChanceFinder,
     Lazy<UrlProvider> urlProvider)
 {
     _publishedContentFinders = contentFinders;
     _publishedContentLastChanceFinder = contentLastChanceFinder;
     _urlProvider = urlProvider;
 }
开发者ID:ryanmcdonough,项目名称:Umbraco9,代码行数:10,代码来源:RoutingContext.cs


示例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;
        }
开发者ID:phaniarveti,项目名称:Experiments,代码行数:18,代码来源:RoutingContext.cs


示例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;
        }
开发者ID:elrute,项目名称:Triphulcas,代码行数:21,代码来源:RoutingContext.cs


示例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;
            }            
        }
开发者ID:phaniarveti,项目名称:Experiments,代码行数:18,代码来源:UrlProvider.cs


示例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;
		}
开发者ID:saciervo,项目名称:Umbraco-CMS,代码行数:14,代码来源:PublishedMediaCache.cs


示例16: RouteUmbracoContentAsync

        internal async Task<bool> RouteUmbracoContentAsync(UmbracoContext umbCtx, PublishedContentRequest pcr, RouteData routeData)
        {
            //Initialize the context, this will be called a few times but the initialize logic
            // only executes once. There might be a nicer way to do this but the RouteContext and 
            // other request scoped instances are not available yet.
            umbCtx.Initialize(pcr);

            //Prepare the request if it hasn't already been done
            if (pcr.IsPrepared == false)
            {                
                if (await pcr.PrepareAsync(routeData))
                {
                    if (umbCtx.HasContent == false) return false;
                }
            }
            return umbCtx.HasContent;            
        }
开发者ID:vnbaaij,项目名称:Umbraco9,代码行数:17,代码来源:UmbracoRouter.cs


示例17: GetRouteById

        public virtual string GetRouteById(UmbracoContext umbracoContext, bool preview, int contentId)
        {
            // try to get from cache if not previewing
            var route = preview ? null : _routesCache.GetRoute(contentId);

            // if found in cache then return
            if (route != null)
                return route;

            // else actually determine the route
            route = DetermineRouteById(umbracoContext, preview, contentId);

            // cache if we have a route and not previewing
            if (route != null && !preview)
                _routesCache.Store(contentId, route);

            return route;
        }
开发者ID:phaniarveti,项目名称:Experiments,代码行数:18,代码来源:PublishedContentCache.cs


示例18: 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 virtual IEnumerable<string> GetOtherUrls(UmbracoContext umbracoContext, int id, Uri 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 domainUris = pos == 0 ? null : DomainHelper.DomainsForNode(int.Parse(route.Substring(0, pos)), current);

            // assemble the alternate urls from domainUris (maybe empty) and path
            return AssembleUrls(domainUris, path).Select(uri => uri.ToString());
        }
开发者ID:phaniarveti,项目名称:Experiments,代码行数:33,代码来源:DefaultUrlProvider.cs


示例19: PartialViewMacroController

 public PartialViewMacroController(UmbracoContext umbracoContext, MacroModel macro, INode currentPage)
 {
     _umbracoContext = umbracoContext;
     _macro = macro;
     _currentPage = currentPage;
 }
开发者ID:CarlSargunar,项目名称:Umbraco-CMS,代码行数:6,代码来源:PartialViewMacroController.cs


示例20: UmbracoController

 protected UmbracoController(UmbracoContext umbracoContext)
 {
     if (umbracoContext == null) throw new ArgumentNullException("umbracoContext");
     UmbracoContext = umbracoContext;
 }
开发者ID:phaniarveti,项目名称:Experiments,代码行数:5,代码来源:UmbracoController.cs



注:本文中的UmbracoContext类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# UmbracoHelper类代码示例发布时间:2022-05-24
下一篇:
C# Umbraco类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap