private void PostProcessPlacedWidget(UpdateContentContext context, WidgetPart part) { if (!part.IsPlaceableContent()) return; // This is a widget placed on a layout, so clear out the zone propertiey // to prevent the widget from appearing on the Widgets screen and on the front-end. part.Zone = null; // To prevent the widget from being recognized as being orphaned, set its container. // If the current container is a LayerPart, override that as well. var commonPart = part.As<ICommonPart>(); if (commonPart != null && (commonPart.Container == null || commonPart.Container.Is<LayerPart>())) { commonPart.Container = _orchardServices.WorkContext.CurrentSite; } }
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"); } }
public void GetWidgetTest() { LayerPart layerPart = _widgetService.CreateLayer(LayerName1, LayerDescription1, ""); WidgetPart widgetResult = _widgetService.GetWidget(0); Assert.That(widgetResult, Is.Null); WidgetPart widgetPart = _widgetService.CreateWidget(layerPart.Id, "HtmlWidget", WidgetTitle1, "1", ""); Assert.That(widgetPart, Is.Not.Null); widgetResult = _widgetService.GetWidget(0); Assert.That(widgetResult, Is.Null, "Still yields null on an invalid identifier"); widgetResult = _widgetService.GetWidget(widgetPart.Id); Assert.That(widgetResult.Id, Is.EqualTo(widgetPart.Id), "Returns correct widget"); }
public bool MoveWidgetUp(WidgetPart widgetPart) { int currentPosition = ParsePosition(widgetPart); WidgetPart widgetBefore = GetWidgets() .Where(widget => widget.Zone == widgetPart.Zone) .OrderByDescending(widget => widget.Position, new UI.FlatPositionComparer()) .FirstOrDefault(widget => ParsePosition(widget) < currentPosition); if (widgetBefore != null) { widgetPart.Position = widgetBefore.Position; MakeRoomForWidgetPosition(widgetPart); return(true); } return(false); }
public bool MoveWidgetDown(WidgetPart widgetPart) { int currentPosition = ParsePosition(widgetPart); WidgetPart widgetAfter = GetWidgets() .Where(widget => widget.Zone == widgetPart.Zone) .OrderBy(widget => widget.Position, new UI.FlatPositionComparer()) .FirstOrDefault(widget => ParsePosition(widget) > currentPosition); if (widgetAfter != null) { widgetAfter.Position = widgetPart.Position; MakeRoomForWidgetPosition(widgetAfter); return(true); } return(false); }
public void GetLayerWidgetsTest() { LayerPart layerPart = _widgetService.CreateLayer(LayerName1, LayerDescription1, ""); // same zone widgets WidgetPart widgetPart1 = _widgetService.CreateWidget(layerPart.Id, "HtmlWidget", WidgetTitle1, Position1, Zone1); WidgetPart widgetPart2 = _widgetService.CreateWidget(layerPart.Id, "HtmlWidget", WidgetTitle2, Position2, Zone1); // different zone widget _widgetService.CreateWidget(layerPart.Id, "HtmlWidget", WidgetTitle3, Position3, Zone2); // test 1 - moving first widget up will have no effect IEnumerable <WidgetPart> layerWidgets = _widgetService.GetWidgets(layerPart.Id); Assert.That(layerWidgets.Count(), Is.EqualTo(2)); Assert.That(layerWidgets.Contains(widgetPart1)); Assert.That(layerWidgets.Contains(widgetPart2)); }
private void PostProcessPlacedWidget(UpdateContentContext context, WidgetPart part) { if (!part.IsPlaceableContent()) { return; } // This is a widget placed on a layout, so clear out the zone propertiey // to prevent the widget from appearing on the Widgets screen and on the front-end. part.Zone = null; // To prevent the widget from being recognized as being orphaned, set its container. // If the current container is a LayerPart, override that as well. var commonPart = part.As <ICommonPart>(); if (commonPart != null && (commonPart.Container == null || commonPart.Container.Is <LayerPart>())) { commonPart.Container = _tomeltServices.WorkContext.CurrentSite; } }
public void MakeRoomForWidgetPosition(WidgetPart widgetPart) { int targetPosition = ParsePosition(widgetPart); IEnumerable <WidgetPart> widgetsToMove = GetWidgets() .Where(widget => widget.Zone == widgetPart.Zone && ParsePosition(widget) >= targetPosition && widget.Id != widgetPart.Id) .OrderBy(widget => widget.Position, new UI.FlatPositionComparer()).ToList(); // no need to continue if there are no widgets that will conflict with this widget's position if (!widgetsToMove.Any() || ParsePosition(widgetsToMove.First()) > targetPosition) { return; } int position = targetPosition; foreach (WidgetPart widget in widgetsToMove) { widget.Position = (++position).ToString(); } }
public void GetWidgetsTest() { LayerPart layerPart = _widgetService.CreateLayer(LayerName1, LayerDescription1, ""); IEnumerable <WidgetPart> widgetResults = _widgetService.GetWidgets(); Assert.That(widgetResults.Count(), Is.EqualTo(0)); WidgetPart widgetPart = _widgetService.CreateWidget(layerPart.Id, "HtmlWidget", WidgetTitle1, "1", ""); Assert.That(widgetPart, Is.Not.Null); widgetResults = _widgetService.GetWidgets(); Assert.That(widgetResults.Count(), Is.EqualTo(1)); Assert.That(widgetResults.First().Id, Is.EqualTo(widgetPart.Id)); _widgetService.CreateWidget(layerPart.Id, "HtmlWidget", WidgetTitle2, "2", ""); widgetResults = _widgetService.GetWidgets(); Assert.That(widgetResults.Count(), Is.EqualTo(2)); }
public void MoveWidgetTest() { LayerPart layerPart = _widgetService.CreateLayer(LayerName1, LayerDescription1, ""); _contentManager.Flush(); // same zone widgets WidgetPart widgetPart1 = _widgetService.CreateWidget(layerPart.Id, "HtmlWidget", WidgetTitle1, Position1, Zone1); WidgetPart widgetPart2 = _widgetService.CreateWidget(layerPart.Id, "HtmlWidget", WidgetTitle2, Position2, Zone1); // different zone widget WidgetPart widgetPart3 = _widgetService.CreateWidget(layerPart.Id, "HtmlWidget", WidgetTitle3, Position3, Zone2); _contentManager.Flush(); // test 1 - moving first widget up will have no effect Assert.That(_widgetService.MoveWidgetUp(widgetPart1), Is.False); // test 2 - moving first widget down will be successfull Assert.That(_widgetService.MoveWidgetDown(widgetPart1), Is.True); widgetPart1 = _widgetService.GetWidget(widgetPart1.Id); Assert.That(widgetPart1.Position, Is.EqualTo(Position2), "First widget moved to second widget position"); widgetPart2 = _widgetService.GetWidget(widgetPart2.Id); Assert.That(widgetPart2.Position, Is.EqualTo(Position1), "Second widget moved to first widget position"); // test 3 - moving last widget down will have no effect even though there is a widget in another zone with a higher position Assert.That(_widgetService.MoveWidgetDown(widgetPart1), Is.False); widgetPart1 = _widgetService.GetWidget(widgetPart1.Id); Assert.That(widgetPart1.Position, Is.EqualTo(Position2), "Widget remained in the same position"); widgetPart2 = _widgetService.GetWidget(widgetPart2.Id); Assert.That(widgetPart2.Position, Is.EqualTo(Position1), "Widget remained in the same position"); widgetPart3 = _widgetService.GetWidget(widgetPart3.Id); Assert.That(widgetPart3.Position, Is.EqualTo(Position3), "Widget remained in the same position"); }
private dynamic BuildCachedWidgetShape(WidgetPart widgetPart, ControllerContext controllerContext) { var reinstateResources = true; var cacheKey = ComputeCacheKey(widgetPart, controllerContext); var cachedModel = _cacheManager.Get(cacheKey, context => { context.Monitor(_signals.When(OutputCachePart.GenericSignalName)); context.Monitor(_signals.When(OutputCachePart.ContentSignalName(widgetPart.Id))); context.Monitor(_signals.When(OutputCachePart.TypeSignalName(widgetPart.ContentItem.ContentType))); reinstateResources = false; return(_ouputCachedWidgetsService.CaptureWidgetOutput(() => RenderWidget(widgetPart))); }); if (reinstateResources) { ReinstateResources(cachedModel); } return(_orchardServices.New.RawOutput(Content: cachedModel.Html)); }
public ActionResult AddWidgetPOST([Bind(Prefix = "WidgetPart.LayerId")] int layerId, string widgetType, string returnUrl) { if (!IsAuthorizedToManageWidgets()) { return(new HttpUnauthorizedResult()); } WidgetPart widgetPart = _widgetsService.CreateWidget(layerId, widgetType, "", "", ""); if (widgetPart == null) { return(HttpNotFound()); } var model = Services.ContentManager.UpdateEditor(widgetPart, this); try { // override the CommonPart's persisting of the current container widgetPart.LayerPart = _widgetsService.GetLayer(layerId); } catch (Exception exception) { Logger.Error(T("Creating widget failed: {0}", exception.Message).Text); Services.Notifier.Error(T("Creating widget failed: {0}", exception.Message)); return(this.RedirectLocal(returnUrl, () => RedirectToAction("Index"))); } if (!ModelState.IsValid) { Services.TransactionManager.Cancel(); // Casting to avoid invalid (under medium trust) reflection over the protected View method and force a static invocation. return(View((object)model)); } Services.Notifier.Information(T("Your {0} has been added.", widgetPart.TypeDefinition.DisplayName)); return(this.RedirectLocal(returnUrl, () => RedirectToAction("Index"))); }
private ActionResult EditWidgetPOST(int id, int layerId, string returnUrl, Action <ContentItem> conditionallyPublish) { if (!IsAuthorizedToManageWidgets()) { return(new HttpUnauthorizedResult()); } WidgetPart widgetPart = null; widgetPart = Services.ContentManager.Get <WidgetPart>(id, VersionOptions.DraftRequired); if (widgetPart == null) { return(HttpNotFound()); } try { var model = Services.ContentManager.UpdateEditor(widgetPart, this); // override the CommonPart's persisting of the current container widgetPart.LayerPart = _widgetsService.GetLayer(layerId); if (!ModelState.IsValid) { Services.TransactionManager.Cancel(); return(View(model)); } conditionallyPublish(widgetPart.ContentItem); Services.Notifier.Information(T("Your {0} has been saved.", widgetPart.TypeDefinition.DisplayName)); } catch (Exception exception) { Logger.Error(T("Editing widget failed: {0}", exception.Message).Text); Services.Notifier.Error(T("Editing widget failed: {0}", exception.Message)); } return(this.RedirectLocal(returnUrl, () => RedirectToAction("Index"))); }
private static int ParsePosition(WidgetPart widgetPart) { int value; if (!int.TryParse(widgetPart.Record.Position, out value)) return 0; return value; }
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 bool MoveWidgetToLayer(WidgetPart widgetPart, int? layerId) { LayerPart layer = layerId.HasValue ? GetLayer(layerId.Value) : GetLayers().FirstOrDefault(); if (layer != null) { widgetPart.LayerPart = layer; return true; } return false; }
public void MakeRoomForWidgetPosition(WidgetPart widgetPart) { int targetPosition = ParsePosition(widgetPart); IEnumerable<WidgetPart> widgetsToMove = GetWidgets() .Where(widget => widget.Zone == widgetPart.Zone && ParsePosition(widget) >= targetPosition && widget.Id != widgetPart.Id) .OrderBy(widget => widget.Position, new UI.FlatPositionComparer()).ToList(); // no need to continue if there are no widgets that will conflict with this widget's position if (widgetsToMove.Count() == 0 || ParsePosition(widgetsToMove.First()) > targetPosition) return; int position = targetPosition; foreach (WidgetPart widget in widgetsToMove) widget.Position = (++position).ToString(); }
public bool MoveWidgetUp(WidgetPart widgetPart) { int currentPosition = ParsePosition(widgetPart); WidgetPart widgetBefore = GetWidgets() .Where(widget => widget.Zone == widgetPart.Zone) .OrderByDescending(widget => widget.Position, new UI.FlatPositionComparer()) .FirstOrDefault(widget => ParsePosition(widget) < currentPosition); if (widgetBefore != null) { widgetPart.Position = widgetBefore.Position; MakeRoomForWidgetPosition(widgetPart); return true; } return false; }
public bool MoveWidgetDown(WidgetPart widgetPart) { int currentPosition = ParsePosition(widgetPart); WidgetPart widgetAfter = GetWidgets() .Where(widget => widget.Zone == widgetPart.Zone) .OrderBy(widget => widget.Position, new UI.FlatPositionComparer()) .FirstOrDefault(widget => ParsePosition(widget) > currentPosition); if (widgetAfter != null) { widgetAfter.Position = widgetPart.Position; MakeRoomForWidgetPosition(widgetAfter); return true; } return false; }
private string ComputeCacheKey(WidgetPart widgetPart, ControllerContext controllerContext) { var sb = new StringBuilder(); var workContext = controllerContext.GetWorkContext(); var theme = _themeManager.GetRequestTheme(controllerContext.RequestContext).Id; var url = GetAbsoluteUrl(controllerContext); var settings = GetCacheSettings(workContext); var varyByHeaders = new HashSet<string>(settings.VaryByRequestHeaders); // Different tenants with the same urls have different entries. varyByHeaders.Add("HOST"); var queryString = controllerContext.RequestContext.HttpContext.Request.QueryString; var requestHeaders = controllerContext.RequestContext.HttpContext.Request.Headers; var parameters = new Dictionary<string, object>(); foreach (var key in queryString.AllKeys.Where(x => x != null)) { parameters[key] = queryString[key]; } foreach (var header in varyByHeaders) { if (requestHeaders.AllKeys.Contains(header)) { parameters["HEADER:" + header] = requestHeaders[header]; } } sb.Append("layer=").Append(widgetPart.LayerId.ToString(CultureInfo.InvariantCulture)).Append(";"); sb.Append("zone=").Append(widgetPart.Zone).Append(";"); sb.Append("widget=").Append(widgetPart.Id.ToString(CultureInfo.InvariantCulture)).Append(";"); sb.Append("tenant=").Append(_shellSettings.Name).Append(";"); sb.Append("url=").Append(url.ToLowerInvariant()).Append(";"); if (settings.VaryByCulture) { sb.Append("culture=").Append(workContext.CurrentCulture.ToLowerInvariant()).Append(";"); } sb.Append("theme=").Append(theme.ToLowerInvariant()).Append(";"); foreach (var pair in parameters) { sb.AppendFormat("{0}={1};", pair.Key.ToLowerInvariant(), Convert.ToString(pair.Value).ToLowerInvariant()); } return sb.ToString(); }
private static bool UseCache(WidgetPart widgetPart, ControllerContext controllerContext) { var cachePart = widgetPart.As<OutputCachePart>(); return cachePart != null && cachePart.Enabled; }
private dynamic BuildWidgetShape(WidgetPart widgetPart) { return _orchardServices.ContentManager.BuildDisplay(widgetPart); }
private dynamic BuildCachedWidgetShape(WidgetPart widgetPart, ControllerContext controllerContext) { var cacheKey = ComputeCacheKey(widgetPart, controllerContext); var widgetOutput = _cacheManager.Get(cacheKey, context => { context.Monitor(_signals.When(OutputCachePart.GenericSignalName)); context.Monitor(_signals.When(OutputCachePart.ContentSignalName(widgetPart.Id))); context.Monitor(_signals.When(OutputCachePart.TypeSignalName(widgetPart.ContentItem.ContentType))); var output = RenderWidget(widgetPart); return output; }); return _orchardServices.New.RawOutput(Content: widgetOutput); }
public void Publish(WidgetPart widget) { _contentManager.Publish(widget.ContentItem); }
private dynamic BuildWidgetShape(WidgetPart widgetPart) { return(_orchardServices.ContentManager.BuildDisplay(widgetPart)); }
public void OnActionExecuted(ActionExecutedContext filterContext) { //Page var page = GetPage(filterContext); if (page != null) { if (GetPageViewMode() == PageViewMode.Publish) { var cacheService = ServiceLocator.Current.GetInstance <IStaticPageCache>(); if (cacheService != null) { var cache = cacheService.Get(page, filterContext.RequestContext.HttpContext.Request); if (cache != null) { var result = new ContentResult(); result.Content = cache; result.ContentType = "text/html"; filterContext.Result = result; return; } } } 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); 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 if (!(filterContext.Result is RedirectResult)) { filterContext.Result = new RedirectResult("~/error/notfond"); } }
public DesignWidgetViewModel(WidgetPart widgetPart, string pageId) { PageID = pageId; ViewModel = widgetPart.ViewModel; Widget = widgetPart.Widget; }
private static bool UseCache(WidgetPart widgetPart, ControllerContext controllerContext) { var cachePart = widgetPart.As <OutputCachePart>(); return(cachePart != null && cachePart.Enabled); }