Пример #1
0
        internal void SetMatchedActionUrl(UrlMatcher matcher, UrlMatch match)
        {
            _actionMatcher = matcher;
            _actionMatch   = match;

            _urlMatcher = new ConcatenatedPrefixMatcher(ControllerMatcher, ActionMatcher);
        }
Пример #2
0
        internal int GetLastIndex(UrlMatch match)
        {
            if (Count == 0)
            {
                return(-1);
            }
            for (var i = _segments.Length - 1; i >= 0; --i)
            {
                if (_segments[i].EndIndex > match.EndIndex)
                {
                    continue;
                }
                if (_segments[i].Index >= match.Index)
                {
                    return(i);
                }
                return(-1);
            }

            return(-1);
        }
Пример #3
0
        internal int GetFirstIndex(UrlMatch match)
        {
            if (Count == 0)
            {
                return(-1);
            }
            for (var i = 0; i < _segments.Length; ++i)
            {
                if (_segments[i].Index < match.Index)
                {
                    continue;
                }
                if (_segments[i].EndIndex <= match.EndIndex)
                {
                    return(i);
                }
                return(-1);
            }

            return(-1);
        }
Пример #4
0
 private static bool IsMatchingAllUrl(UrlMatch match, Uri uri)
 {
     return(match.EndIndex == uri.AbsolutePath.TrimEnd('/').Length);
 }
Пример #5
0
        internal bool Service(HttpListenerContext context, Session session)
        {
            // Debug.Assert( session == Session || Session == null );
            if (Session == null)
            {
                session.AddController(this);
            }

            _request  = context.Request;
            _response = context.Response;
            _session  = session;

            switch (Request.HttpMethod)
            {
            case "GET": _httpMethod = HttpMethod.Get; break;

            case "POST": _httpMethod = HttpMethod.Post; break;

            case "HEAD": _httpMethod = HttpMethod.Head; break;

            case "DELETE": _httpMethod = HttpMethod.Delete; break;

            case "OPTIONS": _httpMethod = HttpMethod.Options; break;

            case "PUT": _httpMethod = HttpMethod.Put; break;

            case "TRACE": _httpMethod = HttpMethod.Trace; break;

            default: _httpMethod = null; break;
            }

            LastRequestTime = DateTime.UtcNow;

            _entityBodyString = null;
            _formData         = null;
            _urlSegments      = null;

            _controllerMatch = ControllerMatcher.Match(Request.Url);
            _actionMatch     = UrlMatch.Failure;

            try
            {
                return(ActionMap.TryInvokeAction(this, context.Request));
            }
            catch (ControllerActionException e)
            {
                if (!e.RequestHandled)
                {
                    return(false);
                }

                OnUnhandledException(e);
                return(true);
            }
#if !DEBUG
            catch (Exception e)
            {
                OnUnhandledException(new ControllerActionException(Request, false, HttpStatusCode.InternalServerError, e.Message, e));
                return(true);
            }
#endif
        }