/// <summary>
        /// Make OpenWeather API Call to get location coordinates from search string
        /// </summary>
        public async void SetLocation()
        {
            try
            {
                await LocationSearch.SearchLocations();
            }
            catch (Exception)
            {
                var E = new ErrorMessage("An error occurred whilst searching for location");
                DisplayErrors.Add(E);
            }

            if (LocationSearch.SearchResults.Count == 0)
            {
                var E = new ErrorMessage($"Could not find a Match for {LocationSearch.SearchText}");
                DisplayErrors.Clear();
                DisplayErrors.Add(E);
            }
            else
            {   // results found
                DisplayErrors.Clear();
                Location = LocationSearch.SearchResults[0];
                GetForecast();
            }
        }
Exemplo n.º 2
0
        private void BuildingCardsErrors(object sender, CardMimicStatusEventArgs e)
        {
            if (!e.IsError)
            {
                return;
            }

            DisplayErrors.Add(e.Message);
        }
        /// <summary>
        /// Make OpenWeather API Call to get weather information
        /// </summary>
        public async void GetForecast()
        {
            try
            {
                var excludePeriod = new PeriodOptions[] { PeriodOptions.Minutely, PeriodOptions.Hourly };
                OneCallResponse = await OpenWeather.OneCall(Location.Lat, Location.Lon, excludePeriod);

                SetForecast();
            }
            catch (Exception)
            {
                var E = new ErrorMessage("An error occurred whilst getting weather forecast");
                DisplayErrors.Add(E);
            }
        }