示例#1
0
        public MobilePage GetPage(int id, string parameter = "")
        {
            var person = GetPerson();

            if (!HttpContext.Current.Items.Contains("CurrentPerson"))
            {
                HttpContext.Current.Items.Add("CurrentPerson", person);
            }

            var pageCache = PageCache.Read(id);

            if (!pageCache.IsAuthorized(Authorization.VIEW, person))
            {
                return(new MobilePage());
            }

            SavePageViewInteraction(pageCache, person);

            string theme      = pageCache.Layout.Site.Theme;
            string layout     = pageCache.Layout.FileName;
            string layoutPath = PageCache.FormatPath(theme, layout);

            Rock.Web.UI.RockPage cmsPage = (Rock.Web.UI.RockPage)BuildManager.CreateInstanceFromVirtualPath(layoutPath, typeof(Rock.Web.UI.RockPage));

            MobilePage mobilePage = new MobilePage();

            mobilePage.Layout    = AvalancheUtilities.GetLayout(pageCache.Layout.Name);
            mobilePage.Title     = pageCache.PageTitle;
            mobilePage.ShowTitle = pageCache.PageDisplayTitle;
            foreach (var attribute in pageCache.AttributeValues)
            {
                mobilePage.Attributes.Add(attribute.Key, attribute.Value.ValueFormatted);
            }
            foreach (var block in pageCache.Blocks)
            {
                if (block.IsAuthorized(Authorization.VIEW, person))
                {
                    var blockCache = BlockCache.Read(block.Id);
                    try
                    {
                        var control = ( RockBlock )cmsPage.TemplateControl.LoadControl(blockCache.BlockType.Path);
                        if (control is RockBlock && control is IMobileResource)
                        {
                            control.SetBlock(pageCache, blockCache);
                            var mobileResource = control as IMobileResource;
                            var mobileBlock    = mobileResource.GetMobile(parameter);
                            mobileBlock.BlockId = blockCache.Id;
                            mobileBlock.Zone    = blockCache.Zone;
                            mobilePage.Blocks.Add(mobileBlock);
                        }
                    }
                    catch (Exception e)
                    {
                        ExceptionLogService.LogException(e, HttpContext.Current);
                    }
                }
            }
            HttpContext.Current.Response.Headers.Set("TTL", pageCache.OutputCacheDuration.ToString());
            return(mobilePage);
        }