Exemplo n.º 1
0
 /// <summary>
 /// Initialize LoadingBar service instance.
 /// </summary>
 public LoadingBar(HttpClientInterceptor interceptor, IJSRuntime jSRuntime)
 {
     this.Interceptor             = interceptor;
     this.JSRuntime               = jSRuntime;
     interceptor.BeforeSendAsync += this.Interceptor_BeforeSendAsync;
     interceptor.AfterSend       += this.Interceptor_AfterSend;
 }
Exemplo n.º 2
0
        protected override async Task <HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
        {
            if (this.Interceptor == null)
            {
                this.Interceptor = this.Services.GetService <HttpClientInterceptor>();
            }
            var response = default(HttpResponseMessage);

            try
            {
                this.Interceptor.InvokeBeforeSend(new HttpClientInterceptorEventArgs(request, response));
                response = await(SendAsyncMethod.Invoke(this.BaseHandler, new object[] { request, cancellationToken }) as Task <HttpResponseMessage>);
                return(response);
            }
            finally
            {
                this.Interceptor.InvokeAfterSend(new HttpClientInterceptorEventArgs(request, response));
            }
        }
Exemplo n.º 3
0
        protected override async Task <HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
        {
            if (this.Interceptor == null)
            {
                this.Interceptor = this.Services.GetService <HttpClientInterceptor>();
            }
            var response  = default(HttpResponseMessage);
            var exception = default(Exception);
            var args      = new HttpClientInterceptorEventArgs(request);

            try
            {
                await this.Interceptor.InvokeBeforeSendAsync(args);

                if (args.Cancel)
                {
                    response = new HttpResponseMessage(HttpStatusCode.NoContent);
                }
                else
                {
                    response = await(SendAsyncMethod.Invoke(this.BaseHandler, new object[] { request, cancellationToken }) as Task <HttpResponseMessage>);
                }
                return(response);
            }
            catch (Exception e)
            {
                exception = e;
                throw;
            }
            finally
            {
                if (!args.Cancel)
                {
                    var argsAfter = new HttpClientInterceptorEventArgs(request, response, exception);
                    await this.Interceptor.InvokeAfterSendAsync(argsAfter);

                    await args._AsyncTask;
                }
            }
        }