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); } }
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; page.Favicon = ServiceLocator.Current.GetInstance <IApplicationSettingService>().Get(SettingKeys.Favicon, "~/favicon.ico"); 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(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; } if (page.IsPublishedPage) { ServiceLocator.Current.GetAllInstances <IOnPageExecuted>().Each(m => m.OnExecuted(page, HttpContext.Current)); } } else { filterContext.Result = new RedirectResult("~/error/notfond"); } }
public override void OnActionExecuted(ActionExecutedContext filterContext) { //Page var page = GetPage(filterContext); if (page != null) { var requestServices = filterContext.HttpContext.RequestServices; var onPageExecuteds = requestServices.GetServices <IOnPageExecuted>(); var layoutService = requestServices.GetService <ILayoutService>(); var widgetService = requestServices.GetService <IWidgetBasePartService>(); var applicationSettingService = requestServices.GetService <IApplicationSettingService>(); var themeService = requestServices.GetService <IThemeService>(); var widgetActivator = requestServices.GetService <IWidgetActivator>(); LayoutEntity layout = layoutService.Get(page.LayoutId); layout.Page = page; page.Favicon = applicationSettingService.Get(SettingKeys.Favicon, "~/favicon.ico"); if (filterContext.HttpContext.User.Identity.IsAuthenticated && page.IsPublishedPage) { layout.PreViewPage = requestServices.GetService <IPageService>().Get(page.ReferencePageID); } layout.CurrentTheme = themeService.GetCurrentTheme(); layout.ZoneWidgets = new ZoneWidgetCollection(); filterContext.HttpContext.TrySetLayout(layout); widgetService.GetAllByPage(page, GetPageViewMode() == PageViewMode.Publish && !IsPreView(filterContext)).Each(widget => { if (widget != null) { IWidgetPartDriver partDriver = widgetActivator.Create(widget); WidgetViewModelPart part = partDriver.Display(widget, filterContext); 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 }); } } partDriver.Dispose(); } }); var viewResult = (filterContext.Result as ViewResult); if (viewResult != null) { layout.Layout = GetLayout(); if (GetPageViewMode() == PageViewMode.Design) { layout.Templates = widgetService.Get(m => m.IsTemplate == true); } (filterContext.Controller as Controller).ViewData.Model = layout; } if (page.IsPublishedPage && onPageExecuteds != null) { onPageExecuteds.Each(m => m.OnExecuted(page, filterContext.HttpContext)); } layoutService.Dispose(); applicationSettingService.Dispose(); widgetService.Dispose(); themeService.Dispose(); } else { if (!(filterContext.Result is RedirectResult)) { filterContext.Result = new RedirectResult("~/error/notfond?f=" + filterContext.HttpContext.Request.Path); } } }
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 override void OnActionExecuted(ActionExecutedContext filterContext) { //Page var page = GetPage(filterContext); if (page != null) { var requestServices = filterContext.HttpContext.RequestServices; var onPageExecuteds = requestServices.GetServices <IOnPageExecuted>(); var layoutService = requestServices.GetService <ILayoutService>(); var widgetService = requestServices.GetService <IWidgetBasePartService>(); var applicationSettingService = requestServices.GetService <IApplicationSettingService>(); var themeService = requestServices.GetService <IThemeService>(); var widgetActivator = requestServices.GetService <IWidgetActivator>(); var ruleService = requestServices.GetService <IRuleService>(); LayoutEntity layout = layoutService.GetByPage(page); layout.Page = page; page.Favicon = applicationSettingService.Get(SettingKeys.Favicon, "~/favicon.ico"); if (filterContext.HttpContext.User.Identity.IsAuthenticated && page.IsPublishedPage) { layout.PreViewPage = requestServices.GetService <IPageService>().Get(page.ReferencePageID); } layout.CurrentTheme = themeService.GetCurrentTheme(); layout.ZoneWidgets = new ZoneWidgetCollection(); filterContext.HttpContext.TrySetLayout(layout); widgetService.GetAllByPage(page).Each(widget => { if (widget != null) { IWidgetPartDriver partDriver = widgetActivator.Create(widget); WidgetViewModelPart part = partDriver.Display(widget, filterContext); if (part != null) { if (layout.ZoneWidgets.ContainsKey(part.Widget.ZoneID ?? UnknownZone)) { layout.ZoneWidgets[part.Widget.ZoneID ?? UnknownZone].TryAdd(part); } else { layout.ZoneWidgets.Add(part.Widget.ZoneID ?? UnknownZone, new WidgetCollection { part }); } } partDriver.Dispose(); } }); var ruleWorkContext = new RuleWorkContext { Url = filterContext.HttpContext.Request.Path.Value, QueryString = filterContext.HttpContext.Request.QueryString.ToString(), UserAgent = filterContext.HttpContext.Request.Headers["User-Agent"] }; var rules = ruleService.GetMatchRule(ruleWorkContext); var rulesID = rules.Select(m => m.RuleID).ToArray(); if (rules.Any()) { widgetService.GetAllByRule(rulesID, !IsPreView(filterContext)).Each(widget => { if (widget != null) { IWidgetPartDriver partDriver = widgetActivator.Create(widget); WidgetViewModelPart part = partDriver.Display(widget, filterContext); var zone = layout.Zones.FirstOrDefault(z => z.ZoneName == rules.First(m => m.RuleID == widget.RuleID).ZoneName); if (part != null && zone != null) { part.Widget.ZoneID = zone.HeadingCode; if (layout.ZoneWidgets.ContainsKey(part.Widget.ZoneID ?? UnknownZone)) { layout.ZoneWidgets[part.Widget.ZoneID ?? UnknownZone].TryAdd(part); } else { layout.ZoneWidgets.Add(part.Widget.ZoneID ?? UnknownZone, new WidgetCollection { part }); } } partDriver.Dispose(); } }); } var viewResult = (filterContext.Result as ViewResult); if (viewResult != null) { layout.Layout = GetLayout(); if (GetPageViewMode() == PageViewMode.Design) { layout.Templates = widgetService.Get(m => m.IsTemplate == true); } (filterContext.Controller as Controller).ViewData.Model = layout; } if (page.IsPublishedPage && onPageExecuteds != null) { onPageExecuteds.Each(m => m.OnExecuted(page, filterContext.HttpContext)); } layoutService.Dispose(); applicationSettingService.Dispose(); widgetService.Dispose(); themeService.Dispose(); } else { if (!(filterContext.Result is RedirectResult)) { var viewResult = filterContext.Result as ViewResult; if (viewResult != null) { viewResult.StatusCode = 404; viewResult.ViewName = "NotFound"; } else { filterContext.Result = new RedirectResult("~/error/notfond?f=" + filterContext.HttpContext.Request.Path); } } } }
public override void OnActionExecuted(ActionExecutedContext filterContext) { //Page var page = GetPage(filterContext); if (page != null) { var requestServices = filterContext.HttpContext.RequestServices; var eventManager = requestServices.GetService <IEventManager>(); var layoutService = requestServices.GetService <ILayoutService>(); var widgetService = requestServices.GetService <IWidgetBasePartService>(); var applicationSettingService = requestServices.GetService <IApplicationSettingService>(); var themeService = requestServices.GetService <IThemeService>(); var widgetActivator = requestServices.GetService <IWidgetActivator>(); var ruleService = requestServices.GetService <IRuleService>(); var logger = requestServices.GetService <ILogger <WidgetAttribute> >(); var viewResult = (filterContext.Result as ViewResult); LayoutEntity layout = layoutService.GetByPage(page); layout.Page = page; page.Favicon = applicationSettingService.Get(SettingKeys.Favicon, "~/favicon.ico"); if (filterContext.HttpContext.User.Identity.IsAuthenticated && page.IsPublishedPage) { layout.PreViewPage = requestServices.GetService <IPageService>().Get(page.ReferencePageID); } layout.CurrentTheme = themeService.GetCurrentTheme(); layout.ZoneWidgets = new ZoneWidgetCollection(); widgetService.GetAllByPage(page).Each(widget => { if (widget != null) { DateTime startTime = DateTime.Now; IWidgetPartDriver partDriver = widgetActivator.Create(widget); object viewModel = partDriver.Display(new WidgetDisplayContext { PageLayout = layout, ActionContext = filterContext, Widget = widget, FormModel = viewResult?.Model }); WidgetViewModelPart part = new WidgetViewModelPart(widget, viewModel); logger.LogInformation("{0}.Display(): {1}ms", widget.ServiceTypeName, (DateTime.Now - startTime).TotalMilliseconds); if (part != null) { if (layout.ZoneWidgets.ContainsKey(part.Widget.ZoneID ?? UnknownZone)) { layout.ZoneWidgets[part.Widget.ZoneID ?? UnknownZone].TryAdd(part); } else { layout.ZoneWidgets.Add(part.Widget.ZoneID ?? UnknownZone, new WidgetCollection { part }); } } partDriver.Dispose(); } }); var ruleWorkContext = new RuleWorkContext { Url = (filterContext.Controller as Controller).Url.Content(page.Url), QueryString = filterContext.HttpContext.Request.QueryString.ToString(), UserAgent = filterContext.HttpContext.Request.Headers["User-Agent"] }; var rules = ruleService.GetMatchRule(ruleWorkContext); var ruleDic = rules.ToDictionary(m => m.RuleID, m => m); var rulesID = rules.Select(m => m.RuleID).ToArray(); if (rules.Any()) { widgetService.GetAllByRule(rulesID, !IsPreView(filterContext)).Each(widget => { if (widget != null) { DateTime startTime = DateTime.Now; IWidgetPartDriver partDriver = widgetActivator.Create(widget); object viewModel = partDriver.Display(new WidgetDisplayContext { PageLayout = layout, ActionContext = filterContext, Widget = widget, FormModel = viewResult?.Model }); WidgetViewModelPart part = new WidgetViewModelPart(widget, viewModel); logger.LogInformation("{0}.Display(): {1}ms", widget.ServiceTypeName, (DateTime.Now - startTime).TotalMilliseconds); if (part != null) { var availableZones = layout.Zones.Where(z => ruleDic[widget.RuleID.Value].ZoneNames.Contains(z.ZoneName)); foreach (var zone in availableZones) { part.Widget.SetZone(zone.HeadingCode); if (layout.ZoneWidgets.ContainsKey(zone.HeadingCode ?? UnknownZone)) { layout.ZoneWidgets[zone.HeadingCode ?? UnknownZone].TryAdd(part); } else { layout.ZoneWidgets.Add(zone.HeadingCode ?? UnknownZone, new WidgetCollection { part }); } } } partDriver.Dispose(); } }); } if (viewResult != null) { layout.Layout = GetLayout(filterContext, layout.CurrentTheme); if (GetPageViewMode() == PageViewMode.Design) { layout.Templates = widgetService.Get(m => m.IsTemplate == true); } (filterContext.Controller as Controller).ViewData.Model = layout; } eventManager.Trigger(Events.OnPageExecuted, layout); layoutService.Dispose(); applicationSettingService.Dispose(); widgetService.Dispose(); themeService.Dispose(); } else { if (!(filterContext.Result is RedirectResult)) { var viewResult = filterContext.Result as ViewResult; if (viewResult != null) { viewResult.StatusCode = 404; viewResult.ViewName = "NotFound"; } else { filterContext.Result = new RedirectResult("~/error/notfond?f=" + filterContext.HttpContext.Request.Path); } } } }