private async Task RegisterBackgroundTask() { foreach (var task in BackgroundTaskRegistration.AllTasks) { task.Value.Unregister(true); } BackgroundTaskBuilder builder = new BackgroundTaskBuilder(); builder.Name = "PodCatchHouseKeeping"; builder.TaskEntryPoint = "PodCatch.BackgroundTasks.BackgroundTask"; builder.SetTrigger(new MaintenanceTrigger(15, false)); builder.AddCondition(new SystemCondition(SystemConditionType.InternetAvailable)); builder.AddCondition(new SystemCondition(SystemConditionType.UserNotPresent)); try { BackgroundAccessStatus status = await BackgroundExecutionManager.RequestAccessAsync(); IBackgroundTaskRegistration backgroundTaskRegistration = builder.Register(); backgroundTaskRegistration.Completed += ((s, a) => UIThread.RunInBackground(() => Data.Load(true))); } catch (Exception ex) { Tracer.TraceError("Error registering background task: {0}", ex); } }
private async void ExecuteSearchForPodcastCommand() { m_View.BottomAppBar.IsOpen = false; // show input dialog InputMessageDialog dlg = new InputMessageDialog("Search term or RSS feed URL:"); bool result = await dlg.ShowAsync(); // cancel pressed if (result == false) { return; } string searchTerm = dlg.TextBox.Text; IEnumerable <Podcast> searchResults; searchResults = await UIThread.RunInBackground <IEnumerable <Podcast> >(async() => { return(await Data.Search(searchTerm)); }); await UIThread.Dispatch(async() => { await Data.UpdateSearchResults(searchResults); }); }
public async Task OnPodcastTapped(PodcastSummaryViewModel podcast, Point position) { if (m_ShowingPopUp == true) { return; } m_ShowingPopUp = true; try { PopupMenu popupMenu = new PopupMenu(); // this is useful for debugging //popupMenu.Commands.Add(new UICommand(){Id=1, Label="Copy RSS feed URL to clipboard"}); if (Data.IsPodcastInFavorites(podcast.Data)) { popupMenu.Commands.Add(new UICommand() { Id = 2, Label = "Remove from favorites" }); } else { popupMenu.Commands.Add(new UICommand() { Id = 3, Label = "Add to favorites" }); } IUICommand selectedCommand = await popupMenu.ShowAsync(position); if (selectedCommand == null) { return; } switch ((int)selectedCommand.Id) { case 1: // Copy RSS feed to clipboard DataPackage dataPackage = new DataPackage(); dataPackage.SetText(podcast.Data.PodcastUri); Clipboard.SetContent(dataPackage); break; case 2: // Remove from favorites Task t = Data.RemoveFromFavorites(podcast.Data); m_View.NavigationHelper.GoBack(); break; case 3: // Add to favorites // Don't wait for this - It will leave the m_ShowingPopUp open await UIThread.RunInBackground(() => Data.AddToFavorites(podcast.Data)); podcast.DownloadEpisodes(); break; } } finally { m_ShowingPopUp = false; } }
private void ExecuteAllUnplayedCommand() { foreach (Episode episode in m_AllEpisodes) { episode.Played = false; } UIThread.RunInBackground(() => Data.Store()); }
public async void ExecuteEpisodeRightClickedCommand(EpisodeViewModel episode, Point point) { PopupMenu popupMenu = new PopupMenu(); if (episode.Played) { popupMenu.Commands.Add(new UICommand() { Id = 1, Label = "Mark as unplayed" }); } else { popupMenu.Commands.Add(new UICommand() { Id = 2, Label = "Mark as played" }); } if (episode.Data.State is EpisodeStateDownloaded) { popupMenu.Commands.Add(new UICommand() { Id = 3, Label = "Download again" }); } try { IUICommand selectedCommand = await popupMenu.ShowAsync(point); if (selectedCommand == null) { return; } switch ((int)selectedCommand.Id) { case 1: episode.Data.Played = false; UIThread.RunInBackground(() => Data.Store()); break; case 2: episode.Data.Played = true; UIThread.RunInBackground(() => Data.Store()); break; case 3: Task t = episode.Data.PostEvent(EpisodeEvent.Refresh); break; } } catch (Exception ex) { Tracer.TraceError("PodcastPage.xaml.Grid_RightTapped() - Error occured displaying popup menu {0}", ex); } }
public void DownloadEpisodes() { int i = 0; foreach (Episode episode in Data.Episodes) { if (i++ > 3) { break; } UIThread.RunInBackground(() => episode.Download()); } }
public StartPageViewModel(StartPage startPage, IServiceContext serviceContext) : base(serviceContext.GetService <IPodcastDataSource>(), serviceContext) { m_View = startPage; m_MediaPlayer = serviceContext.GetService <IMediaPlayer>(); ObservableCollection <PodcastGroup> podcastGroups = Data.GetGroups(); podcastGroups.CollectionChanged += OnPodcastGroupsChanged; // load from cache UIThread.RunInBackground(() => Data.Load(false)); Task t = RegisterBackgroundTask(); UpdateFields(); }
private async void ExecuteRefreshCommand() { MessageDialog dlg = null; Podcast podcastDataItem = Podcast; try { await UIThread.RunInBackground(async() => await podcastDataItem.RefreshFromRss(true)); await podcastDataItem.Store(); } catch (Exception ex) { dlg = new MessageDialog(string.Format("Unable to refresh {0}. {1}", podcastDataItem.Title, ex.Message)); } if (dlg != null) { await dlg.ShowAsync(); } }