コード例 #1
0
        /// <summary>
        /// Refreshes the visibility of the categories based on if the games should be categorized
        /// </summary>
        /// <returns>The task</returns>
        public async Task RefreshCategorizedVisibilityAsync()
        {
            using (await AsyncLock.LockAsync())
            {
                try
                {
                    // Get the master category
                    var master = GameCategories.FindItem(x => x.IsMaster);

                    // Set the master category visibility
                    master.IsVisible = false;

                    // Set the categories visibility
                    GameCategories.Where(x => !x.IsMaster).ForEach(x => x.IsVisible = Data.CategorizeGames);

                    // Set the selected index
                    SelectedCategoryIndex = Data.CategorizeGames ? GameCategories.FindItemIndex(x => !x.IsMaster) : GameCategories.FindItemIndex(x => x == master);
                }
                catch (Exception ex)
                {
                    ex.HandleError("Refreshing game category visibility");

                    throw;
                }
            }
        }
コード例 #2
0
    public void RefreshCategorizedVisibility()
    {
        lock (GameCategories)
        {
            try
            {
                // Get the master category
                var master = GameCategories.First(x => x.IsMaster);

                // Set the master category visibility
                master.IsVisible = false;

                // Set the categories visibility
                GameCategories.Where(x => !x.IsMaster).ForEach(x => x.IsVisible = Data.UI_CategorizeGames);

                // Set the selected index
                SelectedCategoryIndex = Data.UI_CategorizeGames ? GameCategories.FindItemIndex(x => !x.IsMaster) : GameCategories.FindItemIndex(x => x == master);
            }
            catch (Exception ex)
            {
                Logger.Error(ex, "Refreshing game category visibility");

                throw;
            }
        }
    }
コード例 #3
0
 public void Create(GameCategories gameCategories)
 {
     if (_context.Games.Where(a => a.GameId == gameCategories.GameId).FirstOrDefault() != null)
     {
         foreach (var categoryId in gameCategories.CategoriesId)
         {
             if (_context.Categories.Where(a => a.CategoryId == categoryId).SingleOrDefault() != null)
             {
                 CategoryGame categoryGame = new CategoryGame
                 {
                     GameId     = gameCategories.GameId,
                     CategoryId = categoryId
                 };
                 _context.CategoryGames.Add(categoryGame);
                 _context.SaveChanges();
             }
             else
             {
                 throw new Exception("Category does not exist!");
             }
         }
     }
     else
     {
         throw new Exception("Gameroom does not exist!");
     }
 }
コード例 #4
0
        /// <summary>
        /// Refreshes the added game
        /// </summary>
        /// <returns>The task</returns>
        public async Task RefreshGameAsync(Games game)
        {
            RL.Logger?.LogInformationSource($"The displayed game {game} is being refreshed...");

            using (await AsyncLock.LockAsync())
            {
                try
                {
                    // Make sure the game has been added
                    if (!game.IsAdded())
                    {
                        throw new Exception("Only added games can be refreshed individually");
                    }

                    if (Application.Current.Dispatcher == null)
                    {
                        throw new Exception("Dispatcher can not be NULL");
                    }

                    // Get the display view model
                    var displayVM = game.GetGameInfo().GetDisplayViewModel();

                    // Refresh the game in every category it's available in
                    foreach (var category in GameCategories.Where(x => x.Games.Contains(game)))
                    {
                        RL.Logger?.LogTraceSource($"The displayed game {game} in {category.DisplayName} is being refreshed...");

                        // Get the collection containing the game
                        var collection = category.InstalledGames.Any(x => x.Game == game) ? category.InstalledGames : category.NotInstalledGames;

                        // Get the game index
                        var index = collection.FindItemIndex(x => x.Game == game);

                        // Make sure we got a valid index
                        if (index == -1)
                        {
                            RL.Logger?.LogWarningSource($"The displayed game {game} in {category.DisplayName} could not be refreshed due to not existing in either game collection");

                            return;
                        }

                        // Refresh the game
                        Application.Current.Dispatcher.Invoke(() => collection[index] = displayVM);

                        RL.Logger?.LogTraceSource($"The displayed game {game} in {category.DisplayName} has been refreshed");
                    }
                }
                catch (Exception ex)
                {
                    ex.HandleCritical("Refreshing game", game);
                    throw;
                }
            }

            RL.Logger?.LogInformationSource($"The displayed game {game} has been refreshed");
        }
コード例 #5
0
        public IActionResult PostGameCategories([FromBody] GameCategories GameCategories)
        {
            // UPDATE USER TRACKING INFORMATION
            userTracker.UpdateUserActivity(Request);

            _context.GameCategories.Add(GameCategories);
            _context.SaveChanges();

            return(Created("api/game/gamecategories/" + GameCategories.Id, GameCategories.Id));
        }
コード例 #6
0
 public void PopulateGameList(GameCategories categories)
 {
     GameList.Clear();
     GameList.AddRange(
         categories switch {
         GameCategories.FanGame => _settingsAndGamesManager.FanGames,
         _ => _settingsAndGamesManager.OfficialGames
         .Where(game => categories.HasFlag(game.Categories))
         .ToList()
     }
コード例 #7
0
 public ActionResult AddCategoriesToGame([FromBody] GameCategories gameCategories)
 {
     try
     {
         _repo.Create(gameCategories);
         return(Ok("Categories were successfully added"));
     }
     catch
     {
         return(BadRequest("Categories were not added!"));
     }
 }
コード例 #8
0
    public async Task RefreshGameAsync(Games game)
    {
        Logger.Info("The displayed game {0} is being refreshed...", game);

        using (await AsyncLock.LockAsync())
        {
            try
            {
                // Make sure the game has been added
                if (!game.IsAdded())
                {
                    throw new Exception("Only added games can be refreshed individually");
                }

                // Get the display view model
                var displayVM = game.GetGameInfo().GetDisplayViewModel();

                // Refresh the game in every category it's available in
                foreach (var category in GameCategories.Where(x => x.Games.Contains(game)))
                {
                    Logger.Trace("The displayed game {0} in {1} is being refreshed...", game, category.DisplayName);

                    // Get the collection containing the game
                    var collection = category.InstalledGames.Any(x => x.Game == game) ? category.InstalledGames : category.NotInstalledGames;

                    // Get the game index
                    var index = collection.FindItemIndex(x => x.Game == game);

                    // Make sure we got a valid index
                    if (index == -1)
                    {
                        Logger.Warn("The displayed game {0} in {1} could not be refreshed due to not existing in either game collection", game, category.DisplayName);

                        return;
                    }

                    // Refresh the game
                    collection[index] = displayVM;

                    Logger.Trace("The displayed game {0} in {1} has been refreshed", game, category.DisplayName);
                }
            }
            catch (Exception ex)
            {
                Logger.Fatal(ex, "Refreshing game {0}", game);
                throw;
            }
        }

        Logger.Info("The displayed game {0} has been refreshed", game);
    }
コード例 #9
0
        public void TestAddCategoriesToGame()
        {
            CategoryGameRepository categoryGameRepo       = new CategoryGameRepository(DatabaseDummy.DatabaseDummyCreate("TestAddCategoriesToGame"));
            CategoryGameController categoryGameController = new CategoryGameController(categoryGameRepo);
            GameCategories         gameCategories         = new GameCategories
            {
                GameId       = 4,
                CategoriesId = new List <int>()
                {
                    34, 35
                }
            };
            var actionResult = categoryGameController.AddCategoriesToGame(gameCategories);

            Assert.IsNotType <BadRequestObjectResult>(actionResult);
        }
コード例 #10
0
        public IActionResult PutGameCategories(int id, [FromBody] GameCategories GameCategories)
        {
            // UPDATE USER TRACKING INFORMATION
            userTracker.UpdateUserActivity(Request);

            var record2 = _context.GameCategories.Where(c => c.Id == id).Count();


            if (record2 == 0)
            {
                return(NoContent());
            }

            GameCategories.Id = id;
            _context.GameCategories.Update(GameCategories);
            _context.SaveChanges();
            return(Ok(GameCategories));
        }
コード例 #11
0
        public void MoveCurrentPlayer()
        {
            const string playerId = "p1Id";
            var          game     = GetGame(
                new GameStarted("gameId", "name", GameCategories),
                new PlayerAdded(playerId, "player1"),
                new CurrentPlayerChanged(playerId),
                new PlayerAdded("p2Id", "player2"));
            var fakeDice = new FakeDice(2);

            var events = game.Move(fakeDice, playerId);

            var question = GameCategories.First().Questions.First().Question;

            Check.That(events).ContainsExactly(
                new Moved(playerId, 2),
                new QuestionAsked(question.Id, question.Text, question.Answer));
        }
コード例 #12
0
        public void TestCreateCategoryGame()
        {
            CategoryGameRepository categoryGameRepo = new CategoryGameRepository(DatabaseDummy.DatabaseDummyCreate("TestCreateCategoryGame"));
            GameCategories         gameCategories   = new GameCategories
            {
                GameId       = 4,
                CategoriesId = new List <int>()
                {
                    34, 35
                }
            };

            try
            {
                categoryGameRepo.Create(gameCategories);
                Assert.True(true);
            }
            catch
            {
                Assert.True(false);
            }
        }
コード例 #13
0
        private static void InsertGameCategoryTestData(MySqlConnection conn, WorkBook workBook)
        {
            if (DoesDataExist(conn, "GameCategory"))
            {
                return;
            }
            var workSheet = workBook.GetWorkSheet("GameCategories");
            var range     = workSheet.GetRange("A2:B77");

            foreach (var row in range.Rows)
            {
                GameCategories gameCategories = new GameCategories();
                gameCategories.gameId     = row.Columns[0].IntValue;
                gameCategories.categoryId = row.Columns[1].IntValue;

                Console.WriteLine(gameCategories.ToString());

                MySqlCommand cmd;

                cmd = new MySqlCommand($"INSERT INTO gamecategory (`gameId`, `categoryId`) VALUES ('{gameCategories.gameId}', '{gameCategories.categoryId}')", conn);
                cmd.ExecuteNonQuery();
            }
        }
コード例 #14
0
        public void MoveCurrentPlayerIfInPenaltyBoxButRollOddDice()
        {
            const string player1Id = "p1Id";
            const string player2Id = "p2Id";
            var          game      = GetGame(
                new GameStarted("gameId", "name", GameCategories),
                new PlayerAdded(player1Id, "player1"),
                new CurrentPlayerChanged(player1Id),
                new PlayerAdded(player2Id, "player2"),
                new Moved(player1Id, 2),
                new QuestionAsked(1, "question", "answer"),
                new GoneToPenaltyBox(player1Id)
                /* Bypass Player2 turn */);
            var fakeDice = new FakeDice(3);

            var events = game.Move(fakeDice, player1Id);

            var question = GameCategories.First().Questions.First().Question;

            Check.That(events).ContainsExactly(
                new GetOutOfPenaltyBox(player1Id),
                new Moved(player1Id, 5),
                new QuestionAsked(question.Id, question.Text, question.Answer));
        }
コード例 #15
0
 public void Dispose()
 {
     GameCategories?.DisposeAll();
 }
コード例 #16
0
    public async Task RefreshAsync()
    {
        using (await AsyncLock.LockAsync())
        {
            try
            {
                RefreshingGames = true;

                // Cache the game view models
                var displayVMCache = new Dictionary <Games, Page_Games_GameViewModel>();

                Logger.Info("All displayed games are being refreshed...");

                // Refresh all categories
                foreach (var category in GameCategories)
                {
                    Logger.Info("The displayed games in {0} are being refreshed...", category.DisplayName.Value);

                    try
                    {
                        // Clear collections
                        category.InstalledGames.Clear();
                        category.NotInstalledGames.Clear();

                        category.AnyInstalledGames    = false;
                        category.AnyNotInstalledGames = false;

                        // Enumerate each game
                        foreach (Games game in category.Games)
                        {
                            // Get the game info
                            var info = game.GetGameInfo();

                            // If cached, reuse the view model, otherwise create new and add to cache
                            Page_Games_GameViewModel displayVM = displayVMCache.ContainsKey(game)
                                ? displayVMCache[game]
                                : displayVMCache[game] = info.GetDisplayViewModel();

                            // Check if it has been added
                            if (info.IsAdded)
                            {
                                // Add the game to the collection
                                category.InstalledGames.Add(displayVM);
                                category.AnyInstalledGames = true;
                            }
                            else
                            {
                                category.NotInstalledGames.Add(displayVM);
                                category.AnyNotInstalledGames = true;
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Logger.Fatal(ex, "Refreshing games in {0}", category.DisplayName);
                        throw;
                    }

                    Logger.Info("The displayed games in {0} have been refreshed with {1} installed and {2} not installed games", category.DisplayName, category.InstalledGames.Count, category.NotInstalledGames.Count);
                }

                // Allow game finder to run only if there are games which have not been found
                CanRunGameFinder = GameCategories.Any(x => x.AnyNotInstalledGames);
            }
            catch (Exception ex)
            {
                Logger.Fatal(ex, "Refreshing games");
                throw;
            }
            finally
            {
                RefreshingGames = false;
            }
        }
    }
コード例 #17
0
 public void Dispose()
 {
     GameCategories?.ForEach(x => x.Dispose());
 }
コード例 #18
0
        /// <summary>
        /// Refreshes the games
        /// </summary>
        /// <returns>The task</returns>
        public async Task RefreshAsync()
        {
            using (await AsyncLock.LockAsync())
            {
                try
                {
                    RefreshingGames = true;

                    if (Application.Current.Dispatcher == null)
                    {
                        throw new Exception("Dispatcher can not be NULL");
                    }

                    // Cache the game view models
                    var displayVMCache = new Dictionary <Games, GameDisplayViewModel>();

                    RL.Logger?.LogInformationSource($"All displayed games are being refreshed...");

                    // Refresh all categories
                    foreach (var category in GameCategories)
                    {
                        RL.Logger?.LogInformationSource($"The displayed games in {category.DisplayName.Value} are being refreshed...");

                        try
                        {
                            // Clear collections
                            Application.Current.Dispatcher.Invoke(() => category.InstalledGames.Clear());
                            Application.Current.Dispatcher.Invoke(() => category.NotInstalledGames.Clear());

                            category.AnyInstalledGames    = false;
                            category.AnyNotInstalledGames = false;

                            // Enumerate each game
                            foreach (Games game in category.Games)
                            {
                                // Get the game info
                                var info = game.GetGameInfo();

                                // If cached, reuse the view model, otherwise create new and add to cache
                                GameDisplayViewModel displayVM = displayVMCache.ContainsKey(game)
                                    ? displayVMCache[game]
                                    : displayVMCache[game] = info.GetDisplayViewModel();

                                // Check if it has been added
                                if (info.IsAdded)
                                {
                                    // Add the game to the collection
                                    Application.Current.Dispatcher.Invoke(() => category.InstalledGames.Add(displayVM));
                                    category.AnyInstalledGames = true;
                                }
                                else
                                {
                                    Application.Current.Dispatcher.Invoke(() => category.NotInstalledGames.Add(displayVM));
                                    category.AnyNotInstalledGames = true;
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            ex.HandleCritical($"Refreshing games in {category.DisplayName}");
                            throw;
                        }

                        RL.Logger?.LogInformationSource($"The displayed games in {category.DisplayName} have been refreshed with {category.InstalledGames.Count} installed and {category.NotInstalledGames.Count} not installed games");
                    }

                    // Allow game finder to run only if there are games which have not been found
                    // ReSharper disable once PossibleNullReferenceException
                    await Application.Current.Dispatcher.InvokeAsync(() =>
                    {
                        RunGameFinderCommand.CanExecuteCommand = GameCategories.Any(x => x.AnyNotInstalledGames);

                        //// NOTE: This is a hacky solution to a weird WPF issue where an item can get duplicated in the view
                        //foreach (var c in GameCategories)
                        //{
                        //    CollectionViewSource.GetDefaultView(c.InstalledGames).Refresh();
                        //    CollectionViewSource.GetDefaultView(c.NotInstalledGames).Refresh();
                        //}
                    });
                }
                catch (Exception ex)
                {
                    ex.HandleCritical("Refreshing games");
                    throw;
                }
                finally
                {
                    RefreshingGames = false;
                }
            }
        }