public void TestFixtureSetUp() { // Deserialize test data string fileName = Path.Combine(GetTestDataPath(), testJsonFileName); testJsonSet = DeserailizeJsonSet(fileName); testJsonCards = DeserializeJsonCards(fileName); }
private SetEntity GetDistinctNewEntities(MtgJsonSet mtgJsonSet, List <SetEntity> setEntities) { if (setEntities == null || !setEntities.Any(s => s.Code == mtgJsonSet.Code)) { return(_mapper.Map <MtgJsonSet, SetEntity>(mtgJsonSet)); } return(null); }
private List <MtgJsonCard> MapPropertiesFromSetToCards(MtgJsonSet mtgJsonSet) { foreach (var card in mtgJsonSet.Cards) { card.Border = card.Border ?? mtgJsonSet.Border; card.SetTypeCode = mtgJsonSet.Code; } return(mtgJsonSet.Cards.ToList()); }
private void ImportAndInsertSets(MtgJsonSet mtgJsonSet) { //get from DB var entitiesFromDb = _codesRepo.GetSetEntities().ToList(); //Filter to exclude what is already in DB and map to entity var setEntityToAdd = GetDistinctNewEntities(mtgJsonSet, entitiesFromDb); if (setEntityToAdd != null) { //Insert new entities to DB _codesRepo.InsertSetEntity(setEntityToAdd); } }
public void TestFixtureSetUp() { searchUtilityMock = new Mock <SearchUtility>(); searchUtilityMock.Setup(s => s.GetSearchValue(It.IsAny <string>())) .Returns((string s) => this.GetSearchValue(s)); searchUtilityMock.Setup(s => s.GetRegexSearchValue(It.IsAny <string>())) .Returns((string s) => this.GetRegexSearchValue(s)); // Deserialize test data string fileName = Path.Combine(GetTestDataPath(), testJsonFileName); testJsonSet = DeserailizeJsonSet(fileName); testJsonCards = DeserializeJsonCards(fileName); }
private MtgJsonSet DeserailizeJsonSet(string fileName) { string data = File.ReadAllText(fileName); var settings = new JsonSerializerSettings(); settings.MissingMemberHandling = MissingMemberHandling.Ignore; MtgJsonSet set = JsonConvert.DeserializeObject <MtgJsonSet>(data, settings); // Get rarity quantities JObject cardObject = JObject.Parse(data); IList <JToken> results = cardObject["cards"].Children().ToList(); foreach (JToken result in results) { string rarity = result["rarity"].ToString(); switch (rarity.ToLower()) { case "basic land": set.BasicLandQty += 1; break; case "common": set.CommonQty += 1; break; case "mythic": case "mythic rare": set.MythicQty += 1; break; case "uncommon": set.UncommonQty += 1; break; case "rare": set.RareQty += 1; break; } } return(set); }
private MtgJsonSet ImportMtgJsonFromFile(string filename) { MtgJsonSet result = null; try { var path = $".\\MtgJsonSetFiles\\{filename}.json"; result = JsonConvert.DeserializeObject <MtgJsonSet>(File.ReadAllText(path)); } catch (Exception ex) { _logger.LogCritical($"Import from AllSets-x.json failed. {ex.Message}", new object[] { ex }); throw; } return(result); }
public IEnumerable <Card> ReadCards(string data) { if (string.IsNullOrEmpty(data)) { throw new ArgumentException("data"); } this.mLoggingService.Trace("JSON data = {0}", data); JObject cardObject = JObject.Parse(data); IList <JToken> results = cardObject["cards"].Children().ToList(); var settings = new JsonSerializerSettings(); settings.MissingMemberHandling = MissingMemberHandling.Ignore; // Read set info MtgJsonSet setData = JsonConvert.DeserializeObject <MtgJsonSet>(data, settings); foreach (JToken result in results) { this.mLoggingService.Debug("Deserializing MtgJsonCard..."); MtgJsonCard cardData = JsonConvert.DeserializeObject <MtgJsonCard>(result.ToString(), settings); this.mLoggingService.Debug("MtgJsonCard deserialized!"); if (this.mSkipTokens) { if (!string.IsNullOrEmpty(cardData.Layout) && cardData.Layout.ToLower() == "token") { this.mLoggingService.Debug("Card is a token, skipping..."); continue; } } this.mLoggingService.Debug("Mapping data..."); var card = this.mDataMapper.GetCard(cardData, setData.Name, setData.Code); this.mLoggingService.Debug("Data mapped for card '{0}'!", cardData.Name); yield return(card); } }
public bool ImportMtgJsonToDatabase(string filename) { MtgJsonSet mtgJsonSet = ImportMtgJsonFromFile(filename); List <MtgJsonCard> mtgJsonAllCards = MapPropertiesFromSetToCards(mtgJsonSet); ImportAndInsertLayouts(mtgJsonAllCards); ImportAndInsertBorders(mtgJsonAllCards); ImportAndInsertColors(mtgJsonAllCards); ImportAndInsertFormats(mtgJsonAllCards); ImportAndInsertLegalities(mtgJsonAllCards); ImportAndInsertRarities(mtgJsonAllCards); ImportAndInsertType(mtgJsonAllCards); ImportAndInsertSupertypes(mtgJsonAllCards); ImportAndInsertSubtypes(mtgJsonAllCards); ImportAndInsertSets(mtgJsonSet); ImportAndInsertCards(mtgJsonAllCards); return(true); }
public Set ReadSet(string data) { if (string.IsNullOrEmpty(data)) { throw new ArgumentException("data"); } var settings = new JsonSerializerSettings(); settings.MissingMemberHandling = MissingMemberHandling.Ignore; this.mLoggingService.Trace("JSON data = {0}", data); this.mLoggingService.Debug("Deserializing MtgJsonSet..."); MtgJsonSet setData = JsonConvert.DeserializeObject <MtgJsonSet>(data, settings); this.mLoggingService.Debug("Deserialized MtgJsonSet!"); if (this.mSkipPromos) { if (setData.Type.ToLower() == "promo") { this.mLoggingService.Warning("Set type is '{0}', skipping...", setData.Type); return(null); } } // Get rarity quantities this.mLoggingService.Debug("Getting rarity quantities..."); JObject cardObject = JObject.Parse(data); IList <JToken> results = cardObject["cards"].Children().ToList(); foreach (JToken result in results) { string rarity = result["rarity"].ToString(); switch (rarity.ToLower()) { case "basic land": setData.BasicLandQty += 1; break; case "common": setData.CommonQty += 1; break; case "mythic": case "mythic rare": setData.MythicQty += 1; break; case "uncommon": setData.UncommonQty += 1; break; case "rare": setData.RareQty += 1; break; } } this.mLoggingService.Trace("Rarity quantifies: BasicLand = {0}; Common = {1}; Mythic = {2}; Uncommon = {3}; Rare = {4}", setData.BasicLandQty, setData.CommonQty, setData.MythicQty, setData.UncommonQty, setData.RareQty); this.mLoggingService.Debug("Mapping data..."); var set = this.mDataMapper.GetSet(setData); this.mLoggingService.Debug("Data mapped for set '{0}'!", setData.Name); return(set); }
public void TestFixtureTearDown() { testJsonSet = null; }