示例#1
0
        public void OnActionExecuting(ActionExecutingContext context)
        {
            var controller = context.Controller as Controller;

            if (controller != null)
            {
                if (controller.GetType().Name.StartsWith("Admin"))
                {
                    AdminAttribute.Apply(context.HttpContext);
                }
            }
        }
示例#2
0
        public async Task OnResultExecutionAsync(ResultExecutingContext context, ResultExecutionDelegate next)
        {
            // Should only run on the front-end for a full view
            if ((context.Result is ViewResult || context.Result is PageResult) && !AdminAttribute.IsApplied(context.HttpContext))
            {
                //var widgets = await _memoryCache.GetOrCreateAsync("OCore.Layers.LayerFilter:AllWidgets", entry =>
                //{
                //    entry.AddExpirationToken(_signal.GetToken(LayerMetadataHandler.LayerChangeToken));
                //    return _layerService.GetLayerWidgetsAsync(x => x.Published);
                //});

                //var layers = (await _layerService.GetLayersAsync()).Layers.ToDictionary(x => x.Name);

                dynamic layout = await _layoutAccessor.GetLayoutAsync();

                var layout2 = layout;
                //var updater = _modelUpdaterAccessor.ModelUpdater;

                //var engine = _scriptingManager.GetScriptingEngine("js");
                //var scope = engine.CreateScope(_scriptingManager.GlobalMethodProviders.SelectMany(x => x.GetMethods()), _serviceProvider);

                //var layersCache = new Dictionary<string, bool>();

                //foreach (var widget in widgets)
                //{
                //    var layer = layers[widget.Layer];

                //    if (layer == null)
                //    {
                //        continue;
                //    }

                //    bool display;
                //    if (!layersCache.TryGetValue(layer.Name, out display))
                //    {
                //        if (String.IsNullOrEmpty(layer.Rule))
                //        {
                //            display = false;
                //        }
                //        else
                //        {
                //            display = Convert.ToBoolean(engine.Evaluate(scope, layer.Rule));
                //        }

                //        layersCache[layer.Rule] = display;
                //    }

                //    if (!display)
                //    {
                //        continue;
                //    }

                //    IShape widgetContent = await _contentItemDisplayManager.BuildDisplayAsync(widget.ContentItem, updater);

                //    widgetContent.Classes.Add("widget");
                //    widgetContent.Classes.Add("widget-" + widget.ContentItem.ContentType.HtmlClassify());

                //    var wrapper = await _shapeFactory.CreateAsync("Widget_Wrapper", new { Widget = widget.ContentItem, Content = widgetContent });
                //    wrapper.Metadata.Alternates.Add("Widget_Wrapper__" + widget.ContentItem.ContentType);

                //    var contentZone = layout.Zones[widget.Zone];
                //    contentZone.Add(wrapper);
                //}
            }

            await next.Invoke();
        }