/// <summary>
 /// A collection of Themes owned by this member.
 /// </summary>
 public ICollection <Theme> GetOwnedThemes(ThemeFilter filter)
 {
     filter = filter ?? new ThemeFilter();
     filter.Owners.Clear();
     filter.Owners.Add(this);
     return(Instance.Get.Themes(filter));
 }
 /// <summary>
 /// Child Themes of this Theme.
 /// </summary>
 public ICollection <Theme> GetChildThemes(ThemeFilter filter)
 {
     filter = filter ?? new ThemeFilter();
     filter.Parent.Clear();
     filter.Parent.Add(this);
     return(Instance.Get.Themes(filter));
 }
Ejemplo n.º 3
0
        [Test] public void Source()
        {
            ThemeFilter filter = GetFilter();

            filter.Source.Add("Sales");
            Assert.AreEqual(2, Instance.Get.Themes(filter).Count);
        }
Ejemplo n.º 4
0
        [Test] public void Parent()
        {
            ThemeFilter filter = GetFilter();

            filter.Parent.Add(_theme1);
            Assert.AreEqual(1, Instance.Get.Themes(filter).Count);
        }
Ejemplo n.º 5
0
        [Test] public void Priority()
        {
            ThemeFilter filter = GetFilter();

            filter.Priority.Add("Medium");
            Assert.AreEqual(2, Instance.Get.Themes(filter).Count);
        }
Ejemplo n.º 6
0
        [Test] public void Type()
        {
            ThemeFilter filter = GetFilter();

            filter.Type.Add(null);
            Assert.AreEqual(3, Instance.Get.Themes(filter).Count);
        }
Ejemplo n.º 7
0
        [Test] public void Risk()
        {
            ThemeFilter filter = GetFilter();

            filter.Risk.Add("Low");
            Assert.AreEqual(1, Instance.Get.Themes(filter).Count);
        }
Ejemplo n.º 8
0
        [Test] public void Customer()
        {
            ThemeFilter filter = GetFilter();

            filter.Customer.Add(_andre);
            Assert.AreEqual(2, Instance.Get.Themes(filter).Count);
        }
Ejemplo n.º 9
0
        private ThemeFilter GetFilter()
        {
            ThemeFilter filter = new ThemeFilter();

            filter.Project.Add(_sandboxProject);
            return(filter);
        }
Ejemplo n.º 10
0
 protected override DriverResult Display(DisableThemePart part, string displayType, dynamic shapeHelper)
 {
     return(ContentShape("Parts_DisableTheme", () => {
         ThemeFilter.Disable(_httpContext.Request.RequestContext);
         return null;
     }));
 }
Ejemplo n.º 11
0
        public ThemeSelectorResult GetTheme(RequestContext context)
        {
            var workContext = workContextAccessor.GetContext(context.HttpContext);
            var culture     = workContext.CurrentCulture;

            if (!string.IsNullOrEmpty(culture))
            {
                var languageService = workContext.Resolve <ILanguageService>();
                var language        = languageService.GetLanguage(culture);
                if (language != null && !string.IsNullOrEmpty(language.Theme))
                {
                    ThemedAttribute attribute;
                    if (ThemeFilter.IsApplied(context, out attribute) && attribute.IsDashboard)
                    {
                        return(new ThemeSelectorResult {
                            IsDashboard = attribute.IsDashboard, Priority = attribute.Priority, Name = language.Theme
                        });
                    }

                    return(null);
                }
            }

            return(null);
        }
Ejemplo n.º 12
0
        public void OnResultExecuting(ResultExecutingContext filterContext)
        {
            var workContext = workContextAccessor.GetContext();

            ThemedAttribute themedAttribute;

            if (ThemeFilter.IsApplied(filterContext.RequestContext, out themedAttribute))
            {
                if (themedAttribute.Minimal)
                {
                    workContext.Layout.Metadata.Alternates.Add("Layout__Minimal");
                }
            }
        }
Ejemplo n.º 13
0
        public async Task <PagedList <ThemeModel> > GetThemesAsync(ThemeFilter filter, ListOptions listOptions)
        {
            var themes = Context.Themes.Include(t => t.Author).AsQueryable();

            if (filter != null)
            {
                if (filter.AuthorId.HasValue)
                {
                    themes = themes.Where(t => t.AuthorId == filter.AuthorId);
                }
                if (filter.SubjectId.HasValue)
                {
                    themes = themes.Where(t => t.SubjectId == filter.SubjectId);
                }
                if (filter.CreateDateAfter.HasValue)
                {
                    themes = themes.Where(t => t.CreationDate >= filter.CreateDateAfter);
                }
                if (filter.CreateDateBefore.HasValue)
                {
                    themes = themes.Where(t => t.CreationDate <= filter.CreateDateBefore);
                }
                if (!string.IsNullOrEmpty(filter.SearchString))
                {
                    themes =
                        themes.Where(
                            t => t.Title.Contains(filter.SearchString));
                }
            }

            var result = new PagedList <ThemeModel>();

            if (listOptions != null)
            {
                themes          = themes.OrderBy(t => t.CreationDate).Skip(listOptions.Offset).Take(listOptions.PageSize);
                result.Page     = listOptions.Page;
                result.PageSize = listOptions.PageSize;
            }

            var themeList = await themes.ToListAsync();

            result.AddRange(Mapper.Map <IEnumerable <Theme>, IEnumerable <ThemeModel> >(themeList));
            return(result);
        }
Ejemplo n.º 14
0
        public void OnResultExecuting(ResultExecutingContext filterContext)
        {
            // should only run on a full view rendering result
            if (!(filterContext.Result is ViewResult))
            {
                return;
            }

            if (filterContext.HttpContext.Request.IsAjaxRequest())
            {
                return;
            }

            var workContext = workContextAccessor.GetContext(filterContext);

            ThemedAttribute themedAttribute;

            if (!ThemeFilter.IsApplied(filterContext.RequestContext, out themedAttribute))
            {
                return;
            }

            if (!themedAttribute.IsDashboard)
            {
                return;
            }

            var menuItems = navigationManager.BuildMenu();

            if (menuItems.Count == 0)
            {
                return;
            }

            // Set the currently selected path
            SetSelectedPath(menuItems, filterContext.RouteData);

            // Populate main nav
            var menuShape = shapeFactory.Menu();

            menuShape.MenuItems = menuItems;

            workContext.Layout.Navigation.Add(menuShape);
        }
        public ViewEngineResult FindView(ControllerContext controllerContext, string viewName, string masterName, bool useCache)
        {
            var viewResult = themeAwareViewEngine.FindPartialView(controllerContext, viewName, useCache, true);

            if (viewResult.View == null)
            {
                return(viewResult);
            }

            ThemedAttribute attribute;

            if (!ThemeFilter.IsApplied(controllerContext.RequestContext, out attribute))
            {
                return(viewResult);
            }

            var layoutView = new LayoutView((viewContext, writer, viewDataContainer) =>
            {
                Logger.Info("Rendering layout view");

                var childContentWriter = new HtmlStringWriter();

                var childContentViewContext = new ViewContext(
                    viewContext,
                    viewContext.View,
                    viewContext.ViewData,
                    viewContext.TempData,
                    childContentWriter);

                viewResult.View.Render(childContentViewContext, childContentWriter);
                workContext.Layout.Metadata.ChildContent = childContentWriter;

                var display        = displayHelperFactory.CreateHelper(viewContext, viewDataContainer);
                IHtmlString result = display(workContext.Layout);
                writer.Write(result.ToHtmlString());

                Logger.Info("Done rendering layout view");
            }, (context, view) => viewResult.ViewEngine.ReleaseView(context, viewResult.View));

            return(new ViewEngineResult(layoutView, this));
        }
Ejemplo n.º 16
0
 /// <summary>
 /// Get themes filtered by the criteria specified in the passed in filter.
 /// </summary>
 /// <param name="filter">Limit the items returned. If null, then all items returned.</param>
 /// <returns>ICollection of items as specified in the filter.</returns>
 public ICollection <Theme> Themes(ThemeFilter filter)
 {
     return(Get <Theme>(filter ?? new ThemeFilter()));
 }
Ejemplo n.º 17
0
        public void OnResultExecuting(ResultExecutingContext filterContext)
        {
            // layers and widgets should only run on a full view rendering result
            var viewResult = filterContext.Result as ViewResult;

            if (viewResult == null)
            {
                return;
            }

            var workContext = _workContextAccessor.GetContext(filterContext);

            if (workContext == null ||
                workContext.Layout == null ||
                workContext.CurrentSite == null ||
                AdminFilter.IsApplied(filterContext.RequestContext) ||
                !ThemeFilter.IsApplied(filterContext.RequestContext))
            {
                return;
            }

            var widgetParts = _widgetsService.GetWidgets(_layerEvaluationService.GetActiveLayerIds());

            // Build and add shape to zone.
            var zones          = workContext.Layout.Zones;
            var defaultCulture = workContext.CurrentSite.As <SiteSettingsPart>().SiteCulture;
            var currentCulture = workContext.CurrentCulture;

            foreach (var widgetPart in widgetParts)
            {
                var commonPart = widgetPart.As <ICommonPart>();
                if (commonPart == null || commonPart.Container == null)
                {
                    Logger.Warning("The widget '{0}' has no assigned layer or the layer does not exist.", widgetPart.Title);
                    continue;
                }

                // ignore widget for different cultures
                var localizablePart = widgetPart.As <ILocalizableAspect>();
                if (localizablePart != null)
                {
                    // if localized culture is null then show if current culture is the default
                    // this allows a user to show a content item for the default culture only
                    if (localizablePart.Culture == null && defaultCulture != currentCulture)
                    {
                        continue;
                    }

                    // if culture is set, show only if current culture is the same
                    if (localizablePart.Culture != null && localizablePart.Culture != currentCulture)
                    {
                        continue;
                    }
                }

                // check permissions
                if (!_tomeltServices.Authorizer.Authorize(Core.Contents.Permissions.ViewContent, widgetPart))
                {
                    continue;
                }

                var widgetShape = _tomeltServices.ContentManager.BuildDisplay(widgetPart);
                zones[widgetPart.Zone].Add(widgetShape, widgetPart.Position);
            }
        }
 /// <summary>
 /// Get Themes in this Project filtered as specified in the passed in filter.
 /// </summary>
 /// <param name="filter">Criteria to filter on. Project will be set automatically. If null, all themes in the project are returned.</param>
 /// <param name="includeSubprojects">Specifies whether to include items from sub project or not. This only adds open subprojects.</param>
 /// <returns>A readonly ICollection of Theme</returns>
 public ICollection <Theme> GetThemes(ThemeFilter filter, bool includeSubprojects)
 {
     return(Instance.Get.Themes(WithThisProjectIncludedIn(filter, includeSubprojects)));
 }
 /// <summary>
 /// Get Themes in this Project filtered as specified in the passed in filter.
 /// </summary>
 /// <param name="filter">Criteria to filter on. Project will be set automatically. If null, all themes in the project are returned.</param>
 /// <returns>A readonly ICollection of Theme</returns>
 public ICollection <Theme> GetThemes(ThemeFilter filter)
 {
     return(GetThemes(filter, false));
 }
Ejemplo n.º 20
0
        public void OnResultExecuting(ResultExecutingContext filterContext)
        {
            // layers and widgets should only run on a full view rendering result
            var viewResult = filterContext.Result as ViewResult;

            if (viewResult == null)
            {
                return;
            }

            var workContext = _workContextAccessor.GetContext(filterContext);

            if (workContext == null ||
                workContext.Layout == null ||
                workContext.CurrentSite == null ||
                AdminFilter.IsApplied(filterContext.RequestContext) ||
                !ThemeFilter.IsApplied(filterContext.RequestContext))
            {
                return;
            }

            // Once the Rule Engine is done:
            // Get Layers and filter by zone and rule
            IEnumerable <LayerPart> activeLayers = _orchardServices.ContentManager.Query <LayerPart, LayerPartRecord>().List();

            var activeLayerIds = new List <int>();

            foreach (var activeLayer in activeLayers)
            {
                // ignore the rule if it fails to execute
                try
                {
                    var currentLayer     = activeLayer;
                    var layerRuleMatches = _performanceMonitor.PublishTimedAction(() => _ruleManager.Matches(currentLayer.Record.LayerRule), (r, t) => new LayerMessage
                    {
                        Active   = r,
                        Name     = currentLayer.Record.Name,
                        Rule     = currentLayer.Record.LayerRule,
                        Duration = t.Duration
                    }, TimelineCategories.Layers, "Layer Evaluation", currentLayer.Record.Name).ActionResult;

                    if (layerRuleMatches)
                    {
                        activeLayerIds.Add(activeLayer.ContentItem.Id);
                    }
                }
                catch (Exception e)
                {
                    Logger.Warning(e, T("An error occured during layer evaluation on: {0}", activeLayer.Name).Text);
                }
            }

            IEnumerable <WidgetPart> widgetParts = _widgetsService.GetWidgets(layerIds: activeLayerIds.ToArray());

            // Build and add shape to zone.
            var zones          = workContext.Layout.Zones;
            var defaultCulture = workContext.CurrentSite.As <SiteSettingsPart>().SiteCulture;
            var currentCulture = workContext.CurrentCulture;

            foreach (var widgetPart in widgetParts)
            {
                var commonPart = widgetPart.As <ICommonPart>();
                if (commonPart == null || commonPart.Container == null)
                {
                    Logger.Warning("The widget '{0}' is has no assigned layer or the layer does not exist.", widgetPart.Title);
                    continue;
                }

                // ignore widget for different cultures
                var localizablePart = widgetPart.As <ILocalizableAspect>();
                if (localizablePart != null)
                {
                    // if localized culture is null then show if current culture is the default
                    // this allows a user to show a content item for the default culture only
                    if (localizablePart.Culture == null && defaultCulture != currentCulture)
                    {
                        continue;
                    }

                    // if culture is set, show only if current culture is the same
                    if (localizablePart.Culture != null && localizablePart.Culture != currentCulture)
                    {
                        continue;
                    }
                }

                // check permissions
                if (!_orchardServices.Authorizer.Authorize(global::Orchard.Core.Contents.Permissions.ViewContent, widgetPart))
                {
                    continue;
                }

                var scopedWidgetPart       = widgetPart;
                var widgetBuildDisplayTime = _performanceMonitor.Time(() => _orchardServices.ContentManager.BuildDisplay(scopedWidgetPart));
                var widgetShape            = widgetBuildDisplayTime.ActionResult;

                _performanceMonitor.PublishMessage(new WidgetMessage
                {
                    Title         = widgetPart.Title,
                    Type          = widgetPart.ContentItem.ContentType,
                    Zone          = widgetPart.Zone,
                    Layer         = widgetPart.LayerPart,
                    Position      = widgetPart.Position,
                    TechnicalName = widgetPart.Name,
                    Duration      = widgetBuildDisplayTime.TimerResult.Duration
                });

                zones[widgetPart.Record.Zone].Add(widgetShape, widgetPart.Record.Position);
            }
        }
        public void OnResultExecuting(ResultExecutingContext filterContext)
        {
            // layers and widgets should only run on a full view rendering result
            var viewResult = filterContext.Result as ViewResult;

            if (viewResult == null)
            {
                return;
            }

            var workContext = _workContextAccessor.GetContext(filterContext);

            if (workContext == null ||
                workContext.Layout == null ||
                workContext.CurrentSite == null ||
                AdminFilter.IsApplied(filterContext.RequestContext) ||
                !ThemeFilter.IsApplied(filterContext.RequestContext))
            {
                return;
            }

            // Once the Rule Engine is done:
            // Get Layers and filter by zone and rule
            // NOTE: .ForType("Layer") is faster than .Query<LayerPart, LayerPartRecord>()
            IEnumerable <LayerPart> activeLayers = _orchardServices.ContentManager.Query <LayerPart>().ForType("Layer").List();

            var activeLayerIds = new List <int>();

            foreach (var activeLayer in activeLayers)
            {
                // ignore the rule if it fails to execute
                try {
                    if (_ruleManager.Matches(activeLayer.LayerRule))
                    {
                        activeLayerIds.Add(activeLayer.ContentItem.Id);
                    }
                }
                catch (Exception e) {
                    Logger.Warning(e, T("An error occured during layer evaluation on: {0}", activeLayer.Name).Text);
                }
            }

            IEnumerable <WidgetPart> widgetParts = _widgetsService.GetWidgets(layerIds: activeLayerIds.ToArray());

            // Build and add shape to zone.
            var zones          = workContext.Layout.Zones;
            var defaultCulture = workContext.CurrentSite.As <SiteSettingsPart>().SiteCulture;
            var currentCulture = workContext.CurrentCulture;

            foreach (var widgetPart in widgetParts)
            {
                var commonPart = widgetPart.As <ICommonPart>();
                if (commonPart == null || commonPart.Container == null)
                {
                    Logger.Warning("The widget '{0}' is has no assigned layer or the layer does not exist.", widgetPart.Title);
                    continue;
                }

                // ignore widget for different cultures
                var localizablePart = widgetPart.As <ILocalizableAspect>();
                if (localizablePart != null)
                {
                    // if localized culture is null then show if current culture is the default
                    // this allows a user to show a content item for the default culture only
                    if (localizablePart.Culture == null && defaultCulture != currentCulture)
                    {
                        continue;
                    }

                    // if culture is set, show only if current culture is the same
                    if (localizablePart.Culture != null && localizablePart.Culture != currentCulture)
                    {
                        continue;
                    }
                }

                // check permissions
                if (!_orchardServices.Authorizer.Authorize(Core.Contents.Permissions.ViewContent, widgetPart))
                {
                    continue;
                }

                var widgetShape = _orchardServices.ContentManager.BuildDisplay(widgetPart);
                zones[widgetPart.Zone].Add(widgetShape, widgetPart.Position);
            }
        }
Ejemplo n.º 22
0
        public void OnResultExecuting(ResultExecutingContext filterContext)
        {
            // layers and widgets should only run on a full view rendering result
            var viewResult = filterContext.Result as ViewResult;

            if (viewResult == null)
            {
                return;
            }

            var workContext = _workContextAccessor.GetContext(filterContext.HttpContext);

            if (workContext == null ||
                workContext.Layout == null ||
                workContext.CurrentSite == null ||
                AdminFilter.IsApplied(filterContext.RequestContext) ||
                !ThemeFilter.IsApplied(filterContext.RequestContext))
            {
                return;
            }

            IEnumerable <WidgetPart> widgetParts = _widgetsService.GetWidgets(_layerEvaluationService.GetActiveLayerIds().ToArray());

            // Build and add shape to zone.
            var zones          = workContext.Layout.Zones;
            var defaultCulture = workContext.CurrentSite.As <SiteSettingsPart>().SiteCulture;
            var currentCulture = workContext.CurrentCulture;

            foreach (var widgetPart in widgetParts)
            {
                var commonPart = widgetPart.As <ICommonPart>();
                if (commonPart == null || commonPart.Container == null)
                {
                    Logger.Warning("The widget '{0}' is has no assigned layer or the layer does not exist.", widgetPart.Title);
                    continue;
                }

                // ignore widget for different cultures
                var localizablePart = widgetPart.As <ILocalizableAspect>();
                if (localizablePart != null)
                {
                    // if localized culture is null then show if current culture is the default
                    // this allows a user to show a content item for the default culture only
                    if (localizablePart.Culture == null && defaultCulture != currentCulture)
                    {
                        continue;
                    }

                    // if culture is set, show only if current culture is the same
                    if (localizablePart.Culture != null && localizablePart.Culture != currentCulture)
                    {
                        continue;
                    }
                }

                // check permissions
                if (!_orchardServices.Authorizer.Authorize(global::Orchard.Core.Contents.Permissions.ViewContent, widgetPart))
                {
                    continue;
                }

                var scopedWidgetPart = widgetPart;
                var widgetShape      = _performanceMonitor.PublishTimedAction(() => _orchardServices.ContentManager.BuildDisplay(scopedWidgetPart), (r, t) =>
                                                                              new WidgetMessage
                {
                    Title         = scopedWidgetPart.Title,
                    Type          = scopedWidgetPart.ContentItem.ContentType,
                    Zone          = scopedWidgetPart.Zone,
                    Layer         = scopedWidgetPart.LayerPart,
                    Position      = scopedWidgetPart.Position,
                    TechnicalName = scopedWidgetPart.Name,
                    Duration      = t.Duration
                }, TimelineCategories.Widgets, string.Format("Build Display ({0})", scopedWidgetPart.ContentItem.ContentType), scopedWidgetPart.Title);

                zones[widgetPart.Record.Zone].Add(widgetShape.ActionResult, widgetPart.Record.Position);
            }
        }