コード例 #1
0
		public override void Initialize()
		{
			base.Initialize();

			var url = "/test";
			
			var lookup = new Umbraco.Web.Routing.LookupByNiceUrl();
			var lookups = new Umbraco.Web.Routing.IPublishedContentLookup[] { lookup };

			var t = Template.MakeNew("test", new User(0));

			var umbracoContext = GetUmbracoContext(url, t.Id);
			var contentStore = new DefaultPublishedContentStore();
			var niceUrls = new NiceUrlProvider(contentStore, umbracoContext);
			var routingContext = new RoutingContext(
				umbracoContext,
				lookups,
				new FakeLastChanceLookup(),
				contentStore,
				niceUrls);

			//assign the routing context back to the umbraco context
			umbracoContext.RoutingContext = routingContext;

			////assign the routing context back to the umbraco context
			//umbracoContext.RoutingContext = routingContext;
			Umbraco.Web.UmbracoContext.Current = routingContext.UmbracoContext;
		}
コード例 #2
0
		public override void Initialize()
		{
			base.Initialize();

			var url = "/test";
			
			var lookup = new Umbraco.Web.Routing.ContentFinderByNiceUrl();
			var lookups = new Umbraco.Web.Routing.IContentFinder[] { lookup };

			var t = Template.MakeNew("test", new User(0));

			var umbracoContext = GetUmbracoContext(url, t.Id);
            var urlProvider = new UrlProvider(umbracoContext, new IUrlProvider[] { new DefaultUrlProvider() });
			var routingContext = new RoutingContext(
				umbracoContext,
				lookups,
				new FakeLastChanceFinder(),
                urlProvider);

			//assign the routing context back to the umbraco context
			umbracoContext.RoutingContext = routingContext;

			////assign the routing context back to the umbraco context
			//umbracoContext.RoutingContext = routingContext;
			Umbraco.Web.UmbracoContext.Current = routingContext.UmbracoContext;
		}
コード例 #3
0
		public PublishedContentRequestBuilder(PublishedContentRequest publishedContentRequest)
		{
			if (publishedContentRequest == null) throw new ArgumentNullException("publishedContentRequest");
			_publishedContentRequest = publishedContentRequest;
			_umbracoContext = publishedContentRequest.RoutingContext.UmbracoContext;
			_routingContext = publishedContentRequest.RoutingContext;
		}
コード例 #4
0
ファイル: UmbracoModule.cs プロジェクト: elrute/Triphulcas
		/// <summary>
		/// Begins to process a request.
		/// </summary>
		/// <param name="httpContext"></param>
		void BeginRequest(HttpContextBase httpContext)
		{
			// do not process if client-side request
			if (IsClientSideRequest(httpContext.Request.Url))
				return;			

			// ok, process

			// create the LegacyRequestInitializer
			// and initialize legacy stuff
			var legacyRequestInitializer = new LegacyRequestInitializer(httpContext.Request.Url, httpContext);
			legacyRequestInitializer.InitializeRequest();

			// create the UmbracoContext singleton, one per request, and assign
			var umbracoContext = new UmbracoContext(
				httpContext,
				ApplicationContext.Current,
				RoutesCacheResolver.Current.RoutesCache);
			UmbracoContext.Current = umbracoContext;

			// create the nice urls provider
			var niceUrls = new NiceUrlProvider(PublishedContentStoreResolver.Current.PublishedContentStore, umbracoContext);

			// create the RoutingContext, and assign
			var routingContext = new RoutingContext(
				umbracoContext,
				DocumentLookupsResolver.Current.DocumentLookups,
				LastChanceLookupResolver.Current.LastChanceLookup,
				PublishedContentStoreResolver.Current.PublishedContentStore,
				niceUrls);
			umbracoContext.RoutingContext = routingContext;
		}
コード例 #5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="PublishedContentRequest"/> class with a specific Uri and routing context.
        /// </summary>
        /// <param name="routingContext">A routing context.</param>
        /// <param name="templateService"></param>
        /// <param name="loggerFactor"></param>
        /// <param name="httpContextAccessor"></param>
        public PublishedContentRequest(RoutingContext routingContext, ITemplateService templateService, ILoggerFactory loggerFactor, IHttpContextAccessor httpContextAccessor)
        {            
            if (routingContext == null) throw new ArgumentNullException("routingContext");
            if (templateService == null) throw new ArgumentNullException(nameof(templateService));

            _templateService = templateService;
            RoutingContext = routingContext;

            _engine = new PublishedContentRequestEngine(templateService, this, loggerFactor, httpContextAccessor);
        }
コード例 #6
0
		/// <summary>
		/// Initializes a new instance of the <see cref="PublishedContentRequest"/> class with a specific Uri and routing context.
		/// </summary>
		/// <param name="uri">The request <c>Uri</c>.</param>
		/// <param name="routingContext">A routing context.</param>
		internal PublishedContentRequest(Uri uri, RoutingContext routingContext)
		{
			if (uri == null) throw new ArgumentNullException("uri");
			if (routingContext == null) throw new ArgumentNullException("routingContext");

			Uri = uri;
			RoutingContext = routingContext;

			_engine = new PublishedContentRequestEngine(this);

            RenderingEngine = RenderingEngine.Unknown;
		}
コード例 #7
0
		/// <summary>
		/// Initializes a new instance of the <see cref="PublishedContentRequestEngine"/> class with a content request.
		/// </summary>
		/// <param name="pcr">The content request.</param>
		public PublishedContentRequestEngine(PublishedContentRequest pcr)
		{
			_pcr = pcr;
			_routingContext = pcr.RoutingContext;

			var umbracoContext = _routingContext.UmbracoContext;
			if (_routingContext == null) throw new ArgumentException("pcr.RoutingContext is null.");
			if (umbracoContext == null) throw new ArgumentException("pcr.RoutingContext.UmbracoContext is null.");
			if (umbracoContext.RoutingContext != _routingContext) throw new ArgumentException("RoutingContext confusion.");
			// no! not set yet.
			//if (umbracoContext.PublishedContentRequest != _pcr) throw new ArgumentException("PublishedContentRequest confusion.");
		}
コード例 #8
0
ファイル: BaseRoutingTest.cs プロジェクト: elrute/Triphulcas
		/// <summary>
		/// Return a new RoutingContext
		/// </summary>
		/// <param name="url"></param>
		/// <param name="templateId">
		/// The template Id to insert into the Xml cache file for each node, this is helpful for unit testing with templates but you		 
		/// should normally create the template in the database with this id
		///</param>
		/// <param name="routeData"></param>
		/// <returns></returns>
		protected RoutingContext GetRoutingContext(string url, int templateId, RouteData routeData = null)
		{
			var umbracoContext = GetUmbracoContext(url, templateId, routeData);
			var contentStore = new DefaultPublishedContentStore();
			var niceUrls = new NiceUrlProvider(contentStore, umbracoContext);
			var routingContext = new RoutingContext(
				umbracoContext,
				Enumerable.Empty<IPublishedContentLookup>(),
				new FakeLastChanceLookup(),
				contentStore,
				niceUrls);

			//assign the routing context back to the umbraco context
			umbracoContext.RoutingContext = routingContext;

			return routingContext;
		}
コード例 #9
0
        public async void RouteUmbracoContentAsync_Umbraco_Context_Initialized()
        {
            var router = new UmbracoRouter(Mock.Of<IRouter>());
            var httpCtxAccessor = new Mock<IHttpContextAccessor>();
            var httpContext = new Mock<HttpContext>();
            httpContext.Setup(context => context.Request).Returns(Mock.Of<HttpRequest>());
            httpCtxAccessor.Setup(accessor => accessor.HttpContext).Returns(httpContext.Object);
            var umbCtx = new UmbracoContext(httpCtxAccessor.Object);
            var urlProvider = new UrlProvider(umbCtx, Enumerable.Empty<IUrlProvider>());
            var routingCtx = new RoutingContext(Enumerable.Empty<IContentFinder>(), Mock.Of<ILastChanceContentFinder>(), urlProvider);
            var pcr = new PublishedContentRequest(routingCtx, Mock.Of<ITemplateService>(), Mock.Of<ILoggerFactory>(), httpCtxAccessor.Object);

            var result = await router.RouteUmbracoContentAsync(umbCtx, pcr, new RouteData());

            Assert.Equal(true, umbCtx.Initialized);
            Assert.Equal(false, result);
        }
コード例 #10
0
	    ///  <summary>
	    ///  Return a new RoutingContext
	    ///  </summary>
	    ///  <param name="url"></param>
	    ///  <param name="templateId">
	    ///  The template Id to insert into the Xml cache file for each node, this is helpful for unit testing with templates but you		 
	    ///  should normally create the template in the database with this id
	    /// </param>
	    ///  <param name="routeData"></param>
	    /// <param name="setUmbracoContextCurrent">set to true to also set the singleton UmbracoContext.Current to the context created with this method</param>
	    /// <returns></returns>
	    protected RoutingContext GetRoutingContext(string url, int templateId, RouteData routeData = null, bool setUmbracoContextCurrent = false)
		{
			var umbracoContext = GetUmbracoContext(url, templateId, routeData);
            var urlProvider = new UrlProvider(umbracoContext, new IUrlProvider[] { new DefaultUrlProvider() });
			var routingContext = new RoutingContext(
				umbracoContext,
				Enumerable.Empty<IContentFinder>(),
				new FakeLastChanceFinder(),
                urlProvider);

			//assign the routing context back to the umbraco context
			umbracoContext.RoutingContext = routingContext;

	        if (setUmbracoContextCurrent)
	            UmbracoContext.Current = umbracoContext;

			return routingContext;
		}
コード例 #11
0
        /// <summary>
        /// Initializes a new instance of the <see cref="PublishedContentRequestEngine"/> class with a content request.
        /// </summary>
        /// <param name="pcr">The content request.</param>
        public PublishedContentRequestEngine(PublishedContentRequest pcr)
        {
            _pcr            = pcr;
            _routingContext = pcr.RoutingContext;

            var umbracoContext = _routingContext.UmbracoContext;

            if (_routingContext == null)
            {
                throw new ArgumentException("pcr.RoutingContext is null.");
            }
            if (umbracoContext == null)
            {
                throw new ArgumentException("pcr.RoutingContext.UmbracoContext is null.");
            }
            if (umbracoContext.RoutingContext != _routingContext)
            {
                throw new ArgumentException("RoutingContext confusion.");
            }
            // no! not set yet.
            //if (umbracoContext.PublishedContentRequest != _pcr) throw new ArgumentException("PublishedContentRequest confusion.");
        }
コード例 #12
0
        public void GetUmbracoRouteValues_Find_Custom_Controller()
        {
            var router = new UmbracoRouter(Mock.Of<IRouter>());
            var httpCtxAccessor = new Mock<IHttpContextAccessor>();
            var httpContext = new Mock<HttpContext>();
            httpContext.Setup(context => context.Request).Returns(Mock.Of<HttpRequest>());
            httpCtxAccessor.Setup(accessor => accessor.HttpContext).Returns(httpContext.Object);
            var umbCtx = new UmbracoContext(httpCtxAccessor.Object);
            var urlProvider = new UrlProvider(umbCtx, Enumerable.Empty<IUrlProvider>());
            var routingCtx = new RoutingContext(Enumerable.Empty<IContentFinder>(), Mock.Of<ILastChanceContentFinder>(), urlProvider);
            var templateService = new Mock<ITemplateService>();
            templateService.Setup(service => service.GetTemplate("Hello")).Returns(Mock.Of<ITemplate>(template => template.Alias == "Hello"));
            var pcr = new PublishedContentRequest(routingCtx, templateService.Object, Mock.Of<ILoggerFactory>(), httpCtxAccessor.Object)
            {
                PublishedContent = new PublishedContent()
                {
                    ContentType = "Custom"
                }
            };
            pcr.TrySetTemplate("Hello");
            umbCtx.Initialize(pcr);
            var actionDescriptors = new Mock<IActionDescriptorsCollectionProvider>();
            actionDescriptors.Setup(provider => provider.ActionDescriptors).Returns(new ActionDescriptorsCollection(
                new List<ActionDescriptor>()
                {
                    new ControllerActionDescriptor()
                    {
                        Name = "Hello",
                        ControllerName = "Custom",
                        ControllerTypeInfo = typeof(UmbracoController).GetTypeInfo()
                    }
                }, 0));

            var result = router.GetUmbracoRouteValues(umbCtx, new UmbracoControllerTypeCollection(actionDescriptors.Object));

            Assert.Equal("Custom", result.ControllerName);
            Assert.Equal("Hello", result.ActionName);
        }
コード例 #13
0
        /// <summary>
        /// Initializes a new instance of the <see cref="PublishedContentRequestEngine"/> class with a content request.
        /// </summary>
        /// <param name="templateService"></param>
        /// <param name="pcr">The content request.</param>
        /// <param name="loggerFactory"></param>
        /// <param name="httpContextAccessor"></param>
        public PublishedContentRequestEngine(
            ITemplateService templateService,
            PublishedContentRequest pcr,
            ILoggerFactory loggerFactory,
            IHttpContextAccessor httpContextAccessor)
        {
            if (templateService == null) throw new ArgumentNullException(nameof(templateService));
            if (pcr == null) throw new ArgumentException("pcr is null.");
            if (loggerFactory == null) throw new ArgumentNullException(nameof(loggerFactory));
            if (httpContextAccessor == null) throw new ArgumentNullException(nameof(httpContextAccessor));

            _templateService = templateService;
            _pcr = pcr;
            _httpContextAccessor = httpContextAccessor;
            _logger = loggerFactory.CreateLogger(typeof(PublishedContentRequestEngine).FullName);
            _routingContext = pcr.RoutingContext;

            //var umbracoContext = _routingContext.UmbracoContext;
            //if (umbracoContext == null) throw new ArgumentException("pcr.RoutingContext.UmbracoContext is null.");
            //if (umbracoContext.RoutingContext != _routingContext) throw new ArgumentException("RoutingContext confusion.");
            // no! not set yet.
            //if (umbracoContext.PublishedContentRequest != _pcr) throw new ArgumentException("PublishedContentRequest confusion.");
        }
コード例 #14
0
        public void GetUmbracoRouteValues_Returns_Default()
        {
            var router = new UmbracoRouter(Mock.Of<IRouter>());
            var httpCtxAccessor = new Mock<IHttpContextAccessor>();
            var httpContext = new Mock<HttpContext>();
            httpContext.Setup(context => context.Request).Returns(Mock.Of<HttpRequest>());
            httpCtxAccessor.Setup(accessor => accessor.HttpContext).Returns(httpContext.Object);
            var umbCtx = new UmbracoContext(httpCtxAccessor.Object);            
            var urlProvider = new UrlProvider(umbCtx, Enumerable.Empty<IUrlProvider>());
            var routingCtx = new RoutingContext(Enumerable.Empty<IContentFinder>(), Mock.Of<ILastChanceContentFinder>(), urlProvider);
            var pcr = new PublishedContentRequest(routingCtx, Mock.Of<ITemplateService>(), Mock.Of<ILoggerFactory>(), httpCtxAccessor.Object)
            {
                PublishedContent = new PublishedContent()
            };
            umbCtx.Initialize(pcr);
            var actionDescriptors = new Mock<IActionDescriptorsCollectionProvider>();
            actionDescriptors.Setup(provider => provider.ActionDescriptors).Returns(new ActionDescriptorsCollection(new List<ActionDescriptor>(), 0));

            var result = router.GetUmbracoRouteValues(umbCtx, new UmbracoControllerTypeCollection(actionDescriptors.Object));

            Assert.Equal("Umbraco", result.ControllerName);
            Assert.Equal("Index", result.ActionName);
        }
コード例 #15
0
        /// <summary>
        /// Initializes a new instance of the <see cref="PublishedContentRequest"/> class with a specific Uri and routing context.
        /// </summary>
        /// <param name="routingContext">A routing context.</param>
        /// <param name="templateService"></param>
        /// <param name="loggerFactor"></param>
        /// <param name="httpContextAccessor"></param>
        public PublishedContentRequest(RoutingContext routingContext, ITemplateService templateService, ILoggerFactory loggerFactor, IHttpContextAccessor httpContextAccessor)
        {
            if (routingContext == null)
            {
                throw new ArgumentNullException("routingContext");
            }
            if (templateService == null)
            {
                throw new ArgumentNullException(nameof(templateService));
            }
            if (loggerFactor == null)
            {
                throw new ArgumentNullException(nameof(loggerFactor));
            }
            if (httpContextAccessor == null)
            {
                throw new ArgumentNullException(nameof(httpContextAccessor));
            }

            _templateService = templateService;
            RoutingContext   = routingContext;

            _engine = new PublishedContentRequestEngine(templateService, this, loggerFactor, httpContextAccessor);
        }
コード例 #16
0
 public PublishedContentRequestBuilder(PublishedContentRequest publishedContentRequest)
 {
     _publishedContentRequest = publishedContentRequest;
     _umbracoContext          = publishedContentRequest.RoutingContext.UmbracoContext;
     _routingContext          = publishedContentRequest.RoutingContext;
 }
コード例 #17
0
		/// <summary>
		/// Initializes a new instance of the <see cref="PublishedContentRequest"/> class with a specific Uri and routing context.
		/// </summary>
		/// <param name="uri">The request <c>Uri</c>.</param>
		/// <param name="routingContext">A routing context.</param>
		public PublishedContentRequest(Uri uri, RoutingContext routingContext)
        {
			if (uri == null) throw new ArgumentNullException("uri");
			if (routingContext == null) throw new ArgumentNullException("routingContext");

			this.Uri = uri;
			this.RoutingContext = routingContext;

			_builder = new PublishedContentRequestBuilder(this);
			
			// set default
			this.RenderingEngine = RenderingEngine.Mvc;			
        }
コード例 #18
0
 public PublishedContentRequest(Uri uri, RoutingContext routingContext)
     : this(uri, routingContext, UmbracoConfig.For.UmbracoSettings().WebRouting, s => Roles.Provider.GetRolesForUser(s))
 {
 }
コード例 #19
0
        /// <summary>
        /// This is a helper method which is called to ensure that the singleton context is created and the nice url and routing
        /// context is created and assigned.
        /// </summary>
        /// <param name="httpContext"></param>
        /// <param name="applicationContext"></param>
        /// <param name="webSecurity"></param>
        /// <param name="replaceContext">
        /// if set to true will replace the current singleton with a new one, this is generally only ever used because
        /// during application startup the base url domain will not be available so after app startup we'll replace the current
        /// context with a new one in which we can access the httpcontext.Request object.
        /// </param>
        /// <param name="preview"></param>
        /// <returns>
        /// The Singleton context object
        /// </returns>
        /// <remarks>
        /// This is created in order to standardize the creation of the singleton. Normally it is created during a request
        /// in the UmbracoModule, however this module does not execute during application startup so we need to ensure it
        /// during the startup process as well.
        /// See: http://issues.umbraco.org/issue/U4-1890, http://issues.umbraco.org/issue/U4-1717
        /// </remarks>
        public static UmbracoContext EnsureContext(
            HttpContextBase httpContext,
            ApplicationContext applicationContext,
            WebSecurity webSecurity,
            bool replaceContext,
            bool? preview)
        {
            if (UmbracoContext.Current != null)
            {
                if (!replaceContext)
                    return UmbracoContext.Current;
                UmbracoContext.Current._replacing = true;
            }

            var umbracoContext = new UmbracoContext(
                httpContext,
                applicationContext,
                PublishedCachesResolver.Current.Caches,
                webSecurity,
                preview);

            // create the nice urls provider
            // there's one per request because there are some behavior parameters that can be changed
            var urlProvider = new UrlProvider(
                umbracoContext,
                UrlProviderResolver.Current.Providers);

            // create the RoutingContext, and assign
            var routingContext = new RoutingContext(
                umbracoContext,
                ContentFinderResolver.Current.Finders,
                ContentLastChanceFinderResolver.Current.Finder,
                urlProvider);

            //assign the routing context back
            umbracoContext.RoutingContext = routingContext;

            //assign the singleton
            UmbracoContext.Current = umbracoContext;
            return UmbracoContext.Current;
        }
コード例 #20
0
        /// <summary>
        /// This is a helper method which is called to ensure that the singleton context is created and the nice url and routing
        /// context is created and assigned.
        /// </summary>
        /// <param name="httpContext"></param>
        /// <param name="applicationContext"></param>
        /// <param name="replaceContext">
        /// if set to true will replace the current singleton with a new one, this is generally only ever used because
        /// during application startup the base url domain will not be available so after app startup we'll replace the current
        /// context with a new one in which we can access the httpcontext.Request object.
        /// </param>
        /// <returns>
        /// The Singleton context object
        /// </returns>
        /// <remarks>
        /// This is created in order to standardize the creation of the singleton. Normally it is created during a request
        /// in the UmbracoModule, however this module does not execute during application startup so we need to ensure it
        /// during the startup process as well.
        /// See: http://issues.umbraco.org/issue/U4-1890
        /// </remarks>
        internal static UmbracoContext EnsureContext(HttpContextBase httpContext, ApplicationContext applicationContext, bool replaceContext)
        {
            if (UmbracoContext.Current != null)
            {
                if (!replaceContext)
                    return UmbracoContext.Current;
                UmbracoContext.Current._replacing = true;
            }

            var umbracoContext = new UmbracoContext(httpContext, applicationContext, RoutesCacheResolver.Current.RoutesCache);

            // create the nice urls provider
            var niceUrls = new NiceUrlProvider(PublishedContentStoreResolver.Current.PublishedContentStore, umbracoContext);

            // create the RoutingContext, and assign
            var routingContext = new RoutingContext(
                umbracoContext,
                DocumentLookupsResolver.Current.DocumentLookups,
                LastChanceLookupResolver.Current.LastChanceLookup,
                PublishedContentStoreResolver.Current.PublishedContentStore,
                niceUrls);

            //assign the routing context back
            umbracoContext.RoutingContext = routingContext;

            //assign the singleton
            UmbracoContext.Current = umbracoContext;
            return UmbracoContext.Current;
        }
コード例 #21
0
		public PublishedContentRequestBuilder(PublishedContentRequest publishedContentRequest)
		{
			_publishedContentRequest = publishedContentRequest;
			_umbracoContext = publishedContentRequest.RoutingContext.UmbracoContext;
			_routingContext = publishedContentRequest.RoutingContext;
		}