Exemple #1
0
 public static string ToJson(HistoricalDataRequest req) => JsonConvert.SerializeObject(req, Converter.Settings);
        public async Task <ActionResult <HistoricalDataResponse> > GetHistoricalData(CancellationToken cancellationToken, string machineId, [FromBody] HistoricalDataRequest request)
        {
            try
            {
                var keys = await _historicalDataService.GetHistoricalDataAsync(cancellationToken, machineId, request);

                return(Ok(keys));
            }
            catch (HttpException ex)
            {
                switch (ex.StatusCode)
                {
                case HttpStatusCode.NotFound:
                    return(NotFound());

                default:
                    throw ex;
                }
            }
        }
        public async Task <HistoricalDataResponse> GetHistoricalDataAsync(CancellationToken cancellationToken, string machineId, HistoricalDataRequest historicalDataRequest)
        {
            var token = await _tokenProvider.ReceiveTokenAsync(TapioScope.CoreApi);

            var request = new HttpRequestMessage(HttpMethod.Post, new Uri(String.Format(GetHistoricalData, machineId)));

            request.Content = new StringContent(HistoricalDataReqeuestExtension.ToJson(historicalDataRequest), Encoding.UTF8, "application/json");
            request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", token);
            var responseMessage = await _httpClient.SendAsync(request, cancellationToken);

            Console.WriteLine(responseMessage);
            if (!responseMessage.IsSuccessStatusCode)
            {
                throw new HttpException(responseMessage.StatusCode);
            }
            var content = await responseMessage.Content.ReadAsStringAsync();

            var result = HistoricalDataResponseExtension.FromJson(content);

            return(result);
        }