当前位置: 首页>>代码示例>>C#>>正文


C# HttpActionDescriptor.GetFilters方法代码示例

本文整理汇总了C#中HttpActionDescriptor.GetFilters方法的典型用法代码示例。如果您正苦于以下问题:C# HttpActionDescriptor.GetFilters方法的具体用法?C# HttpActionDescriptor.GetFilters怎么用?C# HttpActionDescriptor.GetFilters使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在HttpActionDescriptor的用法示例。


在下文中一共展示了HttpActionDescriptor.GetFilters方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetFilters

        public IEnumerable<FilterInfo> GetFilters(HttpConfiguration configuration, HttpActionDescriptor actionDescriptor)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException("Configuration is null");
            }

            if (actionDescriptor == null)
            {
                throw new ArgumentNullException("ActionDescriptor is null");
            }

            IEnumerable<CustomFilterInfo> customActionFilters = actionDescriptor.GetFilters().Select(i => new CustomFilterInfo(i, FilterScope.Action)).Where(i => !typeof(IOrderedFilter).IsAssignableFrom(i.Instance.GetType()));
            IEnumerable<CustomFilterInfo> customControllerFilters = actionDescriptor.ControllerDescriptor.GetFilters().Select(i => new CustomFilterInfo(i, FilterScope.Controller)).Where(i => !typeof(IOrderedFilter).IsAssignableFrom(i.Instance.GetType()));

            IEnumerable<CustomFilterInfo> customActionOrderedFilters = actionDescriptor.GetFilters().Select(i => new CustomFilterInfo(i, FilterScope.Action)).Where(i => typeof(IOrderedFilter).IsAssignableFrom(i.Instance.GetType())).OrderByDescending(i => ((IOrderedFilter)i.Instance).Order);
            IEnumerable<CustomFilterInfo> customControllerOrderedFilters = actionDescriptor.ControllerDescriptor.GetFilters().Select(i => new CustomFilterInfo(i, FilterScope.Controller)).Where(i => typeof(IOrderedFilter).IsAssignableFrom(i.Instance.GetType())).OrderByDescending(i => ((IOrderedFilter)i.Instance).Order);

            var filterList = customControllerFilters.Concat(customActionFilters).Concat(customControllerOrderedFilters).Concat(customActionOrderedFilters).Select(i => i.ConvertToFilterInfo());

            return filterList;
        }
开发者ID:jtstriker3,项目名称:Joe.Web.Mvc,代码行数:22,代码来源:CustomerFilterProvider.cs

示例2: GetFilters

        public IEnumerable<FilterInfo> GetFilters(HttpConfiguration configuration, HttpActionDescriptor actionDescriptor)
        {
            IEnumerable<FilterInfo> controllerFilters =
                actionDescriptor.ControllerDescriptor.GetFilters()
                    .Select(instance => new FilterInfo(instance, FilterScope.Controller));
            IEnumerable<FilterInfo> actionFilters =
                actionDescriptor.GetFilters().Select(instance => new FilterInfo(instance, FilterScope.Action));

            return controllerFilters.Concat(actionFilters).Select(p =>
            {
                _container.InjectProperties(p.Instance);
                return p;
            });
        }
开发者ID:GusLab,项目名称:video-portal,代码行数:14,代码来源:SimpleInjectorWebApiFilterProvider.cs

示例3: GetFilters

        public IEnumerable<FilterInfo> GetFilters(HttpConfiguration configuration, HttpActionDescriptor actionDescriptor)
        {
            var controllerFilters = actionDescriptor.ControllerDescriptor.GetFilters().Select(instance => new FilterInfo(instance, FilterScope.Controller));
              var actionFilters = actionDescriptor.GetFilters().Select(instance => new FilterInfo(instance, FilterScope.Action));

              var filters = controllerFilters.Concat(actionFilters);

              foreach (var f in filters)
              {
            // Injection
            _kernel.Inject(f.Instance);
              }

              return filters;
        }
开发者ID:tkalubi,项目名称:MitchellClaim,代码行数:15,代码来源:NinjectWebApiFilterProvider.cs

示例4: GetFilters

        /// <summary>
        /// Returns the collection of filters associated with <paramref name="actionDescriptor"/>.
        /// </summary>
        /// <remarks>
        /// The implementation invokes <see cref="HttpActionDescriptor.GetFilters()"/> and <see cref="HttpControllerDescriptor.GetFilters()"/>.
        /// </remarks>
        /// <param name="configuration">The configuration. This value is not used.</param>
        /// <param name="actionDescriptor">The action descriptor.</param>
        /// <returns>A collection of filters.</returns>
        public IEnumerable<FilterInfo> GetFilters(HttpConfiguration configuration, HttpActionDescriptor actionDescriptor)
        {
            if (configuration == null)
            {
                throw Error.ArgumentNull("configuration");
            }

            if (actionDescriptor == null)
            {
                throw Error.ArgumentNull("actionDescriptor");
            }

            IEnumerable<FilterInfo> controllerFilters = actionDescriptor.ControllerDescriptor.GetFilters().Select(instance => new FilterInfo(instance, FilterScope.Controller));
            IEnumerable<FilterInfo> actionFilters = actionDescriptor.GetFilters().Select(instance => new FilterInfo(instance, FilterScope.Action));

            return controllerFilters.Concat(actionFilters);
        }
开发者ID:haoduotnt,项目名称:aspnetwebstack,代码行数:26,代码来源:ActionDescriptorFilterProvider.cs

示例5: GetFilters

        public IEnumerable<FilterInfo> GetFilters(HttpConfiguration configuration, HttpActionDescriptor actionDescriptor)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException("Configuration is null");                
            }

            if (actionDescriptor == null)
            {
                throw new ArgumentNullException("ActionDescriptor is null");
            }

            IEnumerable<CustomFilterInfo> customActionFilters = actionDescriptor.GetFilters().Select(i => new CustomFilterInfo(i, FilterScope.Controller));
            IEnumerable<CustomFilterInfo> customControllerFilters = actionDescriptor.ControllerDescriptor.GetFilters().Select(i => new CustomFilterInfo(i, FilterScope.Controller));

            return customControllerFilters.Concat(customActionFilters).OrderBy(i => i).Select(i => i.ConvertToFilterInfo());
        }
开发者ID:filipw,项目名称:FilterOrdering.WebAPi,代码行数:17,代码来源:FilterProvider.cs

示例6: GetFilters

            public IEnumerable<FilterInfo> GetFilters(HttpConfiguration configuration, HttpActionDescriptor actionDescriptor)
            {
                if (configuration == null)
                {
                    throw new ArgumentNullException("API Filter Configuration");
                }

                if (actionDescriptor == null)
                {
                    throw new ArgumentNullException("API Filter Action Description");
                }

                foreach (var filter in actionDescriptor.GetFilters())
                {
                    _container.InjectProperties(filter);
                    yield return new FilterInfo(filter, FilterScope.Action);
                }
            }
开发者ID:sbarski,项目名称:transit,代码行数:18,代码来源:ApiDependencyResolver.cs

示例7: GetFilters

        public IEnumerable<FilterInfo> GetFilters(HttpConfiguration configuration, HttpActionDescriptor actionDescriptor)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException("configuration");
            }

            if (actionDescriptor == null)
            {
                throw new ArgumentNullException("actionDescriptor");
            }

            var actionFilters = actionDescriptor.GetFilters().Select(i => new FilterInfo(i, FilterScope.Action));
            var controllerFilters = actionDescriptor.ControllerDescriptor.GetFilters().Select(i => new FilterInfo(i, FilterScope.Controller));;
            var globalFilters = configuration.Filters.Where(i => i.Scope == FilterScope.Global);

            var result = actionFilters.Concat(controllerFilters).Concat(globalFilters).Distinct().ToList();

            object filterMap;
            if (configuration.Properties.TryGetValue("FilterOrder", out filterMap))
            {
                var dictionaryFilterMap = filterMap as Dictionary<Type, int>;
                if (dictionaryFilterMap != null)
                {
                    var orderedFilters = new List<KeyValuePair<FilterInfo, int>>();
                    result.ForEach(x =>
                    {
                        int position;
                        if (dictionaryFilterMap.TryGetValue(x.Instance.GetType(), out position))
                        {
                            orderedFilters.Add(new KeyValuePair<FilterInfo, int>(x, position));
                        }
                        else
                        {
                            orderedFilters.Add(new KeyValuePair<FilterInfo, int>(x, -1));
                        }
                    });

                    result = orderedFilters.OrderBy(x => x.Value).Select(x => x.Key).ToList();
                }
            }

            return result;
        }
开发者ID:diouf,项目名称:apress-recipes-webapi,代码行数:44,代码来源:MappingBasedFilterProvider.cs

示例8: GetFilters

        public IEnumerable<FilterInfo> GetFilters(HttpConfiguration configuration, HttpActionDescriptor actionDescriptor)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException("configuration");
            }

            if (actionDescriptor == null)
            {
                throw new ArgumentNullException("actionDescriptor");
            }

            var customActionFilters = actionDescriptor.GetFilters().Select(i => new CustomFilterInfo(i, FilterScope.Action));
            var customControllerFilters = actionDescriptor.ControllerDescriptor.GetFilters().Select(i => new CustomFilterInfo(i, FilterScope.Controller));
            var customGlobalFilters = configuration.Filters.Select(i => new CustomFilterInfo(i));

            var result = (customControllerFilters.Concat(customActionFilters).Concat(customGlobalFilters)).OrderBy(i => i).Select(i => i.FilterInfo);
            return result;
        }
开发者ID:diouf,项目名称:apress-recipes-webapi,代码行数:19,代码来源:OrderBasedFilterProvider.cs

示例9: GetFilters

        public IEnumerable<FilterInfo> GetFilters(HttpConfiguration configuration, HttpActionDescriptor actionDescriptor)
        {
            Requires.NotNull("configuration", configuration);
            Requires.NotNull("actionDescriptor", actionDescriptor);

            IEnumerable<FilterInfo> controllerFilters = actionDescriptor.ControllerDescriptor.GetFilters().Select(instance => new FilterInfo(instance, FilterScope.Controller));
            IEnumerable<FilterInfo> actionFilters = actionDescriptor.GetFilters().Select(instance => new FilterInfo(instance, FilterScope.Action));

            var allFilters = controllerFilters.Concat(actionFilters).ToList();

            bool overrideFilterPresent = allFilters.Any(x => x.Instance is IOverrideDefaultAuthLevel);

            if(!overrideFilterPresent)
            {
                allFilters.Add(new FilterInfo(new RequireHostAttribute(), FilterScope.Action));
            }

            return allFilters;
        }
开发者ID:VegasoftTI,项目名称:Dnn.Platform,代码行数:19,代码来源:DnnActionFilterProvider.cs

示例10: GetFilters

        public IEnumerable<FilterInfo> GetFilters(
            HttpConfiguration configuration, HttpActionDescriptor actionDescriptor)
        {
            // Taken from ActionDescriptorFilterProvider
            var controllerFilters
                = GetFilterInfos(actionDescriptor.ControllerDescriptor.GetFilters(), FilterScope.Controller);
            var actionFilters
                = GetFilterInfos(actionDescriptor.GetFilters(), FilterScope.Action);
            // Taken from ActionDescriptorFilterProvider

            var controllerProxiedFilters
                = GetFilterInfos(actionDescriptor.ControllerDescriptor.GetCustomAttributes<IServiceAttribute>(),
                                 FilterScope.Controller);
            var actionProxiedFilters
                = GetFilterInfos(actionDescriptor.GetCustomAttributes<IServiceAttribute>(), FilterScope.Action);

            return controllerFilters
                .Concat(controllerProxiedFilters)
                .Concat(actionFilters)
                .Concat(actionProxiedFilters);
        }
开发者ID:mark-breen,项目名称:sandbox-actionfilterinjection,代码行数:21,代码来源:ServiceFilterProvider.cs

示例11: GetFilters

        public IEnumerable<FilterInfo> GetFilters(HttpConfiguration configuration, HttpActionDescriptor actionDescriptor)
        {
            if (configuration == null) throw new ArgumentNullException("configuration");
            if (actionDescriptor == null) throw new ArgumentNullException("actionDescriptor");

            var configFilters = configuration.Filters;
            foreach (var configFilter in configFilters)
                _container.InjectProperties(configFilter);

            var controllerFilters = actionDescriptor.ControllerDescriptor.GetFilters().Select(instance =>
            {
                _container.InjectProperties(instance);
                return new FilterInfo(instance, FilterScope.Controller);
            });
            var actionFilters = actionDescriptor.GetFilters().Select(instance =>
            {
                _container.InjectProperties(instance);
                return new FilterInfo(instance, FilterScope.Action);
            });

            return configFilters.Concat(controllerFilters).Concat(actionFilters);
        }
开发者ID:saibalghosh,项目名称:Layout3,代码行数:22,代码来源:SimpleInjectorHttpFilterProvider.cs

示例12: GetAuthorization

        private string GetAuthorization(HttpActionDescriptor description)
        {
            var filters = description.GetFilters().Union(description.ControllerDescriptor.GetFilters()).ToList();
            var authorizeAdmin = filters.OfType<AuthorizeAdminAttribute>().FirstOrDefault();
            var authorizeUser = filters.OfType<AuthorizeUserAttribute>().FirstOrDefault();
            var authorizeAdminOrCurrentUser = filters.OfType<AuthorizeAdminOrCurrentUser>().FirstOrDefault();
            var authorizeUserOrDevice = filters.OfType<AuthorizeUserOrDeviceAttribute>().FirstOrDefault();

            if (authorizeAdminOrCurrentUser != null)
                return "User or Key (" + authorizeAdminOrCurrentUser.CurrentUserAccessKeyAction + ")";

            if (authorizeAdmin != null)
                return "Administrator or Key (" + authorizeAdmin.AccessKeyAction + ")";

            if (authorizeUser != null)
                return "User" + (authorizeUser.AccessKeyAction == null ? null : " or Key (" + authorizeUser.AccessKeyAction + ")");

            if (authorizeUserOrDevice != null)
                return "User or Device" + (authorizeUserOrDevice.AccessKeyAction == null ? null : " or Key (" + authorizeUserOrDevice.AccessKeyAction + ")");

            return "None";
        }
开发者ID:bestpetrovich,项目名称:devicehive-.net,代码行数:22,代码来源:MetadataGenerator.cs

示例13: GetAuthorization

        private string GetAuthorization(HttpActionDescriptor description)
        {
            var filters = description.GetFilters().Union(description.ControllerDescriptor.GetFilters()).ToList();
            var authorizeUser = filters.OfType<AuthorizeUserAttribute>().FirstOrDefault();
            var authorizeDevice = filters.OfType<AuthorizeDeviceAttribute>().FirstOrDefault();
            var authorizeDeviceOrUser = filters.OfType<AuthorizeDeviceOrUserAttribute>().FirstOrDefault();

            if (authorizeDeviceOrUser != null)
                return string.Format("Device and User ({0})", authorizeDeviceOrUser.Roles ?? "All Roles");

            if (authorizeUser != null)
                return string.Format("User ({0})", authorizeUser.Roles ?? "All Roles");

            if (authorizeDevice != null)
                return "Device";

            return "None";
        }
开发者ID:reven86,项目名称:framework,代码行数:18,代码来源:MetadataController.cs


注:本文中的HttpActionDescriptor.GetFilters方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。