示例#1
0
        public static IActionResult MasterPageDesigner(this Controller controller, string masterPageId, string masterPageVersionCode, ShellSettings shellSettings)
        {
            var contentView = "/UI/Views/Public/Layouts/Empty.cshtml";
            var baseContext = CreateGenericRenderingContext(contentView, null);

            var masterPageSettings = new MasterPageSettings
            {
                MasterPageId = masterPageId,
                VersionCode  = masterPageVersionCode,
                Editable     = true
            };

            var services     = controller.HttpContext.RequestServices;
            var ShellContext = CreateMasterRenderingContext(services, baseContext, shellSettings);

            SetRenderingContext(controller, ShellContext);

            return(controller.View("/UI/Views/Rendering/MasterShell.cshtml", ShellContext));
        }
示例#2
0
        private static ShellContext CreateMasterRenderingContext(IServiceProvider services, RenderingContext baseContext, ShellSettings shellSettings)
        {
            var contentManager      = services.GetService <ContentManager>();
            var masterPageManager   = services.GetService <PageMasterManager>();
            var siteContextAccessor = services.GetService <IContextAccessor <SiteContext> >();
            var siteContext         = siteContextAccessor.GetContext();

            var masterPage = masterPageManager.GetSiteDefaultAsync(siteContext.SiteId).Result;

            if (masterPage == null || masterPage.SiteId != siteContext.SiteId)
            {
                throw new Exception($"Could not locate the deefault Master Page for Site {siteContext.SiteId}");
            }

            var masterPageSettings = new MasterPageSettings
            {
                MasterPageId = masterPage.Id,
                VersionCode  = null, // will retrieve published version
                Editable     = false
            };


            return(CreateMasterRenderingContext(services, baseContext, masterPageSettings, shellSettings));
        }
示例#3
0
        public static IActionResult MasterPageView(this Controller controller, ContentBindings contentBindings, MasterPageSettings masterPageSettings, ShellSettings shellSettings = null)
        {
            var services     = controller.HttpContext.RequestServices;
            var baseContext  = CreateBaseRenderingContext(services, contentBindings);
            var ShellContext = CreateMasterRenderingContext(services, baseContext, masterPageSettings, shellSettings);

            SetRenderingContext(controller, ShellContext);

            return(controller.View("/UI/Views/Rendering/MasterShell.cshtml", ShellContext));
        }
示例#4
0
        private static ShellContext CreateMasterRenderingContext(IServiceProvider services, RenderingContext baseContext, MasterPageSettings masterPageSettings, ShellSettings shellSettings)
        {
            var siteContextAccessor = services.GetService <IContextAccessor <SiteContext> >();
            var contentManager      = services.GetService <ContentManager>();
            var masterPageManager   = services.GetService <PageMasterManager>();

            var siteContext           = siteContextAccessor.GetContext();
            var masterPage            = masterPageManager.GetByIdAsync(masterPageSettings.MasterPageId).Result;
            var masterPageContentType = typeof(PageMaster).FullName;

            if (masterPage == null)
            {
                throw new Exception($"Could not locate a Master Page {masterPageSettings.MasterPageId}");
            }

            var masterPageTemplate = siteContext.Template.PageTemplates.FirstOrDefault(x => x.Id == masterPage.TemplateId);

            if (masterPageTemplate == null)
            {
                throw new Exception($"Could not locate Master Page Template {masterPage.TemplateId}");
            }

            // Version Info & Content Tree
            var masterPageVersion = masterPageSettings.VersionCode == null
                ? contentManager.GetPublishedVersionInfo(masterPageContentType, masterPage.Id).Result
                : contentManager.GetVersionInfo(masterPageContentType, masterPage.Id, masterPageSettings.VersionCode).Result;

            if (masterPageVersion == null)
            {
                throw new Exception($"Could not locate version info for Master Page {masterPage.Id}");
            }

            var masterPageTreeId = contentManager.GetContentTreeId(masterPageVersion).Result;

            // Build master page bindings
            return(new ShellContext(baseContext)
            {
                MasterPageId = masterPage.Id,
                MasterPageVersionInfo = ToVersionInfo(masterPageVersion),
                MasterPageTreeId = masterPageTreeId,
                MasterPageTemplate = masterPageTemplate,
                MasterPageEditable = masterPageSettings.Editable,

                MetaTags = shellSettings.MetaTags,
                Toolbar = shellSettings.Toolbar,
                WindowTitle = shellSettings.WindowTitle
            });
        }