Ejemplo n.º 1
0
        public RenderingFragmentCollection Execute(PageCompositionElement pp)
        {
            var batch   = new RenderingFragmentCollection();
            var allDesc = pp.GetAllDescendents().OfType <CachedContentPageCompositionElement>();

            foreach (var item in allDesc)
            {
                batch.RenderingResults.Add(item.ContentId, item.RenderingResult);
            }

            return(batch);
        }
Ejemplo n.º 2
0
        public RenderingFragmentCollection Execute(Page.Elements.PageComposition pageRendering, FragmentRenderMode renderMode)
        {
            var transformationResult = new RenderingFragmentCollection();

            var cached = new CachedContentFragmentRenderer().Execute(pageRendering.RootElement);

            transformationResult.Add(cached);

            foreach (var engine in _engines)
            {
                var localBatch = engine.Execute(pageRendering.RootElement);
                transformationResult.Add(localBatch);
            }

            return(transformationResult);
        }
        public RenderingFragmentCollection Execute(PageCompositionElement pp)
        {
            RenderingFragmentCollection collection = new RenderingFragmentCollection();

            var allDescendents = pp.GetAllDescendents().OfType <StaticContentPageElement>().ToList();

            foreach (var item in allDescendents)
            {
                var staticContent = item.ContentControl;

                collection.RenderingResults.Add(item.ContentId, new RenderingResult
                {
                    GlobalRendering          = staticContent.GlobalContent.ToDictionary(x => x.Key, x => new[] { x.Value }.ToList()),
                    InlineRenderingFragments = new List <IRenderingFragment> {
                        new HtmlOutput(staticContent.Html)
                    }
                });
            }

            return(collection);
        }
        public RenderingFragmentCollection Execute(PageCompositionElement pp)
        {
            RenderingFragmentCollection collection = new RenderingFragmentCollection();

            var allDescendents = pp.GetAllDescendents().OfType <ControllerPageCompositionElement>();

            foreach (var item in allDescendents)
            {
                //todo: cache.
                var descriptor = new ReflectedAsyncControllerDescriptor(item.Controller.GetType());

                using (var writer = new SwitchingHtmlWriter())
                {
                    var fake = new NoResponseHttpContextBase(HttpContext.Current, writer);
                    var rq   = new RequestContext
                    {
                        HttpContext = fake,
                    };
                    rq.RouteData = new RouteData();
                    rq.RouteData.Values.Add("controller", descriptor.ControllerName);
                    rq.RouteData.Values.Add("action", "Index");

                    writer.BeginWriting(item);
                    item.Controller.Execute(rq);
                    writer.EndWriting();


                    collection.RenderingResults.Add(item.ContentId, writer.output[item.ContentId]);

                    //var placeholderOrder = new Dictionary<string, int>();
                    //foreach (var phId in item.PlaceHolders.Keys)
                    //    placeholderOrder.Add(phId,
                    //        output.IndexOf($"[##Placeholder({nonce+"-"+phId})]", StringComparison.OrdinalIgnoreCase));

                    //var phLocations = placeholderOrder.OrderBy(x => x.Value).Select(x => x.Key).ToList();

                    //List<IRenderingFragment> captured = new List<IRenderingFragment>();
                    //var allSegments = phLocations.Select(x => new{Id=x,Marker=$"[##Placeholder({nonce+"-"+x})]"}).ToList();

                    //var remainingOutput = output;
                    //foreach (var segment in allSegments)
                    //{
                    //    var at = remainingOutput.IndexOf(segment.Marker,StringComparison.OrdinalIgnoreCase);
                    //    if (at == -1)
                    //        throw new Exception("Placeholder with id '" + segment.Id+
                    //                            "' was defined in the internal layout, but was not rendered.");

                    //    var capturedHtml = remainingOutput.Substring(0, at);
                    //    if (capturedHtml.Length >0)
                    //        captured.Add(new HtmlOutput(capturedHtml));

                    //    captured.Add(new LayoutSubstitutionOutput{Id=segment.Id});

                    //    remainingOutput = remainingOutput.Substring(at + segment.Marker.Length);
                    //}
                    //if (remainingOutput.Length >0)
                    //    captured.Add(new HtmlOutput(remainingOutput));



                    //collection.WidgetContent.Add(item.ContentId,captured);
                }
            }
            return(collection);
        }