private async Task ImportPokemonSet(object arg) { using (var client = new WebClient()) { var json = await client.DownloadStringTaskAsync($"https://api.pokemontcg.io/v1/cards?setCode={SelectedSet.SetCode}&supertype=Pok%C3%A9mon").ConfigureAwait(false); var headers = client.ResponseHeaders; int cardsFound = int.Parse(headers.Get("Count")); int pageSize = int.Parse(headers.Get("Page-Size")); if (cardsFound > pageSize) { //TODO MessageBox.Show("There are more cards!!!"); } var pokemons = new List <PokemonViewModel>(); foreach (var card in JsonConvert.DeserializeObject <JsonPokemonList>(json).Cards) { var pokemon = PokemonCreator.CreateCardFromSdkCard(card); var model = new PokemonViewModel(pokemon); model.Card.CardId = NetworkId.Generate(); pokemons.Add(model); } foreach (var pokemon in pokemons.OrderBy(x => x.Card.Name)) { PokemonCards.Add(pokemon); } SelectedCard = PokemonCards.First(); } }
private void ImportPokemon(object obj) { var dialog = new ImportPokemon(); if (dialog.ShowDialog().Value) { using (var client = new WebClient()) { try { var json = client.DownloadString(dialog.Url); var pokemonSdk = JsonConvert.DeserializeObject <JsonPokemon>(json); var pokemon = PokemonCreator.CreateCardFromSdkCard(pokemonSdk); PokemonCards.Add(new PokemonViewModel(pokemon)); SelectedCard = PokemonCards.Last(); SelectedCard.Card.CardId = NetworkId.Generate(); } catch { } } } }
public static async Task <PokemonCards> GetPokemonCardsAsync() { string url = $"https://api.pokemontcg.io/v1/cards"; //Create and use HttpClient using (HttpClient client = GetHttpClient()) { try { PokemonCards result = new PokemonCards(); //Ask for JSON data string content = await client.GetStringAsync(url); //Convert data to Quote object PokemonCards cards = JsonConvert.DeserializeObject <PokemonCards>(content); foreach (var card in cards) { result.Add(card); } return(result); } catch (Exception ex) { throw ex; } } }
internal async Task Load() { if (!File.Exists("Data/pokemon.json")) { return; } var json = await File.ReadAllTextAsync("Data/pokemon.json"); PokemonCards.Clear(); foreach (var pokemon in Serializer.Deserialize <List <PokemonCard> >(json).OrderBy(x => x.SetCode).ThenBy(x => x.Name)) { PokemonCards.Add(new PokemonViewModel(pokemon)); } }
private void AddNewPokemon(object obj) { PokemonCards.Add(new PokemonViewModel()); SelectedCard = PokemonCards.Last(); SelectedCard.Card.CardId = NetworkId.Generate(); }