Ejemplo n.º 1
0
        public virtual void ProvideFilter(FilterProviderContext context, FilterItem filterItem)
        {
            if (filterItem.Filter != null)
            {
                return;
            }

            var filter = filterItem.Descriptor.Filter;

            var filterFactory = filter as IFilterFactory;

            if (filterFactory == null)
            {
                filterItem.Filter = filter;
            }
            else
            {
                var services = context.ActionContext.HttpContext.RequestServices;
                filterItem.Filter = filterFactory.CreateInstance(services);

                if (filterItem.Filter == null)
                {
                    throw new InvalidOperationException(Resources.FormatTypeMethodMustReturnNotNullValue(
                                                            "CreateInstance",
                                                            typeof(IFilterFactory).Name));
                }

                ApplyFilterToContainer(filterItem.Filter, filterFactory);
            }
        }
Ejemplo n.º 2
0
        public virtual void ProvideFilter(FilterProviderContext context, FilterItem filterItem)
        {
            if (filterItem.Filter != null)
            {
                return;
            }

            var filter = filterItem.Descriptor.Filter;

            var filterFactory = filter as IFilterFactory;
            if (filterFactory == null)
            {
                filterItem.Filter = filter;
            }
            else
            {
                var services = context.ActionContext.HttpContext.RequestServices;
                filterItem.Filter = filterFactory.CreateInstance(services);

                if (filterItem.Filter == null)
                {
                    throw new InvalidOperationException(Resources.FormatTypeMethodMustReturnNotNullValue(
                        "CreateInstance",
                        typeof(IFilterFactory).Name));
                }

                ApplyFilterToContainer(filterItem.Filter, filterFactory);
            }
        }
Ejemplo n.º 3
0
        public static bool ContainsMatch(this List<AreaNode> routeTree, FilterProviderContext context)
        {
            ControllerActionDescriptor cad = (ControllerActionDescriptor)context.ActionContext.ActionDescriptor;
            string area = (string)context.ActionContext.RouteData.Values["area"];

            var areaNode = routeTree.Find(x =>
            {
                if (string.IsNullOrEmpty(x.Area) && string.IsNullOrEmpty(area))
                    return true;
                return String.Compare(area, x.Area, StringComparison.OrdinalIgnoreCase) == 0;

            });

            if (areaNode != null)
            {
                if (areaNode.Controllers == null || !areaNode.Controllers.Any())
                    return true;

                var controllerNode = areaNode.Controllers.Find(x => String.Compare(cad.ControllerName, x.Controller, StringComparison.OrdinalIgnoreCase) == 0);
                if (controllerNode != null)
                {
                    if (controllerNode.Actions == null || !controllerNode.Actions.Any())
                        return true;

                    var action = controllerNode.Actions.Find(x => String.Compare(cad.Name, x.Action, StringComparison.OrdinalIgnoreCase) == 0);
                    return action != null;
                }
            }
            return false;
        }
Ejemplo n.º 4
0
 /// <inheritdoc />
 public void OnProvidersExecuting([NotNull] FilterProviderContext context)
 {
     if (context.ActionContext.ActionDescriptor.FilterDescriptors != null)
     {
         foreach (var item in context.Results)
         {
             ProvideFilter(context, item);
         }
     }
 }
Ejemplo n.º 5
0
 /// <inheritdoc />
 public void OnProvidersExecuting([NotNull] FilterProviderContext context)
 {
     if (context.ActionContext.ActionDescriptor.FilterDescriptors != null)
     {
         // Perf: Avoid allocations
         for (var i = 0; i < context.Results.Count; i++)
         {
             ProvideFilter(context, context.Results[i]);
         }
     }
 }
Ejemplo n.º 6
0
        /// <inheritdoc />
        public void OnProvidersExecuting(FilterProviderContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            if (context.ActionContext.ActionDescriptor.FilterDescriptors != null)
            {
                // Perf: Avoid allocations
                for (var i = 0; i < context.Results.Count; i++)
                {
                    ProvideFilter(context, context.Results[i]);
                }
            }
        }
Ejemplo n.º 7
0
        /// <inheritdoc />
        public void OnProvidersExecuting(FilterProviderContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            if (context.ActionContext.ActionDescriptor.FilterDescriptors != null)
            {
                // Perf: Avoid allocations
                for (var i = 0; i < context.Results.Count; i++)
                {
                    ProvideFilter(context, context.Results[i]);
                }
            }
        }
Ejemplo n.º 8
0
        /// <inheritdoc />
        public void OnProvidersExecuting(FilterProviderContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            var services = context.ActionContext.HttpContext.RequestServices;
            var filters = services.GetService<IEnumerable<IFilterMetadata>>();

            if (context.ActionContext.ActionDescriptor.FilterDescriptors != null)
            {
                foreach (var filter in filters)
                {
                    var filterItem = new FilterItem(new FilterDescriptor(filter, FilterScope.Global), filter);
                    context.Results.Add(filterItem);
                }
            }
        }
Ejemplo n.º 9
0
 /// <inheritdoc />
 public void OnProvidersExecuted([NotNull] FilterProviderContext context)
 {
 }
Ejemplo n.º 10
0
 /// <inheritdoc />
 public void OnProvidersExecuted(FilterProviderContext context)
 {
 }
Ejemplo n.º 11
0
 /// <inheritdoc />
 public void OnProvidersExecuted(FilterProviderContext context)
 {
 }