Exemplo n.º 1
0
        public void AttachToPage(Page aspnetPage, PageContentToRender contentToRender)
        {
            Verify.ArgumentNotNull(aspnetPage, "aspnetPage");
            Verify.ArgumentNotNull(contentToRender, "contentToRender");

            aspnetPage.Items.Add(PageRenderingJob_Key, contentToRender);

            Guid templateId = contentToRender.Page.TemplateId;
            var rendering = _renderingInfo[templateId];

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

                Verify.ThrowInvalidOperationException("Failed to get master page by template ID '{0}'. Check for compilation errors".FormatWith(templateId));
            }

            aspnetPage.MasterPageFile = rendering.VirtualPath;
            aspnetPage.PreRender += (e, args) => PageOnPreRender(aspnetPage, contentToRender.Page);

            var master = aspnetPage.Master as MasterPagePageTemplate;
            TemplateDefinitionHelper.BindPlaceholders(master, contentToRender, rendering.PlaceholderProperties, null);
        }
Exemplo n.º 2
0
        public void AttachToPage(Page renderTaget, PageContentToRender contentToRender)
        {
            _aspnetPage = renderTaget;
            _job = contentToRender;

            _aspnetPage.Init += RendererPage;
        }
        /// <summary>
        /// Binds placeholders' content to the related properties on a template definition
        /// </summary>
        /// <param name="template">The template.</param>
        /// <param name="pageContentToRender">The page rendering job.</param>
        /// <param name="placeholderProperties">The placeholder properties.</param>
        /// <param name="functionContextContainer">The function context container, if not null, nested functions fill be evaluated.</param>
        public static void BindPlaceholders(IPageTemplate template,
                                            PageContentToRender pageContentToRender,
                                            IDictionary <string, PropertyInfo> placeholderProperties,
                                            FunctionContextContainer functionContextContainer)
        {
            Verify.ArgumentNotNull(template, "template");
            Verify.ArgumentNotNull(pageContentToRender, "pageContentToRender");
            Verify.ArgumentNotNull(placeholderProperties, "placeholderProperties");

            foreach (var placeholderContent in pageContentToRender.Contents)
            {
                string placeholderId = placeholderContent.PlaceHolderId;

                if (!placeholderProperties.ContainsKey(placeholderId))
                {
                    continue;
                }

                XhtmlDocument placeholderXhtml = PageRenderer.ParsePlaceholderContent(placeholderContent);

                if (functionContextContainer != null)
                {
                    bool allFunctionsExecuted;

                    using (Profiler.Measure($"Evaluating placeholder '{placeholderId}'"))
                    {
                        allFunctionsExecuted = PageRenderer.ExecuteCacheableFunctions(placeholderXhtml.Root, functionContextContainer);
                    }

                    if (allFunctionsExecuted)
                    {
                        using (Profiler.Measure("Normalizing XHTML document"))
                        {
                            PageRenderer.NormalizeXhtmlDocument(placeholderXhtml);
                        }
                    }
                }

                PageRenderer.ResolveRelativePaths(placeholderXhtml);

                PropertyInfo property = placeholderProperties[placeholderId];

                if (!property.ReflectedType.IsInstanceOfType(template))
                {
                    string propertyName = property.Name;
                    property = template.GetType().GetProperty(property.Name);
                    Verify.IsNotNull(property, "Failed to find placeholder property '{0}'", propertyName);
                }

                property.SetValue(template, placeholderXhtml);
            }
        }
        /// <summary>
        /// Binds placeholders' content to the related properties on a template definition
        /// </summary>
        /// <param name="template">The template.</param>
        /// <param name="pageContentToRender">The page rendering job.</param>
        /// <param name="placeholderProperties">The placeholder properties.</param>
        /// <param name="functionContextContainer">The function context container, if not null, nested functions fill be evaluated.</param>
        public static void BindPlaceholders(IPageTemplate template,
                                            PageContentToRender pageContentToRender,
                                            IDictionary <string, PropertyInfo> placeholderProperties,
                                            FunctionContextContainer functionContextContainer)
        {
            Verify.ArgumentNotNull(template, "template");
            Verify.ArgumentNotNull(pageContentToRender, "pageContentToRender");
            Verify.ArgumentNotNull(placeholderProperties, "placeholderProperties");

            foreach (var placeholderContent in pageContentToRender.Contents)
            {
                string placeholderId = placeholderContent.PlaceHolderId;

                if (!placeholderProperties.ContainsKey(placeholderId))
                {
                    continue;
                }

                XhtmlDocument placeholderXhtml = PageRenderer.ParsePlaceholderContent(placeholderContent);

                if (functionContextContainer != null)
                {
                    using (Profiler.Measure("Evaluating placeholder '{0}'".FormatWith(placeholderId)))
                    {
                        PageRenderer.ExecuteEmbeddedFunctions(placeholderXhtml.Root, functionContextContainer);
                    }

                    PageRenderer.NormalizeXhtmlDocument(placeholderXhtml);
                }

                PageRenderer.ResolveRelativePaths(placeholderXhtml);

                PropertyInfo property = placeholderProperties[placeholderId];

                if (!property.ReflectedType.IsAssignableFrom(template.GetType()))
                {
                    string propertyName = property.Name;
                    property = template.GetType().GetProperty(property.Name);
                    Verify.IsNotNull(property, "Failed to find placeholder property '{0}'", propertyName);
                }

                property.SetValue(template, placeholderXhtml, new object[0]);
            }
        }
Exemplo n.º 5
0
        private void InitializeFromHttpContextInternal()
        {
            HttpContext httpContext = HttpContext.Current;
            var request = httpContext.Request;
            var response = httpContext.Response;

               ProfilingEnabled = request.Url.OriginalString.Contains("c1mode=perf");
            if (ProfilingEnabled)
            {
                if (!UserValidationFacade.IsLoggedIn())
                {
                    string loginUrl = GetLoginRedirectUrl(request.RawUrl);
                    response.Write(@"You must be logged into <a href=""" + loginUrl + @""">C1 console</a> to have the performance view enabled");
                    response.End(); // throws ThreadAbortException
                    return;
                }

                Profiler.BeginProfiling();
                _pagePerfMeasuring = Profiler.Measure("C1 Page");
            }

            _previewKey = request.QueryString["previewKey"];
            PreviewMode = !_previewKey.IsNullOrEmpty();

            if (PreviewMode)
            {
                Page = (IPage)HttpRuntime.Cache.Get(_previewKey + "_SelectedPage");
                C1PageRoute.PageUrlData = new PageUrlData(Page);

                PageRenderer.RenderingReason = (RenderingReason) HttpRuntime.Cache.Get(_previewKey + "_RenderingReason");
            }
            else
            {
                PageUrlData pageUrl = C1PageRoute.PageUrlData ??  PageUrls.UrlProvider.ParseInternalUrl(request.Url.OriginalString);
                Page = pageUrl.GetPage();

                _cachedUrl = request.Url.PathAndQuery;

                PageRenderer.RenderingReason = new UrlSpace(httpContext).ForceRelativeUrls
                    ? RenderingReason.C1ConsoleBrowserPageView
                    : RenderingReason.PageView;
            }

            ValidateViewUnpublishedRequest(httpContext);

            if (Page == null)
            {
                throw new HttpException(404, "Page not found - either this page has not been published yet or it has been deleted.");
            }

            if (Page.DataSourceId.PublicationScope != PublicationScope.Published || request.IsSecureConnection)
            {
                response.Cache.SetCacheability(HttpCacheability.NoCache);
                CachingDisabled = true;
            }

            PageRenderer.CurrentPage = Page;

            _dataScope = new DataScope(Page.DataSourceId.PublicationScope, Page.DataSourceId.LocaleScope);

            var pagePlaceholderContents = GetPagePlaceholderContents();
            var pageRenderingJob = new PageContentToRender(Page, pagePlaceholderContents, PreviewMode);

            Verify.IsNotNull(httpContext.Handler, "HttpHandler isn't defined");

            var aspnetPage = (System.Web.UI.Page)httpContext.Handler;

            var pageRenderer = PageTemplateFacade.BuildPageRenderer(Page.TemplateId);
            pageRenderer.AttachToPage(aspnetPage, pageRenderingJob);
        }