Esempio n. 1
0
        public async Task <Response <TResponseParser> > RunAsync <TResponseParser>()
            where TResponseParser : IResponseParser, new()
        {
            _cancelactionTokenSource = new CancellationTokenSource();
            Exception = null;

            var stopwatch = Stopwatch.StartNew();
            Response <TResponseParser> response = null;

            try
            {
                var httpResponse = await SendRequestAsync(
                    CreateClient(), TypedConfig.BuildUrl(), _cancelactionTokenSource.Token);

                response = await CreateResponse <TResponseParser>(httpResponse);
            }
            catch (TaskCanceledException e)
            {
                response = CreateCancelationResponse <TResponseParser>(e);
            }
            catch (HttpRequestException e)
            {
                response = CreateHttpExceptionResponse <TResponseParser>(e);
            }
            finally
            {
                stopwatch.Stop();
                if ((_logger != null) && (response != null))
                {
                    await _logger.LogAsync(response, stopwatch.Elapsed);
                }
            }

            return(response);
        }