/// <exclude />
        protected override void OnInit(System.EventArgs e)
        {
            XhtmlDocument            feature = PageTemplateFeatureFacade.GetPageTemplateFeature(this.Name);
            FunctionContextContainer functionContextContainer = PageRenderer.GetPageRenderFunctionContextContainer();

            var markup = new Markup(feature.Root, functionContextContainer);

            Controls.Add(markup);

            base.OnInit(e);
        }
        private void editPreviewCodeActivity_ExecuteCode(object sender, EventArgs e)
        {
            try
            {
                XhtmlDocument templateDocument = GetTemplateDocumentFromBindings();

                IVisualFunction function      = this.GetBinding <IVisualFunction>("Function");
                Type            interfaceType = TypeManager.GetType(function.TypeManagerName);

                DataTypeDescriptor typeDescriptor = DynamicTypeManager.GetDataTypeDescriptor(interfaceType);

                this.LogMessage(Composite.Core.Logging.LogLevel.Info, DataScopeManager.CurrentDataScope.Name);

                FunctionContextContainer fcc = PageRenderer.GetPageRenderFunctionContextContainer();

                XhtmlDocument result = RenderingHelper.RenderCompleteDataList(function, templateDocument, typeDescriptor, fcc);

                IPage previewPage = DataFacade.BuildNew <IPage>();
                previewPage.Id    = GetRootPageId();
                previewPage.Title = function.Name;
                previewPage.DataSourceId.DataScopeIdentifier = DataScopeIdentifier.Administrated;
                previewPage.DataSourceId.LocaleScope         = LocalizationScopeManager.CurrentLocalizationScope;

                previewPage.TemplateId = this.GetBinding <Guid>("PreviewTemplateId");

                var pageTemplate = PageTemplateFacade.GetPageTemplate(previewPage.TemplateId);
                IPagePlaceholderContent placeHolderContent = DataFacade.BuildNew <IPagePlaceholderContent>();
                placeHolderContent.Content       = string.Concat((result.Body.Elements().Select(b => b.ToString())).ToArray());
                placeHolderContent.PlaceHolderId = pageTemplate.DefaultPlaceholderId;

                string output = PagePreviewBuilder.RenderPreview(previewPage, new List <IPagePlaceholderContent> {
                    placeHolderContent
                });

                var serviceContainer = WorkflowFacade.GetFlowControllerServicesContainer(WorkflowEnvironment.WorkflowInstanceId);

                var webRenderService = serviceContainer.GetService <IFormFlowWebRenderingService>();
                webRenderService.SetNewPageOutput(new LiteralControl(output));
            }
            catch (Exception ex)
            {
                FlowControllerServicesContainer serviceContainer = WorkflowFacade.GetFlowControllerServicesContainer(WorkflowEnvironment.WorkflowInstanceId);
                Control errOutput        = new LiteralControl("<pre>" + ex + "</pre>");
                var     webRenderService = serviceContainer.GetService <IFormFlowWebRenderingService>();
                webRenderService.SetNewPageOutput(errOutput);
            }
        }
Esempio n. 3
0
        /// <exclude />
        protected override void CreateChildControls()
        {
            if (InnerContent == null)
            {
                ProcessInternalControls();
            }

            if (InnerContent != null)
            {
                var functionContextContainer = _functionContextContainer;
                if (functionContextContainer == null && this.NamingContainer is UserControlFunction)
                {
                    var containerFunction = this.NamingContainer as UserControlFunction;
                    functionContextContainer = containerFunction.FunctionContextContainer;
                }

                if (functionContextContainer == null)
                {
                    functionContextContainer = PageRenderer.GetPageRenderFunctionContextContainer();
                }
                var controlMapper = (IXElementToControlMapper)functionContextContainer.XEmbedableMapper;

                PageRenderer.ExecuteEmbeddedFunctions(InnerContent, functionContextContainer);

                var xhmlDocument = new XhtmlDocument(InnerContent);

                PageRenderer.NormalizeXhtmlDocument(xhmlDocument);
                PageRenderer.ResolveRelativePaths(xhmlDocument);

                if (PageRenderer.CurrentPage != null)
                {
                    PageRenderer.ResolvePageFields(xhmlDocument, PageRenderer.CurrentPage);
                }

                NormalizeAspNetForms(xhmlDocument);

                AddNodesAsControls(xhmlDocument.Body.Nodes(), this, controlMapper);

                if (Page.Header != null)
                {
                    MergeHeadSection(xhmlDocument, Page.Header, controlMapper);
                }
            }

            base.CreateChildControls();
        }
Esempio n. 4
0
        private void RendererPage(object sender, EventArgs e)
        {
            var functionContextContainer = PageRenderer.GetPageRenderFunctionContextContainer();

            var resultDocument = Render(_job, functionContextContainer);

            var     controlMapper = (IXElementToControlMapper)functionContextContainer.XEmbedableMapper;
            Control control;

            using (Profiler.Measure("Rendering the page"))
            {
                control = PageRenderer.Render(resultDocument, functionContextContainer, controlMapper, _job.Page);
            }

            using (Profiler.Measure("ASP.NET controls: PagePreInit"))
            {
                _aspnetPage.Controls.Add(control);
            }
        }
Esempio n. 5
0
        public void ProcessRequest(HttpContext context)
        {
            OutputCacheHelper.InitializeFullPageCaching(context);

            using (var renderingContext = RenderingContext.InitializeFromHttpContext())
            {
                bool            cachingEnabled = false;
                string          cacheKey       = null;
                DonutCacheEntry cacheEntry     = null;

                bool consoleUserLoggedIn = Composite.C1Console.Security.UserValidationFacade.IsLoggedIn();

                // "Donut caching" is enabled for logged in users, only if profiling is enabled as well.
                if (!renderingContext.CachingDisabled &&
                    (!consoleUserLoggedIn || renderingContext.ProfilingEnabled))
                {
                    cachingEnabled = OutputCacheHelper.TryGetCacheKey(context, out cacheKey);
                    if (cachingEnabled)
                    {
                        using (Profiler.Measure("Cache lookup"))
                        {
                            cacheEntry = OutputCacheHelper.GetFromCache(context, cacheKey);
                        }
                    }
                }

                XDocument document;
                var       functionContext = PageRenderer.GetPageRenderFunctionContextContainer();

                bool allFunctionsExecuted   = false;
                bool preventResponseCaching = false;

                if (cacheEntry != null)
                {
                    document = cacheEntry.Document;
                    foreach (var header in cacheEntry.OutputHeaders)
                    {
                        context.Response.Headers[header.Name] = header.Value;
                    }

                    // Making sure this response will not go to the output cache
                    preventResponseCaching = true;
                }
                else
                {
                    if (renderingContext.RunResponseHandlers())
                    {
                        return;
                    }

                    var renderer = PageTemplateFacade.BuildPageRenderer(renderingContext.Page.TemplateId);

                    var slimRenderer = (ISlimPageRenderer)renderer;

                    using (Profiler.Measure($"{nameof(ISlimPageRenderer)}.Render"))
                    {
                        document = slimRenderer.Render(renderingContext.PageContentToRender, functionContext);
                    }

                    allFunctionsExecuted = PageRenderer.ExecuteCacheableFunctions(document.Root, functionContext);

                    if (cachingEnabled && !allFunctionsExecuted && OutputCacheHelper.ResponseCacheable(context))
                    {
                        preventResponseCaching = true;

                        if (!functionContext.ExceptionsSuppressed)
                        {
                            using (Profiler.Measure("Adding to cache"))
                            {
                                OutputCacheHelper.AddToCache(context, cacheKey, new DonutCacheEntry(context, document));
                            }
                        }
                    }
                }

                if (!allFunctionsExecuted)
                {
                    using (Profiler.Measure("Executing embedded functions"))
                    {
                        PageRenderer.ExecuteEmbeddedFunctions(document.Root, functionContext);
                    }
                }

                using (Profiler.Measure("Resolving page fields"))
                {
                    PageRenderer.ResolvePageFields(document, renderingContext.Page);
                }

                string xhtml;
                if (document.Root.Name == RenderingElementNames.Html)
                {
                    var xhtmlDocument = new XhtmlDocument(document);

                    PageRenderer.ProcessXhtmlDocument(xhtmlDocument, renderingContext.Page);
                    PageRenderer.ProcessDocumentHead(xhtmlDocument);

                    xhtml = xhtmlDocument.ToString();
                }
                else
                {
                    xhtml = document.ToString();
                }

                if (renderingContext.PreRenderRedirectCheck())
                {
                    return;
                }

                xhtml = renderingContext.ConvertInternalLinks(xhtml);

                if (GlobalSettingsFacade.PrettifyPublicMarkup)
                {
                    xhtml = renderingContext.FormatXhtml(xhtml);
                }

                var response = context.Response;

                if (preventResponseCaching)
                {
                    context.Response.Cache.SetNoServerCaching();
                }

                // Disabling ASP.NET cache if there's a logged-in user
                if (consoleUserLoggedIn)
                {
                    context.Response.Cache.SetCacheability(HttpCacheability.NoCache);
                }

                // Inserting performance profiling information
                if (renderingContext.ProfilingEnabled)
                {
                    xhtml = renderingContext.BuildProfilerReport();

                    response.ContentType = "text/xml";
                }

                response.Write(xhtml);
            }
        }
Esempio n. 6
0
        private void RendererPage(object sender, EventArgs e)
        {
            Guid templateId    = _job.Page.TemplateId;
            var  renderingInfo = _renderingInfo[templateId];

            if (renderingInfo == null)
            {
                Exception loadingException = _loadingExceptions[templateId];
                if (loadingException != null)
                {
                    throw loadingException;
                }

                Verify.ThrowInvalidOperationException("Missing template '{0}'".FormatWith(templateId));
            }

            string output;
            FunctionContextContainer functionContextContainer;

            RazorPageTemplate webPage = null;

            try
            {
                webPage = WebPageBase.CreateInstanceFromVirtualPath(renderingInfo.ControlVirtualPath) as AspNet.Razor.RazorPageTemplate;
                Verify.IsNotNull(webPage, "Razor compilation failed or base type does not inherit '{0}'",
                                 typeof(AspNet.Razor.RazorPageTemplate).FullName);

                webPage.Configure();

                functionContextContainer = PageRenderer.GetPageRenderFunctionContextContainer();

                using (Profiler.Measure("Evaluating placeholders"))
                {
                    TemplateDefinitionHelper.BindPlaceholders(webPage, _job, renderingInfo.PlaceholderProperties,
                                                              functionContextContainer);
                }

                // Executing razor code
                var httpContext = new HttpContextWrapper(HttpContext.Current);
                var startPage   = StartPage.GetStartPage(webPage, "_PageStart", new[] { "cshtml" });
                var pageContext = new WebPageContext(httpContext, webPage, startPage);
                pageContext.PageData.Add(RazorHelper.PageContext_FunctionContextContainer, functionContextContainer);

                var sb = new StringBuilder();
                using (var writer = new StringWriter(sb))
                {
                    using (Profiler.Measure("Executing Razor page template"))
                    {
                        webPage.ExecutePageHierarchy(pageContext, writer);
                    }
                }

                output = sb.ToString();
            }
            finally
            {
                if (webPage != null)
                {
                    webPage.Dispose();
                }
            }

            XDocument resultDocument = XDocument.Parse(output);

            var     controlMapper = (IXElementToControlMapper)functionContextContainer.XEmbedableMapper;
            Control control       = PageRenderer.Render(resultDocument, functionContextContainer, controlMapper, _job.Page);

            using (Profiler.Measure("ASP.NET controls: PagePreInit"))
            {
                _aspnetPage.Controls.Add(control);
            }
        }
Esempio n. 7
0
 public PageRendererHelper()
 {
     FunctionContext = PageRenderer.GetPageRenderFunctionContextContainer();
 }
Esempio n. 8
0
        public override void ExecuteResult(ControllerContext context)
        {
            string markup;

            using (TimerProfilerFacade.CreateTimerProfiler())
            {
                var page          = PageRenderer.CurrentPage;
                var markupBuilder = new StringBuilder();
                var sw            = new StringWriter(markupBuilder);
                var output        = new HtmlTextWriter(sw);

                IView view;
                using (Profiler.Measure("Resolving view for template"))
                {
                    view = FindView(context).View;
                }

                var viewContext = new ViewContext(context, view, ViewData, TempData, output);

                view.Render(viewContext, output);

                markup = markupBuilder.ToString();
                var xml = XDocument.Parse(markup);

                var functionContext = PageRenderer.GetPageRenderFunctionContextContainer();

                functionContext = new FunctionContextContainer(functionContext, new Dictionary <string, object>
                {
                    { "viewContext", viewContext }
                });

                using (Profiler.Measure("Executing embedded functions"))
                {
                    PageRenderer.ExecuteEmbeddedFunctions(xml.Root, functionContext);
                }

                using (Profiler.Measure("Resolving pagefields"))
                {
                    PageRenderer.ResolvePageFields(xml, page);
                }

                var document = new XhtmlDocument(xml);

                using (Profiler.Measure("Normalizing html"))
                {
                    PageRenderer.NormalizeXhtmlDocument(document);
                }

                PageRenderer.ResolveRelativePaths(document);
                PageRenderer.AppendC1MetaTags(page, document);

                using (Profiler.Measure("Resolving localized strings"))
                {
                    LocalizationParser.Parse(document);
                }

                markup = document.ToString();

                using (Profiler.Measure("Changing 'internal' page urls to 'public'"))
                {
                    markup = PageUrlHelper.ChangeRenderingPageUrlsToPublic(markup);
                }

                using (Profiler.Measure("Changing 'internal' media urls to 'public'"))
                {
                    markup = MediaUrlHelper.ChangeInternalMediaUrlsToPublic(markup);
                }

                markup = _mvcContext.FormatXhtml(markup);
            }

            if (_mvcContext.ProfilingEnabled)
            {
                markup = _mvcContext.BuildProfilerReport();

                context.HttpContext.Response.ContentType = "text/xml";
            }

            context.HttpContext.Response.Write(markup);
        }
Esempio n. 9
0
        /// <exclude />
        protected override void OnInit(EventArgs e)
        {
            Type   returnType;
            object result;
            string functionName = Name;

            var functionContextContainer = PageRenderer.GetPageRenderFunctionContextContainer();

            try
            {
                result = GetValue(functionContextContainer, out returnType);
            }
            catch (Exception ex)
            {
                XElement errorBoxHtml;
                if (!functionContextContainer.ProcessException(functionName, ex, LogTitle, out errorBoxHtml))
                {
                    throw;
                }

                result     = errorBoxHtml;
                returnType = typeof(XElement);
            }

            if (result != null)
            {
                if (returnType == typeof(XElement) || returnType == typeof(XhtmlDocument))
                {
                    var element = ValueTypeConverter.Convert <XElement>(result);
                    var markup  = new Markup(element, functionContextContainer);

                    Controls.Add(markup);
                }
                else if (typeof(Control).IsAssignableFrom(returnType))
                {
                    var control = (Control)result;

                    Controls.Add(control);
                }
                else if (result is IEnumerable <XNode> )
                {
                    var nodes = result as IEnumerable <XNode>;

                    foreach (XNode node in nodes)
                    {
                        if (node == null)
                        {
                            continue;
                        }

                        if (node is XElement)
                        {
                            var markup = new Markup(node as XElement, functionContextContainer);

                            Controls.Add(markup);
                        }
                        else
                        {
                            Controls.Add(new LiteralControl(node.ToString()));
                        }
                    }
                }
                else if (result is XAttribute)
                {
                    var parentControl = this.Parent as HtmlGenericControl;
                    if (parentControl != null)
                    {
                        var attr = (XAttribute)result;
                        parentControl.Attributes.Add(attr.Name.ToString(), attr.Value);
                    }
                    else
                    {
                        const string comment = @"<!-- Failed to add attribute, parent control should be of type HtmlGenericControl, check that runat=""server"" attribute is added -->";
                        Controls.Add(new LiteralControl(comment));
                    }
                }
                else
                {
                    var str = result.ToString();

                    Controls.Add(new LiteralControl(str));
                }
            }

            base.OnInit(e);
        }