Example #1
0
        protected override async void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);
            if (RuntimeData.Score == null)
            {
                try
                {
                    RuntimeData.Score = await WebClient.GetScoreAsync(RuntimeData.Token);
                }
                catch (System.Net.Http.HttpRequestException)
                {
                    RefreshFailedNotification.Show("请求失败, 请检查网络连接", 5000);
                    return;
                }
                catch (RequestFailedException ex)
                {
                    RefreshFailedNotification.Show($"服务器未知错误,请稍后再试 (2.{ex.Status})", 5000);
                    return;
                }
            }

            PopulateList(RuntimeData.Score);

            if (RuntimeData.SecondMajorScore == null)
            {
                try
                {
                    RuntimeData.SecondMajorScore = await WebClient.GetScoreAsync(RuntimeData.Token, false);
                }
                catch (System.Net.Http.HttpRequestException) { }
                catch (RequestFailedException) { }
            }
        }
Example #2
0
        private async System.Threading.Tasks.Task Refresh()
        {
            if (!secondMajor)
            {
                try
                {
                    RuntimeData.Score = await WebClient.GetScoreAsync(RuntimeData.Token);

                    PopulateList(RuntimeData.Score);
                }
                catch (System.Net.Http.HttpRequestException)
                {
                    RefreshFailedNotification.Show("刷新失败, 请检查网络连接", 5000);
                }
                catch (RequestFailedException ex)
                {
                    if (ex.Status == 1)
                    {
                        string id, pwdHash;
                        Login.LoadCredentials(out id, out pwdHash);
                        try
                        {
                            string t = await WebClient.LoginAsync(id, pwdHash);

                            if (t.Length > 1)
                            {
                                RuntimeData.Token = t;
                                await Refresh();
                            }
                        }
                        catch (System.Net.Http.HttpRequestException)
                        {
                            RefreshFailedNotification.Show("刷新失败, 请检查网络连接", 5000);
                        }
                    }
                    RefreshFailedNotification.Show($"服务器未知错误,请稍后再试 (2.{ex.Status})", 5000);
                }
            }
            else
            {
                try
                {
                    RuntimeData.SecondMajorScore = await WebClient.GetScoreAsync(RuntimeData.Token, false);

                    PopulateList(RuntimeData.SecondMajorScore);
                }
                catch (System.Net.Http.HttpRequestException)
                {
                    RefreshFailedNotification.Show("刷新失败, 请检查网络连接", 5000);
                }
                catch (RequestFailedException ex)
                {
                    if (ex.Status == 1)
                    {
                        string id, pwdHash;
                        Login.LoadCredentials(out id, out pwdHash);
                        try
                        {
                            string t = await WebClient.LoginAsync(id, pwdHash);

                            if (t.Length > 1)
                            {
                                RuntimeData.Token = t;
                                await Refresh();
                            }
                        }
                        catch (System.Net.Http.HttpRequestException)
                        {
                            RefreshFailedNotification.Show("刷新失败, 请检查网络连接", 5000);
                        }
                    }
                    RefreshFailedNotification.Show($"服务器未知错误,请稍后再试 (2.{ex.Status})", 5000);
                }
            }
        }
Example #3
0
        private async void SecondSwitchBtn_Click(object sender, RoutedEventArgs e)
        {
            if (SecondSwitchBtn.IsChecked == true)
            {
                if (RuntimeData.SecondMajorScore == null)
                {
                    try
                    {
                        RuntimeData.SecondMajorScore = await WebClient.GetScoreAsync(RuntimeData.Token, false);

                        SecondSwitchBtn_Click(null, null);
                    }
                    catch (System.Net.Http.HttpRequestException)
                    {
                        SecondSwitchBtn.IsChecked = false;
                        RefreshFailedNotification.Show("请求失败, 请检查网络连接", 5000);
                    }
                    catch (RequestFailedException ex)
                    {
                        if (ex.Status == 1)
                        {
                            string id, pwdHash;
                            Login.LoadCredentials(out id, out pwdHash);
                            try
                            {
                                string token = await WebClient.LoginAsync(id, pwdHash);

                                if (token.Length > 1)
                                {
                                    RuntimeData.Token = token;
                                    SecondSwitchBtn_Click(null, null);
                                    return;
                                }
                            }
                            catch (System.Net.Http.HttpRequestException)
                            {
                                SecondSwitchBtn.IsChecked = false;
                                RefreshFailedNotification.Show("请求失败, 请检查网络连接", 5000);
                                return;
                            }
                        }
                        SecondSwitchBtn.IsChecked = false;
                        RefreshFailedNotification.Show($"服务器未知错误,请稍后再试 (2.{ex.Status})", 5000);
                    }
                }
                else
                {
                    if (RuntimeData.SecondMajorScore.Terms.Count == 0)
                    {
                        SecondSwitchBtn.IsChecked = false;
                        ContentDialog dialog = new ContentDialog();
                        dialog.Title           = "无辅修数据";
                        dialog.Content         = "未找到任何辅修成绩";
                        dialog.CloseButtonText = "确定";
                        await dialog.ShowAsync();
                    }
                    else
                    {
                        secondMajor = true;
                        PopulateList(RuntimeData.SecondMajorScore);
                    }
                }
            }
            else
            {
                secondMajor = false;
                PopulateList(RuntimeData.Score);
            }
        }