Ejemplo n.º 1
0
 public async Task SendMatchUpdate(LiveMatchStats liveMatchStats)
 {
     if (liveMatchStats != null && currentFootballMatch != null)
     {
         LiveMatchViewModel liveMatchViewModel = new LiveMatchViewModel(currentFootballMatch, liveMatchStats);
         await hubContextMatchHub.Clients.All.SendAsync(Variables.SignalRMethodName_LiveMatch, liveMatchViewModel.SerializeToJson());
     }
 }
Ejemplo n.º 2
0
        private async Task CheckIfGameIsOverAndSetFinalResultIfNecessary(LiveMatchStats liveMatchStats)
        {
            if (liveMatchStats != null && (liveMatchStats.MatchStatus == MatchStatus.ApiCancelled || liveMatchStats.MatchStatus == MatchStatus.FullTime))
            {
                var arsenal            = GetArsernal();
                var resultFullTimeSave = await arsenal.AddFullTimeLiveMatchStats(exceptionNotifier, rootAggregateRepositorySingletonFootballTeams, liveMatchStats);

                if (resultFullTimeSave.Succeeded)
                {
                    matchesForLiveBroadcast = arsenal.JSListOfFootBallMatch_Matches.DeserializeFromJson <List <FootBallMatch> >();
                    currentFootballMatch    = null;
                }
            }
        }
Ejemplo n.º 3
0
 public LiveMatchViewModel(FootBallMatch footBallMatch, LiveMatchStats liveMatchStats)
 {
     AwayTeamLogo            = footBallMatch.AwayTeamLogoUrl;
     HomeTeamLogo            = footBallMatch.HomeTeamLogoUrl;
     AwayTeamName            = footBallMatch.AwayTeamName;
     HomeTeamName            = footBallMatch.HomeTeamName;
     GoalsAwayTeam           = liveMatchStats.GoalsScoredAwaySide;
     GoalsHomeTeam           = liveMatchStats.GoalsScoredHomeSide;
     MatchId                 = liveMatchStats.MatchId;
     MatchStatus             = liveMatchStats.MatchStatus.ToString();
     Minute                  = liveMatchStats.Minute;
     PenaltiesScoredAwayTeam = liveMatchStats.PenaltiesScoredAwaySide;
     PenaltiesScoredHomeTeam = liveMatchStats.PenaltiesScoredHomeSide;
     StartTime               = footBallMatch.TimeOfMatch;
 }
Ejemplo n.º 4
0
        public async Task <Result <LiveMatchStats> > GetLiveDataForMatch(string matchId)
        {
            //Rotate key cause I accidentally exposed it when hurrying to finish up this class. Errors do happen - but naturally, keys are then supposed to be changed when going into production and/or have separate keys for dev, staging and produc

            //SportDataApiResponse_GetLiveDataForMatch

            Result <LiveMatchStats> vtr = new Result <LiveMatchStats>(true);

            try
            {
                string url = $"{urlBaseSportDataApi}matches/{matchId}?apikey={apiKey}";

                SportDataApiResponse_GetLiveDataForMatch_Alt sportDataApiResponse_GetLiveDataForMatch = null; //
                var httpResponse = await httpClient.GetAsync(url);

                if (httpResponse.IsSuccessStatusCode)
                {
                    string content = await httpResponse.Content.ReadAsStringAsync();

                    sportDataApiResponse_GetLiveDataForMatch = Newtonsoft.Json.JsonConvert.DeserializeObject <SportDataApiResponse_GetLiveDataForMatch_Alt>(content);
                }


                if (sportDataApiResponse_GetLiveDataForMatch?.data == null)
                {
                    vtr.SetError($"No live data found for match with id {matchId}");
                }
                else
                {
                    var liveMatchStatsFromApi   = sportDataApiResponse_GetLiveDataForMatch.data;
                    var goalsNormalAndExtraTime = GetScoreExludingPenaltyScore(liveMatchStatsFromApi.stats);
                    var penaltyGoals            = GetGoalsFromStringResult(liveMatchStatsFromApi.stats?.ps_score);


                    LiveMatchStats liveMatchStats =
                        new LiveMatchStats(liveMatchStatsFromApi.match_id.ToString(), goalsNormalAndExtraTime.HomeGoals, goalsNormalAndExtraTime.AwayGoals, penaltyGoals.HomeGoals, penaltyGoals.AwayGoals, GetMatchStatus(liveMatchStatsFromApi), liveMatchStatsFromApi.minute.ToString());

                    vtr.SetSuccessObject(liveMatchStats);
                }
            }
            catch (Exception ex)
            {
                throw;
            }
            return(vtr);
        }
Ejemplo n.º 5
0
        public async Task <Result <LiveMatchStats> > GetLiveDataForMatch(string matchId)
        {
            if (matchId != matchIdForLiveGame)
            {
                matchIdForLiveGame = matchId;
                time        = 0;
                matchStatus = MatchStatus.Started;
                homeScore   = 0;
                awayScore   = 0;
            }

            time++;
            switch (time)
            {
            case 2:
                homeScore++;
                break;

            case 3:
                homeScore++;
                break;

            case 4:
                awayScore++;
                break;

            case 5:
                homeScore++;
                break;

            case 6:
                matchStatus = MatchStatus.HalfTime;
                break;

            case 7:
                matchStatus = MatchStatus.Started;
                break;

            case 8:
                awayScore++;
                break;

            case 9:
                homeScore++;
                break;

            case 10:
                matchStatus = MatchStatus.FullTime;
                break;

            default:
                break;
            }

            LiveMatchStats          liveMatchStats = new LiveMatchStats(matchId, homeScore, awayScore, 0, 0, matchStatus, time.ToString());
            Result <LiveMatchStats> vtr            = new Result <LiveMatchStats>();

            vtr.SetSuccessObject(liveMatchStats);

            return(await Task.FromResult(vtr));
        }