コード例 #1
0
 public void DealWithPreviouslyOccurredExceptions(RequestProcessingContext context)
 {
     var response = CreateResponse(context);
     response.Exception = new ExceptionInfo(new Exception(ExceptionType.EarlierRequestAlreadyFailed.ToString()));
     response.ExceptionType = ExceptionType.EarlierRequestAlreadyFailed;
     context.MarkAsProcessed(response);
 }
コード例 #2
0
 public void DealWithException(RequestProcessingContext context, Exception exception)
 {
     var response = CreateResponse(context);
     response.Exception = new ExceptionInfo(exception);
     SetExceptionType(response, exception);
     context.MarkAsProcessed(response);
 }
コード例 #3
0
 public override void BeforeHandlingRequest(RequestProcessingContext context)
 {
     try
     {
         Validate.Object(context.Request as dynamic);
     }
     catch (ValidationException exc)
     {
         var response = CreateDefaultResponseFor(context.Request);
         response.Exception = new ExceptionInfo(exc);
         response.ExceptionType = ExceptionType.Unknown;
         context.MarkAsProcessed(response);
     }
 }
コード例 #4
0
        private void DispatchRequestsToHandlers(List<Response> responses, params Request[] requests)
        {
            bool exceptionsPreviouslyOccurred = false;

            foreach (var request in requests)
            {
                var requestProcessingState = new RequestProcessingContext(request);
                IList<IRequestHandlerInterceptor> interceptors = new List<IRequestHandlerInterceptor>();
                try
                {
                    IList<IRequestHandlerInterceptor> invokedInterceptors = new List<IRequestHandlerInterceptor>();
                    if (!exceptionsPreviouslyOccurred)
                    {
                        interceptors = ResolveInterceptors();

                        foreach (var interceptor in interceptors)
                        {
                            interceptor.BeforeHandlingRequest(requestProcessingState);
                            invokedInterceptors.Add(interceptor);
                            if (requestProcessingState.IsProcessed)
                            {
                                responses.Add(requestProcessingState.Response);
                                break;
                            }
                        }
                    }

                    if (!requestProcessingState.IsProcessed)
                    {
                        var skipHandler = false;
                        var cachingIsEnabledForThisRequest = _cacheManager.IsCachingEnabledFor(request.GetType());

                        if (cachingIsEnabledForThisRequest)
                        {
                            var cachedResponse = _cacheManager.GetCachedResponseFor(request);

                            if (cachedResponse != null)
                            {
                                if (exceptionsPreviouslyOccurred)
                                {
                                    var dummyResponse = Activator.CreateInstance(cachedResponse.GetType()) as Response;
                                    responses.Add(SetStandardExceptionInfoWhenEarlierRequestsFailed(dummyResponse));
                                    requestProcessingState.MarkAsProcessed(dummyResponse);
                                }
                                else
                                {
                                    responses.Add(cachedResponse);
                                    requestProcessingState.MarkAsProcessed(cachedResponse);
                                }

                                skipHandler = true;
                            }
                        }
                        if (!skipHandler)
                        {
                            BeforeResolvingRequestHandler(request);

                            using (var handler = (IRequestHandler)IoC.Container.Resolve(GetRequestHandlerTypeFor(request)))
                            {
                                try
                                {
                                    if (!exceptionsPreviouslyOccurred)
                                    {
                                        var response = GetResponseFromHandler(request, handler);
                                        exceptionsPreviouslyOccurred = response.ExceptionType != ExceptionType.None;
                                        responses.Add(response);
                                        requestProcessingState.MarkAsProcessed(response);

                                        if (response.ExceptionType == ExceptionType.None && cachingIsEnabledForThisRequest)
                                        {
                                            _cacheManager.StoreInCache(request, response);
                                        }
                                    }
                                    else
                                    {
                                        var response = handler.CreateDefaultResponse();
                                        responses.Add(SetStandardExceptionInfoWhenEarlierRequestsFailed(response));
                                        requestProcessingState.MarkAsProcessed(response);
                                    }
                                }
                                finally
                                {
                                    IoC.Container.Release(handler);
                                }
                            }
                        }
                    }

                    foreach (var interceptor in invokedInterceptors.Reverse())
                    {
                        interceptor.AfterHandlingRequest(requestProcessingState);
                    }
                    invokedInterceptors.Clear();
                }
                finally
                {
                    SaveDisposeInterceptors(interceptors);
                }
            }
        }
コード例 #5
0
ファイル: RequestProcessor.cs プロジェクト: Cyber1000/Agatha
        private void InvokeRequestHandler(RequestProcessingContext requestProcessingState)
        {
            var request = requestProcessingState.Request;

            BeforeResolvingRequestHandler(request);

            using (var handler = (IRequestHandler)IoC.Container.Resolve(GetRequestHandlerTypeFor(request)))
            {
                try
                {
                    var response = GetResponseFromHandler(request, handler);
                    requestProcessingState.MarkAsProcessed(response);
                }
                finally
                {
                    IoC.Container.Release(handler);
                }
            }
        }
コード例 #6
0
ファイル: RequestProcessor.cs プロジェクト: hoghweed/Agatha
        private void HandleRequest(RequestProcessingContext requestProcessingState)
        {
            var request = requestProcessingState.Request;

            if (request is OneWayRequest)
            {
                using (var handler = (IOneWayRequestHandler)IoC.Container.Resolve(GetOneWayRequestHandlerTypeFor(request)))
                {
                    try
                    {
                        ExecuteHandler((OneWayRequest)request, handler);
                    }
                    finally
                    {
                        IoC.Container.Release(handler);
                    }
                }
            }
            else
            {
                using (var handler = (IRequestHandler)IoC.Container.Resolve(GetRequestHandlerTypeFor(request)))
                {
                    try
                    {
                        var response = GetResponseFromHandler(request, handler);
                        requestProcessingState.MarkAsProcessed(response);
                    }
                    finally
                    {
                        IoC.Container.Release(handler);
                    }
                }
            }
        }