Ejemplo n.º 1
0
        private async void EmailReminderSwitch_Checked(object sender, RoutedEventArgs e)
        {
            ProgressBar.Text              = "设置中...";
            ProgressBar.IsVisible         = true;
            EmailReminderSwitch.IsEnabled = false;
            AnimeAPI api = new AnimeAPI();

            try
            {
                await api.SetEmailReminderStatus(true);

/*
 *              string result = await httpRequest.GetAsync("http://apianime.ricter.info/email_reminder_set?key=" + IsolatedStorageSettings.ApplicationSettings["UserKey"] + "&enable=1&hash=" + new Random().Next());
 *              if (result.Contains("ERROR_"))
 *              {
 *                  if (result == "ERROR_INVALID_KEY")
 *                  {
 *                      MessageBox.Show("", "您的帐号已在别的客户端登陆,请重新登陆", MessageBoxButton.OK);
 *                      settings.Remove("UserKey");
 *                      NavigationService.Navigate(new Uri("/LoginPage.xaml", UriKind.Relative));
 *                      return;
 *                  }
 *                  throw new Exception("发生了错误,但我不知道是什么");
 *              }
 */
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.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
            {
                EmailReminderSwitch.IsEnabled = true;
                ProgressBar.IsVisible         = false;
                ProgressBar.Text = "";
            }
        }
        private async void EmailReminderSwitch_Checked(object sender, RoutedEventArgs e)
        {
            ProgressBar.Text = "设置中...";
            ProgressBar.IsVisible = true;
            EmailReminderSwitch.IsEnabled = false;
            AnimeAPI api = new AnimeAPI();
            try
            {
                await api.SetEmailReminderStatus(true);
/*
                string result = await httpRequest.GetAsync("http://apianime.ricter.info/email_reminder_set?key=" + IsolatedStorageSettings.ApplicationSettings["UserKey"] + "&enable=1&hash=" + new Random().Next());
                if (result.Contains("ERROR_"))
                {
                    if (result == "ERROR_INVALID_KEY")
                    {
                        MessageBox.Show("", "您的帐号已在别的客户端登陆,请重新登陆", MessageBoxButton.OK);
                        settings.Remove("UserKey");
                        NavigationService.Navigate(new Uri("/LoginPage.xaml", UriKind.Relative));
                        return;
                    }
                    throw new Exception("发生了错误,但我不知道是什么");
                }
 */
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.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
            {
                EmailReminderSwitch.IsEnabled = true;
                ProgressBar.IsVisible = false;
                ProgressBar.Text = "";
            }
        }