コード例 #1
0
        public static async Task <List <BetaCardData> > LoadBetaCardsList(ICardsDataDownloader cardsDataDownloader, IAdminConfig adminConfig)
        {
            if (betaCardsList == null)
            {
                string betaToOfficialCardsData = await cardsDataDownloader.DownloadCardsFromWebsite(adminConfig.BetaToOfficialCardApiURL);

                JArray betaCardsListJArray = JsonConvert.DeserializeObject <JArray>(betaToOfficialCardsData);
                betaCardsList = new List <BetaCardData>();
                lock (betaCardsList)
                {
                    foreach (JObject jObject in betaCardsListJArray)
                    {
                        int    officialId = jObject.Value <int>("ocode");
                        int    betaId     = jObject.Value <int>("ucode");
                        string name       = jObject.Value <string>("name");
                        if (officialId > 0 && betaId > 0)
                        {
                            betaCardsList.Add(new BetaCardData(name, officialId, betaId));
                        }
                    }
                }
            }

            return(betaCardsList);
        }
コード例 #2
0
        public async Task DownloadCardsFromWebsite_SourceShouldBeAvailable_WeGetDataAsStringLongerThen0()
        {
            _downloader = new CardsDataDownloader();
            string result = await _downloader.DownloadCardsFromWebsite("https://db.ygoprodeck.com/api/v3/cardinfo.php");

            Assert.NotZero(result.Count());
        }
        /// <summary>
        /// Updates the cards and archetypes.
        /// </summary>
        /// <param name="URL">The URL.</param>
        /// <exception cref="DbUpdateException"></exception>
        /// <exception cref="DbUpdateConcurrencyException"></exception>
        public async Task UpdateCardsAndArchetypes(string URL)
        {
            _archetypes = _db.Archetypes.ToList();
            _cards      = _db.Cards.ToList();
            string cardsData = await _cardsDataDownloader.DownloadCardsFromWebsite(URL);

            JToken cardsDataList = (JsonConvert.DeserializeObject <JArray>(cardsData)).First;

            foreach (JObject item in cardsDataList.Children <JObject>())
            {
                if (_cardAlreadyExistInOurDatabase(item))
                {
                    continue;
                }

                string    type = item.Value <string>("type").ToUpper();
                Archetype archetype;
                if (item.GetValue("archetype").ToString() == string.Empty)
                {
                    archetype = _getArchetype(Archetype.Default);
                }
                else
                {
                    archetype = _getArchetype(item.Value <string>("archetype"));
                }

                if (type.Contains("MONSTER"))
                {
                    _addMonsterProperties(type, archetype, item);
                }

                _addBasicCardProperties(item, archetype);
                _db.Cards.Add(_cardBuilder.Build());
            }

            await _db.SaveChangesAsync();
        }
コード例 #4
0
        public void DownloadCardsFromWebsite_WrongUrlIsGiven_WeGetWebException()
        {
            _downloader = new CardsDataDownloader();

            Assert.ThrowsAsync <System.Net.WebException>(async() => await _downloader.DownloadCardsFromWebsite("Wronghttps://db.ygoprodeck.com/api/v3/cardinfo.php"));
        }