public async Task <IActionResult> Index()
        {
            var apiClient = await _sensorHttpClient.GetClient();

            using (apiClient)
            {
                try
                {
                    var response = await apiClient.GetAsync("api/Logs");

                    if (response.IsSuccessStatusCode)
                    {
                        var result = response.Content.ReadAsStringAsync().Result;

                        var logFiles  = JsonConvert.DeserializeObject <List <Log> >(result);
                        var viewModel = new ShowLogViewModel(logFiles);

                        return(View(viewModel));
                    }
                    throw new Exception($"A problem happened while calling the API: {response.ReasonPhrase}");
                }
                catch (HttpRequestException e)
                {
                    throw new HttpRequestException(e.Message);
                }
                catch (ArgumentNullException n)
                {
                    throw new ArgumentNullException(n.Message);
                }
            }
        }
Esempio n. 2
0
        public object CreateViewModel(DependencyObject sender)
        {
            ShowLogViewModel vm = new ShowLogViewModel();

            return(vm);
        }