Example #1
0
        public string GetGameThumbnail(int gameId)
        {
            var thumbnail = "";

            try
            {
                var apiUri = new Uri(BASE_URL_API_V2 + $"/thing?id={gameId}");
                var xDoc   = _apiDownloadService.DownloadApiResult(apiUri);

                var xElements = xDoc.Descendants("items").ToList();
                if (xElements.Count() == 1)
                {
                    var firstImageElement = xElements.First().Element("item").Element("image");
                    if (firstImageElement != null)
                    {
                        thumbnail = firstImageElement.GetStringValue();
                    }
                }
            }
            catch (Exception ex)
            {
                _rollbar.SendException(ex);
            }

            return(thumbnail);
        }
        public bool Handle(PlayedGameCreatedEvent @event)
        {
            bool noExceptions = true;

            //--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 playerId level instead of locking across the board
            lock (GlobalLockObject)
            {
                var players =
                    DataContext.GetQueryable <PlayerGameResult>().Where(p => p.PlayedGameId == @event.TriggerEntityId)
                    .Select(p => p.Player)
                    .Include(p => p.PlayerAchievements);

                foreach (var player in players.ToList())
                {
                    foreach (var achievement in AchievementFactory.GetAchievements())
                    {
                        try
                        {
                            ProcessAchievement(player, achievement);
                        }
                        catch (Exception ex)
                        {
                            _rollbarClient.SendException(ex);
                            noExceptions = false;
                        }
                    }
                }
            }

            return(noExceptions);
        }
Example #3
0
        public bool ProcessAchievements(int playedGameId)
        {
            bool noExceptions = true;

            var players =
                _dataContext.GetQueryable <PlayerGameResult>().Where(p => p.PlayedGameId == playedGameId)
                .Select(p => p.Player)
                .Include(p => p.PlayerAchievements);

            foreach (var player in players.ToList())
            {
                foreach (var achievement in AchievementFactory.GetAchievements())
                {
                    try
                    {
                        ProcessAchievementForPlayer(player, achievement);
                    }
                    catch (Exception ex)
                    {
                        _rollbarClient.SendException(ex);
                        ex.ToExceptionless();
                        noExceptions = false;
                    }
                }
            }

            return(noExceptions);
        }
        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);
        }
Example #5
0
 public virtual void SendEvent(IBusinessLogicEvent @event)
 {
     Task.Factory.StartNew(() =>
     {
         var eventHandlers = this._handlerFactory.GetHandlers(@event.GetType());
         foreach (var handlerInstance in eventHandlers)
         {
             try
             {
                 handlerInstance.Handle(@event);
             }
             catch (System.Exception ex)
             {
                 _rollbar.SendException(ex);
             }
         }
     });
 }
Example #6
0
 public virtual Task SendEvent(IBusinessLogicEvent @event)
 {
     return(Task.Factory.StartNew(() =>
     {
         var eventHandlers = this._handlerFactory.GetHandlers(@event.GetType());
         foreach (var handlerInstance in eventHandlers)
         {
             try
             {
                 handlerInstance.Handle(@event);
             }
             catch (Exception ex)
             {
                 _rollbar.SendException(ex);
                 ex.ToExceptionless();
             }
         }
     }));
 }