Exemplo n.º 1
0
        //TODO need to have validation logic here (or on PlayedGame similar to what is on NewlyCompletedGame)
        public PlayedGame CreatePlayedGame(NewlyCompletedGame newlyCompletedGame, TransactionSource transactionSource, ApplicationUser currentUser)
        {
            GameDefinition gameDefinition = dataContext.FindById <GameDefinition>(newlyCompletedGame.GameDefinitionId);

            securedEntityValidatorForGameDefinition.ValidateAccess(gameDefinition, currentUser, typeof(GameDefinition), newlyCompletedGame.GameDefinitionId);

            this.ValidateAccessToPlayers(newlyCompletedGame, currentUser);

            List <PlayerGameResult> playerGameResults = TransformNewlyCompletedGamePlayerRanksToPlayerGameResults(newlyCompletedGame);

            PlayedGame playedGame = TransformNewlyCompletedGameIntoPlayedGame(
                newlyCompletedGame,
                currentUser.CurrentGamingGroupId,
                currentUser.Id,
                playerGameResults);

            dataContext.Save(playedGame, currentUser);

            playedGameTracker.TrackPlayedGame(currentUser, transactionSource);

            foreach (PlayerGameResult result in playerGameResults)
            {
                nemesisRecalculator.RecalculateNemesis(result.PlayerId, currentUser);
            }
            championRecalculator.RecalculateChampion(playedGame.GameDefinitionId, currentUser);

            return(playedGame);
        }
Exemplo n.º 2
0
        internal virtual void DoPostSaveStuff(TransactionSource transactionSource,
            ApplicationUser currentUser, int playedGameId, int gameDefinitionId, List<PlayerGameResult> playerGameResults)
        {
            _playedGameTracker.TrackPlayedGame(currentUser, transactionSource);

            foreach (var result in playerGameResults)
            {
                _nemesisRecalculator.RecalculateNemesis(result.PlayerId, currentUser);
            }
            _championRecalculator.RecalculateChampion(gameDefinitionId, currentUser, false);

            SendEvents(new IBusinessLogicEvent[] {new PlayedGameCreatedEvent() {TriggerEntityId = playedGameId}});
        }
        public bool Handle(PlayedGameCreatedEvent @event)
        {
            //--process analytics
            try
            {
                _playedGameEventTracker.TrackPlayedGame(@event.CurrentUser, @event.TransactionSource);
            }
            catch (Exception ex)
            {
                _rollbar.SendException(ex);
                ex.ToExceptionless();
            }

            bool noExceptions;

            //--this is a weak solution to duplicate key exceptions getting logged when multiple games are recorded in quick succession. A better solution
            //  would be to only lock at the level required instead of locking globally
            lock (ChampionLock)
            {
                //--process champions
                //TODO this should only lock for each distinct GameDefinitionId
                _championRecalculator.RecalculateChampion(@event.GameDefinitionId, @event.CurrentUser, DataContext);
            }

            lock (NemesisLock)
            {
                //--process nemeses
                //TODO this should only lock for each distinct playerId
                foreach (var playerId in @event.ParticipatingPlayerIds)
                {
                    _nemesisRecalculator.RecalculateNemesis(playerId, @event.CurrentUser, DataContext);
                }
            }

            lock (GamingGroupChampionLock)
            {
                _gamingGroupChampionRecalculator.RecalculateGamingGroupChampion(@event.TriggerEntityId);
            }

            lock (AchievementsLock)
            {
                //--process achievements
                //TODO this should probably only lock at the GamingGroupdId level
                noExceptions = _achievementProcessor.ProcessAchievements(@event.TriggerEntityId);
            }

            return(noExceptions);
        }