public void SetLikedPodcast(Podcast podcast, bool liked) { if (liked) { Podcasts.LikePodcast(podcast); } else { Podcasts.DislikePodcast(podcast); } wnd.SetLikedPodcasts(Podcasts.GetLikedPodcasts()); }
public void UpdateDatabase(bool reset = false) { if (wnd == null) { return; } bool cancelled = true; var l = new LoadingWindow("Pobieranie bazy podcastów"); l.SetStatus("Inicjowanie..."); Podcast[] podcasts = null; bool localLoaded = Podcasts.GetLocalPodcasts(out podcasts); bool downloadRemote = true; if (localLoaded && !reset) { if (MessageBox.Show("Czy chcesz zaktualizować listę dostępnych podcastów?", "Tyflopodcast", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) { downloadRemote = false; } } if (downloadRemote) { int totalPages = -1, leftPages = -1; CancellationTokenSource cts = new CancellationTokenSource(); CancellationToken ct = cts.Token; Task.Factory.StartNew(async() => { l.SetStatus("Łączenie..."); bool s = false; int p = -1; for (;;) { await Task.Delay(250); if (!s && totalPages != -1) { s = true; l.SetStatus("Pobieranie informacji o bazie podcastów..."); } else if (s && p != leftPages) { l.SetStatus("Pobieranie strony " + (totalPages - leftPages).ToString() + " z " + totalPages.ToString() + "..."); p = leftPages; int pr = (int)((double)(totalPages - leftPages) / totalPages * 100.0); l.SetPercentage(pr); if (leftPages == 0) { break; } } if (ct.IsCancellationRequested) { return; } } }, ct); Task.Factory.StartNew(() => { podcasts = Podcasts.FetchPodcasts(ref leftPages, ref totalPages, reset); l.SetStatus("Czyszczenie..."); Podcasts.CleanUp(); cancelled = false; l.Close(); }); l.ShowDialog(wnd); cts.Cancel(); if (cancelled || podcasts == null) { return; //Environment.Exit(0); } } wnd.Clear(); foreach (Category c in Podcasts.categories) { wnd.AddCategory(c); } foreach (Podcast p in podcasts) { wnd.AddPodcast(p); } wnd.UpdatePodcasts(); wnd.SetLikedPodcasts(Podcasts.GetLikedPodcasts()); }