private async void Button_Click(object sender, RoutedEventArgs e) { ProgressBar.IsVisible = true; ProgressBar.Text = "正在添加..."; AnimeAPI api = new AnimeAPI(); try { await api.AddAnime(aid); ToastPrompt toast = new ToastPrompt(); toast.Title = "成功将添加到我的订阅"; toast.FontSize = 20; toast.Show(); } catch (Exception excepiton) { MessageBox.Show(excepiton.Message, "错误", MessageBoxButton.OK); if (api.lastError == AnimeAPI.ERROR.ERROR_INVALID_KEY) { IsolatedStorageSettings.ApplicationSettings.Remove("UserKey"); IsolatedStorageSettings.ApplicationSettings.Save(); NavigationService.Navigate(new Uri("/LoginPage.xaml", UriKind.Relative)); } } finally { ProgressBar.IsVisible = false; ProgressBar.Text = ""; } }
private async void AddToSubscription_Click(object sender, RoutedEventArgs e) { IsAddToSubBusy = true; ViewModels.ScheduleModel sm = (ViewModels.ScheduleModel)((MenuItem)sender).DataContext; AnimeAPI api = new AnimeAPI(); try { await api.AddAnime(sm.aid); ToastPrompt toast = new ToastPrompt(); toast.Title = "成功将 " + sm.name + " 添加到 我的订阅"; toast.FontSize = 20; toast.Show(); RefreshSubscription(); } catch (Exception excepiton) { MessageBox.Show(excepiton.Message, "错误", MessageBoxButton.OK); if (api.lastError == AnimeAPI.ERROR.ERROR_INVALID_KEY) { settings.Remove("UserKey"); settings.Save(); NavigationService.Navigate(new Uri("/LoginPage.xaml", UriKind.Relative)); } } finally { IsAddToSubBusy = false; } }