Beispiel #1
0
        public async Task <HttpResponseMessage> HandleActualRequest(RavenBaseApiController controller,
                                                                    HttpControllerContext controllerContext,
                                                                    Func <Task <HttpResponseMessage> > action,
                                                                    Func <HttpException, HttpResponseMessage> onHttpException)
        {
            HttpResponseMessage response = null;

            cancellationToken.ThrowIfCancellationRequested();

            Stopwatch sw = Stopwatch.StartNew();

            try
            {
                Interlocked.Increment(ref concurrentRequests);

                if (controller.SetupRequestToProperDatabase(this))
                {
                    if (controller.ResourceConfiguration.RejectClientsMode && controllerContext.Request.Headers.Contains(Constants.RavenClientVersion))
                    {
                        response = new HttpResponseMessage(HttpStatusCode.ServiceUnavailable)
                        {
                            Content = new MultiGetSafeStringContent("This service is not accepting clients calls")
                        };
                    }
                    else
                    {
                        response = await action();
                    }
                }
            }
            catch (HttpException httpException)
            {
                response = onHttpException(httpException);
            }

            finally
            {
                Interlocked.Decrement(ref concurrentRequests);
                try
                {
                    FinalizeRequestProcessing(controller, response, sw);
                }

                catch (Exception e)
                {
                    var aggregateException = e as AggregateException;
                    if (aggregateException != null)
                    {
                        e = aggregateException.ExtractSingleInnerException();
                    }

                    Logger.ErrorException("Could not finalize request properly", e);
                }
            }
            return(response);
        }
Beispiel #2
0
        public async Task <HttpResponseMessage> HandleActualRequest(RavenBaseApiController controller,
                                                                    Func <Task <HttpResponseMessage> > action,
                                                                    Func <HttpException, HttpResponseMessage> onHttpException)
        {
            HttpResponseMessage response = null;

            cancellationToken.ThrowIfCancellationRequested();

            Stopwatch sw = Stopwatch.StartNew();

            try
            {
                Interlocked.Increment(ref concurrentRequests);
                if (IsWriteRequest(controller.InnerRequest))
                {
                    lastWriteRequest = SystemTime.UtcNow;
                }


                if (controller.SetupRequestToProperDatabase(this))
                {
                    response = await action();
                }
            }


            catch (HttpException httpException)
            {
                response = onHttpException(httpException);
            }

            finally
            {
                Interlocked.Decrement(ref concurrentRequests);
                try
                {
                    FinalizeRequestProcessing(controller, response, sw);
                }

                catch (Exception e)
                {
                    var aggregateException = e as AggregateException;
                    if (aggregateException != null)
                    {
                        e = aggregateException.ExtractSingleInnerException();
                    }

                    Logger.ErrorException("Could not finalize request properly", e);
                }
            }
            return(response);
        }
		public async Task<HttpResponseMessage> HandleActualRequest(RavenBaseApiController controller,
																   HttpControllerContext controllerContext,
																   Func<Task<HttpResponseMessage>> action,
																   Func<HttpException, HttpResponseMessage> onHttpException)
		{

			HttpResponseMessage response = null;
			cancellationToken.ThrowIfCancellationRequested();

			Stopwatch sw = Stopwatch.StartNew();
			try
			{
				Interlocked.Increment(ref concurrentRequests);

				if (controller.SetupRequestToProperDatabase(this))
				{
					if (controller.ResourceConfiguration.RejectClientsMode && controllerContext.Request.Headers.Contains(Constants.RavenClientVersion))
					{
						response = new HttpResponseMessage(HttpStatusCode.ServiceUnavailable)
						{
							Content = new StringContent("This service is not accepting clients calls")
						};
					}
					else
					{
						response = await action();
					}
				}
			}
			catch (HttpException httpException)
			{
				response = onHttpException(httpException);
			}

			finally
			{

				Interlocked.Decrement(ref concurrentRequests);
				try
				{
					FinalizeRequestProcessing(controller, response, sw);
				}

				catch (Exception e)
				{

					var aggregateException = e as AggregateException;
					if (aggregateException != null)
					{

						e = aggregateException.ExtractSingleInnerException();
					}

					Logger.ErrorException("Could not finalize request properly", e);
				}
			}
			return response;
		}
        public async Task<HttpResponseMessage> HandleActualRequest(RavenBaseApiController controller,
		                                                           Func<Task<HttpResponseMessage>> action,
		                                                           Func<HttpException, HttpResponseMessage> onHttpException)
	    {
	        HttpResponseMessage response = null;
            cancellationToken.ThrowIfCancellationRequested();

	        Stopwatch sw = Stopwatch.StartNew();
	        try
	        {
	            Interlocked.Increment(ref concurrentRequests);
	            if (IsWriteRequest(controller.InnerRequest))
	            {
	                lastWriteRequest = SystemTime.UtcNow;
	            }

                if (controller.SetupRequestToProperDatabase(this))
	            {
	                response = await action();
	            }
	        }
	        catch (HttpException httpException)
	        {
	            response = onHttpException(httpException);
	        }
	        finally
	        {
	            Interlocked.Decrement(ref concurrentRequests);
	            try
	            {
	                FinalizeRequestProcessing(controller, response, sw);
	            }
	            catch (Exception e)
	            {
		            var aggregateException = e as AggregateException;
		            if (aggregateException != null)
		            {
			            e = aggregateException.ExtractSingleInnerException();
		            }
		            Logger.ErrorException("Could not finalize request properly", e);
	            }
	        }

	        return response;
	    }