public void SeedCharacterData(WebCharacter character, ICharacterService characterService, IMovementService movementService, IMoveService moveService, ICharacterAttributeRowService characterAttributeRowService, IUniqueDataService uniqueDataService) { Guard.VerifyObjectNotNull(character, nameof(character)); Guard.VerifyObjectNotNull(characterService, nameof(characterService)); Guard.VerifyObjectNotNull(movementService, nameof(movementService)); Guard.VerifyObjectNotNull(moveService, nameof(moveService)); Guard.VerifyObjectNotNull(characterAttributeRowService, nameof(characterAttributeRowService)); Guard.VerifyObjectNotNull(uniqueDataService, nameof(uniqueDataService)); _characterDataScraper.PopulateCharacterFromWeb(character); var entityCharacter = Mapper.Map <Character>(character); characterService.Add(entityCharacter); movementService.AddMany(character.Movements); moveService.AddMany(character.Moves); characterAttributeRowService.AddMany(character.AttributeRows); uniqueDataService.AddMany(character.UniqueProperties); }
private void SeedData(ICharacterDataScraper characterDataScraper, DebugStorageLocationResolver fileLocationResolver) { #if !DEBUG var charactersToSeed = Characters.All; foreach (var character in charactersToSeed) { Console.WriteLine($"Scraping data for '{character.Name}'..."); List <string> sourceUrls = new List <string> { "http://kuroganehammer.com/Smash4/", "http://kuroganehammer.com/Ultimate/" }; if (character.OwnerId > 58) { sourceUrls.RemoveAt(0); //remove the smash 4 url if it's an Ultimate-only character } foreach (var sourceUrl in sourceUrls) { try { var populatedCharacter = characterDataScraper.PopulateCharacterFromWeb(character, sourceUrl); _characterData.Add(populatedCharacter); _moveData.AddRange(populatedCharacter.Moves); _movementData.AddRange(populatedCharacter.Movements); _characterAttributeRowData.AddRange(populatedCharacter.AttributeRows); _uniqueData.AddRange(populatedCharacter.UniqueProperties.Cast <IUniqueData>()); } catch (PageNotFoundException ex) { Console.WriteLine($"Error for '{character.Name}' at '{sourceUrl}' => {ex.Message}"); } } } #endif #if DEBUG _characterData.AddRange(JsonConvert.DeserializeObject <List <Character> >(File.ReadAllText(fileLocationResolver.Character))); _moveData.AddRange(JsonConvert.DeserializeObject <List <Move> >(File.ReadAllText(fileLocationResolver.Move))); _movementData.AddRange(JsonConvert.DeserializeObject <List <Movement> >(File.ReadAllText(fileLocationResolver.Movement))); _characterAttributeRowData.AddRange(JsonConvert.DeserializeObject <List <dynamic> >(File.ReadAllText(fileLocationResolver.Attribute)) .Select(attr => { return(new CharacterAttributeRow { Game = attr["Game"], InstanceId = attr["InstanceId"], Name = attr["Name"], Owner = attr["Owner"], OwnerId = attr["OwnerId"], Values = attr["Values"] as List <IAttribute> }); })); _uniqueData.AddRange(JsonConvert.DeserializeObject <List <UniqueData> >(File.ReadAllText(fileLocationResolver.Unique))); #endif //write pulled data to local //File.WriteAllText(fileLocationResolver.Character, JsonConvert.SerializeObject(_characterData)); //File.WriteAllText(fileLocationResolver.Move, JsonConvert.SerializeObject(_moveData)); //File.WriteAllText(fileLocationResolver.Movement, JsonConvert.SerializeObject(_movementData)); //File.WriteAllText(fileLocationResolver.Attribute, JsonConvert.SerializeObject(_characterAttributeRowData)); //File.WriteAllText(fileLocationResolver.Unique, JsonConvert.SerializeObject(_uniqueData)); //done writing to local }