/// <inheritdoc /> public string UpdateDataFromOnlineServices() { try { var config = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile("appsettings.json", true) .Build(); string place = config.GetSection("Place").Value != null? config.GetSection("Place").Value: "Harku"; string station = config.GetSection("Station").Value != null? config.GetSection("Station").Value: "Tallinn-Harku"; var observationsStation = ObservationsServiceRepository.GetStationData(station); ForecastsServiceRepository.GetServiceData(); var forecasts = ForecastsServiceRepository.Parse().Items; var observation = new Observation { AirTemperature = double.Parse(observationsStation.airtemperature), Date = new DateTime().FromUnixTimeStamp(double.Parse(ObservationsServiceRepository.Data.timestamp)) }; ObservationRepository.AddOrUpdate(observation); foreach (var forecastPlaceObj in forecasts) { forecastsForecast forecastPlace = (forecastsForecast)forecastPlaceObj; var forecast = new Forecast(); forecast.Date = DateTime.Parse(forecastPlace.date); //These temperatures are regional forecast.MinDayTemperature = double.Parse(forecastPlace.day[0].tempmin); forecast.MaxNightTemperature = double.Parse(forecastPlace.night[0].tempmax); //These temperatures are place specific but not always available try { forecast.MaxDayTemperature = double.Parse( (from p in forecastPlace.day[0].place where p.name.Equals(place) select p.tempmax).FirstOrDefault()); } catch { forecast.MaxDayTemperature = double.Parse(forecastPlace.day[0].tempmax); } try { forecast.MinNightTemperature = double.Parse( (from p in forecastPlace.night[0].place where p.name.Equals(place) select p.tempmin).FirstOrDefault()); } catch { forecast.MinNightTemperature = double.Parse(forecastPlace.night[0].tempmin); } ForecastRepository.AddOrUpdate(forecast); } } catch (System.Net.WebException) { return("The weather service is off-line"); } catch (Exception e) { return("There was an Internal error when the server tried to update the weather information: \n" + e.Message); } return(""); }