public CardsService(XmlDocument cardDatabase, XmlDocument cardLangDatabase, CardTypesService typesService) { this.cardDatabase = cardDatabase; this.cardLangDatabase = cardLangDatabase; this.typesService = typesService; XmlDocument xColors = new XmlDocument(); cardsNsManager = new XmlNamespaceManager(cardDatabase.NameTable); cardsNsManager.AddNamespace("ns", "http://www.w3.org/2005/xpath-functions"); foreach(XmlNode nodeCard in cardDatabase.DocumentElement.ChildNodes) cardNodesById.Add(nodeCard.SelectSingleNode("id").InnerText, nodeCard); foreach(XmlNode nodeLang in cardLangDatabase.DocumentElement.ChildNodes) langNodesById.Add(nodeLang.SelectSingleNode("id").InnerText, nodeLang); }
public void LoadGame(GameInfoItem gameInfoItem) { string gameCode = gameInfoItem.Code; string gameDataBasePath = Path.Combine(gameInfoItem.GamePath, "game.xml"); if(!File.Exists(gameDataBasePath)) throw new InvalidSourceException("File " + gameDataBasePath + " not found."); string gameLangDataBasePath = Path.Combine(gameInfoItem.GamePath, "game." + GameLanguageCode + ".xml"); if(!File.Exists(gameLangDataBasePath)) throw new InvalidSourceException("File " + gameLangDataBasePath + " not found."); string gameStringsDatabasePath = Path.Combine(gameInfoItem.GamePath, "strings." + GameLanguageCode + ".xml"); if(!File.Exists(gameStringsDatabasePath)) throw new InvalidSourceException("File " + gameStringsDatabasePath + " not found."); string setCodesFilePath = Path.Combine(Path.Combine(SettingsManager.Settings.DataPath, gameCode), "set-codes.xml"); #region crc //SHA256 sha256Encoder = SHA256Managed.Create(); //try //{ // using(FileStream fs = File.Open(gameDataBasePath, FileMode.Open, FileAccess.Read, FileShare.Read)) // gameDatabaseCrc = Convert.ToBase64String(sha256Encoder.ComputeHash(fs)); // using(FileStream fs = File.Open(cardDataBasePath, FileMode.Open, FileAccess.Read, FileShare.Read)) // cardDatabaseCrc = Convert.ToBase64String(sha256Encoder.ComputeHash(fs)); //} //finally //{ // sha256Encoder.Clear(); //} #endregion try { XmlDocument gameDatabase = new XmlDocument(); gameDatabase.Load(gameDataBasePath); XmlDocument gameLangDatabase = new XmlDocument(); gameLangDatabase.Load(gameLangDataBasePath); XmlDocument gameStringsDatabase = new XmlDocument(); gameStringsDatabase.Load(gameStringsDatabasePath); if(File.Exists(setCodesFilePath)) setCodesMapService = new CodesMapService(setCodesFilePath); imagesService = new Services.ImagesService(setCodesMapService); typesService = new CardTypesService(gameDatabase.DocumentElement["card_types"], gameLangDatabase.DocumentElement["card_types_lang"]); colorsService = new BaseItemService(gameDatabase.DocumentElement["card_colors"], gameLangDatabase.DocumentElement["card_colors_lang"]); raritiesService = new BaseItemService(gameDatabase.DocumentElement["card_rarities"], gameLangDatabase.DocumentElement["card_rarities_lang"]); stylesService = new BaseItemService(gameDatabase.DocumentElement["card_styles"], gameLangDatabase.DocumentElement["card_styles_lang"]); commandsService = new BaseItemService(gameDatabase.DocumentElement["commands"], gameLangDatabase.DocumentElement["commands_lang"]); stylesBehaviorsService = new CardStyleBehaviorsService(gameDatabase.DocumentElement["card_style_behaviors"], gameDatabase.DocumentElement["card_styles"]); sectorsService = new SectorsService(gameDatabase.DocumentElement["sectors"], gameLangDatabase.DocumentElement["sectors_lang"]); numCountersService = new NumCountersService(gameDatabase.DocumentElement["numCounters"], gameLangDatabase.DocumentElement["numCounters_lang"]); XmlDocument cardsDatabase; XmlDocument cardsLangDatabase; List<GameSetItem> gameSets; LoadCards(gameInfoItem, out cardsDatabase, out cardsLangDatabase, out gameSets); cardService = new CardsService(cardsDatabase, cardsLangDatabase, typesService); gameSetsService = new GameSetsService(gameSets); deckService = new DecksService(this); gameStringsService = new StringService(gameStringsDatabase); } catch(Exception ex) { throw new InvalidSourceException("Invalid data source." + Environment.NewLine + ex.Message, ex); } }