Ejemplo n.º 1
0
        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;
            }
        }
Ejemplo n.º 2
0
        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      = "";
            }
        }
Ejemplo n.º 3
0
        private async void MarkReadOrUnread_Click(object sender, RoutedEventArgs e)
        {
            ProgressBar.Text                 = "执行中...";
            ProgressBar.IsVisible            = true;
            UpdateButton.IsEnabled           = false;
            MarkReadOrUnreadButton.IsEnabled = false;
            DeleteButton.IsEnabled           = false;
            AnimeAPI api = new AnimeAPI();

            try
            {
                if ((MarkReadOrUnreadButton.Content as string) == "标记为更新")
                {
                    await api.AddHighlight(subscriptionIndex.aid, "2");
                }
                else
                {
                    await api.DelHighlight(subscriptionIndex.aid);
                }
                if (settings.Contains("MustRefresh"))
                {
                    settings.Remove("MustRefresh");
                }
                settings.Add("MustRefresh", true);
                settings.Save();
                ToastPrompt toast = new ToastPrompt();
                if ((MarkReadOrUnreadButton.Content as string) == "标记为更新")
                {
                    MarkReadOrUnreadButton.Content = "标记为未更新";
                    toast.Title = "成功标记为更新";
                }
                else
                {
                    MarkReadOrUnreadButton.Content = "标记为更新";
                    toast.Title = "成功标记为未更新";
                }
                toast.FontSize = 20;
                toast.Show();
            }
            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
            {
                UpdateButton.IsEnabled           = true;
                MarkReadOrUnreadButton.IsEnabled = true;
                DeleteButton.IsEnabled           = true;
                ProgressBar.IsVisible            = false;
                ProgressBar.Text = "";
            }
        }
Ejemplo n.º 4
0
        private async void Login()
        {
            ProgressBar.Text      = "登陆中...";
            ProgressBar.IsVisible = true;
            UserNameBox.IsEnabled = false;
            PasswordBox.IsEnabled = false;
            LoginButton.IsEnabled = false;
            try
            {
                if (UserNameBox.Text == "邮箱")
                {
                    throw new Exception("请输入邮箱");
                }
                if (PasswordBox.Password == "")
                {
                    throw new Exception("请输入密码");
                }
                AnimeAPI api = new AnimeAPI();
                await api.Login(UserNameBox.Text, PasswordBox.Password);

/*
 *              HttpEngine httpRequest = new HttpEngine();
 *              string UserKey = await httpRequest.GetAsync("http://apianime.ricter.info/login?u=" + UserNameBox.Text + "&p=" + PasswordBox.Password + "&hash=" + new Random().Next());
 *              if (UserKey.Contains("ERROR_"))
 *              {
 *                  if (UserKey == "ERROR_INVALID_PSW")
 *                      throw new Exception("邮箱或密码错误");
 *                  throw new Exception("发生了错误,但我不知道是什么");
 *              }
 */
                IsolatedStorageSettings settings = IsolatedStorageSettings.ApplicationSettings;
                settings.Add("UserKey", api.key);
                settings.Add("UserName", UserNameBox.Text);
                if (settings.Contains("MustRefresh"))
                {
                    settings.Remove("MustRefresh");
                }
                settings.Add("MustRefresh", true);
                settings.Save();
                NavigationService.Navigate(new Uri("/MainPage.xaml", UriKind.Relative));
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message, "错误", MessageBoxButton.OK);
            }
            finally
            {
                UserNameBox.IsEnabled = true;
                PasswordBox.IsEnabled = true;
                LoginButton.IsEnabled = true;
                ProgressBar.IsVisible = false;
                ProgressBar.Text      = "";
            }
        }
Ejemplo n.º 5
0
        private async void EmailReminderSwitch_Loaded(object sender, RoutedEventArgs e)
        {
            ProgressBar.Text      = "获取中...";
            ProgressBar.IsVisible = true;
            AnimeAPI api = new AnimeAPI();

            try
            {
                await api.GetEmailReminderStatus();

/*
 *              string result = await httpRequest.GetAsync("http://apianime.ricter.info/email_reminder_get?key=" + IsolatedStorageSettings.ApplicationSettings["UserKey"] + "&hash=" + new Random().Next());
 *              if (result.Contains("ERROR_"))
 *              {
 *                  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("发生了错误,但我不知道是什么");
 *                  }
 *              }
 *              if (result == "1")
 *                  EmailReminderSwitch.IsChecked = true;
 *              else
 *                  EmailReminderSwitch.IsChecked = false;
 */
                EmailReminderSwitch.IsChecked = api.emailReminderStatus;
                EmailReminderSwitch.IsEnabled = true;
            }
            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
            {
                ProgressBar.IsVisible = false;
                ProgressBar.Text      = "";
            }
        }
        private async void EmailReminderSwitch_Loaded(object sender, RoutedEventArgs e)
        {
            ProgressBar.Text = "获取中...";
            ProgressBar.IsVisible = true;
            AnimeAPI api = new AnimeAPI();
            try
            {
                await api.GetEmailReminderStatus();
/*
                string result = await httpRequest.GetAsync("http://apianime.ricter.info/email_reminder_get?key=" + IsolatedStorageSettings.ApplicationSettings["UserKey"] + "&hash=" + new Random().Next());
                if (result.Contains("ERROR_"))
                {
                    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("发生了错误,但我不知道是什么");
                    }
                }
                if (result == "1")
                    EmailReminderSwitch.IsChecked = true;
                else
                    EmailReminderSwitch.IsChecked = false;
 */
                EmailReminderSwitch.IsChecked = api.emailReminderStatus;
                EmailReminderSwitch.IsEnabled = true;
            }
            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
            {
                ProgressBar.IsVisible = false;
                ProgressBar.Text = "";
            }

        }
Ejemplo n.º 7
0
        private async void Delete_Click(object sender, RoutedEventArgs e)
        {
            if (MessageBox.Show("", "确定删除此订阅?", MessageBoxButton.OKCancel) == MessageBoxResult.Cancel)
            {
                return;
            }
            ProgressBar.Text                 = "删除中...";
            ProgressBar.IsVisible            = true;
            UpdateButton.IsEnabled           = false;
            MarkReadOrUnreadButton.IsEnabled = false;
            DeleteButton.IsEnabled           = false;
            AnimeAPI api = new AnimeAPI();

            try
            {
                await api.DelAnime(subscriptionIndex.aid);

                App.ViewModel.SubscriptionItems.Remove(subscriptionIndex);
                if (settings.Contains("MustRefresh"))
                {
                    settings.Remove("MustRefresh");
                }
                settings.Add("MustRefresh", true);
                settings.Save();
                NavigationService.GoBack();
            }
            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
            {
                UpdateButton.IsEnabled           = true;
                MarkReadOrUnreadButton.IsEnabled = true;
                DeleteButton.IsEnabled           = true;
                ProgressBar.IsVisible            = false;
                ProgressBar.Text = "";
            }
        }
Ejemplo n.º 8
0
        public async void RefreshUpdatedSchedule()
        {
            IsRefreshScheBusy = true;
            AnimeAPI api = new AnimeAPI();

            try
            {
                await api.GetUpdateSchedule();

                while (App.ViewModel.ScheduleItems.Count > 0)
                {
                    App.ViewModel.ScheduleItems.RemoveAt(App.ViewModel.ScheduleItems.Count - 1);
                    LongListSelector.UpdateLayout();
                }
                foreach (AnimeAPI.Anime item in api.scheduleList)
                {
                    string text;
                    text = item.week + " " + item.time;
                    App.ViewModel.ScheduleItems.Add(new ViewModels.ScheduleModel()
                    {
                        num  = item.num,
                        aid  = item.aid,
                        name = item.name,
                        time = text,
                        pic  = "http://images.movie.xunlei.com/submovie_img/" + item.aid[0] + item.aid[1] + "/" + item.aid + "/1_1_115x70.jpg"
                    });
                }
            }
            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
            {
                IsRefreshScheBusy = false;
            }
        }
Ejemplo n.º 9
0
        private async void MarkRead_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("", "是否将所有订阅标记为未更新?", MessageBoxButton.OKCancel) == MessageBoxResult.Cancel)
            {
                return;
            }
            IsMarkReadBusy = true;
            AnimeAPI api = new AnimeAPI();

            try
            {
                foreach (ViewModels.SubscriptionModel item in App.ViewModel.SubscriptionItems)
                {
                    if (item.highlight != "0")
                    {
                        await api.DelHighlight(item.aid);
                    }
                }
                ToastPrompt toast = new ToastPrompt();
                toast.Title    = "成功将所有订阅标记为未更新";
                toast.FontSize = 20;
                toast.Show();
            }
            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
            {
                IsMarkReadBusy = false;
                RefreshSubscription();
            }
        }
Ejemplo n.º 10
0
        public async void RefreshSubscription()
        {
            IsRefreshSubBusy = true;
            AnimeAPI api = new AnimeAPI();
            try
            {
                await api.GetSubscriptionList();
                App.ViewModel.SubscriptionItems.Clear();
                string[] TileContent = new string[3] { "", "", "" };
                foreach (AnimeAPI.Anime item in api.subscriptionList)
                {
                    string text;
                    if (item.status == "1")
                        text = "已完结,共 " + item.epi + " 集";
                    else
                        text = "更新到第 " + item.epi + " 集";
                    if (item.read != "0")
                        text += ",已看 " + item.read + " 集";
                    System.Windows.Visibility updated;
                    if (item.highlight != "0")
                        updated = System.Windows.Visibility.Visible;
                    else
                        updated = System.Windows.Visibility.Collapsed;
                    App.ViewModel.SubscriptionItems.Add(new ViewModels.SubscriptionModel() 
                    {
                        num     = item.num, 
                        aid     = item.aid, 
                        name    = item.name, 
                        status  = item.status, 
                        epi     = item.epi,
                        read    = item.read, 
                        highlight = item.highlight,
                        text    = text,
                        updated = updated
                    });
                }

                if (App.ViewModel.SubscriptionItems.Count >= 1 && App.ViewModel.SubscriptionItems[0].highlight != "0")
                {
                    TileContent[0] = "订阅更新";
                    TileContent[1] = App.ViewModel.SubscriptionItems[0].name + " 更新到第 " + App.ViewModel.SubscriptionItems[0].epi + " 集";
                }
                if (App.ViewModel.SubscriptionItems.Count >= 2 && App.ViewModel.SubscriptionItems[1].highlight != "0")
                {
                    TileContent[2] = App.ViewModel.SubscriptionItems[1].name + " 更新到第 " + App.ViewModel.SubscriptionItems[1].epi + " 集";
                }
                ShellTile Tile = ShellTile.ActiveTiles.FirstOrDefault();
                if (Tile != null)
                {
                    var TileData = new IconicTileData()
                    {
                        Title = "新番提醒",
                        Count = api.updateNumber,
                        BackgroundColor = System.Windows.Media.Colors.Transparent,
                        WideContent1 = TileContent[0],
                        WideContent2 = TileContent[1],
                        WideContent3 = TileContent[2]
                    };
                    Tile.Update(TileData);
                }

/*
                HttpEngine httpRequest = new HttpEngine();
                string result = await httpRequest.GetAsync("http://api2.ricter.info/get_subscription_list?key=" + settings["UserKey"] + "&hash=" + new Random().Next());
                if (result.IndexOf("ERROR_") != -1)
                {
                    if (result == "ERROR_INVALID_KEY")
                    {
                        MessageBox.Show("", "您的帐号已在别的客户端登陆,请重新登陆", MessageBoxButton.OK);
                        settings.Remove("UserKey");
                        NavigationService.Navigate(new Uri("/LoginPage.xaml", UriKind.Relative));
                        return;
                    }
                    throw new Exception("发生了错误,但我不知道是什么");
                }
                App.ViewModel.SubscriptionItems.Clear();
                string[] list = result.Split('\n');
                int updatedNumber = 0;
                int number = 0;
                string[] TileContent = new string[3] { "", "", "" };
                for (int i = 0; i < list.Length; ++i)
                {
                    string[] item   = list[i].Split('|');
                    if (item.Length < 6)
                        continue;
                    number++;
                    string isUpdate = item[0];
                    string id       = item[1];
                    string name     = item[2];
                    string epi      = item[3];
                    string isDone   = item[4];
                    string readed   = item[5];
                    string showEpi;
                    if (isDone == "0")
                        showEpi = "已完结,共 " + epi + " 集";
                    else
                        showEpi = "更新到第 " + epi + " 集";
                    if (readed != "0")
                        showEpi += ",看到第 " + readed + " 集";
                    System.Windows.Visibility updated;
                    if (isUpdate != "0")
                    {
                        updated = System.Windows.Visibility.Visible;
                        updatedNumber++;
                        if (updatedNumber == 1)
                        {
                            TileContent[0] = " ";
                            TileContent[1] = name + " 更新到第 " + epi + " 集";
                        }
                        else if (updatedNumber == 2)
                        {
                            TileContent[2] = name + " 更新到第 " + epi + " 集";
                        }
                    }
                    else
                    {
                        updated = System.Windows.Visibility.Collapsed;
                    }
                    App.ViewModel.SubscriptionItems.Add(new ViewModels.SubscriptionModel() { Number = number, ID = id, Name = name, Epi = epi, Readed = readed, ShowEpi = showEpi, Updated = updated });
                }
                ShellTile Tile = ShellTile.ActiveTiles.FirstOrDefault();
                if (Tile != null)
                {
                    var TileData = new IconicTileData()
                    {
                        Title = "新番提醒",
                        Count = updatedNumber,
                        BackgroundColor = System.Windows.Media.Colors.Transparent,
                        WideContent1 = TileContent[0],
                        WideContent2 = TileContent[1],
                        WideContent3 = TileContent[2]
                    };
                    Tile.Update(TileData);
                }
 */
            }
            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
            {
                IsRefreshSubBusy = false;
            }
        }
        private async void ChangePassword()
        {
            ProgressBar.IsVisible = true;
            Logout.IsEnabled = false;
            ChangePsw.IsEnabled = false;

            AnimeAPI api = new AnimeAPI();
            try
            {
                if (OldPasswordBox.Password == "")
                    throw new Exception("请输入原密码");
                if (NewPasswordBox.Password == "")
                    throw new Exception("请输入新密码");
                if (RepasswordBox.Password == "")
                    throw new Exception("请输入密码确认");
                if (OldPasswordBox.Password.Length < 6 || OldPasswordBox.Password.Length > 16)
                    throw new Exception("密码的长度必须在 6 到 16 之间");
                if (NewPasswordBox.Password.Length < 6 || NewPasswordBox.Password.Length > 16)
                    throw new Exception("密码的长度必须在 6 到 16 之间");
                if (RepasswordBox.Password.Length < 6 || RepasswordBox.Password.Length > 16)
                    throw new Exception("密码的长度必须在 6 到 16 之间");
                if (NewPasswordBox.Password != RepasswordBox.Password)
                    throw new Exception("两次输入的密码不一致");

                await api.ChangePsw(OldPasswordBox.Password, NewPasswordBox.Password);
                IsolatedStorageSettings.ApplicationSettings.Remove("UserKey");
                IsolatedStorageSettings.ApplicationSettings.Save();
                MessageBox.Show("", "修改密码成功,请重新登陆", MessageBoxButton.OK);
                NavigationService.Navigate(new Uri("/LoginPage.xaml", UriKind.Relative));
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.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;
                Logout.IsEnabled = true;
                ChangePsw.IsEnabled = true;
            }
        }
Ejemplo n.º 12
0
        private async void Update_Click(object sender, RoutedEventArgs e)
        {
            ProgressBar.Text = "更新中...";
            ProgressBar.IsVisible = true;
            UpdateButton.IsEnabled = false;
            MarkReadOrUnreadButton.IsEnabled = false;
            DeleteButton.IsEnabled = false;
            AnimeAPI api = new AnimeAPI();
            try
            {
/*
                HttpEngine httpRequest = new HttpEngine();
                string result = await httpRequest.GetAsync("http://apianime.ricter.info/epiedit?key=" + settings["UserKey"] + "&aid=" + subscriptionIndex.aid + "&epi=" + EpiTextBox.Text + "&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("发生了错误,但我不知道是什么");
                }
*/
                await api.SetReadEpi(subscriptionIndex.aid, EpiTextBox.Text);
                if (settings.Contains("MustRefresh"))
                    settings.Remove("MustRefresh");
                settings.Add("MustRefresh", true);
                settings.Save();
                ToastPrompt toast = new ToastPrompt();
                toast.Title = "更新成功";
                toast.FontSize = 20;
                toast.Show();
            }
            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
            {
                ProgressBar.IsVisible = false;
                UpdateButton.IsEnabled = true;
                MarkReadOrUnreadButton.IsEnabled = true;
                DeleteButton.IsEnabled = true;
                ProgressBar.Text = "";
            }
        }
Ejemplo n.º 13
0
        private async void Delete_Click(object sender, RoutedEventArgs e)
        {
            if (MessageBox.Show("", "确定删除此订阅?", MessageBoxButton.OKCancel) == MessageBoxResult.Cancel)
                return;
            ProgressBar.Text = "删除中...";
            ProgressBar.IsVisible = true;
            UpdateButton.IsEnabled = false;
            MarkReadOrUnreadButton.IsEnabled = false;
            DeleteButton.IsEnabled = false;
            AnimeAPI api = new AnimeAPI();
            try
            {
/*
                HttpEngine httpRequest = new HttpEngine();
                string result = await httpRequest.GetAsync("http://apianime.ricter.info/del?key=" + settings["UserKey"] + "&id=" + subscriptionIndex.aid);
                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;
                    }
                    if (result == "ERROR_INVALID_ID")
                    {
                        throw new Exception("您选择的内容可能已经被删除,请刷新后重试");
                    }
                    throw new Exception("发生了错误,但我不知道是什么");
                }
 */
                await api.DelAnime(subscriptionIndex.aid);
                App.ViewModel.SubscriptionItems.Remove(subscriptionIndex);
                if (settings.Contains("MustRefresh"))
                    settings.Remove("MustRefresh");
                settings.Add("MustRefresh", true);
                settings.Save();
                NavigationService.GoBack();
            }
            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
            {
                UpdateButton.IsEnabled = true;
                MarkReadOrUnreadButton.IsEnabled = true;
                DeleteButton.IsEnabled = true;
                ProgressBar.IsVisible = false;
                ProgressBar.Text = "";
            }
        }
        protected async override void OnNavigatedTo(NavigationEventArgs e)
        {
            if (NavigationContext.QueryString.TryGetValue("title", out title))
            {
                Content.Header = title;
            }

            if (NavigationContext.QueryString.TryGetValue("aid", out aid))
            {
                try
                {
                    AnimeAPI api = new AnimeAPI();
                    await api.GetAnimeDetail(aid);

                    Loading.Visibility = System.Windows.Visibility.Collapsed;
                    LoadingProgress.Visibility = System.Windows.Visibility.Collapsed;

                    Content.Header = api.animeDetail.title;

                    Directors.Text = api.animeDetail.directorName + ":";
                    foreach (string item in api.animeDetail.directors)
                        Directors.Text += item + " ";

                    Actors.Text = api.animeDetail.actorName + ":";
                    foreach (string item in api.animeDetail.actors)
                        Actors.Text += item + " ";

                    Tags.Text = "标签:";
                    foreach (string item in api.animeDetail.tags)
                        Tags.Text += item + " ";

                    Year.Text = "上映:" + api.animeDetail.year;

                    Aera.Text = "地区:" + api.animeDetail.area;

                    Score.Text = "评分:" + api.animeDetail.score.ToString();

                    if (api.animeDetail.totalEpisodeCount == 0)
                    {
                        State.Text = "状态:更新到第 " + api.animeDetail.episodeCount + " 集";
                    }
                    else
                    {
                        State.Text = "状态:已完结,共 " + api.animeDetail.totalEpisodeCount + " 集";
                    }

                    Intro.Text = api.animeDetail.intro;

                    
                    
                    if (DeviceNetworkInformation.IsWiFiEnabled || !IsolatedStorageSettings.ApplicationSettings.Contains("ShowImage") || (bool)IsolatedStorageSettings.ApplicationSettings["ShowImage"])
                    {
                        try
                        {
                            HttpLibrary.HttpEngine httpRequest = new HttpLibrary.HttpEngine();
                            Stream stream = await httpRequest.GetAsyncForData("http://images.movie.xunlei.com/gallery" + api.animeDetail.poster);
                            BitmapImage image = new BitmapImage();
                            image.SetSource(stream);

                            Background.Source = ((ImageBrush)App.Current.Resources["BackgroundBrush"]).ImageSource;
                            Background.Opacity = 0.7;
                            Background.Visibility = System.Windows.Visibility.Visible;
                            Pivot.Background = new SolidColorBrush(Colors.Transparent);
                            Transform.Source = image;
                            Transform.Opacity = 0.7;
                            Transform.Visibility = System.Windows.Visibility.Visible;

                            DoubleAnimation animation = new DoubleAnimation();
                            animation.From = 0.7;
                            animation.To = 0;
                            animation.Duration = new Duration(TimeSpan.FromMilliseconds(1500));
                            animation.BeginTime = TimeSpan.FromMilliseconds(500);
                            animation.Completed += AnimationCompleted;

                            DoubleAnimation animationTwo = new DoubleAnimation();
                            animationTwo.From = 1;
                            animationTwo.To = 0;
                            animationTwo.Duration = new Duration(TimeSpan.FromMilliseconds(1500));
                            animationTwo.BeginTime = TimeSpan.FromMilliseconds(500);

                            Storyboard.SetTarget(animation, Background);
                            Storyboard.SetTargetProperty(animation, new PropertyPath(Image.OpacityProperty));

                            Storyboard.SetTarget(animationTwo, Rect);
                            Storyboard.SetTargetProperty(animationTwo, new PropertyPath(Image.OpacityProperty));

                            Storyboard storyboard = new Storyboard();
                            storyboard.Children.Add(animation);
                            storyboard.Children.Add(animationTwo);
                            storyboard.Begin();
                        }
                        catch
                        {
                            // do nothing
                            
                        }
                    }
                }
                catch
                {
                    Loading.Visibility = System.Windows.Visibility.Collapsed;
                    LoadingProgress.Visibility = System.Windows.Visibility.Collapsed;
                    IntroPanel.Visibility = System.Windows.Visibility.Collapsed;
                    Error.Visibility = System.Windows.Visibility.Visible;
                }
            }
            
        }
Ejemplo n.º 15
0
 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;
     }
 }
Ejemplo n.º 16
0
        public async void RefreshUpdatedSchedule()
        {
            IsRefreshScheBusy = true;
            AnimeAPI api = new AnimeAPI();
            try
            {
                await api.GetUpdateSchedule();
                App.ViewModel.ScheduleItems.Clear();
                foreach (AnimeAPI.Anime item in api.scheduleList)
                {
                    string text;
                    if (item.date == "0")
                        text = "今天 " + item.time;
                    else
                        text = "明天 " + item.time;
                    App.ViewModel.ScheduleItems.Add(new ViewModels.ScheduleModel()
                    {
                        num  = item.num,
                        aid  = item.aid,
                        name = item.name,
                        time = text
                    });
                }

/*
                HttpEngine httpRequest = new HttpEngine();
                string result = await httpRequest.GetAsync("http://api2.ricter.info/get_update_schedule?hash=" + new Random().Next());
                App.ViewModel.ScheduleItems.Clear();
                string[] List = result.Split('\n');
                int number = 0;
                for (int i = 0; i < List.Length; ++i)
                {
                    string[] item = List[i].Split('|');
                    if (item.Length < 4)
                        return;
                    number++;
                    string whichDay = item[0]; 
                    string id       = item[1];
                    string name     = item[2];
                    string time     = item[3];
                    if (whichDay == "0")
                        time = "今天 " + time;
                    else if (whichDay == "1")
                        time = "明天 " + time;
                    App.ViewModel.ScheduleItems.Add(new ViewModels.ScheduleModel() { Number = number, ID = id, Name = name, Time = time });
                }
 */
            }
            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
            {
                IsRefreshScheBusy = false;
            }
        }
Ejemplo n.º 17
0
        private async void ChangePassword()
        {
            ProgressBar.IsVisible = true;
            Logout.IsEnabled      = false;
            ChangePsw.IsEnabled   = false;

            AnimeAPI api = new AnimeAPI();

            try
            {
                if (OldPasswordBox.Password == "")
                {
                    throw new Exception("请输入原密码");
                }
                if (NewPasswordBox.Password == "")
                {
                    throw new Exception("请输入新密码");
                }
                if (RepasswordBox.Password == "")
                {
                    throw new Exception("请输入密码确认");
                }
                if (OldPasswordBox.Password.Length < 6 || OldPasswordBox.Password.Length > 16)
                {
                    throw new Exception("密码的长度必须在 6 到 16 之间");
                }
                if (NewPasswordBox.Password.Length < 6 || NewPasswordBox.Password.Length > 16)
                {
                    throw new Exception("密码的长度必须在 6 到 16 之间");
                }
                if (RepasswordBox.Password.Length < 6 || RepasswordBox.Password.Length > 16)
                {
                    throw new Exception("密码的长度必须在 6 到 16 之间");
                }
                if (NewPasswordBox.Password != RepasswordBox.Password)
                {
                    throw new Exception("两次输入的密码不一致");
                }

                await api.ChangePsw(OldPasswordBox.Password, NewPasswordBox.Password);

                IsolatedStorageSettings.ApplicationSettings.Remove("UserKey");
                IsolatedStorageSettings.ApplicationSettings.Save();
                MessageBox.Show("", "修改密码成功,请重新登陆", MessageBoxButton.OK);
                NavigationService.Navigate(new Uri("/LoginPage.xaml", UriKind.Relative));
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.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;
                Logout.IsEnabled      = true;
                ChangePsw.IsEnabled   = true;
            }
        }
Ejemplo n.º 18
0
        protected async override void OnNavigatedTo(NavigationEventArgs e)
        {
            if (NavigationContext.QueryString.TryGetValue("title", out title))
            {
                Content.Header = title;
            }

            if (NavigationContext.QueryString.TryGetValue("aid", out aid))
            {
                try
                {
                    AnimeAPI api = new AnimeAPI();
                    await api.GetAnimeDetail(aid);

                    Loading.Visibility         = System.Windows.Visibility.Collapsed;
                    LoadingProgress.Visibility = System.Windows.Visibility.Collapsed;

                    Content.Header = api.animeDetail.title;

                    Directors.Text = api.animeDetail.directorName + ":";
                    foreach (string item in api.animeDetail.directors)
                    {
                        Directors.Text += item + " ";
                    }

                    Actors.Text = api.animeDetail.actorName + ":";
                    foreach (string item in api.animeDetail.actors)
                    {
                        Actors.Text += item + " ";
                    }

                    Tags.Text = "标签:";
                    foreach (string item in api.animeDetail.tags)
                    {
                        Tags.Text += item + " ";
                    }

                    Year.Text = "上映:" + api.animeDetail.year;

                    Aera.Text = "地区:" + api.animeDetail.area;

                    Score.Text = "评分:" + api.animeDetail.score.ToString();

                    if (api.animeDetail.totalEpisodeCount == 0)
                    {
                        State.Text = "状态:更新到第 " + api.animeDetail.episodeCount + " 集";
                    }
                    else
                    {
                        State.Text = "状态:已完结,共 " + api.animeDetail.totalEpisodeCount + " 集";
                    }

                    Intro.Text = api.animeDetail.intro;



                    if (DeviceNetworkInformation.IsWiFiEnabled || !IsolatedStorageSettings.ApplicationSettings.Contains("ShowImage") || (bool)IsolatedStorageSettings.ApplicationSettings["ShowImage"])
                    {
                        try
                        {
                            BitmapImage image    = new BitmapImage();
                            string      filePath = "/Cache/" + api.animeDetail.id + "_intro.jpg";
                            using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication())
                            {
                                if (isf.FileExists(filePath))
                                {
                                    using (IsolatedStorageFileStream iss = isf.OpenFile(filePath, FileMode.Open))
                                    {
                                        image.SetSource(iss);
                                    }
                                }
                                else
                                {
                                    HttpLibrary.HttpEngine httpRequest = new HttpLibrary.HttpEngine();
                                    Stream stream = await httpRequest.GetAsyncForData("http://images.movie.xunlei.com/gallery" + api.animeDetail.poster);

                                    image.SetSource(stream);
                                    if (!isf.DirectoryExists("/Cache"))
                                    {
                                        isf.CreateDirectory("/Cache");
                                    }
                                    using (IsolatedStorageFileStream iss = isf.OpenFile(filePath, FileMode.Create))
                                    {
                                        WriteableBitmap bitmap = new WriteableBitmap(image);
                                        bitmap.SaveJpeg(iss, bitmap.PixelWidth, bitmap.PixelHeight, 0, 100);
                                        iss.Close();
                                    }
                                }
                            }

                            Background.Source     = ((ImageBrush)App.Current.Resources["BackgroundBrush"]).ImageSource;
                            Background.Opacity    = 0.4;
                            Background.Visibility = System.Windows.Visibility.Visible;
                            Pivot.Background      = new SolidColorBrush(Colors.Transparent);
                            Transform.Source      = image;
                            Transform.Opacity     = 0.4;
                            Transform.Visibility  = System.Windows.Visibility.Visible;

                            DoubleAnimation animation = new DoubleAnimation();
                            animation.From       = 0.4;
                            animation.To         = 0;
                            animation.Duration   = new Duration(TimeSpan.FromMilliseconds(1500));
                            animation.BeginTime  = TimeSpan.FromMilliseconds(500);
                            animation.Completed += AnimationCompleted;

                            Storyboard.SetTarget(animation, Background);
                            Storyboard.SetTargetProperty(animation, new PropertyPath(Image.OpacityProperty));

                            DoubleAnimation animationTwo = new DoubleAnimation();
                            animationTwo.From      = 1;
                            animationTwo.To        = 0;
                            animationTwo.Duration  = new Duration(TimeSpan.FromMilliseconds(1500));
                            animationTwo.BeginTime = TimeSpan.FromMilliseconds(500);

                            Storyboard.SetTarget(animationTwo, Rect);
                            Storyboard.SetTargetProperty(animationTwo, new PropertyPath(Image.OpacityProperty));

                            Storyboard storyboard = new Storyboard();
                            storyboard.Children.Add(animation);
                            storyboard.Children.Add(animationTwo);
                            storyboard.Begin();
                        }
                        catch
                        {
                            // do nothing
                        }
                    }
                }
                catch
                {
                    Loading.Visibility         = System.Windows.Visibility.Collapsed;
                    LoadingProgress.Visibility = System.Windows.Visibility.Collapsed;
                    IntroPanel.Visibility      = System.Windows.Visibility.Collapsed;
                    Error.Visibility           = System.Windows.Visibility.Visible;
                }
            }
        }
Ejemplo n.º 19
0
/*
        private async void Delete_Click(object sender, RoutedEventArgs e)
        {
            Debug.WriteLine(((ViewModels.SubscriptionModel)((MenuItem)sender).DataContext).name);
            Debug.WriteLine(App.ViewModel.SubscriptionItems.Count);
            SetBusy("DeleteItem");
            try
            {
                ViewModels.SubscriptionModel vi = (ViewModels.SubscriptionModel)((MenuItem)sender).DataContext;
                HttpEngine httpRequest = new HttpEngine();
                string result = await httpRequest.GetAsync("http://api2.ricter.info/del_anime?key=" + settings["UserKey"] + "&aid=" + vi.aid);
                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;
                    }
                    if (result == "ERROR_INVALID_ID")
                    {
                        throw new Exception("您选择的内容可能已经被删除,请刷新后重试");
                    }
                    throw new Exception("发生了错误,但我不知道是什么");
                }
                int index = App.ViewModel.SubscriptionItems.IndexOf(vi); 
                App.ViewModel.SubscriptionItems.Remove(vi);
                ((MenuItem)sender).UpdateLayout();
            }
            catch (Exception exception)
            {
                MessageBox.Show("", exception.Message, MessageBoxButton.OK);
            }
            finally
            {
                SetIdle("DeleteItem");
            }
        }
 */
        #endregion

        #region 标记已读
        private async void MarkRead_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("", "确定将所有更新标记为已读?", MessageBoxButton.OKCancel) == MessageBoxResult.Cancel)
                return;
            IsMarkReadBusy = true;
            AnimeAPI api = new AnimeAPI();
            try
            {
                foreach (ViewModels.SubscriptionModel item in App.ViewModel.SubscriptionItems)
                {
                    if (item.updated == System.Windows.Visibility.Visible)
                    {
                        await api.DelHighlight(item.aid);
                    }
                }
/*
                foreach (ViewModels.SubscriptionModel Items in App.ViewModel.SubscriptionItems)
                {
                    if (Items.updated == System.Windows.Visibility.Visible)
                    {
                        HttpEngine httpRequest = new HttpEngine();
                        string result = await httpRequest.GetAsync("http://apianime.ricter.info/del_highlight?key=" + settings["UserKey"] + "&id=" + Items.aid + "&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("发生了错误,但我不知道是什么");
                        }
                    }
                }
 */
                ToastPrompt toast = new ToastPrompt();
                toast.Title = "成功将所有更新标记为已读";
                toast.FontSize = 20;
                toast.Show();
            }
            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
            {
                IsMarkReadBusy = false;
                RefreshSubscription();
            }
        }
Ejemplo n.º 20
0
        private async void Login()
        {
            ProgressBar.Text = "登陆中...";
            ProgressBar.IsVisible = true;
            UserNameBox.IsEnabled = false;
            PasswordBox.IsEnabled = false;
            LoginButton.IsEnabled = false;
            try
            {
                if (UserNameBox.Text == "邮箱")
                    throw new Exception("请输入邮箱");
                if (PasswordBox.Password == "")
                    throw new Exception("请输入密码");
                AnimeAPI api = new AnimeAPI();
                await api.Login(UserNameBox.Text, PasswordBox.Password);
/*
                HttpEngine httpRequest = new HttpEngine();
                string UserKey = await httpRequest.GetAsync("http://apianime.ricter.info/login?u=" + UserNameBox.Text + "&p=" + PasswordBox.Password + "&hash=" + new Random().Next());
                if (UserKey.Contains("ERROR_"))
                {
                    if (UserKey == "ERROR_INVALID_PSW")
                        throw new Exception("邮箱或密码错误");
                    throw new Exception("发生了错误,但我不知道是什么");
                }
 */
                IsolatedStorageSettings settings = IsolatedStorageSettings.ApplicationSettings;
                settings.Add("UserKey", api.key);
                settings.Add("UserName", UserNameBox.Text);
                if (settings.Contains("MustRefresh"))
                    settings.Remove("MustRefresh");
                settings.Add("MustRefresh", true);
                settings.Save();
                NavigationService.Navigate(new Uri("/MainPage.xaml", UriKind.Relative));
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message, "错误", MessageBoxButton.OK);
            }
            finally
            {
                UserNameBox.IsEnabled = true;
                PasswordBox.IsEnabled = true;
                LoginButton.IsEnabled = true;
                ProgressBar.IsVisible = false;
                ProgressBar.Text = "";
            }
        }
Ejemplo n.º 21
0
        private async void Register()
        {
            ProgressBar.Text = "注册中...";
            ProgressBar.IsVisible = true;
            RegUserNameBox.IsEnabled = false;
            RegPasswordBox.IsEnabled = false;
            RegRepasswordBox.IsEnabled = false;
            CheckBox.IsEnabled = false;
            RegButton.IsEnabled = false;
            try
            {
                if (RegUserNameBox.Text == "邮箱")
                    throw new Exception("请填写正确的邮箱以便向您的邮箱中发送新番提醒(可选)");
                if (RegPasswordBox.Password == "")
                    throw new Exception("请填写密码");
                if (RegRepasswordBox.Password == "")
                    throw new Exception("请填写密码确认");
                if (CheckBox.IsChecked == false)
                    throw new Exception("您必须认真阅读并同意用户注册协议才能继续注册");
                Regex regex = new Regex("^[\\w-]+(\\.[\\w-]+)*@[\\w-]+(\\.[\\w-]+)+$");
                if (!regex.IsMatch(RegUserNameBox.Text))
                    throw new Exception("请填写正确的邮箱以便向您的邮箱中发送新番提醒(可选)");
                if (RegPasswordBox.Password.Length < 6 || RegPasswordBox.Password.Length > 16)
                    throw new Exception("密码的长度必须为6到16位");
                if (RegPasswordBox.Password != RegRepasswordBox.Password)
                    throw new Exception("两次输入的密码不一致");

                AnimeAPI api = new AnimeAPI();
                await api.Register(RegUserNameBox.Text, RegPasswordBox.Password);
/*
                HttpEngine httpRequest = new HttpEngine();
                string UserKey = await httpRequest.GetAsync("http://apianime.ricter.info/reg?u=" + RegUserNameBox.Text + "&p=" + RegPasswordBox.Password + "&hash=" + new Random().Next());
                if (UserKey.Contains("ERROR_"))
                {
                    if (UserKey == "ERROR_EXIST_REG")
                        throw new Exception("您填写的邮箱已经被注册");
                    throw new Exception("发生了错误,但我不知道是什么");
                }
 */
                IsolatedStorageSettings settings = IsolatedStorageSettings.ApplicationSettings;
                settings.Add("UserKey", api.key);
                settings.Add("UserName", RegUserNameBox.Text);
                if (settings.Contains("MustRefresh"))
                    settings.Remove("MustRefresh");
                settings.Add("MustRefresh", true);
                settings.Save();
                ProgressBar.IsVisible = false;
                MessageBox.Show("", "注册成功", MessageBoxButton.OK);
                NavigationService.Navigate(new Uri("/MainPage.xaml", UriKind.Relative));
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message, "错误", MessageBoxButton.OK);
            }
            finally
            {
                RegUserNameBox.IsEnabled = true;
                RegPasswordBox.IsEnabled = true;
                RegRepasswordBox.IsEnabled = true;
                CheckBox.IsEnabled = true;
                RegButton.IsEnabled = true;
                ProgressBar.IsVisible = false;
                ProgressBar.Text = "";
            }
        }
 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 = "";
     }
 }
Ejemplo n.º 23
0
        private async void Register()
        {
            ProgressBar.Text           = "注册中...";
            ProgressBar.IsVisible      = true;
            RegUserNameBox.IsEnabled   = false;
            RegPasswordBox.IsEnabled   = false;
            RegRepasswordBox.IsEnabled = false;
            CheckBox.IsEnabled         = false;
            RegButton.IsEnabled        = false;
            try
            {
                if (RegUserNameBox.Text == "邮箱")
                {
                    throw new Exception("请填写正确的邮箱以便向您的邮箱中发送新番提醒(可选)");
                }
                if (RegPasswordBox.Password == "")
                {
                    throw new Exception("请填写密码");
                }
                if (RegRepasswordBox.Password == "")
                {
                    throw new Exception("请填写密码确认");
                }
                if (CheckBox.IsChecked == false)
                {
                    throw new Exception("您必须认真阅读并同意用户注册协议才能继续注册");
                }
                Regex regex = new Regex("^[\\w-]+(\\.[\\w-]+)*@[\\w-]+(\\.[\\w-]+)+$");
                if (!regex.IsMatch(RegUserNameBox.Text))
                {
                    throw new Exception("请填写正确的邮箱以便向您的邮箱中发送新番提醒(可选)");
                }
                if (RegPasswordBox.Password.Length < 6 || RegPasswordBox.Password.Length > 16)
                {
                    throw new Exception("密码的长度必须为6到16位");
                }
                if (RegPasswordBox.Password != RegRepasswordBox.Password)
                {
                    throw new Exception("两次输入的密码不一致");
                }

                AnimeAPI api = new AnimeAPI();
                await api.Register(RegUserNameBox.Text, RegPasswordBox.Password);

/*
 *              HttpEngine httpRequest = new HttpEngine();
 *              string UserKey = await httpRequest.GetAsync("http://apianime.ricter.info/reg?u=" + RegUserNameBox.Text + "&p=" + RegPasswordBox.Password + "&hash=" + new Random().Next());
 *              if (UserKey.Contains("ERROR_"))
 *              {
 *                  if (UserKey == "ERROR_EXIST_REG")
 *                      throw new Exception("您填写的邮箱已经被注册");
 *                  throw new Exception("发生了错误,但我不知道是什么");
 *              }
 */
                IsolatedStorageSettings settings = IsolatedStorageSettings.ApplicationSettings;
                settings.Add("UserKey", api.key);
                settings.Add("UserName", RegUserNameBox.Text);
                if (settings.Contains("MustRefresh"))
                {
                    settings.Remove("MustRefresh");
                }
                settings.Add("MustRefresh", true);
                settings.Save();
                ProgressBar.IsVisible = false;
                MessageBox.Show("", "注册成功", MessageBoxButton.OK);
                NavigationService.Navigate(new Uri("/MainPage.xaml", UriKind.Relative));
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message, "错误", MessageBoxButton.OK);
            }
            finally
            {
                RegUserNameBox.IsEnabled   = true;
                RegPasswordBox.IsEnabled   = true;
                RegRepasswordBox.IsEnabled = true;
                CheckBox.IsEnabled         = true;
                RegButton.IsEnabled        = true;
                ProgressBar.IsVisible      = false;
                ProgressBar.Text           = "";
            }
        }
Ejemplo n.º 24
0
        public async void RefreshSubscription()
        {
            IsRefreshSubBusy = true;
            AnimeAPI api = new AnimeAPI();

            try
            {
                await api.GetSubscriptionList();

                while (App.ViewModel.SubscriptionItems.Count > 0)
                {
                    App.ViewModel.SubscriptionItems.RemoveAt(0);
                }
                LongListSelector.UpdateLayout();
                string[] TileContent = new string[3] {
                    "", "", ""
                };
                foreach (AnimeAPI.Anime item in api.subscriptionList)
                {
                    string name;
                    string text;
                    string readText = "";
                    if (item.status == "1")
                    {
                        text = "已完结,共 " + item.epi + " 集";
                    }
                    else
                    {
                        text = "更新到第 " + item.epi + " 集";
                    }
                    if (item.read != "0")
                    {
                        readText = "已看 " + item.read + " 集";
                    }
                    if (item.highlight != "0")
                    {
                        name = "[更新] " + item.name;
                    }
                    else
                    {
                        name = item.name;
                    }

                    App.ViewModel.SubscriptionItems.Add(new ViewModels.SubscriptionModel()
                    {
                        num       = item.num,
                        aid       = item.aid,
                        name      = name,
                        status    = item.status,
                        epi       = item.epi,
                        read      = item.read,
                        readText  = readText,
                        highlight = item.highlight,
                        text      = text,
                        pic       = "http://images.movie.xunlei.com/submovie_img/" + item.aid[0] + item.aid[1] + "/" + item.aid + "/" + item.epi + "_1_115x70.jpg"
                    });
                }

                if (App.ViewModel.SubscriptionItems.Count >= 1 && App.ViewModel.SubscriptionItems[0].highlight != "0")
                {
                    TileContent[0] = "订阅更新";
                    TileContent[1] = App.ViewModel.SubscriptionItems[0].name + " 更新到第 " + App.ViewModel.SubscriptionItems[0].epi + " 集";
                }
                if (App.ViewModel.SubscriptionItems.Count >= 2 && App.ViewModel.SubscriptionItems[1].highlight != "0")
                {
                    TileContent[2] = App.ViewModel.SubscriptionItems[1].name + " 更新到第 " + App.ViewModel.SubscriptionItems[1].epi + " 集";
                }
                ShellTile Tile = ShellTile.ActiveTiles.FirstOrDefault();
                if (Tile != null)
                {
                    var TileData = new IconicTileData()
                    {
                        Title           = "新番提醒",
                        Count           = api.updateNumber,
                        BackgroundColor = System.Windows.Media.Colors.Transparent,
                        WideContent1    = TileContent[0],
                        WideContent2    = TileContent[1],
                        WideContent3    = TileContent[2]
                    };
                    Tile.Update(TileData);
                }
            }
            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
            {
                IsRefreshSubBusy = false;
            }
        }