Пример #1
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
        }