Esempio n. 1
0
        private async void GetSchedule(int academicYear)
        {
            try
            {
                var schedule = await NPAPI.GetSchedule(academicYear);

                this.schedule             = schedule;
                calendar.DisplayDateStart = new DateTime(academicYear + 1911, 8, 1);
                calendar.DisplayDateEnd   = new DateTime(academicYear + 1 + 1911, 7, 31);
                calendar.SelectionMode    = WinRTXamlToolkit.Controls.CalendarSelectionMode.SingleDate;
                if (this.schedule.monthSchedules.ContainsKey(calendar.DisplayDate.Month))
                {
                    listView.ItemsSource = this.schedule.monthSchedules[calendar.DisplayDate.Month];
                }
                else
                {
                    listView.ItemsSource = null;
                    listView.Items.Clear();
                }
            }
            catch (Exception e)
            {
                listView.ItemsSource = null;
                listView.Items.Clear();
                listView.Items.Add("讀取失敗,請稍後再試。");
                listView.Items.Add(e.Message);
            }
        }
Esempio n. 2
0
        private async Task GetCredits()
        {
            try
            {
                var result = await NPAPI.GetCredits();

                ApplyCredits(result);
            }
            catch (NPAPI.SessionExpiredException)
            {
                //Send GA Event
                App.Current.GATracker.SendEvent("Session", "Session Expired", null, 0);

                //Try background login
                try
                {
                    await NPAPI.BackgroundLogin();
                    await GetCredits();
                }
                catch
                {
                    Frame.Navigate(typeof(LoginPage));
                }
            }
            catch (Exception e)
            {
                summaryTextBlock.Text = e.Message;
            }
        }
Esempio n. 3
0
        private async Task SearchForId(string id)
        {
            var semestersRequest = await NPAPI.GetSemesters(id);

            bool saveSearchId = true;

            if (semestersRequest.Success)
            {
                //Update label
                name = semestersRequest.Name;
                searchResultLabelTextBlock.Text = name;

                //Update comoboBox
                semesterComboBox.ItemsSource = semestersRequest.Semesters;
                if (semesterComboBox.Items.Count > 0)
                {
                    semesterComboBox.SelectedIndex = 0;
                }
                semesterComboBox.Visibility = semesterComboBox.Items.Count > 0 ? Visibility.Visible : Visibility.Collapsed;

                //Save request to roaming settings
                SaveToSettings(localSettings, "name", name);
                var semestersJson = JsonConvert.SerializeObject(semestersRequest.Semesters);
                SaveToSettings(localSettings, "semesters", semestersJson.ToString());

                //Send GA Event
                bool searchSelf = roamingSettings.Values.ContainsKey("id") && roamingSettings.Values["id"] as string == id;
                App.Current.GATracker.SendEvent("Get Semesters", null, id, searchSelf ? 0 : 1);
            }
            else
            {
                if (semestersRequest.Error == NPAPI.RequestResult.ErrorType.Unauthorized)
                {
                    //Send GA Event
                    App.Current.GATracker.SendEvent("Session", "Session Expired", null, 0);

                    //Try background login
                    var result = await NPAPI.BackgroundLogin();

                    if (result.Success)
                    {
                        await SearchForId(id);
                    }
                    else
                    {
                        Frame.Navigate(typeof(LoginPage));
                    }
                }
                else
                {
                    await new MessageDialog(semestersRequest.Message).ShowAsync();
                    saveSearchId = false;
                }
            }

            if (saveSearchId)
            {
                SaveToSettings(localSettings, "searchId", id);
            }
        }
Esempio n. 4
0
        private async Task SearchForId(string id)
        {
            //Disable user input
            searchForIdTextBox.IsEnabled = searchSelfButton.IsEnabled = semesterComboBox.IsEnabled = getSemestersButton.IsEnabled = false;

            try
            {
                var semestersRequest = await NPAPI.GetSemesters(id);

                //Update label
                name = semestersRequest.Name;
                searchResultLabelTextBlock.Text = name;

                //Update comoboBox
                semesterComboBox.ItemsSource = semestersRequest.Semesters;
                if (semesterComboBox.Items.Count > 0)
                {
                    semesterComboBox.SelectedIndex = 0;
                }

                //Save request to local settings
                SaveToSettings(localSettings, "name", name);
                var semestersJson = JsonConvert.SerializeObject(semestersRequest.Semesters);
                SaveToSettings(localSettings, "semesters", semestersJson.ToString());

                //Send GA Event
                bool searchSelf = roamingSettings.Values.ContainsKey("id") && roamingSettings.Values["id"] as string == id;
                App.Current.GATracker.SendEvent("Get Semesters", null, id, searchSelf ? 0 : 1);

                //Save search id
                SaveToSettings(localSettings, "searchId", id);
            }
            catch (NPAPI.SessionExpiredException)
            {
                //Send GA Event
                App.Current.GATracker.SendEvent("Session", "Session Expired", null, 0);

                //Try background login
                try
                {
                    await NPAPI.BackgroundLogin();
                    await SearchForId(id);
                }
                catch
                {
                    Frame.Navigate(typeof(LoginPage));
                }
            }
            catch (Exception e)
            {
                await new MessageDialog(e.Message, "錯誤").ShowAsync();
            }

            //Enableuser input
            searchForIdTextBox.IsEnabled = searchSelfButton.IsEnabled = semesterComboBox.IsEnabled = getSemestersButton.IsEnabled = true;

            semesterComboBox.Focus(FocusState.Programmatic);
        }
Esempio n. 5
0
        private async void Login()
        {
            //Send GA Event
            App.Current.GATracker.SendEvent("Session", "Attempt Login", null, 0);

            string id = idTextBox.Text, password = passwordTextBox.Password;

            passwordTextBox.IsEnabled = loginAppBarButton.IsEnabled = false;
            idTextBox.IsReadOnly      = true;

            await progressbar.ShowAsync();

            var loginResult = await NPAPI.LoginNPortal(id, password);

            await progressbar.HideAsync();

            if (loginResult.Success)
            {
                //Store logged id, password
                var roamingSettings = Windows.Storage.ApplicationData.Current.RoamingSettings;

                if (roamingSettings.Values.ContainsKey("id"))
                {
                    roamingSettings.Values["id"] = id;
                }
                else
                {
                    roamingSettings.Values.Add("id", id);
                }

                if (roamingSettings.Values.ContainsKey("password"))
                {
                    roamingSettings.Values["password"] = password;
                }
                else
                {
                    roamingSettings.Values.Add("password", password);
                }

                //Login Aps

                await NPAPI.LoginAps();

                //Go to previous page
                if (Frame.CanGoBack)
                {
                    Frame.GoBack();
                }
            }
            else
            {
                await new MessageDialog(loginResult.Message).ShowAsync();
            }

            passwordTextBox.IsEnabled = loginAppBarButton.IsEnabled = true;
            idTextBox.IsReadOnly      = false;
        }
Esempio n. 6
0
        async private Task Login()
        {
            //Set progress
            progressStackPanel.Visibility = Visibility.Visible;
            progressRing.IsActive         = true;
            progressTextBlock.Text        = "檢查登入狀態";

            try
            {
                var isLoggedIn = await NPAPI.IsLoggedIn();

                var roamingSettings = ApplicationData.Current.RoamingSettings;

                if (!isLoggedIn)
                {
                    //Not logged in, login now
                    progressTextBlock.Text = "登入中";
                    throw new NPAPI.SessionExpiredException();
                }

                //Set global cookie to current saved JSESSIONID
                HttpBaseProtocolFilter filter = new HttpBaseProtocolFilter();
                HttpCookie             cookie = new HttpCookie("JSESSIONID", baseUri.Host, "/");
                cookie.Value = roamingSettings.Values["JSESSIONID"].ToString();
                filter.CookieManager.SetCookie(cookie, false);

                //Set progress
                progressTextBlock.Text = "載入中";

                //
                GoHome();
            }
            catch (NPAPI.SessionExpiredException)
            {
                //Send GA Event
                App.Current.GATracker.SendEvent("Session", "Session Expired", null, 0);

                //Try background login
                try
                {
                    await NPAPI.BackgroundLogin();
                    await Login();
                }
                catch
                {
                    Frame.Navigate(typeof(LoginPage));
                }
            }
            catch (Exception e)
            {
                //Show message
                progressRing.IsActive  = false;
                progressTextBlock.Text = e.Message;
            }
        }
Esempio n. 7
0
        private async void Login()
        {
            string id = idTextBox.Text, password = passwordTextBox.Password;

            //Send GA Event
            App.Current.GATracker.SendEvent("Session", "Attempt Login", id, 0);

            //Disable user input
            passwordTextBox.IsEnabled = loginButton.IsEnabled = idTextBox.IsEnabled = false;

            errorTextBlock.Visibility = Visibility.Collapsed;

            //await progressbar.ShowAsync();

            try
            {
                await NPAPI.LoginNPortal(id, password);

                //Store logged id, password
                var roamingSettings = Windows.Storage.ApplicationData.Current.RoamingSettings;

                if (roamingSettings.Values.ContainsKey("id"))
                {
                    roamingSettings.Values["id"] = id;
                }
                else
                {
                    roamingSettings.Values.Add("id", id);
                }

                if (roamingSettings.Values.ContainsKey("password"))
                {
                    roamingSettings.Values["password"] = password;
                }
                else
                {
                    roamingSettings.Values.Add("password", password);
                }

                //Go to previous page
                if (Frame.CanGoBack)
                {
                    Frame.GoBack();
                }
            }
            catch (Exception e)
            {
                errorTextBlock.Text       = e.Message;
                errorTextBlock.Visibility = Visibility.Visible;
            }

            //Enable user input
            passwordTextBox.IsEnabled = loginButton.IsEnabled = idTextBox.IsEnabled = true;
        }
Esempio n. 8
0
        private async void logoutAppBarButton_Click(object sender, RoutedEventArgs e)
        {
            var result = await NPAPI.LogoutNPortal();

            if (result.Success)
            {
                Frame.Navigate(typeof(LoginPage));
            }
            else
            {
                await new MessageDialog(result.Message).ShowAsync();
            }
        }
Esempio n. 9
0
        private async Task GetSchedule(Semester semester)
        {
            var coursesRequest = await NPAPI.GetCourses(searchForIdTextBox.Text, semester.Year, semester.SemesterNumber);

            if (coursesRequest.Success)
            {
                //Fill scheduleGrid
                FillCoursesIntoGrid(coursesRequest.Data);

                //Update result label
                searchResultLabelTextBlock.Text = name + " " + semester;

                //Save to roaming settings
                var coursesJson  = JsonConvert.SerializeObject(coursesRequest.Data);
                var semesterJson = JsonConvert.SerializeObject(semester);
                SaveToSettings(localSettings, "courses", coursesJson.ToString());
                SaveToSettings(localSettings, "semester", semesterJson.ToString());

                //Send GA Event
                bool searchSelf = roamingSettings.Values.ContainsKey("id") && roamingSettings.Values["id"] as string == searchForIdTextBox.Text;
                App.Current.GATracker.SendEvent("Get Curriculum", semester.ToString(), searchForIdTextBox.Text, searchSelf ? 0 : 1);
            }
            else
            {
                if (coursesRequest.Error == NPAPI.RequestResult.ErrorType.Unauthorized)
                {
                    //Send GA Event
                    App.Current.GATracker.SendEvent("Session", "Session Expired", null, 0);

                    //Try background login
                    var result = await NPAPI.BackgroundLogin();

                    if (result.Success)
                    {
                        await GetSchedule(semester);
                    }
                    else
                    {
                        Frame.Navigate(typeof(LoginPage));
                    }
                }
                else
                {
                    await new MessageDialog(coursesRequest.Message).ShowAsync();
                }
            }
        }
Esempio n. 10
0
        private async Task GetSchedule(Semester semester)
        {
            try
            {
                var courses = await NPAPI.GetCourses(searchForIdTextBox.Text, semester.Year, semester.SemesterNumber);

                //Fill scheduleGrid
                FillCoursesIntoGrid(courses);

                //Update result label
                searchResultLabelTextBlock.Text = name + " " + semester;

                //Show searchAppBarToggleButton
                //searchAppBarToggleButton.Visibility = Visibility.Visible;

                //Save to roaming settings
                var coursesJson  = JsonConvert.SerializeObject(courses);
                var semesterJson = JsonConvert.SerializeObject(semester);
                SaveToSettings(localSettings, "courses", coursesJson.ToString());
                SaveToSettings(localSettings, "semester", semesterJson.ToString());

                //Send GA Event
                bool searchSelf = roamingSettings.Values.ContainsKey("id") && roamingSettings.Values["id"] as string == searchForIdTextBox.Text;
                App.Current.GATracker.SendEvent("Get Curriculum", semester.ToString(), searchForIdTextBox.Text, searchSelf ? 0 : 1);
            }
            catch (NPAPI.SessionExpiredException)
            {
                //Send GA Event
                App.Current.GATracker.SendEvent("Session", "Session Expired", null, 0);

                //Try background login
                try
                {
                    await NPAPI.BackgroundLogin();
                    await GetSchedule(semester);
                }
                catch
                {
                    Frame.Navigate(typeof(LoginPage));
                }
            }
            catch (Exception e)
            {
                await new MessageDialog(e.Message, "錯誤").ShowAsync();
            }
        }
Esempio n. 11
0
        private async void logoutButton_Click(object sender, RoutedEventArgs args)
        {
            logoutButton.IsEnabled = false;
            try
            {
                await NPAPI.LogoutNPortal();

                frame.Navigate(typeof(LoginPage));

                //Send GA Event
                string id = ApplicationData.Current.RoamingSettings.Values.ContainsKey("id") ? ApplicationData.Current.RoamingSettings.Values["id"] as string : "N/A";
                App.Current.GATracker.SendEvent("Session", "Logout", id, 0);
            }
            catch (Exception e)
            {
                await new MessageDialog(e.Message, "錯誤").ShowAsync();
            }

            logoutButton.IsEnabled = true;
        }
Esempio n. 12
0
        private async Task GetAttendenceAndHonors()
        {
            semestersComboBox.ItemsSource = null;
            semestersComboBox.Items.Clear();
            semestersComboBox.Items.Add("讀取中...");
            semestersComboBox.SelectedIndex = 0;
            try
            {
                var result = await NPAPI.GetAttendenceAndHonors();

                semestersComboBox.ItemsSource = result.Semesters;
                if (semestersComboBox.Items.Count > 0)
                {
                    semestersComboBox.SelectedIndex = 0;
                }
            }
            catch (NPAPI.SessionExpiredException)
            {
                //Send GA Event
                App.Current.GATracker.SendEvent("Session", "Session Expired", null, 0);

                //Try background login
                try
                {
                    await NPAPI.BackgroundLogin();
                }
                catch
                {
                    Frame.Navigate(typeof(LoginPage));
                }
            }
            catch (Exception e)
            {
                semestersComboBox.ItemsSource = null;
                semestersComboBox.Items.Clear();
                semestersComboBox.Items.Add(e.Message);
                semestersComboBox.SelectedIndex = 0;
            }
        }
Esempio n. 13
0
        private async Task GetMidAlert()
        {
            courseNameTextBlock.Text = "";
            try
            {
                var midAlerts = await NPAPI.GetMidAlerts();

                courseNameTextBlock.Text = "(請選擇)";
                titleTextBlock.Text      = midAlerts.Semester + " 期中預警";
                listView.ItemsSource     = midAlerts.Alerts;

                //Send GA Event
                string id = ApplicationData.Current.RoamingSettings.Values.ContainsKey("id") ? ApplicationData.Current.RoamingSettings.Values["id"] as string : "N/A";
                App.Current.GATracker.SendEvent("Mid Alert", "Get Mid Alert", id, 0);
            }
            catch (NPAPI.SessionExpiredException)
            {
                //Send GA Event
                App.Current.GATracker.SendEvent("Session", "Session Expired", null, 0);

                //Try background login
                try
                {
                    await NPAPI.BackgroundLogin();
                    await GetMidAlert();
                }
                catch
                {
                    Frame.Navigate(typeof(LoginPage));
                }
            }
            catch (Exception e)
            {
                listView.Items.Clear();
                listView.Items.Add("讀取失敗,請稍後再試。");
                listView.Items.Add(e.Message);
            }
        }
Esempio n. 14
0
        public static async Task <Credits> Parse(string html)
        {
            var blockMatch = new Regex("請先完成[^教]+教學評量。", RegexOptions.IgnoreCase | RegexOptions.Multiline).Match(html);

            if (blockMatch.Success)
            {
                throw new System.Exception(blockMatch.Value);
            }

            var credits      = new Credits();
            var tableRegex   = new Regex("<img src=\\./image/or_ball\\.gif>([^<]+)</h3>\n<table border=1 BGCOLOR=#CCFFFF>(?:(?!<\\/table>).|\n)*", RegexOptions.Multiline | RegexOptions.IgnoreCase);
            var tablematches = tableRegex.Matches(html);
            var semesters    = new List <Semester>();

            foreach (Match match in tablematches)
            {
                semesters.Add(ParseTable(match));
            }
            credits.Semesters = semesters;


            var tasks = new List <Task>();

            foreach (Semester semester in semesters)
            {
                tasks.AddRange(semester.Credits.Select(async credit =>
                {
                    var courseDetail = await NPAPI.GetCourseDetail(credit.CourseId);

                    //Set course detail
                    credit.Detail = courseDetail;

                    if (credit.Grade >= 60)
                    {
                        //Sum credits for each detailed type
                        if (credits.TotalDetailTypeCredits.ContainsKey(credit.Detail.Type))
                        {
                            credits.TotalDetailTypeCredits[credit.Detail.Type] += credit.Credits;
                        }
                        else
                        {
                            credits.TotalDetailTypeCredits.Add(credit.Detail.Type, credit.Credits);
                        }

                        //Sum credits for each type
                        if (credits.TotalTypeCredits.ContainsKey(credit.Type))
                        {
                            credits.TotalTypeCredits[credit.Type] += credit.Credits;
                        }
                        else
                        {
                            credits.TotalTypeCredits.Add(credit.Type, credit.Credits);
                        }

                        //Sum semester credits
                        credits.TotalCreditsGot += credit.Credits;
                    }
                }));
            }

            //Run all tasks in parallel
            await Task.WhenAll(tasks.ToArray());

            return(credits);
        }