private async Task RefreshGameData() { try { JObject gameData = await NetworkCalls.ApiCallAsync($"http://live.nhl.com/GameData/{_seasonCode}/{_id}/gc/gcsb.jsonp"); this.Period = gameData["p"].Value <string>(); this.SecondsLeftInPeriod = gameData["sr"].Value <int>(); this.HomeTeamScore = gameData["h"]["tot"]["g"].Value <int>(); this.AwayTeamScore = gameData["a"]["tot"]["g"].Value <int>(); // After the first time the scores are set the goal horn is enabled if (_suppressGoalHorn) { _suppressGoalHorn = false; } } catch (Exception) { /* Don't crash VS if any of the above lines throw, just try to poll again next period */ } if (IsGameOver) { OnNotifyPropertyChanged("IsGameOver"); OnNotifyPropertyChanged("TimeDisplay"); OnNotifyPropertyChanged("FinalText"); this.IsGameLive = false; // Stop refreshing the game data if the game is over _refreshDataTimer.Change(Timeout.Infinite, Timeout.Infinite); } }
private async Task <IEnumerable <RawGameInfo> > GetGameSchedule(string todayStringCode) { string currentSeasonScheduleYears = GetSeasonScheduleYear(); if (_rawGameInfo == null || currentSeasonScheduleYears != cachedSeasonScheduleYears) { cachedSeasonScheduleYears = currentSeasonScheduleYears; string jsonFile = await NetworkCalls.GetJsonFromApiAsync($"http://live.nhl.com/GameData/SeasonSchedule-{cachedSeasonScheduleYears}.json"); _rawGameInfo = JsonConvert.DeserializeObject <List <RawGameInfo> >(jsonFile); if (_rawGameInfo == null) { _rawGameInfo = new List <RawGameInfo>(); } } return(_rawGameInfo.Where(x => x.est.Contains(todayStringCode))); }
public async Task GetUpdateScoringSummary() { IEnumerable <Goal> tempFirstPeriodGoals = Enumerable.Empty <Goal>(); IEnumerable <Goal> tempSecondPeriodGoals = Enumerable.Empty <Goal>(); IEnumerable <Goal> tempThirdPeriodGoals = Enumerable.Empty <Goal>(); IEnumerable <Goal> tempOTGoals = Enumerable.Empty <Goal>(); JObject gameData = await NetworkCalls.ApiCallAsync($"http://live.nhl.com/GameData/{_seasonCode}/{_gameCode}/gc/gcbx.jsonp"); var goals = gameData["goalSummary"].Values(); List <Goal> tempGoalsList = new List <Goal>(); foreach (var goalsList in goals) { try { int period = goalsList.First().Value <int>(); tempGoalsList.Sort(); switch (period) { case 1: tempFirstPeriodGoals = new List <Goal>(tempGoalsList); break; case 2: tempSecondPeriodGoals = new List <Goal>(tempGoalsList); break; case 3: tempThirdPeriodGoals = new List <Goal>(tempGoalsList); break; // Any overtime goals go here (including double, triple, etc.) default: tempOTGoals = new List <Goal>(tempGoalsList); break; } tempGoalsList = new List <Goal>(); continue; } catch (Exception) { } foreach (var goal in goalsList.First()) { string goalString = ""; string team = ""; int? secondsInPeriod = null; try { goalString = goal["desc"].Value <string>(); team = goal["t1"].Value <string>(); secondsInPeriod = goal["sip"].Value <int?>(); } catch (Exception) { } tempGoalsList.Add(new Goal(team, goalString, secondsInPeriod)); } } // Don't reverse OT, there can only ever be one goal there var list = new List <IEnumerable <Goal> >() { tempFirstPeriodGoals, tempSecondPeriodGoals, tempThirdPeriodGoals, tempOTGoals }; this.RefreshGoalSummary(list); }