Ejemplo n.º 1
0
        /// <summary>
        /// Parses the given URL into segments, and if this matcher has any named captures specified
        /// it adds them to the collection to be indexed.
        /// </summary>
        /// <param name="uri">URL to parse and match.</param>
        /// <param name="startIndex">Index to start matching from.</param>
        public UrlSegmentCollection GetSegments(Uri uri, int startIndex = 0)
        {
            var segments = new UrlSegmentCollection(uri);

            FurnishMatchedSegments(uri, segments, ref startIndex);
            return(segments);
        }
Ejemplo n.º 2
0
        internal override void FurnishMatchedSegments(Uri uri, UrlSegmentCollection collection, ref int startIndex)
        {
            var match = Match(uri, startIndex);
            var first = collection.GetFirstIndex(match);
            var last  = collection.GetLastIndex(match);

            for (var i = first; i <= last; ++i)
            {
                var capture = _captures[i - first];
                if (capture == null)
                {
                    continue;
                }
                collection.SetIndexName(i, capture.Name, capture.Prefix.Length, capture.Postfix.Length);
            }

            startIndex = match.EndIndex;
        }
Ejemplo n.º 3
0
 internal override void FurnishMatchedSegments(Uri uri, UrlSegmentCollection collection, ref int startIndex)
 {
     _first.FurnishMatchedSegments(uri, collection, ref startIndex);
     _second.FurnishMatchedSegments(uri, collection, ref startIndex);
 }
Ejemplo n.º 4
0
 internal virtual void FurnishMatchedSegments(Uri uri, UrlSegmentCollection collection, ref int startIndex)
 {
     startIndex = Match(uri, startIndex).EndIndex;
 }
Ejemplo n.º 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
        }