private int[] PopulateActiveLayers()
        {
            // Once the Rule Engine is done:
            // Get Layers and filter by zone and rule
            // NOTE: .ForType("Layer") is faster than .Query<LayerPart, LayerPartRecord>()
            var activeLayers = _orchardServices.ContentManager.Query <LayerPart>().WithQueryHints(new QueryHints().ExpandParts <LayerPart>()).ForType("Layer").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 = _glimpseService.PublishTimedAction(() => _conditionManager.Matches(currentLayer.Record.LayerRule), (r, t) => new LayerMessage {
                        Active   = r,
                        Name     = currentLayer.Record.Name,
                        Rule     = currentLayer.Record.LayerRule,
                        EditUrl  = GlimpseHelpers.AppendReturnUrl(_urlHelper.ItemAdminUrl(activeLayer), _urlHelper),
                        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 occurred during layer evaluation on: {0}", activeLayer.Name).Text);
                }
            }

            return(activeLayerIds.ToArray());
        }
Exemplo n.º 2
0
        public dynamic BuildDisplay(IContent content, string displayType = "", string groupId = "")
        {
            var widgetPart = content.As <WidgetPart>();

            if (widgetPart == null)
            {
                return(_decoratedService.BuildDisplay(content, displayType, groupId));
            }

            return(_glimpseService.PublishTimedAction(() => _decoratedService.BuildDisplay(content, displayType, groupId),
                                                      (r, t) => new WidgetMessage {
                ContentId = content.Id,
                Title = widgetPart.Title,
                Type = widgetPart.ContentItem.ContentType,
                Zone = widgetPart.Zone,
                Layer = widgetPart.LayerPart,
                Position = widgetPart.Position,
                TechnicalName = widgetPart.Name,
                EditUrl = GlimpseHelpers.AppendReturnUrl(_urlHelper.ItemAdminUrl(content), _urlHelper),
                Duration = t.Duration
            }, TimelineCategories.Widgets, $"Build Display: {widgetPart.ContentItem.ContentType}", widgetPart.Title).ActionResult);
        }