Exemplo n.º 1
0
 private void LoadTestDataButton_OnClick(object sender, RoutedEventArgs e)
 {
     Global.InputSlotList.AddRange(TestData.TestSlots);
     NavigationService.Navigate(
         Page_CreateTimetable.GetInstance(Global.Settings.SearchByConsideringWeekNumber,
                                          Global.Settings.GeneralizeSlot));
 }
Exemplo n.º 2
0
        private void Browser_OnLoadCompleted(object sender, NavigationEventArgs e)
        {
            Browser.InvokeScript("execScript", "document.documentElement.style.overflow ='hidden'", "JavaScript");
            RefreshButton.IsEnabled = true;
            string currentUrl = Browser.Source.ToString();

            //if (currentUrl == LoginPageUrl) return;
            //if(currentUrl == LoginSuccessUrl)
            //if(currentUrl == LoginFailedUrl) Browser.Navigate(LoginPageUrl);
            if (currentUrl == LoginPageUrl || currentUrl == LoginFailedUrl || currentUrl == EndUrl)
            {
                _navigationCount = 0;
                return;
            }
            if (currentUrl.Contains(CourseTimetablePreviewUrl) == false)
            {
                _currentPage = 1;
                if (_browsingToCourseTimetablePreview == false)
                {
                    if (_navigationCount < NavigationCountUpperLimit)
                    {
                        Browser.Navigate(CourseTimetablePreviewUrl);
                        _navigationCount++;
                    }
                    else
                    {
                        Browser.Navigate(LoginPageUrl);
                        Global.Snackbar.MessageQueue.Enqueue("No record found, please try again.");
                    }
                }
                return;
            }
            Browser.Visibility = Visibility.Hidden;
            string plainText = GetPlainTextOfHtml(Browser);
            var    bg        = CustomBackgroundWorker <string, List <Slot> > .RunAndShowLoadingScreen(
                new SlotParser().Parse, plainText, "Loading slots . . .");

            TryGetStartDateAndEndDate(plainText);
            Global.InputSlotList.AddRange(bg.GetResult());
            if (CanGoToPage(_currentPage + 1))
            {
                Browser.InvokeScript("changePage", _currentPage + 1);
                _currentPage++;
            }
            else
            {
                Browser.Navigate(EndUrl);
                NavigationService.Navigate(
                    Page_CreateTimetable.GetInstance(Global.Settings.SearchByConsideringWeekNumber,
                                                     Global.Settings.GeneralizeSlot));
            }
        }
Exemplo n.º 3
0
        private void TryLoadAutoSavedData()
        {
            List <Slot> data = new UserSlotManager().GetAutoSavedData(_studentIdInput);

            if (data == null)
            {
                return;
            }
            Global.Snackbar.MessageQueue.Enqueue($"Loading auto-saved data.");
            Global.InputSlotList.Clear();
            Global.InputSlotList.AddRange(data);
            NavigationService.Navigate(
                Page_CreateTimetable.GetInstance(Global.Settings.SearchByConsideringWeekNumber,
                                                 Global.Settings.GeneralizeSlot));
        }
Exemplo n.º 4
0
 private void CreateTimetableButton_Click(object sender, RoutedEventArgs e)
 {
     NavigationService.Navigate(Page_CreateTimetable.GetInstance(Global.Settings.SearchByConsideringWeekNumber,
                                                                 Global.Settings.GeneralizeSlot));
 }
Exemplo n.º 5
0
        private async void Browser_OnLoadCompleted(object sender, NavigationEventArgs e)
        {
            KapchaBrowser.Navigate(_urlProvider.KaptchaUrl);
            ResetButton.IsEnabled = true;
            string currentUrl = Browser.Source.ToString();

            if (currentUrl == _urlProvider.EndUrl)
            {
                return;
            }
            if (currentUrl.Contains(_urlProvider.TestServerUrl))
            {
                ExtractData();
            }
            else if (_urlProvider.IsLoginFailed(currentUrl))
            {
                DisplayLoginFailedMessage();
            }
            else if (_urlProvider.IsAtLoginPage(currentUrl))
            {
                AssertLoginPageIsLoadedProperly();
            }
            else if (!currentUrl.Contains(_urlProvider.CourseTimetablePreviewUrl))
            {
                NavigateToCourseTimeTablePreview();
            }
            else if (currentUrl.Contains(_urlProvider.CourseTimetablePreviewUrl))
            {
                ExtractData();
            }

            #region NestedFunctions

            void AssertLoginPageIsLoadedProperly()
            {
                string html = GetHtml(Browser);

                if (!html.Contains("Course Registration System"))
                {
                    Browser.Navigate(_urlProvider.LoginPageUrl);
                }
            }

            void DisplayLoginFailedMessage()
            {
                Global.Snackbar.MessageQueue.Enqueue(
                    "Login failed. Please make sure you entered the correct information.");
                NavigationService.Refresh();
                CaptchaBox.Text  = "";
                _navigationCount = 0;
            }

            void NavigateToCourseTimeTablePreview()
            {
                Global.CurrentUser = new UserInfo(_studentIdInput, _passwordInput);
                new UserInfoManager().SaveData(Global.CurrentUser);
                _currentPage = 1;
                if (_browsingToCourseTimetablePreview)
                {
                    return;
                }
                if (_navigationCount < NavigationCountUpperLimit)
                {
                    Browser.Navigate(_urlProvider.CourseTimetablePreviewUrl);
                    _navigationCount++;
                }
                else
                {
                    Browser.Navigate(_urlProvider.LoginPageUrl);
                    CaptchaBox.Text = "";
                    ResetButton_OnClick(null, null);
                    Global.Snackbar.MessageQueue.Enqueue($"No record found.");
                    TryLoadAutoSavedData();
                }
            }

            async void ExtractData()
            {
                string html = GetHtml(Browser);

                DisplayLoadingBar(true);
                await Task.Run(() => {
                    if (Global.Toggles.SaveLoadedHtmlToggle.IsToggledOn)
                    {
                        SaveToFile(html);
                    }
                    Global.InputSlotList.AddRange(new HtmlSlotParser().Parse(html));
                    Global.LoadedHtml += html;
                    TryGetStartDateAndEndDate(html);
                });

                if (CanGoToPage(_currentPage + 1))
                {
                    Browser.InvokeScript("changePage", _currentPage + 1);
                    _currentPage++;
                }
                else
                {
                    DisplayLoadingBar(false);
                    if (Global.InputSlotList.Count == 0)
                    {
                        DialogBox.Show("No data available.", "", "OK");
                        ResetButton_OnClick(null, null);
                        return;
                    }
                    Browser.Navigate(_urlProvider.EndUrl);
                    new UserSlotManager().SaveSlotDataAsync(Global.CurrentUser.UserId, Global.LoadedHtml);
                    NavigationService.Navigate(
                        Page_CreateTimetable.GetInstance(Global.Settings.SearchByConsideringWeekNumber,
                                                         Global.Settings.GeneralizeSlot));
                }

                #region NestedFunctions

                bool CanGoToPage(int pageNumber)
                {
                    dynamic doc      = Browser.Document;
                    string  htmlText = doc.documentElement.InnerHtml;

                    return(htmlText.Contains($"javascript:changePage(\'{pageNumber}\')"));
                }

                void TryGetStartDateAndEndDate(string input)
                {
                    try {
                        var parser = new StartDateEndDateFinder(input);
                        Global.TimetableStartDate = parser.GetStartDate();
                        Global.TimetableEndDate   = parser.GetEndDate();
                    }
                    catch { }
                }

                #endregion
            }

            #endregion
        }
Exemplo n.º 6
0
        private void Browser_OnLoadCompleted(object sender, NavigationEventArgs e)
        {
            Browser.InvokeScript("execScript", "document.documentElement.style.overflow ='hidden'", "JavaScript");
            RefreshButton.IsEnabled = true;
            string currentUrl = Browser.Source.ToString();

            if (currentUrl.Contains(TestServerUrl))
            {
                goto here;
            }
            if (currentUrl == LoginPageUrl || currentUrl == LoginFailedUrl)
            {
                _navigationCount = 0;
                return;
            }
            if (currentUrl.Contains(CourseTimetablePreviewUrl) == false)
            {
                _currentPage = 1;
                if (_browsingToCourseTimetablePreview == false)
                {
                    if (_navigationCount < NavigationCountUpperLimit)
                    {
                        Browser.Navigate(CourseTimetablePreviewUrl);
                        _navigationCount++;
                    }
                    else
                    {
                        Browser.Navigate(LoginPageUrl);
                        Global.Snackbar.MessageQueue.Enqueue("No record found, please try again.");
                    }
                }
                return;
            }

here:
            string html = GetHtml(Browser);

            if (Global.Toggles.SaveLoadedHtmlToggle.IsToggledOn)
            {
                SaveToFile(html);
            }
            var bg = CustomBackgroundWorker <string, List <Slot> > .RunAndShowLoadingScreen(
                new HtmlSlotParser().Parse, html, "Loading slots . . .");

            //    TryGetStartDateAndEndDate(plainText);
            Global.InputSlotList.AddRange(bg.GetResult());
            if (CanGoToPage(_currentPage + 1))
            {
                Browser.InvokeScript("changePage", _currentPage + 1);
                _currentPage++;
            }
            else
            {
                if (Global.InputSlotList.Count == 0)
                {
                    DialogBox.Show("No data available.", "", "OK");
                    if (DialogBox.Result == DialogBox.ResultEnum.RightButtonClicked)
                    {
                        LoadTestDataButton_OnClick(null, null);
                    }
                    return;
                }

                NavigationService.Navigate(
                    Page_CreateTimetable.GetInstance(Global.Settings.SearchByConsideringWeekNumber,
                                                     Global.Settings.GeneralizeSlot));
            }
        }