private void Load(bool refresh) { if (lecturesLazyBlock != null) { lecturesLazyBlock.Cancel(); lecturesLazyBlock = null; } var course = App.Crawler.GetCourse(courseId); if (!course.Active) { if (course.HasFinished) { messageTextBlock.Text = "Lectures no longer available"; } else { messageTextBlock.Text = "Lectures not available yet"; } } else { if (refresh) { course = App.Crawler.RefreshCourse(course.Id); } lecturesLazyBlock = new LazyBlock <LectureSection[]>( "lectures", "No lectures available. Make sure you have accepted the honor code.", course.LectureSections, a => a.Length == 0, new LazyBlockUI <LectureSection[]>( this, lectureSections => pivot.ItemsSource = lectureSections, () => pivot.ItemsSource != null, messageTextBlock), false, null, success => { if (!success) { ErrorReporting.Log("Failed to get lectures"); } }, null); } }
protected override void OnNavigatedTo(NavigationEventArgs e) { base.OnNavigatedTo(e); if (journeyElementsLazyAsync == null) { ErrorReporting.Log("journeyElementsLazyAsync is null"); if (NavigationService.CanGoBack) { NavigationService.GoBack(); } else { ErrorReporting.Log("Can not go back"); } return; } if (journeyElementsLazyBlock != null) { if (journeyElements.ItemsSource == null) { journeyElementsLazyBlock.Refresh(); } } else { title.Text = trainTitle; if (title.Text.Length > 40) { title.Text = title.Text.Replace(" to ", "\nto "); } journeyElementsLazyBlock = new LazyBlock <JourneyElement[]>( "live progress", "No information available", journeyElementsLazyAsync, items => items.Length == 0, new LazyBlockUI <JourneyElement>(this, journeyElements, journeyElementsMessageTextBlock, journeyElementsLastUpdatedTextBlock), Settings.GetBool(Setting.AutoRefresh), null, null, null); } }
protected override void OnNavigatedTo(NavigationEventArgs e) { base.OnNavigatedTo(e); if (journeyElementsLazyAsync == null) { ErrorReporting.Log("journeyElementsLazyAsync is null"); if (NavigationService.CanGoBack) { NavigationService.GoBack(); } else { ErrorReporting.Log("Can not go back"); } return; } if (journeyElementsLazyBlock != null) { if (journeyElements.ItemsSource == null) { journeyElementsLazyBlock.Refresh(); } } else { title.Text = trainTitle; if (title.Text.Length > 40) title.Text = title.Text.Replace(" to ", "\nto "); journeyElementsLazyBlock = new LazyBlock<JourneyElement[]>( "live progress", "No information available", journeyElementsLazyAsync, items => items.Length == 0, new LazyBlockUI<JourneyElement>(this, journeyElements, journeyElementsMessageTextBlock, journeyElementsLastUpdatedTextBlock), Settings.GetBool(Setting.AutoRefresh), null, null, null); } }
private void LoadArrivals() { if (arrivalsLazyBlock == null) { arrivalsLazyBlock = new LazyBlock <Arrival[]>( "arrivals", "No more trains today", departuresAndArrivalsTable.GetArrivals(), items => items.Length == 0, new LazyBlockUI <Arrival>(this, arrivals, arrivalsMessageTextBlock, arrivalsLastUpdatedTextBlock), Settings.GetBool(Setting.AutoRefresh), null, null, null); } else if (arrivals.ItemsSource == null) { arrivalsLazyBlock.Refresh(); } }
private void Load(bool refresh) { if (refresh) { App.Crawler.RefreshCourse(course.Id); } lecturesLazyBlock = new LazyBlock <LectureSection[]>( "lectures", "No lectures available. Make sure you have acceted the honor code.", course.LectureSections, a => a.Length == 0, new LazyBlockUI <LectureSection[]>( this, lectureSections => pivot.ItemsSource = lectureSections, () => pivot.ItemsSource != null, messageTextBlock), false, null, null, null); }
private void OnLectureVideoClick(object sender, RoutedEventArgs e) { if (videoLazyBlock != null) { return; } var lecture = (Coursera.Lecture)((Button)sender).DataContext; videoLazyBlock = new LazyBlock <string>( "video", null, lecture.VideoUrl, _ => false, new LazyBlockUI <string>( this, videoUrl => { try { var launcher = new MediaPlayerLauncher(); launcher.Media = new Uri(videoUrl, UriKind.Absolute); launcher.Show(); } catch (Exception ex) { LittleWatson.ReportException(ex, string.Format("Opening video for lecture '{0}' of course '{1}' ({2})", lecture.Title, pivot.Title, videoUrl)); LittleWatson.CheckForPreviousException(false); } }, () => false, null), false, null, _ => videoLazyBlock = null, null); }
private void Load(bool refresh) { if (lecturesLazyBlock != null) { lecturesLazyBlock.Cancel(); lecturesLazyBlock = null; } var course = App.Crawler.GetCourse(courseId); if (!course.Active) { if (course.HasFinished) { messageTextBlock.Text = "Lectures no longer available"; } else { messageTextBlock.Text = "Lectures not available yet"; } } else { if (refresh) { course = App.Crawler.RefreshCourse(course.Id); } lecturesLazyBlock = new LazyBlock<LectureSection[]>( "lectures", "No lectures available. Make sure you have accepted the honor code.", course.LectureSections, a => a.Length == 0, new LazyBlockUI<LectureSection[]>( this, lectureSections => pivot.ItemsSource = lectureSections, () => pivot.ItemsSource != null, messageTextBlock), false, null, success => { if (!success) { ErrorReporting.Log("Failed to get lectures"); } }, null); } }
private void LoadDepartures() { if (departuresLazyBlock == null) { departuresLazyBlock = new LazyBlock<Departure[]>( "departures", "No more trains today", departuresAndArrivalsTable.GetDepartures(), items => items.Length == 0, new LazyBlockUI<Departure>(this, departures, departuresMessageTextBlock, departuresLastUpdatedTextBlock), Settings.GetBool(Setting.AutoRefresh), null, null, null); } else if (departures.ItemsSource == null) { departuresLazyBlock.Refresh(); } }
private void LoadNearestStations() { if (nearestLazyBlock != null) { nearestLazyBlock.Cancel(); } var lazyBlockUI = new LazyBlockUI <Tuple <double, Station> >(this, nearestStations, nearestStationsMessageTextBlock, null); LatLong from; if (fromStation == null) { var currentPosition = LocationService.CurrentPosition; if (!Settings.GetBool(Setting.LocationServicesEnabled)) { lazyBlockUI.SetItems(null); lazyBlockUI.SetLocalProgressMessage("Locations Services are disabled.\nYou can enable them in the Settings."); nearestLazyBlock = null; return; } else if (currentPosition == null || currentPosition.IsUnknown) { lazyBlockUI.SetLocalProgressMessage("Acquiring position..."); lazyBlockUI.SetGlobalProgressMessage("Acquiring position..."); nearestLazyBlock = null; return; } from = LatLong.Create(currentPosition.Latitude, currentPosition.Longitude); } else { from = fromStation.Location; } lazyBlockUI.SetLocalProgressMessage(""); lazyBlockUI.SetGlobalProgressMessage(""); nearestLazyBlock = new LazyBlock <Tuple <double, Station>[]>( "nearest stations", "No nearby stations", Stations.GetNearestAsync(from, 150), items => items.Length == 0, lazyBlockUI, false, null, null, nearestUnfiltered => { var nearestFiltered = nearestUnfiltered.AsEnumerable(); if (fromStation != null) { nearestFiltered = nearestFiltered.Where(t => t.Item2.Code != fromStation.Code); } if (excludeStation != null) { nearestFiltered = nearestFiltered.Where(t => t.Item2.Code != excludeStation); } return(nearestFiltered.ToArray()); }); }
private void LoadCourses(string email, string password, bool refresh) { if (App.Crawler == null) { App.Crawler = new Crawler(email, password, Cache.GetFiles(), Cache.SaveFile, DownloadInfo.Create); } if (refresh) { App.Crawler.RefreshCourses(); } if (coursesLazyBlock != null) { coursesLazyBlock.Cancel(); } coursesLazyBlock = new LazyBlock<Course[]>( "courses", null, App.Crawler.Courses, _ => false, new LazyBlockUI<Course[]>( this, courses => { var active = new List<Course>(); var upcoming = new List<Course>(); var finished = new List<Course>(); foreach (var course in courses) { if (course.HasFinished) finished.Add(course); else if (course.Active) active.Add(course); else upcoming.Add(course); } activeCourses.ItemsSource = active; upcomingCourses.ItemsSource = upcoming; finishedCourses.ItemsSource = finished; activeCoursesCourseCatalogButton.Visibility = activeCoursesEmptyMessage.Visibility = active.Count == 0 ? Visibility.Visible : Visibility.Collapsed; upcomingCoursesCourseCatalogButton.Visibility = upcomingCoursesEmptyMessage.Visibility = upcoming.Count == 0 ? Visibility.Visible : Visibility.Collapsed; finishedCoursesEmptyMessage.Visibility = finished.Count == 0 ? Visibility.Visible : Visibility.Collapsed; if (active.Count == 0) { if (upcoming.Count == 0) { pivot.SelectedIndex = 2; } else { pivot.SelectedIndex = 1; } } }, () => activeCourses.ItemsSource != null, messageTextBlock), false, _ => { activeCoursesEmptyMessage.Visibility = Visibility.Collapsed; upcomingCoursesEmptyMessage.Visibility = Visibility.Collapsed; finishedCoursesEmptyMessage.Visibility = Visibility.Collapsed; }, success => { if (!success) { ErrorReporting.Log("Failed to get courses"); } }, null); }
private void LoadNearestStations() { if (nearestLazyBlock != null) { nearestLazyBlock.Cancel(); } var lazyBlockUI = new LazyBlockUI<Tuple<double, Station>>(this, nearestStations, nearestStationsMessageTextBlock, null); LatLong from; if (fromStation == null) { var currentPosition = LocationService.CurrentPosition; if (!Settings.GetBool(Setting.LocationServicesEnabled)) { lazyBlockUI.SetItems(null); lazyBlockUI.SetLocalProgressMessage("Locations Services are disabled.\nYou can enable them in the Settings."); nearestLazyBlock = null; return; } else if (currentPosition == null || currentPosition.IsUnknown) { lazyBlockUI.SetLocalProgressMessage("Acquiring position..."); lazyBlockUI.SetGlobalProgressMessage("Acquiring position..."); nearestLazyBlock = null; return; } from = LatLong.Create(currentPosition.Latitude, currentPosition.Longitude); } else { from = fromStation.Location; } lazyBlockUI.SetLocalProgressMessage(""); lazyBlockUI.SetGlobalProgressMessage(""); nearestLazyBlock = new LazyBlock<Tuple<double, Station>[]>( "nearest stations", "No nearby stations", Stations.GetNearestAsync(from, 150), items => items.Length == 0, lazyBlockUI, false, null, null, nearestUnfiltered => { var nearestFiltered = nearestUnfiltered.AsEnumerable(); if (fromStation != null) { nearestFiltered = nearestFiltered.Where(t => t.Item2.Code != fromStation.Code); } if (excludeStation != null) { nearestFiltered = nearestFiltered.Where(t => t.Item2.Code != excludeStation); } return nearestFiltered.ToArray(); }); }
private void LoadCourses(string email, string password, bool refresh) { if (App.Crawler == null) { App.Crawler = new Crawler(email, password, Cache.GetFiles(), Cache.SaveFile, DownloadInfo.Create); } if (refresh) { App.Crawler.RefreshCourses(); } if (coursesLazyBlock != null) { coursesLazyBlock.Cancel(); } coursesLazyBlock = new LazyBlock <Course[]>( "courses", null, App.Crawler.Courses, _ => false, new LazyBlockUI <Course[]>( this, courses => { var active = new List <Course>(); var upcoming = new List <Course>(); var finished = new List <Course>(); foreach (var course in courses) { if (course.HasFinished) { finished.Add(course); } else if (course.Active) { active.Add(course); } else { upcoming.Add(course); } } activeCourses.ItemsSource = active; upcomingCourses.ItemsSource = upcoming; finishedCourses.ItemsSource = finished; activeCoursesCourseCatalogButton.Visibility = activeCoursesEmptyMessage.Visibility = active.Count == 0 ? Visibility.Visible : Visibility.Collapsed; upcomingCoursesCourseCatalogButton.Visibility = upcomingCoursesEmptyMessage.Visibility = upcoming.Count == 0 ? Visibility.Visible : Visibility.Collapsed; finishedCoursesEmptyMessage.Visibility = finished.Count == 0 ? Visibility.Visible : Visibility.Collapsed; if (active.Count == 0) { if (upcoming.Count == 0) { pivot.SelectedIndex = 2; } else { pivot.SelectedIndex = 1; } } }, () => activeCourses.ItemsSource != null, messageTextBlock), false, _ => { activeCoursesEmptyMessage.Visibility = Visibility.Collapsed; upcomingCoursesEmptyMessage.Visibility = Visibility.Collapsed; finishedCoursesEmptyMessage.Visibility = Visibility.Collapsed; }, success => { if (!success) { ErrorReporting.Log("Failed to get courses"); } }, null); }
private void LoadCourses(string email, string password, bool refresh) { if (App.Crawler == null) { App.Crawler = new Crawler(email, password, Cache.GetFiles(), Cache.SaveFile); } if (refresh) { App.Crawler.RefreshCourses(); } coursesLazyBlock = new LazyBlock <Course[]>( "courses", "No courses", App.Crawler.Courses, a => a.Length == 0, new LazyBlockUI <Course[]>( this, courses => { var active = new List <Coursera.Course>(); var upcoming = new List <Coursera.Course>(); var completed = new List <Coursera.Course>(); foreach (var course in courses) { if (course.HasFinished) { completed.Add(course); } else if (course.HasStarted) { active.Add(course); } else { upcoming.Add(course); } } activeCourses.ItemsSource = active; upcomingCourses.ItemsSource = upcoming; completedCourses.ItemsSource = completed; activeCoursesEmptyMessage.Visibility = active.Count == 0 ? Visibility.Visible : Visibility.Collapsed; upcomingCoursesEmptyMessage.Visibility = upcoming.Count == 0 ? Visibility.Visible : Visibility.Collapsed; completedCoursesEmptyMessage.Visibility = completed.Count == 0 ? Visibility.Visible : Visibility.Collapsed; if (active.Count == 0) { if (upcoming.Count == 0) { pivot.SelectedIndex = 2; } else { pivot.SelectedIndex = 1; } } }, () => activeCourses.ItemsSource != null, messageTextBlock), false, _ => { activeCoursesEmptyMessage.Visibility = Visibility.Collapsed; upcomingCoursesEmptyMessage.Visibility = Visibility.Collapsed; completedCoursesEmptyMessage.Visibility = Visibility.Collapsed; }, null, null); }