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
		/// <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;
		}
示例#3
0
		/// <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;
        }
示例#4
0
 /// <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;
 }
示例#5
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>
		/// <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;
		}
示例#6
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;
        }