Esempio n. 1
0
        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();
            }
        }
Esempio n. 2
0
        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;
                }
            }
        }
Esempio n. 4
0
        private void UpdatePokemonFilter()
        {
            if (SelectedSet == null)
            {
                FilteredPokemonCards = PokemonCards.ToList();
                return;
            }

            FilteredPokemonCards = pokemonCards.Where(card => card.Card.SetCode == SelectedSet.SetCode).ToList();
        }
Esempio n. 5
0
        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));
            }
        }
Esempio n. 6
0
 private void DeletePokemon(object obj)
 {
     PokemonCards.Remove((PokemonViewModel)obj);
     UpdatePokemonFilter();
     SelectedCard = PokemonCards.First();
 }
Esempio n. 7
0
 private void PokemonCards_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
 {
     UpdatePokemonFilter();
     AllPokemonNames = PokemonCards.Select(p => p.Card.Name).Distinct().ToList();
     AllPokemonNames.Insert(0, string.Empty);
 }
Esempio n. 8
0
        internal async Task Save()
        {
            var json = Serializer.SerializeFormatted(PokemonCards.Select(card => card.Card).ToList());

            await File.WriteAllTextAsync("Data/pokemon.json", json);
        }
Esempio n. 9
0
 private void AddNewPokemon(object obj)
 {
     PokemonCards.Add(new PokemonViewModel());
     SelectedCard             = PokemonCards.Last();
     SelectedCard.Card.CardId = NetworkId.Generate();
 }
Esempio n. 10
0
 public async Task TestPokemonTGCInfo()
 {
     // get cards
     PokemonCards cards = await PokemonRepository.GetPokemonCardsAsync();
 }