コード例 #1
0
ファイル: WeatherListViewModel.cs プロジェクト: xamcat/xvts
        private async Task LoadDataAsync()
        {
            var currentLocationTask = _locationService.GetCurrentLocationAsync();
            var favoriteCitiesTask  = _favoritesService.GetFavoriteCitiesAsync();

            await Task.WhenAll(currentLocationTask, favoriteCitiesTask).ConfigureAwait(false);

            var currentLocation = currentLocationTask.Result;
            var favoriteCities  = favoriteCitiesTask.Result;

            var requests = new ObservableCollection <WeatherRequest>(favoriteCities.Select(c => new WeatherRequest
            {
                City = c
            }));

            if (currentLocation != null)
            {
                var lwr = new LocationWeatherRequest
                {
                    City = new City {
                        Name = "Loading..."
                    }
                };

                requests.Insert(0, lwr);
                GetCurrentLocationWeather(currentLocation);
            }

            WeatherRequests = requests;

            ReloadAction?.Invoke();
        }
コード例 #2
0
 private async void PART_Reload_Click(object sender, RoutedEventArgs e)
 {
     if (ReloadEnabled && ReloadAction is Action)
     {
         e.Handled = true;
         await ReloadAction.InvokeAsync();
     }
 }
コード例 #3
0
ファイル: WeatherListViewModel.cs プロジェクト: xamcat/xvts
        private async Task AddFavorite()
        {
            var favoriteText = await _alertService.DisplayInputEntryAsync("MCWeather", "Enter city name", validator : (text) =>
            {
                return(WeatherRequests?.Where((WeatherRequest i) => (i as WeatherRequest)?.City?.Name == text).Count() == 0);
            });

            if (!string.IsNullOrWhiteSpace(favoriteText))
            {
                Weather weather = null;

                try
                {
                    weather = await _weatherService.GetWeatherAsync(favoriteText);
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex.Message);
                }
                finally
                {
                    if (weather == null)
                    {
                        await _alertService.DisplayAsync("MCWeather", $"Cannot find weather data for {favoriteText}", "OK");
                    }
                    else
                    {
                        var favoriteCity = await _favoritesService.AddFavoriteCityAsync(new City { Name = favoriteText });

                        WeatherRequests.Add(new WeatherRequest {
                            City = new City {
                                Name = favoriteText
                            }
                        });
                        ReloadAction?.Invoke();
                    }
                }
            }
        }
コード例 #4
0
ファイル: WeatherListViewModel.cs プロジェクト: xamcat/xvts
        private void GetCurrentLocationWeather(LocationInfo currentLocation)
        {
            Task.Run(async() =>
            {
                var currentCityName = await _locationService.GetCityNameFromLocationAsync(currentLocation);
                var currentWeather  = await _weatherService.GetWeatherAsync(currentCityName);

                var lwr = new LocationWeatherRequest
                {
                    City = new City {
                        Name = currentCityName
                    },
                    Position = new Position {
                        Latitude = currentLocation.Latitude, Longitude = currentLocation.Longitude
                    },
                    Weather = currentWeather
                };

                WeatherRequests[0] = lwr;
                ReloadAction?.Invoke();
            });
        }
コード例 #5
0
 public AutoResult(string message, string reloadUrl, ReloadAction reloadOption)
 {
     Message      = message;
     ReloadUrl    = reloadUrl;
     ReloadOption = reloadOption;
 }
コード例 #6
0
ファイル: AutoResult.cs プロジェクト: mbsky/myextensions
 public AutoResult(string message, string reloadUrl, ReloadAction reloadOption)
 {
     Message = message;
     ReloadUrl = reloadUrl;
     ReloadOption = reloadOption;
 }