本文整理汇总了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;
}
示例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;
});
}
示例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;
}
示例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);
}
示例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());
}
示例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);
}
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
示例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);
}
示例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";
}
示例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";
}