本文整理汇总了C#中HttpHeaderValueCollection.Any方法的典型用法代码示例。如果您正苦于以下问题:C# HttpHeaderValueCollection.Any方法的具体用法?C# HttpHeaderValueCollection.Any怎么用?C# HttpHeaderValueCollection.Any使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HttpHeaderValueCollection
的用法示例。
在下文中一共展示了HttpHeaderValueCollection.Any方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: IsRequestedMediaTypeAccepted
private static bool IsRequestedMediaTypeAccepted(HttpHeaderValueCollection<MediaTypeWithQualityHeaderValue> acceptHeader)
{
return GlobalConfiguration
.Configuration
.Formatters
.Any(formatter => acceptHeader.Any(mediaType => FormatterSuportsMediaType(mediaType, formatter)));
}
示例2: GetEncoder
public Func<Stream, Stream> GetEncoder(HttpHeaderValueCollection<StringWithQualityHeaderValue> list)
{
// The following steps will walk you through
// completing the implementation of this method
if (list != null && list.Count > 0)
{
// More code goes here
var headerValue = list.OrderByDescending(e => e.Quality ?? 1.0D).Where(e => !e.Quality.HasValue || e.Quality.Value > 0.0D).FirstOrDefault(e => supported.Keys.Contains(e.Value, StringComparer.OrdinalIgnoreCase));
// Case 1: We can support what client has asked for
if (headerValue != null)
return GetStreamForSchema(headerValue.Value);
// Case 2: Client will accept anything we support except
// the ones explicitly specified as not preferred by setting q=0
if (list.Any(e => e.Value == "*" &&
(!e.Quality.HasValue || e.Quality.Value > 0.0D)))
{
var encoding = supported.Keys.Where(se =>
!list.Any(e =>
e.Value.Equals(se, StringComparison.OrdinalIgnoreCase) &&
e.Quality.HasValue &&
e.Quality.Value == 0.0D))
.FirstOrDefault();
if (encoding != null)
return GetStreamForSchema(encoding);
}
// Case 3: Client specifically refusing identity
if (list.Any(e => e.Value.Equals(IDENTITY, StringComparison.OrdinalIgnoreCase) &&
e.Quality.HasValue && e.Quality.Value == 0.0D))
{
throw new NegotiationFailedException();
}
// Case 4: Client is not willing to accept any of the encodings
// we support and is not willing to accept identity
if (list.Any(e => e.Value == "*" &&
(e.Quality.HasValue || e.Quality.Value == 0.0D)))
{
if (!list.Any(e => e.Value.Equals(IDENTITY, StringComparison.OrdinalIgnoreCase)))
throw new NegotiationFailedException();
}
}
// Settle for the default, which is no transformation whatsoever
return null;
}
示例3: ValidateAcceptsSData
private bool ValidateAcceptsSData(HttpHeaderValueCollection<MediaTypeWithQualityHeaderValue> acceptHeader)
{
if (acceptHeader != null && !acceptHeader.Any(x => x.MediaType == ALL_MEDIA_TYPE))
{
bool acceptsJson = acceptHeader.Any(x => x.MediaType == JSON_MEDIA_TYPE);
if (!acceptsJson)
{
return false;
}
bool acceptsSData = acceptHeader.Any(x => x.MediaType == JSON_MEDIA_TYPE &&
x.Parameters.Any(p => p.Name == SDATA_MEDIA_TYPE_VALUE_VND));
if (!acceptsSData)
{
// does not mention SData check if OData mentioned
bool acceptsOData = acceptHeader.Any(x => x.MediaType == JSON_MEDIA_TYPE &&
x.Parameters.Any(p => p.Name == ODATA_MEDIA_TYPE_VALUE_VND));
if (acceptsOData)
{
// OData JSON Request; i.e. Accept header equals: application/json;odata=[verbose, etc]
return false;
}
// consumer asked for JSON but did not indicated SData or OData so default is return SData; just continue
}
}
return true;
}