public TResponse ExecuteRequest <TResponse>(IRestRequest restRequest) where TResponse : new()
        {
            _teamCityRequestPreparer.Prepare(restRequest);
            var response = _client.Execute <TResponse>(restRequest);

            _responseValidator.Validate(response);
            return(response.Data);
        }
Exemple #2
0
        public async Task <TResponse> ExecuteRequestAsync <TResponse>(IRestRequest restRequest) where TResponse : new()
        {
            _teamCityRequestPreparer.Prepare(restRequest);
            var taskCompletionSource = new TaskCompletionSource <IRestResponse <TResponse> >();

            _client.ExecuteAsync <TResponse>(restRequest, restResponse => {
                if (restResponse.ErrorException != null)
                {
                    try {
                        var responseContent = System.Text.Encoding.UTF8.GetString(restResponse.RawBytes);
                        _logger.Error(restResponse.ErrorException, "Error response from TeamCity: {status} {responseContent}", restResponse.StatusCode, responseContent);
                    } catch (Exception e) {
                        var aggregateException = new AggregateException(restResponse.ErrorException, e);
                        _logger.Error(aggregateException, "Error when calling TeamCity {status}", restResponse.StatusCode);
                    } finally {
                        taskCompletionSource.SetException(new Exception("Failed to make request to the TeamCity server", restResponse.ErrorException));
                    }
                }
                else
                {
                    taskCompletionSource.SetResult(restResponse);
                }
            });
            var responseTask = taskCompletionSource.Task;
            var response     = await responseTask;

            _responseValidator.Validate(response);
            return(response.Data);
        }
Exemple #3
0
        public async Task <Response <IEnumerable <MatchDetailsModel> > > GetMatchDetailsAsync(MatchBaseRequest request)
        {
            var validationResponse = _responseValidator.Validate(request);
            var response           = new Response <IEnumerable <MatchDetailsModel> >
            {
                ValidationResults = _responseValidator.Map(validationResponse)
            };

            if (!response.ValidationResults.IsValid)
            {
                return(response);
            }
            response.Data = await GetMatchStored(request);

            if (response.Data.IsNotNull())
            {
                return(response);
            }
            request.SessionId = await _sessionManager.GetKey();

            var clientResponse = await _matchClient.GetClientMatchDetailsAsync(request);

            response.Data = clientResponse.Select(x => _matchDetailsMapper.Map(x));
            response      = await MapChampionDetails(response);

            return(response);
        }
        public static async Task <Endpoints> Get(IRestClient restClient, IResponseValidator responseValidator)
        {
            var request = new RestRequest();

            var response = await restClient.ExecuteTaskAsync <EndpointList>(request);

            responseValidator.Validate(response);
            var endpoints = Convert(response.Data);

            endpoints.BaseUrl = restClient.BaseUrl;
            return(endpoints);
        }
Exemple #5
0
        public async Task <TResponse> ExecuteRequestAsync <TResponse>(IRestRequest restRequest) where TResponse : new()
        {
            _teamCityRequestPreparer.Prepare(restRequest);
            var taskCompletionSource = new TaskCompletionSource <IRestResponse <TResponse> >();

            _client.ExecuteAsync <TResponse>(restRequest, restResponse => {
                if (restResponse.ErrorException != null)
                {
                    const string message = "Failed to make request to the TeamCity server";
                    taskCompletionSource.SetException(new Exception(message, restResponse.ErrorException));
                }
                else
                {
                    taskCompletionSource.SetResult(restResponse);
                }
            });
            var responseTask = taskCompletionSource.Task;
            var response     = await responseTask;

            _responseValidator.Validate(response);
            return(response.Data);
        }