예제 #1
0
        public async Task GetWeatherConditions(bool GenerateLocation = false)
        {
            try
            {
                if (_connectivity.IsConnected())
                {
                    var CurrentResult = await _weather.GetCurrentWeather(GenerateLocation);

                    if (CurrentResult != null)
                    {
                        CurrentConditions = CurrentResult;
                    }
                    else
                    {
                        await _pageDialogService.DisplayAlertAsync("Error", "Unable to fetch Current Location, please make sure location is enabled", "OK");

                        NoInternet();
                    }

                    var ForeCastResult = await _weather.GetForecastWeather(GenerateLocation);

                    if (ForeCastResult != null)
                    {
                        ForeCastConditions = new ObservableCollection <List>(ForeCastResult);
                    }
                    else
                    {
                        await _pageDialogService.DisplayAlertAsync("Error", "Unable to fetch forecast , please make sure location is enabled", "OK");

                        NoInternet();
                    }
                }
                else
                {
                    await Task.Delay(100);

                    await _pageDialogService.DisplayAlertAsync("Internet", "Please enable internet and restart app to continue", "OK");

                    NoInternet();
                }
            }
            catch (System.Exception ex)
            {
                await Task.Delay(100);

                Debug.WriteLine(ex);
                await _pageDialogService.DisplayAlertAsync("Internet", "Unknow error, please try again later", "OK");

                NoInternet();
            }
        }