コード例 #1
0
        public void Test_1()
        {
            var parser = new StartDateEndDateFinder(input);

            Assert.True(parser.GetStartDate() == new DateTime(2017, 5, 29, 0, 0, 0));
            Assert.True(parser.GetEndDate() == new DateTime(2017, 9, 3, 0, 0, 0));
        }
コード例 #2
0
 private void GetStartDateAndEndDate(string input)
 {
     try {
         var parser = new StartDateEndDateFinder(input);
         Global.TimetableStartDate = parser.GetStartDate();
         Global.TimetableEndDate   = parser.GetEndDate();
     }
     catch { }
 }
コード例 #3
0
        public void Test_2()
        {
            string htmlText = Helper.RawStringOfTestFile("Sample HTML.txt");
            string plain    = ExtensionMethods.RemoveTags(htmlText);
            var    parser   = new StartDateEndDateFinder(plain);

            Assert.True(parser.GetStartDate() == new DateTime(2017, 5, 29, 0, 0, 0));
            Assert.True(parser.GetEndDate() == new DateTime(2017, 9, 3, 0, 0, 0));
        }
コード例 #4
0
        protected override string Execute(string resourceName)
        {
            if (resourceName == "default")
            {
                resourceName = Arguments()[0];
            }
            string raw   = Helper.RawStringOfTestFile(resourceName, leadingNamespace + ".");
            var    slots = new HtmlSlotParser().Parse(raw);

            try {
                var parser = new StartDateEndDateFinder(raw);
                Global.TimetableStartDate = parser.GetStartDate();
                Global.TimetableEndDate   = parser.GetEndDate();
            }
            catch { }
            ((MainWindow)Commandee).LoadTestData(slots);
            return($"Loaded data from {resourceName}" +
                   "\nStarting date: " + Global.TimetableStartDate.ToLongDateString() +
                   " EndingDate: " + Global.TimetableEndDate.ToLongDateString());
        }
コード例 #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
        }
コード例 #6
0
        public void Test_StartDateEndDateFinder_GetEndDate2()
        {
            var parser = new StartDateEndDateFinder(input2);

            Assert.True(parser.GetEndDate() == new DateTime(2017, 12, 3, 0, 0, 0));
        }