public async override void OnNavigatedTo(NavigatedToEventArgs e, Dictionary<string, object> viewModelState) { FileService fileService = new FileService(); ObservableCollection<Team> teams = await fileService.GetTeamsAsync(); BoxScoreParameters parms = (BoxScoreParameters)e.Parameter; CurrentSeason = parms.SelectedSeason; CurrentWeek = parms.SelectedWeek; string gameId = parms.GamePageVM.GameId; Game game = await NFLService.GetGameFromUrlAsync(string.Format("http://www.nfl.com/liveupdate/game-center/{0}/{0}_gtd.json", gameId)); string imagePath = string.Empty; string nickName = string.Empty; if (game == null || game.Away == null || game.Home == null) { var messageDialog = new MessageDialog("Please try again later.", "Sorry, stats not available yet."); await messageDialog.ShowAsync(); } else { FindTeamValues(game.Away.Abbr, teams, ref imagePath, ref nickName); AwayImagePath = imagePath; // needed because Image not deep binding to AwayImagePath AwayNickName = nickName; AwayQ1 = game.Away.Score.Q1.ToString(); AwayQ2 = game.Away.Score.Q2.ToString(); AwayQ3 = game.Away.Score.Q3.ToString(); AwayQ4 = game.Away.Score.Q4.ToString(); AwayQ5 = game.Away.Score.Q5 == 0 ? string.Empty : game.Away.Score.Q5.ToString(); AwayTotal = game.Away.Score.Total.ToString(); FindTeamValues(game.Home.Abbr, teams, ref imagePath, ref nickName); HomeImagePath = imagePath; // needed because Image not deep binding to BoxScoreVM.HomeImagePath HomeNickName = nickName; HomeQ1 = game.Home.Score.Q1.ToString(); HomeQ2 = game.Home.Score.Q2.ToString(); HomeQ3 = game.Home.Score.Q3.ToString(); HomeQ4 = game.Home.Score.Q4.ToString(); HomeQ5 = game.Home.Score.Q5 == 0 ? string.Empty : game.Home.Score.Q5.ToString(); HomeTotal = game.Home.Score.Total.ToString(); if (game.Qtr == null) { Qtr = "Qtr N/A"; } else { Qtr = game.Qtr.ToLower() != "final" ? string.Format("Q{0} {1}", game.Qtr, game.Clock) : game.Qtr; } } base.OnNavigatedTo(e, viewModelState); }
public async static Task<WeekDateSpan> GetCurrentWeekAsync(DateTime date, string fileName) { // Need to adjust year because NFL Season starts in Aug and continues on to Feb of next year. string year = date.Month > 6 ? date.Year.ToString() : (date.Year - 1).ToString(); WeekDateSpan span = new WeekDateSpan(); // Building calendar every time takes too long. //YearCalendar yearCalendar = await NFLService.BuildYearCalendarAsync(year); // Build calendar one time then save it for reuse. FileService fileService = new FileService(); string readjson = await fileService.ReadYearCalendarAsync(fileName); YearCalendar yearCalendar; if (string.IsNullOrEmpty(readjson)) { yearCalendar = await NFLService.BuildYearCalendarAsync(year); string json = JsonConvert.SerializeObject(yearCalendar, Formatting.None); await fileService.WriteYearCalendarAsync("YearCalendar.json", json); } else { yearCalendar = JsonConvert.DeserializeObject<YearCalendar>(readjson); } for (int i = 0; i < yearCalendar.WeekDates.Count; i++) { if (date > yearCalendar.WeekDates[i].StartDate && date < yearCalendar.WeekDates[i].EndDate) { span.Year = yearCalendar.WeekDates[i].Year; span.Season = yearCalendar.WeekDates[i].Season; span.Week = yearCalendar.WeekDates[i].Week.Length == 1 ? "0" + yearCalendar.WeekDates[i].Week : yearCalendar.WeekDates[i].Week; span.StartDate = DateTime.Now; span.EndDate = DateTime.Now; break; } } return span; }