internal void Load(string fileName)
        {
            _logger.LogMessage($"Loading game from file {fileName}.");
            if (File.Exists(fileName))
            {
                try {
                    var gameFile = JsonConvert.DeserializeObject <GameFile>(File.ReadAllText(fileName));

                    var game = _appData.Game;
                    game.ClearAllCardsLists();

                    gameFile.CopyTo(game);
                    game.OnEncounterSetsChanged();

                    for (var index = 0; index < gameFile.DeckIds.Count && index < game.Players.Count; index++)
                    {
                        game.Players[index].DeckId = gameFile.DeckIds[index];
                        if (!string.IsNullOrEmpty(game.Players[index].DeckId))
                        {
                            try {
                                _loadingStatusService.ReportPlayerStatus(game.Players[index].ID, Status.LoadingCards);
                                _arkhamDbService.LoadPlayer(game.Players[index]);
                            }
                            catch (Exception ex) {
                                _logger.LogException(ex, $"Error loading player {game.Players[index].ID}.");
                                _loadingStatusService.ReportPlayerStatus(game.Players[index].ID, Status.Error);
                            }
                        }
                    }

                    game.OnPlayersChanged();
                    _appData.OnGameChanged();
                    _logger.LogMessage($"Finished reading game file: {fileName}.");
                } catch (Exception ex) {
                    // if there's an error, we don't care- just use the existing game
                    _logger.LogException(ex, $"Error reading game file: {fileName}.");
                }
            }
        }
Beispiel #2
0
        private void LoadPlayerCards()
        {
            var worker = new BackgroundWorker();

            worker.DoWork += (x, y) => {
                foreach (var player in _appData.Game.Players)
                {
                    if (!string.IsNullOrEmpty(player.DeckId))
                    {
                        _loadingStatusService.ReportPlayerStatus(player.ID, Status.LoadingCards);
                        try {
                            _arkhamDbService.LoadPlayerCards(player);
                            _loadingStatusService.ReportPlayerStatus(player.ID, Status.Finished);
                        }
                        catch (Exception ex) {
                            _logger.LogException(ex, $"Error loading player cards for player {player.ID}");
                            _loadingStatusService.ReportPlayerStatus(player.ID, Status.Error);
                        }
                    }
                }
            };
            worker.RunWorkerAsync();
        }