Exemple #1
0
        private PageContext CreatePageContext(System.Web.HttpContextWrapper context)
        {
            PageContext pageContext = new PageContext();
            RouteData   routeData   = CreateRouteData();

            pageContext.RequestContext = this.CreateRequestContext(context, routeData);
            return(pageContext);
        }
Exemple #2
0
        public PersonalisationContext(string placeholder)
        {
            PageContext pageContext = this.CreatePageContext(new System.Web.HttpContextWrapper(HttpContext.Current));

            _context = ContextService.Get().Push(pageContext);
            var tracker = new NullTracker(new StandardSession())
            {
                IsActive = true
            };

            Context.Site.SetDisplayMode(DisplayMode.Normal, DisplayModeDuration.Temporary);
            _tracker     = new TrackerSwitcher(tracker);
            _placeholder = ContextService.Get().Push(new PlaceholderContext(placeholder));
        }
        public override void Process(InsertRenderingsArgs args)
        {
            //Get the merged item layout field value
            Field layoutField = args.ContextItem.Fields[FieldIDs.LayoutField];

            if (layoutField == null)
            {
                return;
            }

            string fieldValue = LayoutField.GetFieldValue(layoutField);

            if (string.IsNullOrEmpty(fieldValue))
            {
                return;
            }

            //Parse it for easier processing
            XDocument layout = XDocument.Parse(fieldValue);

            XmlBasedRenderingParser parser = new XmlBasedRenderingParser();

            //Build a shared page context
            Sitecore.Mvc.Presentation.PageContext pageCtx = new Sitecore.Mvc.Presentation.PageContext();

            HttpContextWrapper httpCtxWrapper = new HttpContextWrapper(HttpContext.Current);
            RouteData          routeData      = CreateRouteData();

            pageCtx.RequestContext = CreateRequestContext(httpCtxWrapper, routeData);

            string deviceId = Sitecore.Context.Device.ID.ToString();

            //Loop through the renderings
            foreach (RenderingReference renderingReference in args.Renderings)
            {
                string templateName = renderingReference.RenderingItem.InnerItem.TemplateName;

                //Only do the replacement for MVC renderings
                if (templateName == "View rendering" || templateName == "Controller rendering" || templateName == "Item rendering")
                {
                    XElement  renderingXml = layout.XPathSelectElement("/r/d[@id='" + deviceId + "']/r[@id='" + renderingReference.RenderingID + "']");
                    Rendering rendering    = parser.Parse(renderingXml, false);

                    renderingReference.SetControl(new RenderingWrapper(rendering, pageCtx));
                }
            }
        }
        public override void Process(InsertRenderingsArgs args)
        {
            //Get the merged item layout field value
            Field layoutField = args.ContextItem.Fields[FieldIDs.LayoutField];
            if (layoutField == null)
            {
                return;
            }

            string fieldValue = LayoutField.GetFieldValue(layoutField);
            if (string.IsNullOrEmpty(fieldValue))
            {
                return;
            }

            //Parse it for easier processing
            XDocument layout = XDocument.Parse(fieldValue);

            XmlBasedRenderingParser parser = new XmlBasedRenderingParser();

            //Build a shared page context
            Sitecore.Mvc.Presentation.PageContext pageCtx = new Sitecore.Mvc.Presentation.PageContext();

            HttpContextWrapper httpCtxWrapper = new HttpContextWrapper(HttpContext.Current);
            RouteData routeData = CreateRouteData();

            pageCtx.RequestContext = CreateRequestContext(httpCtxWrapper, routeData);

            string deviceId = Sitecore.Context.Device.ID.ToString();

            //Loop through the renderings
            foreach (RenderingReference renderingReference in args.Renderings)
            {
                string templateName = renderingReference.RenderingItem.InnerItem.TemplateName;

                //Only do the replacement for MVC renderings
                if (templateName == "View rendering" || templateName == "Controller rendering" || templateName == "Item rendering")
                {
                    XElement renderingXml = layout.XPathSelectElement("/r/d[@id='" + deviceId + "']/r[@id='" + renderingReference.RenderingID + "']");
                    Rendering rendering = parser.Parse(renderingXml, false);

                    renderingReference.SetControl(new RenderingWrapper(rendering, pageCtx));
                }
            }
        }
 public RenderingWrapper(Rendering rendering, Sitecore.Mvc.Presentation.PageContext pageCtx)
 {
     _rendering = rendering;
     _pageCtx   = pageCtx;
 }
Exemple #6
0
 public void DemoContent_RenderingContextNotDerivedFromSpecificTemplate_ShouldThrowException(Db db, [Substitute] Sitecore.Mvc.Presentation.PageContext pageContext, [Frozen] IDemoStateService demoState, [Greedy] DemoController sut, Item ctxItem)
 {
     pageContext.Database.Returns(db.Database);
     Sitecore.Mvc.Common.ContextService.Get().Push(pageContext);
     demoState.IsDemoEnabled.Returns(true);
     using (RenderingContext.EnterContext(new Rendering(), ctxItem))
     {
         sut.Invoking(x => x.DemoContent()).Should().Throw <InvalidDataSourceItemException>();
     }
 }
Exemple #7
0
 public void DemoContent_RenderingContextItemInitialized_ShouldReturnDemoContentView(Db db, [Substitute] Sitecore.Mvc.Presentation.PageContext pageContext, [Frozen] IDemoStateService demoState, [Greedy] DemoController sut, [Content] DemoContentItem item)
 {
     pageContext.Database.Returns(db.Database);
     Sitecore.Mvc.Common.ContextService.Get().Push(pageContext);
     demoState.IsDemoEnabled.Returns(true);
     using (RenderingContext.EnterContext(new Rendering(), db.GetItem(item.ID)))
     {
         sut.DemoContent().As <ViewResult>().Model.Should().BeOfType <DemoContent>();
     }
 }
 public RenderingWrapper(Rendering rendering, Sitecore.Mvc.Presentation.PageContext pageCtx)
 {
     _rendering = rendering;
     _pageCtx = pageCtx;
 }