Exemplo n.º 1
0
        public void OnActionExecuted(ActionExecutedContext filterContext)
        {
            Zones = new ZoneWidgetCollection();
            //Page
            var page = GetPage(filterContext);

            if (page != null)
            {
                var          cache         = new StaticCache();
                var          layoutService = ServiceLocator.Current.GetInstance <ILayoutService>();
                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 widgetService = ServiceLocator.Current.GetInstance <IWidgetService>();
                IEnumerable <WidgetBase> widgets = widgetService.GetAllByPageId(page.ID);
                var parallel = from widget in widgets.AsParallel() select widget;
                parallel.ForAll(processWidget);

                layout.ZoneWidgets = Zones;
                var viewResult = (filterContext.Result as ViewResult);
                if (viewResult != null)
                {
                    string layoutView = GetLayout();
                    if (layoutView.IsNotNullAndWhiteSpace())
                    {
                        viewResult.MasterName = layoutView;
                    }
                    viewResult.ViewData[LayoutEntity.LayoutKey] = layout;
                }
            }
            else
            {
                filterContext.Result = new HttpStatusCodeResult(404);
            }
        }
        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);
            }
        }
Exemplo n.º 3
0
        public ActionResult Create(QueryContext context)
        {
            WidgetBase        widget           = null;
            IWidgetPartDriver widgetPartDriver = null;

            if (context.WidgetTemplateID.IsNotNullAndWhiteSpace())
            {
                var template = _widgetTemplateService.Get(context.WidgetTemplateID);
                widget = template.ToWidget(HttpContext.RequestServices);
            }
            else if (context.WidgetID.IsNotNullAndWhiteSpace())
            {
                var widgetBasePart = _widgetService.Get(context.WidgetID);
                widgetPartDriver  = _widgetActivator.Create(widgetBasePart);
                widget            = widgetPartDriver.GetWidget(widgetBasePart.ToWidgetBase());
                widget.IsTemplate = false;
                widget.IsSystem   = false;
                widget.Thumbnail  = null;
                widget.RuleID     = null;
            }
            if (widget == null)
            {
                return(BadRequest());
            }

            widget.PageID   = context.PageID;
            widget.LayoutID = context.LayoutID;
            widget.ZoneID   = context.ZoneID;
            widget.RuleID   = context.RuleID;
            if (widget.PageID.IsNotNullAndWhiteSpace())
            {
                widget.Position = _widgetService.GetAllByPage(_pageService.Get(context.PageID)).Count(m => m.ZoneID == context.ZoneID) + 1;
            }
            else if (context.LayoutID.IsNotNullAndWhiteSpace())
            {
                widget.Position = _widgetService.GetByLayoutId(context.LayoutID).Count(m => m.ZoneID == context.ZoneID) + 1;
            }
            SetDataSource(widget);
            ViewBag.ReturnUrl = context.ReturnUrl;
            if (widgetPartDriver != null)
            {
                widgetPartDriver.AddWidget(widget);
                return(RedirectToAction("Edit", new { ID = widget.ID, ReturnUrl = context.ReturnUrl }));
            }

            if (widget.FormView.IsNotNullAndWhiteSpace())
            {
                return(View(widget.FormView, widget));
            }

            return(View(widget));
        }
Exemplo n.º 4
0
        public void OnActionExecuted(ActionExecutedContext filterContext)
        {
            //Page
            var page = GetPage(filterContext);

            if (page != null)
            {
                LayoutEntity layout = ServiceLocator.Current.GetInstance <ILayoutService>().Get(page.LayoutId);
                layout.Page = page;
                if (filterContext.RequestContext.HttpContext.Request.IsAuthenticated && page.IsPublishedPage)
                {
                    layout.PreViewPage = PageService.GetByPath(page.Url, true);
                }
                layout.CurrentTheme = ServiceLocator.Current.GetInstance <IThemeService>().GetCurrentTheme();
                layout.ZoneWidgets  = new ZoneWidgetCollection();
                filterContext.HttpContext.TrySetLayout(layout);
                var widgetService = ServiceLocator.Current.GetInstance <IWidgetService>();
                widgetService.GetAllByPage(page).Each(widget =>
                {
                    IWidgetPartDriver partDriver = widget.CreateServiceInstance();
                    WidgetPart part = partDriver.Display(partDriver.GetWidget(widget), filterContext.HttpContext);
                    lock (layout.ZoneWidgets)
                    {
                        if (layout.ZoneWidgets.ContainsKey(part.Widget.ZoneID))
                        {
                            layout.ZoneWidgets[part.Widget.ZoneID].TryAdd(part);
                        }
                        else
                        {
                            layout.ZoneWidgets.Add(part.Widget.ZoneID, new WidgetCollection {
                                part
                            });
                        }
                    }
                });
                var viewResult = (filterContext.Result as ViewResult);
                if (viewResult != null)
                {
                    viewResult.MasterName = GetLayout();
                    filterContext.Controller.ViewData.Model = layout;
                }
            }
            else
            {
                filterContext.Result = new RedirectResult("~/error/notfond");
            }
        }
Exemplo n.º 5
0
        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);
            }
        }