コード例 #1
0
    public bool Match(HttpRequestMessage request, IHttpRoute route, string parameterName,
                      IDictionary <string, object> values, HttpRouteDirection routeDirection)
    {
        if (string.IsNullOrEmpty(parameterName))
        {
            return(false);
        }
        var properties    = request.ApiVersionProperties();
        var versionString = "";

        if (values.TryGetValue(parameterName, out object value))
        {
            //This is the real 'magic' here, just replacing the underscore with a period
            versionString = ((string)value).Replace('_', '.');

            properties.RawApiVersion = versionString;
        }
        else
        {
            return(false);
        }
        if (ApiVersion.TryParse(versionString, out var requestedVersion))
        {
            properties.ApiVersion = requestedVersion;
            return(true);
        }
        return(false);
    }
コード例 #2
0
        /// <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);
        }
コード例 #3
0
ファイル: HttpRoute.cs プロジェクト: belav/AspNetWebStack
        private bool ProcessConstraints(
            HttpRequestMessage request,
            HttpRouteValueDictionary values,
            HttpRouteDirection routeDirection
            )
        {
            if (Constraints != null)
            {
                foreach (KeyValuePair <string, object> constraintsItem in Constraints)
                {
                    if (
                        !ProcessConstraint(
                            request,
                            constraintsItem.Value,
                            constraintsItem.Key,
                            values,
                            routeDirection
                            )
                        )
                    {
                        return(false);
                    }
                }
            }

            return(true);
        }
コード例 #4
0
        public bool Match(HttpRequestMessage request, IHttpRoute route, string parameterName,
                          IDictionary <string, object> values, HttpRouteDirection routeDirection)
        {
            object value;

            if (values.TryGetValue(parameterName, out value) && value != null)
            {
                var stringValue = value as string;
                var intValue    = 0;

                if (stringValue != null && int.TryParse(stringValue, out intValue))
                {
                    if (intValue >= _from && intValue <= _to)
                    {
                        return(true);
                    }

                    //only throw if we had the expected type of value
                    //but it fell out of range
                    throw new HttpResponseException(_statusCode);
                }
            }

            return(false);
        }
コード例 #5
0
ファイル: StartsWithConstraint.cs プロジェクト: liumeifu/OSky
 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;
 }
コード例 #6
0
        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);
        }
コード例 #7
0
        /// <inheritdoc />
#if ASPNETWEBAPI
        public bool Match(
            HttpRequestMessage request,
            IHttpRoute route,
            string parameterName,
            IDictionary <string, object> values,
            HttpRouteDirection routeDirection
            )
コード例 #8
0
        public bool Match(HttpRequestMessage request, IHttpRoute route,
                          string parameterName, IDictionary <string, object> values, HttpRouteDirection routeDirection)
        {
            if (routeDirection == HttpRouteDirection.UriResolution)
            {
                // try custom request header "api-version"
                int?version = GetVersionHeaderOrQuery(request);

                // not found?  Try custom content type in accept header
                if (version == null)
                {
                    version = GetVersionFromCustomContentType(request);
                }

                // could simply permit default version here, but for now we want to ensure clients are making requests for a particular version #.
                //return ((version ?? DefaultVersion) == AllowedVersion);

                if (!version.HasValue && DefaultVersion.HasValue)
                {
                    version = DefaultVersion.Value;
                }

                if (version.HasValue && version.Value == AllowedVersion)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }

            return(true);
        }
コード例 #9
0
 public bool Match(HttpRequestMessage request, IHttpRoute route, string parameterName,
                   IDictionary <string, object> values, HttpRouteDirection routeDirection)
 {
     //get value from values dictionary object
     //return true or false
     //false will block the call
 }
コード例 #10
0
        private bool MatchClientVersion(HttpRequestMessage request, HttpRouteDirection routeDirection)
        {
            if (routeDirection == HttpRouteDirection.UriResolution)
            {
                if (!AllowedClientVersionRangeList.Any())
                {
                    throw new Exception("AllowedClientVersionRange is empty!");
                }

                Version clientVersion = GetClientVersionHeader(request) ?? DefaultClientMinVersion;//请求方未声明,则为1.0.0
                if (clientVersion == null)
                {
                    clientVersion = DefaultClientMinVersion;
                }

                foreach (var range in AllowedClientVersionRangeList)
                {
                    if (range.MinVersion.CompareTo(clientVersion) <= 0 && range.MaxVersion.CompareTo(clientVersion) >= 0)
                    {
                        return(true);
                    }
                }

                return(false);
            }

            return(false);
        }
コード例 #11
0
        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;
        }
コード例 #12
0
        /// <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;
        }
コード例 #13
0
        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;
        }
コード例 #14
0
        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);
        }
コード例 #15
0
        public bool Match(HttpRequestMessage request, IHttpRoute route, string parameterName,
                          IDictionary <string, object> values,
                          HttpRouteDirection routeDirection)
        {
            object pathObj;

            if (values.TryGetValue(parameterName, out pathObj))
            {
                var path = pathObj as string;
                if (!string.IsNullOrEmpty(path))
                {
                    // TODO Find async way
                    var templateInfo = _templateRepository.GetTemplateAsync(path).Result;
                    if (templateInfo != null)
                    {
                        return(true);
                    }

                    var fileName = _fileSystem.Path.ChangeExtension(_fileSystem.Path.Combine(_viewPathInfo, PathInfo.Create(path)),
                                                                    "html.json");
                    if (_fileSystem.FileExists(fileName))
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
コード例 #16
0
 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;
 }
コード例 #17
0
        public bool Match(HttpRequestMessage request, IHttpRoute route, string parameterName, IDictionary <string, object> values,
                          HttpRouteDirection routeDirection)
        {
            object value;

            if (values.TryGetValue(parameterName, out value) && value != null)
            {
                var stringValue = value as string;
                if (stringValue == null)
                {
                    return(false);
                }

                try
                {
                    var email = new MailAddress(stringValue);
                    return(true);
                }
                catch (FormatException)
                {
                    return(false);
                }
            }

            return(false);
        }
コード例 #18
0
        /// <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;
        }
コード例 #19
0
        public bool Match(HttpRequestMessage request, IHttpRoute route, string parameterName, IDictionary <string, object> values,
                          HttpRouteDirection routeDirection)
        {
            bool noDoubleRoutes = !request.RequestUri.ToString().Contains("attachments"); /* <- I should play with it because
                                                                                           * "Web API (1.x-2.x) does not support multiple attribute routes with the same path on different controllers".*/

            if (noDoubleRoutes && _requiredVersion == MinVersion)
            {
                return(true);
            }

            IEnumerable <string> headerValues;

            if (request.Headers.TryGetValues("api-version", out headerValues))
            {
                int version = GetMaxVersion(headerValues.FirstOrDefault());

                if (version == _requiredVersion)
                {
                    return(true);
                }
            }

            return(false);
        }
コード例 #20
0
ファイル: StartWithConstraint.cs プロジェクト: ud7070/UDTest
        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;
        }
コード例 #21
0
        private static bool TestValue(
            IHttpRouteConstraint constraint,
            object value,
            Action <IHttpRoute> routeConfig = null
            )
        {
            HttpRequestMessage httpRequestMessage = new HttpRequestMessage();

            HttpRoute httpRoute = new HttpRoute();

            if (routeConfig != null)
            {
                routeConfig(httpRoute);
            }
            const string             parameterName = "fake";
            HttpRouteValueDictionary values        = new HttpRouteValueDictionary
            {
                { parameterName, value }
            };
            const HttpRouteDirection httpRouteDirection = HttpRouteDirection.UriResolution;

            return(constraint.Match(
                       httpRequestMessage,
                       httpRoute,
                       parameterName,
                       values,
                       httpRouteDirection
                       ));
        }
コード例 #22
0
        /// <inheritdoc />
        public bool Match(HttpRequestMessage request, IHttpRoute route, string parameterName,
                          IDictionary <string, object> values, HttpRouteDirection routeDirection)
        {
            if (!values.TryGetValue(parameterName, out var value) || value == null)
            {
                return(false);
            }

            if (!(value is string stringValue))
            {
                return(false);
            }

            var tmp = stringValue.Split(',');

            if (tmp.Length != 4)
            {
                return(false);
            }

            if (long.TryParse(tmp[0], out var x) && x >= -2147483648 && x <= 2147483648 &&
                long.TryParse(tmp[1], out var y) && y >= -2147483648 && y <= 2147483648 &&
                long.TryParse(tmp[2], out var w) && w >= -2147483648 && w <= 2147483648 &&
                long.TryParse(tmp[3], out var h) && h >= -2147483648 && h <= 2147483648)
            {
                return(true);
            }

            return(false);
        }
コード例 #23
0
 public bool Match(
     HttpRequestMessage request,
     IHttpRoute route,
     string parameterName,
     IDictionary<string, object> values,
     HttpRouteDirection routeDirection) =>
         Match(parameterName, values);
コード例 #24
0
        /// <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);
        }
コード例 #25
0
        /// <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;
        }
コード例 #26
0
        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);
        }
コード例 #27
0
        /// <inheritdoc />
        public bool Match(HttpRequestMessage request, IHttpRoute route, string parameterName,
                          IDictionary <string, object> values, HttpRouteDirection routeDirection)
        {
            if (!values.TryGetValue(parameterName, out var value) || value == null)
            {
                return(false);
            }

            var stringValue = value as string;

            switch (stringValue)
            {
            case null:
                return(false);

            case "rotate-cw":
                values[parameterName] = RotateFlipType.Rotate90FlipNone;
                return(true);

            case "rotate-ccw":
                values[parameterName] = RotateFlipType.Rotate270FlipNone;
                return(true);

            case "flip-h":
                values[parameterName] = RotateFlipType.RotateNoneFlipX;
                return(true);

            case "flip-v":
                values[parameterName] = RotateFlipType.RotateNoneFlipY;
                return(true);
            }

            return(false);
        }
コード例 #28
0
        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);
        }
コード例 #29
0
        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));
        }
コード例 #30
0
        /// <summary>
        ///   Determines whether or not the route can be matched based on the constraint.
        /// </summary>
        ///
        /// <param name="request">The request being processed.</param>
        /// <param name="route">The route identified as potentially matching the request.</param>
        /// <param name="parameterName">The name of the parameter that the constraint is being evaluated for.</param>
        /// <param name="values">A list of parameter values available to the request.</param>
        /// <param name="routeDirection">An indicator of whether the route is being generated or resolved.</param>

        /// <returns><c>true</c> if the constraint is satisfied and the route should match; otherwise, <c>false</c>.</returns>
        ///
        public bool Match(HttpRequestMessage request,
                          IHttpRoute route,
                          string parameterName,
                          IDictionary <string, object> values,
                          HttpRouteDirection routeDirection)
        {
            // If the parameter was present, then ensure that it has a valid set of characters and the length
            // is within the expected bounds.

            if (values.TryGetValue(parameterName, out object value))
            {
                var parameterValue = value?.ToString() ?? String.Empty;

                if ((parameterValue.Length < this.minimumLength) ||
                    (parameterValue.Length > this.maximumLength) ||
                    (!IdentifierRouteConstraint.IdentityMatcher.IsMatch(parameterValue)))
                {
                    throw IdentifierRouteConstraint.LogAndCreateFailureException(request, parameterName, this.errorCode, this.errorDescription);
                }
            }

            // If the constraint was not violated, then allow the route to match.

            return(true);
        }
コード例 #31
0
        public bool Match(
            HttpRequestMessage request
            , IHttpRoute route
            , string parameterName
            , IDictionary <string, object> values
            , HttpRouteDirection routeDirection
            )
        {
            object value;

            if (values.TryGetValue(parameterName, out value) && value != null)
            {
                long longValue;
                if (value is long)
                {
                    longValue = (long)value;
                    return(longValue != 0);
                }

                string valueString = Convert.ToString(value, CultureInfo.InvariantCulture);
                if (Int64.TryParse(valueString, NumberStyles.Integer,
                                   CultureInfo.InvariantCulture, out longValue))
                {
                    return(longValue != 0);
                }
            }
            return(false);
        }
コード例 #32
0
 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);
 }
コード例 #33
0
 public bool Match(HttpRequestMessage request,
                   IHttpRoute route,
                   string parameterName,
                   IDictionary <string, object> values,
                   HttpRouteDirection routeDirection)
 {
     return(Methods.Contains(request.Method));
 }
コード例 #34
0
 public bool Match(HttpRequestMessage request,
     IHttpRoute route,
     string parameterName,
     IDictionary<string, object> values,
     HttpRouteDirection routeDirection)
 {
     return request.Method == Method;
 }
コード例 #35
0
 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));
 }
コード例 #36
0
        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);
        }
コード例 #37
0
        public bool Match(HttpRequestMessage request, IHttpRoute route, string parameterName,
                          IDictionary <string, object> values,
                          HttpRouteDirection routeDirection)
        {
            var paramVal = values[parameterName].ToString();

            return(paramVal.StartsWith("r") || paramVal.StartsWith("b") || paramVal.StartsWith("y"));
        }
コード例 #38
0
 public bool Match(System.Net.Http.HttpRequestMessage request, IHttpRoute route, string parameterName, IDictionary<string, object> values, HttpRouteDirection routeDirection)
 {
     object value = null;
     if (values.TryGetValue(parameterName, out value))
     {
         return value == RouteParameter.Optional;
     }
     return true;
 }
コード例 #39
0
        public bool Match(HttpRequestMessage request, IHttpRoute route, string parameterName, IDictionary<string, object> values, HttpRouteDirection routeDirection)
        {
            if (routeDirection != HttpRouteDirection.UriResolution)
                return true;

            var version = GetVersionHeader(request) ?? DefaultVersion;

            return (version == AllowedVersion);
        }
コード例 #40
0
 public bool Match(HttpRequestMessage request, IHttpRoute route, string parameterName, IDictionary<string, object> values, HttpRouteDirection routeDirection)
 {
     object value;
     if (values.TryGetValue(parameterName, out value) && value != null)
     {
         return AllowedVersion.Equals(value.ToString().ToLowerInvariant());
     }
     return false;
 }
コード例 #41
0
 public bool Match(HttpRequestMessage request, IHttpRoute route, string parameterName, IDictionary <string, object> values,
                   HttpRouteDirection routeDirection)
 {
     if (values.TryGetValue(parameterName, out object value) && value != null)
     {
         return(AllowedVersion.Equals(value.ToString().ToLowerInvariant()));
     }
     return(false);
 }
コード例 #42
0
 /// <summary>
 /// Determines whether this instance equals a specified route.
 /// </summary>
 /// <returns>
 /// True if this instance equals a specified route; otherwise, false.
 /// </returns>
 /// <param name="request">The request.</param><param name="route">The route to compare.</param><param name="parameterName">The name of the parameter.</param><param name="values">A list of parameter values.</param><param name="routeDirection">The route direction.</param>
 public bool Match(
     HttpRequestMessage request,
     IHttpRoute route,
     string parameterName,
     IDictionary<string, object> values,
     HttpRouteDirection routeDirection)
 {
     return ((IHttpRouteConstraint) selfHostConstraint).Match(request, route, parameterName, values, routeDirection);
 }
コード例 #43
0
 /// <summary>
 /// Determines whether this instance equals a specified route.
 /// </summary>
 /// <returns>
 /// True if this instance equals a specified route; otherwise, false.
 /// </returns>
 /// <param name="request">The request.</param><param name="route">The route to compare.</param><param name="parameterName">The name of the parameter.</param><param name="values">A list of parameter values.</param><param name="routeDirection">The route direction.</param>
 public bool Match(
     HttpRequestMessage request,
     IHttpRoute route,
     string parameterName,
     IDictionary<string, object> values,
     HttpRouteDirection routeDirection)
 {
     return ((IHttpRouteConstraint) selfHostConstraint).Match(request, route, parameterName, values, routeDirection);
 }
コード例 #44
0
        public bool Match(System.Net.Http.HttpRequestMessage request, IHttpRoute route, string parameterName, IDictionary<string, object> values, HttpRouteDirection routeDirection)
        {
            if (routeDirection == HttpRouteDirection.UriResolution)
            {
                return true;
            }

            return false;
        }
コード例 #45
0
        public bool Match(HttpRequestMessage request, IHttpRoute route, string parameterName, IDictionary<string, object> values, HttpRouteDirection routeDirection)
        {
            if (routeDirection == HttpRouteDirection.UriResolution)
            {
                return IsRequiredHeaderPresent(request);
            }

            return false;
        }
 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;
 }
コード例 #47
0
        /// <summary>
        /// <see cref="IHttpRouteConstraint.Match(HttpRequestMessage, IHttpRoute, string, IDictionary{string, object}, HttpRouteDirection)">Match</see>
        /// </summary>
        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");
            }

            bool match = false;

            // If the segmentPrefix is "controller", then the route constraint has been based on the routing tables
            // of the WebApiConfig.cs file. In this case, the URI will need to be parsed to remove Matrix Parameters
            // before checking against recognised controllers.
            if (ControllerKey.Equals(segmentPrefix))
            {
                string[] segments = request.RequestUri.Segments;
                Array.Reverse(segments);

                foreach (string segment in segments)
                {
                    if (Regex.IsMatch(segment, ControllerNamePattern))
                    {
                        string controllerName = Regex.Match(segment, ControllerNamePattern).Groups[1].Value;
                        match = GlobalConfiguration.Configuration.Services.GetHttpControllerSelector().GetControllerMapping().ContainsKey(controllerName);

                        if (match)
                        {
                            break;
                        }
                    }
                }
            }
            // If the segmentPrefix is some other value, then the route constraint has been defined using attribute
            // routing and refers to a controller name.
            else
            {
                object value;

                if (values.TryGetValue(segmentPrefix, out value))
                {
                    string valueString = (string)value;
                    match = valueString != null &&
                            (valueString.StartsWith(segmentPrefix + ";", StringComparison.OrdinalIgnoreCase) ||
                             string.Equals(valueString, segmentPrefix, StringComparison.OrdinalIgnoreCase));
                }
            }

            return(match);
        }
コード例 #48
0
 public bool Match(
     HttpRequestMessage request,
     IHttpRoute route,
     string parameterName,
     IDictionary <string, object> values,
     HttpRouteDirection routeDirection)
 {
     return(routeDirection == this._allowedDirection);
 }
コード例 #49
0
 public bool Match(
     HttpRequestMessage request,
     IHttpRoute route,
     string parameterName,
     IDictionary<string, object> values,
     HttpRouteDirection routeDirection)
 {
     return routeDirection == _allowedDirection;
 }
コード例 #50
0
        public bool Match(HttpRequestMessage request, IHttpRoute route, string parameterName, IDictionary<string, object> values, HttpRouteDirection routeDirection)
        {
            // TODO
            //if (Path.GetExtension(request..AppRelativeCurrentExecutionFilePath).Equals(".js", StringComparison.OrdinalIgnoreCase))
            //{
            //    return false;
            //}

            return true;
        }
コード例 #51
0
        public bool Match(HttpRequestMessage request, IHttpRoute route, string parameterName, IDictionary<string, object> values, HttpRouteDirection routeDirection)
        {
            if (!values.ContainsKey(parameterName)) return false;
            var stringValue = values[parameterName] as string;

            if (string.IsNullOrEmpty(stringValue)) return false;
            Guid guidValue;

            return Guid.TryParse(stringValue, out guidValue) && (guidValue != Guid.Empty);
        }
コード例 #52
0
 /// <inheritdoc />
 public bool Match(
     HttpRequestMessage request,
     IHttpRoute route,
     string parameterName,
     IDictionary <string, object> values,
     HttpRouteDirection routeDirection
     )
 {
     return(values.TryGetValue(parameterName, out var value) && value != null);
 }
 public bool Match(HttpRequestMessage request, IHttpRoute route,
                   string parameterName, IDictionary <string, object> values,
                   HttpRouteDirection routeDirection)
 {
     return(request.Headers.UserAgent
            .Where(x =>
                   x.Product != null && x.Product.Name != null &&
                   x.Product.Name.ToLowerInvariant().Contains(requiredUA))
            .Count() > 0);
 }
コード例 #54
0
 bool IHttpRouteConstraint.Match(
     HttpRequestMessage request,
     IHttpRoute route,
     string parameterName,
     IDictionary <string, object> values,
     HttpRouteDirection routeDirection
     )
 {
     return(Match(request, route, parameterName, values, routeDirection));
 }
コード例 #55
0
        public bool Match(HttpRequestMessage request, IHttpRoute route, string parameterName, IDictionary<string, object> values,
                          HttpRouteDirection routeDirection)
        {
            if (routeDirection == HttpRouteDirection.UriGeneration)
            {
                return true;
            }

            return request.Headers.Accept.Any(ah => ah.MediaType == "text/html");
        }
コード例 #56
0
 /// <inheritdoc />
 public bool Match(HttpRequestMessage request, IHttpRoute route, string parameterName, IDictionary<string, object> values, HttpRouteDirection routeDirection)
 {
     foreach (IHttpRouteConstraint constraint in Constraints)
     {
         if (!constraint.Match(request, route, parameterName, values, routeDirection))
         {
             return false;
         }
     }
     return true;
 }
コード例 #57
0
        public bool Match(HttpRequestMessage request, IHttpRoute route, string parameterName,
            IDictionary<string, object> values, HttpRouteDirection routeDirection)
        {
            object value;
            if (values.TryGetValue(parameterName, out value) && value != null)
            {
                return Values.Contains(value.ToString(), StringComparer.OrdinalIgnoreCase);
            }

            return false;
        }
コード例 #58
0
		public bool Match(
			HttpRequestMessage request,
			IHttpRoute route,
			string parameterName,
			IDictionary<string, object> values,
			HttpRouteDirection routeDirection)
		{
			var isSwagger = "swagger".Equals(values["controller"] as string, StringComparison.InvariantCultureIgnoreCase);

			return !isSwagger;
		}
コード例 #59
0
ファイル: GuidConstraint.cs プロジェクト: stevenbey/elfar
 public bool Match(
     HttpRequestMessage request,
     IHttpRoute route,
     string parameterName,
     IDictionary<string, object> values,
     HttpRouteDirection routeDirection)
 {
     var value = values[parameterName];
     Guid guid;
     return value is RouteParameter || value is Guid || (value is string && Guid.TryParse((string)value, out guid));
 }
 protected override bool Match(HttpRequestMessage request, IHttpRoute route, string parameterName, System.Collections.Generic.IDictionary<string, object> values, HttpRouteDirection routeDirection)
 {
     if (routeDirection == HttpRouteDirection.UriResolution)
     {
         var method = request.RequestUri.ParseQueryString()["_method"];
         if (method != null)
         {
             request.Method = new HttpMethod(method);
         }
     }
     return base.Match(request, route, parameterName, values, routeDirection);
 }