本文整理汇总了C#中HttpRouteDirection类的典型用法代码示例。如果您正苦于以下问题:C# HttpRouteDirection类的具体用法?C# HttpRouteDirection怎么用?C# HttpRouteDirection使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
HttpRouteDirection类属于命名空间,在下文中一共展示了HttpRouteDirection类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Match
public bool Match(
HttpRequestMessage request,
IHttpRoute route,
string parameterName,
IDictionary<string, object> values,
HttpRouteDirection routeDirection) =>
Match(parameterName, values);
示例2: Match
public bool Match(System.Net.Http.HttpRequestMessage request, IHttpRoute route, string parameterName, IDictionary<string, object> values, HttpRouteDirection routeDirection)
{
if (values == null) // shouldn't ever hit this.
return true;
if (!values.ContainsKey(parameterName) || !values.ContainsKey(_id)) // make sure the parameter is there.
return true;
var action = values[parameterName].ToString().ToLower();
if (string.IsNullOrEmpty(action)) // if the param key is empty in this case "action" add the method so it doesn't hit other methods like "GetStatus"
{
values[parameterName] = request.Method.ToString();
}
else if (string.IsNullOrEmpty(values[_id].ToString()))
{
var isidstr = true;
array.ToList().ForEach(x =>
{
if (action.StartsWith(x.ToLower()))
isidstr = false;
});
if (isidstr)
{
values[_id] = values[parameterName];
values[parameterName] = request.Method.ToString();
}
}
return true;
}
示例3: Match
protected override bool Match(HttpRequestMessage request, IHttpRoute route, string parameterName, IDictionary<string, object> values, HttpRouteDirection routeDirection)
{
if (routeDirection == HttpRouteDirection.UriGeneration)
return true;
return base.Match(request, route, parameterName, values, routeDirection);
}
示例4: Match
public override bool Match(
HttpRequestMessage request,
IHttpRoute route,
string parameterName,
IDictionary<string, object> values,
HttpRouteDirection routeDirection)
{
foreach (string key in HeaderConstraints.Keys)
{
if (!request.Headers.Contains(key)
|| string.Compare(request.Headers.GetValues(key).FirstOrDefault(), HeaderConstraints[key].ToString(), true) != 0)
{
return false;
}
}
var queries = request.GetQueryNameValuePairs().ToDictionary(p => p.Key, p => p.Value);
foreach (var key in QueryStringConstraints.Keys)
{
if (!queries.ContainsKey(key)
|| string.Compare(queries[key], QueryStringConstraints[key].ToString(), true) != 0)
{
return false;
}
}
return base.Match(request, route, parameterName, values, routeDirection);
}
示例5: Match
/// <inheritdoc />
public bool Match(HttpRequestMessage request, IHttpRoute route, string parameterName, IDictionary<string, object> values, HttpRouteDirection routeDirection)
{
if (parameterName == null)
{
throw Error.ArgumentNull("parameterName");
}
if (values == null)
{
throw Error.ArgumentNull("values");
}
object value;
if (values.TryGetValue(parameterName, out value) && value != null)
{
string valueString = Convert.ToString(value, CultureInfo.InvariantCulture);
int length = valueString.Length;
if (Length.HasValue)
{
return length == Length.Value;
}
else
{
return length >= MinLength.Value && length <= MaxLength.Value;
}
}
return false;
}
示例6: Match
/// <inheritdoc />
public bool Match(HttpRequestMessage request, IHttpRoute route, string parameterName, IDictionary<string, object> values, HttpRouteDirection routeDirection)
{
if (parameterName == null)
{
throw Error.ArgumentNull("parameterName");
}
if (values == null)
{
throw Error.ArgumentNull("values");
}
object value;
if (values.TryGetValue(parameterName, out value) && value != null)
{
if (value is long)
{
return true;
}
long result;
string valueString = Convert.ToString(value, CultureInfo.InvariantCulture);
return Int64.TryParse(valueString, NumberStyles.Integer, CultureInfo.InvariantCulture, out result);
}
return false;
}
示例7: Match
public bool Match(HttpRequestMessage request, IHttpRoute route, string parameterName,
IDictionary<string, object> values, HttpRouteDirection routeDirection)
{
var versionFinder = new VersionFinder();
var version = versionFinder.GetVersionFromRequest(request);
return _version == version;
}
示例8: Match
/// <inheritdoc />
public bool Match(HttpRequestMessage request, IHttpRoute route, string parameterName, IDictionary<string, object> values, HttpRouteDirection routeDirection)
{
if (route == null)
{
throw Error.ArgumentNull("route");
}
if (parameterName == null)
{
throw Error.ArgumentNull("parameterName");
}
if (values == null)
{
throw Error.ArgumentNull("values");
}
// If the parameter is optional and has no value, then pass the constraint
object defaultValue;
if (route.Defaults.TryGetValue(parameterName, out defaultValue) && defaultValue == RouteParameter.Optional)
{
object value;
if (values.TryGetValue(parameterName, out value) && value == RouteParameter.Optional)
{
return true;
}
}
return InnerConstraint.Match(request, route, parameterName, values, routeDirection);
}
示例9: Match
public bool Match(HttpRequestMessage request,
IHttpRoute route,
string segmentPrefix,
IDictionary<string, object> values,
HttpRouteDirection routeDirection)
{
if (segmentPrefix == null)
{
throw new ArgumentNullException("segmentPrefix");
}
if (values == null)
{
throw new ArgumentNullException("values");
}
object value;
if (values.TryGetValue(segmentPrefix, out value))
{
string valueString = value as string;
return valueString != null
&& (valueString.StartsWith(segmentPrefix + ";", StringComparison.OrdinalIgnoreCase)
|| String.Equals(valueString, segmentPrefix, StringComparison.OrdinalIgnoreCase));
}
return false;
}
示例10: Match
public bool Match(HttpRequestMessage request, IHttpRoute route, string parameterName, IDictionary<string, object> values, HttpRouteDirection routeDirection)
{
object rawValue;
if (!values.TryGetValue(parameterName, out rawValue)
|| rawValue == null) {
return true;
}
if (this.ParameterType.IsInstanceOfType(rawValue)) {
return true;
}
string attemptedValue = Convert.ToString(rawValue, CultureInfo.InvariantCulture);
if (attemptedValue.Length == 0) {
return true;
}
object parsedVal;
if (!TryParse(request, parameterName, rawValue, attemptedValue, CultureInfo.InvariantCulture, out parsedVal)) {
return false;
}
if (routeDirection == HttpRouteDirection.UriResolution) {
values[parameterName] = parsedVal;
}
return true;
}
示例11: Match
/// <inheritdoc />
public bool Match(HttpRequestMessage request, IHttpRoute route, string parameterName,
IDictionary<string, object> values, HttpRouteDirection routeDirection)
{
// The match behaviour depends on value of IsRelaxedMatch.
// If users select using relaxed match logic, the header contains both V3 (or before) and V4 style version
// will be regarded as valid. While under non-relaxed match logic, both version headers presented will be
// regarded as invalid. The behavior for other situations are the same. When non version headers present,
// assume using MaxVersion.
if (request == null)
{
throw Error.ArgumentNull("request");
}
if (routeDirection == HttpRouteDirection.UriGeneration)
{
return true;
}
if (!ValidateVersionHeaders(request))
{
return false;
}
ODataVersion? requestVersion = GetVersion(request);
return requestVersion.HasValue && requestVersion.Value >= MinVersion && requestVersion.Value <= MaxVersion;
}
示例12: Match
public bool Match(HttpRequestMessage request, IHttpRoute route, string parameterName,
IDictionary<string, object> values, HttpRouteDirection routeDirection)
{
if (values == null)
{
return true;
}
if (!values.ContainsKey(parameterName) || !values.ContainsKey(Id))
{
return true;
}
string action = values[parameterName].ToString().ToLower();
if (string.IsNullOrEmpty(action))
{
values[parameterName] = request.Method.ToString();
}
else if (string.IsNullOrEmpty(values[Id].ToString()))
{
bool isAction = _array.All(item => action.StartsWith(item.ToLower()));
if (isAction)
{
return true;
}
//values[Id] = values[parameterName];
//values[parameterName] = request.Method.ToString();
}
return true;
}
示例13: Match
public bool Match(HttpRequestMessage request, IHttpRoute route, string parameterName, IDictionary<string, object> values,
HttpRouteDirection routeDirection)
{
return request.Headers.UserAgent
.Where(ua => ua.Product != null)
.Where(ua => ua.Product.Name != null)
.Any(ua => ua.Product.Name.IndexOf("NuGet", StringComparison.InvariantCultureIgnoreCase) != -1);
}
示例14: Match
public bool Match(HttpRequestMessage request,
IHttpRoute route,
string parameterName,
IDictionary<string, object> values,
HttpRouteDirection routeDirection)
{
return request.Method == Method;
}
示例15: Match
public bool Match(HttpRequestMessage request, IHttpRoute route, string parameterName, IDictionary<string, object> values, HttpRouteDirection routeDirection)
{
object culture;
if (values.TryGetValue(parameterName, out culture))
{
return allCultures.Any(c => string.Compare(c, culture.ToString(), true) == 0);
}
return false;
}