/// <summary>
        /// Handles the Click event of the DeleteLayout control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="Rock.Web.UI.Controls.RowEventArgs" /> instance containing the event data.</param>
        protected void DeleteLayout_Click(object sender, Rock.Web.UI.Controls.RowEventArgs e)
        {
            bool canDelete = false;

            var           rockContext   = new RockContext();
            LayoutService layoutService = new LayoutService(rockContext);

            Layout layout = layoutService.Get(e.RowKeyId);

            if (layout != null)
            {
                string errorMessage;
                canDelete = layoutService.CanDelete(layout, out errorMessage);
                if (!canDelete)
                {
                    mdGridWarning.Show(errorMessage, ModalAlertType.Alert);
                    return;
                }

                int siteId = layout.SiteId;

                layoutService.Delete(layout);
                rockContext.SaveChanges();

                LayoutCache.Flush(e.RowKeyId);
            }

            BindLayoutsGrid();
        }
Beispiel #2
0
        /// <summary>
        /// Returns Layout object from cache.  If Layout does not already exist in cache, it
        /// will be read and added to cache
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public static LayoutCache Read(int id)
        {
            string cacheKey = LayoutCache.CacheKey(id);

            ObjectCache cache  = MemoryCache.Default;
            LayoutCache Layout = cache[cacheKey] as LayoutCache;

            if (Layout != null)
            {
                return(Layout);
            }
            else
            {
                var LayoutService = new LayoutService();
                var LayoutModel   = LayoutService.Get(id);
                if (LayoutModel != null)
                {
                    LayoutModel.LoadAttributes();
                    Layout = new LayoutCache(LayoutModel);

                    var cachePolicy = new CacheItemPolicy();
                    cache.Set(cacheKey, Layout, cachePolicy);
                    cache.Set(Layout.Guid.ToString(), Layout.Id, cachePolicy);

                    return(Layout);
                }
                else
                {
                    return(null);
                }
            }
        }
Beispiel #3
0
        /// <summary>
        /// Reads the specified GUID.
        /// </summary>
        /// <param name="guid">The GUID.</param>
        /// <returns></returns>
        public static LayoutCache Read(Guid guid)
        {
            ObjectCache cache    = MemoryCache.Default;
            object      cacheObj = cache[guid.ToString()];

            if (cacheObj != null)
            {
                return(Read((int)cacheObj));
            }
            else
            {
                var LayoutService = new LayoutService();
                var LayoutModel   = LayoutService.Get(guid);
                if (LayoutModel != null)
                {
                    LayoutModel.LoadAttributes();
                    var Layout = new LayoutCache(LayoutModel);

                    var cachePolicy = new CacheItemPolicy();
                    cache.Set(LayoutCache.CacheKey(Layout.Id), Layout, cachePolicy);
                    cache.Set(Layout.Guid.ToString(), Layout.Id, cachePolicy);

                    return(Layout);
                }
                else
                {
                    return(null);
                }
            }
        }
Beispiel #4
0
        /// <summary>
        /// Handles the Click event of the DeleteLayout control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="Rock.Web.UI.Controls.RowEventArgs" /> instance containing the event data.</param>
        protected void DeleteLayout_Click(object sender, Rock.Web.UI.Controls.RowEventArgs e)
        {
            RockTransactionScope.WrapTransaction(() =>
            {
                LayoutService layoutService = new LayoutService();
                Layout layout = layoutService.Get(e.RowKeyId);
                if (layout != null)
                {
                    string errorMessage;
                    if (!layoutService.CanDelete(layout, out errorMessage))
                    {
                        mdGridWarning.Show(errorMessage, ModalAlertType.Information);
                        return;
                    }

                    int siteId = layout.SiteId;

                    layoutService.Delete(layout, CurrentPersonId);
                    layoutService.Save(layout, CurrentPersonId);

                    LayoutCache.Flush(e.RowKeyId);
                }
            });

            BindLayoutsGrid();
        }
        /// <summary>
        /// Handles the Click event of the lbSave control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
        protected void lbSave_Click(object sender, EventArgs e)
        {
            var rockContext   = new RockContext();
            var layoutService = new LayoutService(rockContext);

            var layout = layoutService.Get(PageParameter("LayoutId").AsInteger());

            if (layout == null)
            {
                layout = new Layout
                {
                    SiteId = PageParameter("SiteId").AsInteger()
                };
                layoutService.Add(layout);
            }

            layout.Name               = tbName.Text;
            layout.FileName           = tbName.Text + ".xaml";
            layout.Description        = tbDescription.Text;
            layout.LayoutMobilePhone  = cePhoneLayout.Text;
            layout.LayoutMobileTablet = ceTabletLayout.Text;

            rockContext.SaveChanges();

            NavigateToParentPage(new Dictionary <string, string>
            {
                { "SiteId", PageParameter("SiteId") },
                { "Tab", "Layouts" }
            });
        }
        public void OnActionExecuted(ActionExecutedContext filterContext)
        {
            ZoneWidgetCollection zones = new ZoneWidgetCollection();

            //Page
            string      pageId      = filterContext.RequestContext.HttpContext.Request.QueryString["ID"];
            PageService pageService = new PageService();
            PageEntity  page        = pageService.Get(pageId);

            if (page != null)
            {
                LayoutService layoutService = new LayoutService();
                var           layout        = layoutService.Get(page.LayoutId);
                layout.Page = page;
                WidgetService            widgetService = new WidgetService();
                IEnumerable <WidgetBase> widgets       = widgetService.Get(new DataFilter().Where <WidgetBase>(m => m.PageID, OperatorType.Equal, page.ID));
                Action <WidgetBase>      processWidget = m =>
                {
                    IWidgetPartDriver partDriver = Activator.CreateInstance(m.AssemblyName, m.ServiceTypeName).Unwrap() as IWidgetPartDriver;
                    WidgetPart        part       = partDriver.Display(partDriver.GetWidget(m), filterContext.HttpContext);
                    lock (zones)
                    {
                        if (zones.ContainsKey(part.Widget.ZoneID))
                        {
                            zones[part.Widget.ZoneID].Add(part);
                        }
                        else
                        {
                            WidgetCollection partCollection = new WidgetCollection();
                            partCollection.Add(part);
                            zones.Add(part.Widget.ZoneID, partCollection);
                        }
                    }
                };
                widgets.Each(processWidget);

                IEnumerable <WidgetBase> Layoutwidgets = widgetService.Get(new Data.DataFilter().Where <WidgetBase>(m => m.LayoutID, OperatorType.Equal, page.LayoutId));

                Layoutwidgets.Each(processWidget);

                layout.ZoneWidgets = zones;
                ViewResult viewResult = (filterContext.Result as ViewResult);
                if (viewResult != null)
                {
                    viewResult.MasterName = "~/Modules/Common/Views/Shared/_DesignPageLayout.cshtml";
                    viewResult.ViewData[LayoutEntity.LayoutKey] = layout;
                }
            }
            else
            {
                filterContext.Result = new HttpStatusCodeResult(404);
            }
        }
Beispiel #7
0
        private static LayoutCache LoadById2(int id, RockContext rockContext)
        {
            var layoutService = new LayoutService(rockContext);
            var layoutModel   = layoutService.Get(id);

            if (layoutModel != null)
            {
                return(new LayoutCache(layoutModel));
            }

            return(null);
        }
        public void OnActionExecuted(ActionExecutedContext filterContext)
        {
            ZoneWidgetCollection zones = new ZoneWidgetCollection();

            //Page
            string pageId = filterContext.RequestContext.HttpContext.Request.QueryString["ID"];
            PageService pageService = new PageService();
            PageEntity page = pageService.Get(pageId);

            if (page != null)
            {
                LayoutService layoutService = new LayoutService();
                var layout = layoutService.Get(page.LayoutId);
                layout.Page = page;
                WidgetService widgetService = new WidgetService();
                IEnumerable<WidgetBase> widgets = widgetService.Get(new DataFilter().Where<WidgetBase>(m => m.PageID, OperatorType.Equal, page.ID));
                Action<WidgetBase> processWidget = m =>
                {
                    IWidgetPartDriver partDriver = Activator.CreateInstance(m.AssemblyName, m.ServiceTypeName).Unwrap() as IWidgetPartDriver;
                    WidgetPart part = partDriver.Display(partDriver.GetWidget(m), filterContext.HttpContext);
                    lock (zones)
                    {
                        if (zones.ContainsKey(part.Widget.ZoneID))
                        {
                            zones[part.Widget.ZoneID].Add(part);
                        }
                        else
                        {
                            WidgetCollection partCollection = new WidgetCollection();
                            partCollection.Add(part);
                            zones.Add(part.Widget.ZoneID, partCollection);
                        }
                    }
                };
                widgets.Each(processWidget);

                IEnumerable<WidgetBase> Layoutwidgets = widgetService.Get(new Data.DataFilter().Where<WidgetBase>(m => m.LayoutID, OperatorType.Equal, page.LayoutId));

                Layoutwidgets.Each(processWidget);

                layout.ZoneWidgets = zones;
                ViewResult viewResult = (filterContext.Result as ViewResult);
                if (viewResult != null)
                {
                    viewResult.MasterName = "~/Modules/Common/Views/Shared/_DesignPageLayout.cshtml";
                    viewResult.ViewData[LayoutEntity.LayoutKey] = layout;
                }
            }
            else
            {
                filterContext.Result = new HttpStatusCodeResult(404);
            }
        }
        private static LayoutCache LoadById2(int id, RockContext rockContext)
        {
            var LayoutService = new LayoutService(rockContext);
            var LayoutModel   = LayoutService.Get(id);

            if (LayoutModel != null)
            {
                LayoutModel.LoadAttributes(rockContext);
                return(new LayoutCache(LayoutModel));
            }

            return(null);
        }
Beispiel #10
0
        /// <summary>
        /// Handles the Click event of the btnSave control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
        protected void btnSave_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                LayoutService layoutService = new LayoutService();
                Layout        layout;

                int layoutId = int.Parse(hfLayoutId.Value);

                // if adding a new layout
                if (layoutId.Equals(0))
                {
                    layout = new Layout {
                        Id = 0
                    };
                    layout.SiteId = hfSiteId.ValueAsInt();
                }
                else
                {
                    //load existing group member
                    layout = layoutService.Get(layoutId);
                }

                layout.Name        = tbLayoutName.Text;
                layout.Description = tbDescription.Text;
                layout.FileName    = ddlLayout.SelectedValue;

                if (!layout.IsValid)
                {
                    return;
                }

                RockTransactionScope.WrapTransaction(() =>
                {
                    if (layout.Id.Equals(0))
                    {
                        layoutService.Add(layout, CurrentPersonId);
                    }

                    layoutService.Save(layout, CurrentPersonId);
                });

                LayoutCache.Flush(layout.Id);

                Dictionary <string, string> qryString = new Dictionary <string, string>();
                qryString["siteId"] = hfSiteId.Value;
                NavigateToParentPage(qryString);
            }
        }
        /// <summary>
        /// Handles the Click event of the btnSave control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
        protected void btnSave_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                var           rockContext   = new RockContext();
                LayoutService layoutService = new LayoutService(rockContext);
                Layout        layout;

                int layoutId = int.Parse(hfLayoutId.Value);

                // if adding a new layout
                if (layoutId.Equals(0))
                {
                    layout = new Layout {
                        Id = 0
                    };
                    layout.SiteId = hfSiteId.ValueAsInt();
                }
                else
                {
                    //load existing group member
                    layout = layoutService.Get(layoutId);
                }

                layout.Name        = tbLayoutName.Text;
                layout.Description = tbDescription.Text;
                layout.FileName    = ddlLayout.SelectedValue;

                if (!layout.IsValid)
                {
                    return;
                }

                if (layout.Id.Equals(0))
                {
                    layoutService.Add(layout);
                }

                rockContext.SaveChanges();

                LayoutCache.Flush(layout.Id);

                Dictionary <string, string> qryParams = new Dictionary <string, string>();
                qryParams["layoutId"] = layout.Id.ToString();
                NavigateToPage(RockPage.Guid, qryParams);
            }
        }
        public ActionResult PageZones(QueryContext context)
        {
            var zoneService   = new ZoneService();
            var widgetService = new WidgetService();
            var page          = Service.Get(context.PageID);
            var layoutService = new LayoutService();
            var layout        = layoutService.Get(page.LayoutId);
            var viewModel     = new ViewModels.LayoutZonesViewModel
            {
                PageID     = context.PageID,
                Zones      = zoneService.GetZonesByPageId(context.PageID),
                Widgets    = widgetService.GetAllByPageId(context.PageID),
                LayoutHtml = layout.Html
            };

            return(View(viewModel));
        }
Beispiel #13
0
        /// <summary>
        /// Handles the Click event of the btnCancel control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
        protected void btnCancel_Click(object sender, EventArgs e)
        {
            if (hfLayoutId.Value.Equals("0"))
            {
                // Cancelling on Add
                Dictionary <string, string> qryString = new Dictionary <string, string>();
                qryString["siteId"] = hfSiteId.Value;
                NavigateToParentPage(qryString);
            }
            else
            {
                // Cancelling on Edit
                LayoutService layoutService = new LayoutService();
                Layout        layout        = layoutService.Get(int.Parse(hfLayoutId.Value));

                Dictionary <string, string> qryString = new Dictionary <string, string>();
                qryString["siteId"] = layout.SiteId.ToString();
                NavigateToParentPage(qryString);
            }
        }
        public void OnActionExecuted(ActionExecutedContext filterContext)
        {
            var zones = new ZoneWidgetCollection();
            var cache = new StaticCache();
            //Page
            string path = filterContext.RequestContext.HttpContext.Request.Path;

            if (path.EndsWith("/") && path.Length > 1)
            {
                path = path.Substring(0, path.Length - 1);
                //filterContext.HttpContext.Response.Redirect(path);
                filterContext.Result = new RedirectResult(path);
                return;
            }
            bool publish = !ReView.Review.Equals(filterContext.RequestContext.HttpContext.Request.QueryString[ReView.QueryKey], StringComparison.CurrentCultureIgnoreCase);
            var  page    = new PageService().GetByPath(path, publish);

            if (page != null)
            {
                var          layoutService = new LayoutService();
                LayoutEntity layout        = layoutService.Get(page.LayoutId);
                layout.Page = page;

                Action <WidgetBase> processWidget = m =>
                {
                    IWidgetPartDriver partDriver = cache.Get("IWidgetPartDriver_" + m.AssemblyName + m.ServiceTypeName, source =>
                                                             Activator.CreateInstance(m.AssemblyName, m.ServiceTypeName).Unwrap() as IWidgetPartDriver
                                                             );
                    WidgetPart part = partDriver.Display(partDriver.GetWidget(m), filterContext.HttpContext);
                    lock (zones)
                    {
                        if (zones.ContainsKey(part.Widget.ZoneID))
                        {
                            zones[part.Widget.ZoneID].Add(part);
                        }
                        else
                        {
                            var partCollection = new WidgetCollection {
                                part
                            };
                            zones.Add(part.Widget.ZoneID, partCollection);
                        }
                    }
                };
                var layoutWidgetsTask = Task.Factory.StartNew(layoutId =>
                {
                    var widgetServiceIn = new WidgetService();
                    IEnumerable <WidgetBase> layoutwidgets = widgetServiceIn.Get(new DataFilter().Where("LayoutID", OperatorType.Equal, layoutId));
                    layoutwidgets.Each(processWidget);
                }, page.LayoutId);


                var widgetService = new WidgetService();
                IEnumerable <WidgetBase> widgets = widgetService.Get(new DataFilter().Where("PageID", OperatorType.Equal, page.ID));
                int middle          = widgets.Count() / 2;
                var pageWidgetsTask = Task.Factory.StartNew(() => widgets.Skip(middle).Each(processWidget));
                widgets.Take(middle).Each(processWidget);
                Task.WaitAll(new[] { pageWidgetsTask, layoutWidgetsTask });

                layout.ZoneWidgets = zones;
                var viewResult = (filterContext.Result as ViewResult);
                if (viewResult != null)
                {
                    //viewResult.MasterName = "~/Modules/Easy.Web.CMS.Page/Views/Shared/_Layout.cshtml";
                    viewResult.ViewData[LayoutEntity.LayoutKey] = layout;
                }
            }
            else
            {
                filterContext.Result = new HttpStatusCodeResult(404);
            }
        }
        public void OnActionExecuted(ActionExecutedContext filterContext)
        {
            var zones = new ZoneWidgetCollection();
            var cache = new StaticCache();
            //Page
            string path = filterContext.RequestContext.HttpContext.Request.Path;
            if (path.EndsWith("/") && path.Length > 1)
            {
                path = path.Substring(0, path.Length - 1);
                //filterContext.HttpContext.Response.Redirect(path);
                filterContext.Result = new RedirectResult(path);
                return;
            }
            bool publish = !ReView.Review.Equals(filterContext.RequestContext.HttpContext.Request.QueryString[ReView.QueryKey], StringComparison.CurrentCultureIgnoreCase);
            var page = new PageService().GetByPath(path, publish);
            if (page != null)
            {
                var layoutService = new LayoutService();
                LayoutEntity layout = layoutService.Get(page.LayoutId);
                layout.Page = page;

                Action<WidgetBase> processWidget = m =>
                {
                    IWidgetPartDriver partDriver = cache.Get("IWidgetPartDriver_" + m.AssemblyName + m.ServiceTypeName, source =>
                         Activator.CreateInstance(m.AssemblyName, m.ServiceTypeName).Unwrap() as IWidgetPartDriver
                    );
                    WidgetPart part = partDriver.Display(partDriver.GetWidget(m), filterContext.HttpContext);
                    lock (zones)
                    {
                        if (zones.ContainsKey(part.Widget.ZoneID))
                        {
                            zones[part.Widget.ZoneID].Add(part);
                        }
                        else
                        {
                            var partCollection = new WidgetCollection { part };
                            zones.Add(part.Widget.ZoneID, partCollection);
                        }
                    }
                };
                var layoutWidgetsTask = Task.Factory.StartNew(layoutId =>
                {
                    var widgetServiceIn = new WidgetService();
                    IEnumerable<WidgetBase> layoutwidgets = widgetServiceIn.Get(new DataFilter().Where("LayoutID", OperatorType.Equal, layoutId));
                    layoutwidgets.Each(processWidget);
                }, page.LayoutId);


                var widgetService = new WidgetService();
                IEnumerable<WidgetBase> widgets = widgetService.Get(new DataFilter().Where("PageID", OperatorType.Equal, page.ID));
                int middle = widgets.Count() / 2;
                var pageWidgetsTask = Task.Factory.StartNew(() => widgets.Skip(middle).Each(processWidget));
                widgets.Take(middle).Each(processWidget);
                Task.WaitAll(new[] { pageWidgetsTask, layoutWidgetsTask });

                layout.ZoneWidgets = zones;
                var viewResult = (filterContext.Result as ViewResult);
                if (viewResult != null)
                {
                    //viewResult.MasterName = "~/Modules/Easy.Web.CMS.Page/Views/Shared/_Layout.cshtml";
                    viewResult.ViewData[LayoutEntity.LayoutKey] = layout;
                }
            }
            else
            {
                filterContext.Result = new HttpStatusCodeResult(404);
            }
        }