コード例 #1
0
 public bool Match(string part, string value, int index, MatchData matchData)
 {
     if (!OnMatch(part, matchData))
     {
         return false;
     }
     if (index == -1)
     {
         if (_typeInfos == null) return false;
         matchData.Add(_typeInfos);
         return true;
     }
     int nextIndex = value.IndexOf('/', ++index);
     part = nextIndex == -1 ? value.Substring(index) : value.Substring(index, nextIndex - index);
     IMatcher matcher;
     if (_statics.TryGetValue(part, out matcher))
     {
         return matcher.Match(part, value, nextIndex, matchData);
     }
     bool found = false;
     foreach (var t in _matchers)
     {
         found = t.Match(part, value, nextIndex, matchData) || found;
     }
     return found;
 }
コード例 #2
0
        /// <summary>
        /// Gets the type of handler for the specified URL.
        /// </summary>
        /// <param name="url">The URL.</param>
        /// <param name="variables">The variables.</param>
        /// <param name="contentType">Value of the Content-Type header from the Request.</param>
        /// <param name="acceptTypes">Values of the Accepts header from the Request.</param>
        /// <returns></returns>
        public Type Get(string url, out IDictionary<string, string> variables, string contentType = null, IList<string> acceptTypes = null)
        {
            variables = null;
            url = url.Trim('/');
            int nextIndex = url.IndexOf('/');
            string part = nextIndex >= 0 ? url.Substring(0, nextIndex) : url;
            IMatcher matcher;
            var matchData = new MatchData();
            bool found = false;
            if (_statics.TryGetValue(part, out matcher))
            {
                found = matcher.Match(part, url, nextIndex, matchData);
            }
            if (!found)
            {
                found = _matchers.Aggregate(false, (current, t) => t.Match(part, url, nextIndex, matchData) || current);
            }

            if (!found) return null;

            variables = matchData.Variables;
            if (matchData.Single != null)
            {
                return matchData.Single.HandlerType;
            }

            return matchData.ResolveByMediaTypes(contentType, acceptTypes);
        }
コード例 #3
0
 protected override bool OnMatch(string part, MatchData matchData)
 {
     matchData.SetVariable(_trimmed, part);
     return true;
 }
コード例 #4
0
 protected override bool OnMatch(string value, MatchData matchData)
 {
     return value.Equals(Pattern, StringComparison.OrdinalIgnoreCase);
 }
コード例 #5
0
 protected abstract bool OnMatch(string part, MatchData matchData);
コード例 #6
0
 protected override bool OnMatch(string part, MatchData matchData)
 {
     matchData.SetVariable(_trimmed, part);
     return(true);
 }