Beispiel #1
0
 public LiveStat[] GetLatestLiveStats(int matchId)
 {
     using (var dbContext = new ContosoWebContext(StaticConfig.DbContext.WebConnectionStringName))
     {
         return(RetrieveLatestLiveStats(dbContext, matchId));
     }
 }
Beispiel #2
0
        private static void SendGameUpdateNotifications(int matchId)
        {
            Trace.TraceInformation("Match updated ({0}), sending notifications", matchId);

            using (var dbContext = new ContosoWebContext(StaticConfig.DbContext.WebConnectionStringName))
            {
                var stats = LiveStatsHub.RetrieveLatestLiveStats(dbContext, matchId);
                if (stats != null)
                {
                    var liveStatsHub = GlobalHost.ConnectionManager.GetHubContext <LiveStatsHub, ILiveStatsClient>();

                    liveStatsHub.Clients.Group(matchId.ToString()).LiveStatsUpdated(matchId, stats);
                }
            }
        }
        private static void SendGameUpdateNotifications(int matchId)
        {
            Trace.TraceInformation("Match updated ({0}), sending notifications", matchId);

            using (var dbContext = new ContosoWebContext(StaticConfig.DbContext.WebConnectionStringName))
            {
                var stats = LiveStatsHub.RetrieveLatestLiveStats(dbContext, matchId);
                if (stats != null)
                {
                    var liveStatsHub = GlobalHost.ConnectionManager.GetHubContext<LiveStatsHub, ILiveStatsClient>();

                    liveStatsHub.Clients.Group(matchId.ToString()).LiveStatsUpdated(matchId, stats);
                }
            }
        }
Beispiel #4
0
        public GameInfo GetCurrentGameInfo()
        {
            try
            {
                using (var dbContext = new ContosoWebContext(StaticConfig.DbContext.WebConnectionStringName))
                {
                    var currentMatch = dbContext.Matches.Where(x => x.Progress == MatchProgress.InProgress)
                                       .OrderBy(x => x.MatchDate)
                                       .Select(x => new
                    {
                        x.MatchId,
                        x.MatchDate,
                        HomeTeamId   = x.HomeTeam.TeamId,
                        HomeTeamName = x.HomeTeam.Name,
                        AwayTeamId   = x.AwayTeam.TeamId,
                        AwayTeamName = x.AwayTeam.Name,
                    })
                                       .FirstOrDefault();

                    if (currentMatch == null)
                    {
                        return(null);
                    }

                    var previousMeetings = dbContext.Matches.Where(x => x.Progress == MatchProgress.Completed)
                                           .OrderBy(x => x.MatchDate)
                                           .Select(x => new PreviousMeetingInfo
                    {
                        HomeTeamAbv   = x.HomeTeam.AbbreviatedName,
                        HomeTeamScore = x.HomeTeamScore,
                        AwayTeamAbv   = x.AwayTeam.AbbreviatedName,
                        AwayTeamScore = x.AwayTeamScore,
                        MatchDate     = x.MatchDate
                    })
                                           .Take(10)
                                           .ToList();

                    var homeTeamLeaders = dbContext.Teams.Where(x => x.TeamId == currentMatch.HomeTeamId)
                                          .SelectMany(x => x.Players)
                                          .OrderByDescending(x => x.GoalsScored)
                                          .Select(x => new PlayerInfo {
                        Name = x.Name, GoalsScored = x.GoalsScored
                    })
                                          .Take(2)
                                          .ToList();

                    var awayTeamLeaders = dbContext.Teams.Where(x => x.TeamId == currentMatch.AwayTeamId)
                                          .SelectMany(x => x.Players)
                                          .OrderByDescending(x => x.GoalsScored)
                                          .Select(x => new PlayerInfo {
                        Name = x.Name, GoalsScored = x.GoalsScored
                    })
                                          .Take(2)
                                          .ToList();

                    var liveStats = RetrieveLatestLiveStats(dbContext, currentMatch.MatchId);

                    return(new GameInfo
                    {
                        MatchId = currentMatch.MatchId,
                        MatchDate = currentMatch.MatchDate,
                        MatchStats = liveStats,
                        PreviousMeetings = previousMeetings,
                        HomeTeamName = currentMatch.HomeTeamName,
                        HomeTeamSeasonGoalLeaders = homeTeamLeaders,
                        AwayTeamName = currentMatch.AwayTeamName,
                        AwayTeamSeasonGoalLeaders = awayTeamLeaders
                    });
                }
            }
            catch (Exception ex)
            {
                Trace.TraceInformation("GetCurrentGameInfo: {0}", ex);
                throw;
            }
        }