Example #1
0
        // This extraction the Action URL form the login webpage.
        // it is used for further requests.
        // The URL is from the College object
        public string PostURL(string URL)
        {
            SendMessage(this, new Information("Webpage Location = " + URL));

            CISWebRequest myWebRequest = new CISWebRequest();
            string        result       = myWebRequest.RetrieveHTMLPage(URL); // get the page

            // Extract From result the POST Action URL "https://www.ctc.edu/cgi-bin/rq160/"
            // and return it to the caller.

            ExtractValue EV = new ExtractValue();

            return(EV.FromJavaScript(result, StrAction, "\"", "\""));
        }
Example #2
0
        public void AddFromCIS(CISLogin MyLogin, ExcelClassSettings ExcelClassSettings, string ActionURL)
        {
            SendMessage(this, new Information("Retrieving Course URL."));

            // Create the http request string for the Instructor
            string HTTPCoursesRequest = MyLogin.HTTPCoursesRequestString;

            SendMessage(this, new Information(HTTPCoursesRequest));

            // Retrieve the Web page with the courses information
            CISWebRequest myWebRequest = new CISWebRequest();
            string        HTTPCourses  = myWebRequest.RetrieveHTMLPage(ActionURL, HTTPCoursesRequest, CISWebRequest.HTMLRequestType.POST, 5000);

            if (HTTPCourses.ToLower().IndexOf("service unavailable") > 0)
            {
                SendMessage(this, new Information(HTTPCourses));
                throw new Exception("Service is unavailable.");
            }
            else if (HTTPCourses.ToLower().IndexOf("pin") > 0)
            {
                SendMessage(this, new Information(HTTPCourses));
                throw new Exception("You have entered an incorrect Employee ID or PIN.");
            }
            else
            {
                SendMessage(this, new Information(HTTPCourses));
            }

            // Extract ticket
            ExtractValue EV          = new ExtractValue();
            string       ticketvalue = EV.FromJavaScript(HTTPCourses, JavaTicketVariable, "'", "'");

            SendMessage(this, new Information("Found Ticket Value " + ticketvalue));

            // Extract Number of classes
            string InstructorName = EV.FromJavaScript(HTTPCourses, JavaInstructorVariable, "'", "'");

            SendMessage(this, new Information("Found Instructor Name " + InstructorName));

            string RawHTML;
            string HTTPRequestString;
            String CourseName;
            String ItemNumber;
            int    Start;
            int    End;
            int    HTTPStart = HTTPCourses.IndexOf(JavaRosterVariable);

            if (HTTPStart >= 0)
            {
                int[] ArrayStart = new int[10];  // list of starting points for courses
                int[] ArrayEnd   = new int[10];  // list of ending points for courses

                int CourseIndex = 0;             // number of courses

                do
                {
                    ArrayStart[CourseIndex] = HTTPStart;
                    ArrayEnd[CourseIndex]   = HTTPCourses.IndexOf(")", HTTPStart);
                    CourseIndex++;
                    HTTPStart = HTTPCourses.IndexOf(JavaRosterVariable, HTTPStart + 1);
                } while ((HTTPStart > 0) && (CourseIndex < 11));

                for (int i = 0; i < CourseIndex; i++)
                {
                    HTTPStart = ArrayStart[i];
                    End       = ArrayEnd[i];
                    String OneCourse = HTTPCourses.Substring(HTTPStart, End - HTTPStart);
                    Start      = OneCourse.IndexOf("'") + 1; // don't include the '
                    End        = OneCourse.IndexOf("'", Start + 1);
                    ItemNumber = OneCourse.Substring(Start, End - Start);

                    Start      = OneCourse.IndexOf("'", End + 1) + 1;
                    End        = OneCourse.IndexOf("'", Start + 1);
                    CourseName = OneCourse.Substring(Start, End - Start).Trim();

                    SendMessage(this, new Information("\r\n\nFound Course " + ItemNumber + " - " + CourseName));

                    // get request String
                    CISCourse myCISCourses = new CISCourse(ItemNumber, ticketvalue, MyLogin.Quarter.YRQ);
                    HTTPRequestString = myCISCourses.HTTPRequestString;
                    try
                    {
                        // retrieve class data
                        RawHTML = myWebRequest.RetrieveHTMLPage(ActionURL, HTTPRequestString, CISWebRequest.HTMLRequestType.POST, 5000);
                    }
                    catch (Exception Ex)
                    {
                        string ErrorMessage = Ex.Message;
                        if (ErrorMessage.IndexOf("403", 0) > 0)
                        {
                            // Error forbidden
                            SendMessage(this, new Information(CourseName + " " + ItemNumber + " " + Ex.Message));

                            // try again
                            RawHTML = myWebRequest.RetrieveHTMLPage(ActionURL, HTTPRequestString, CISWebRequest.HTMLRequestType.POST, 5000);
                        }
                        else
                        {
                            // fail
                            throw;
                        }
                    }

                    SendMessage(this, new Information(RawHTML));

                    this.Add(RawHTML, InstructorName, CourseName, ItemNumber, MyLogin.Quarter.YRQ, MyLogin.Quarter.Name, ExcelClassSettings);
                }
            }
            else
            {
                // error no courses found
                SendMessage(this, new Information(HTTPCourses));
                throw new Exception("No courses found for " + MyLogin.Quarter.Name + " which I have a YRQ " + MyLogin.Quarter.YRQ);
            }
        }
Example #3
0
        //private readonly HeaderColumn Phone;

        public Course(string RawHTML, string InstructorName, string CourseName,
                      string ItemNumber, string YRQ, string QuarterName, ExcelClassSettings ExcelClassSettings)
        {
            SchoolHeaders     = new OptionHeaders();
            StrInstructorName = InstructorName;
            StrCourseName     = CourseName;
            StrItemNumber     = ItemNumber;
            StrYRQ            = YRQ;
            StrQuarterName    = QuarterName;
            // Set to export
            blnExport = true;

            if (RawHTML != "")
            {
                ExtractValue EV = new ExtractValue();
                StrTitle   = EV.FromJavaScript(RawHTML, "title", "'", "'");
                StrSection = EV.FromJavaScript(RawHTML, "sect", "'", "'");
                StrCredits = EV.FromJavaScript(RawHTML, "credit", "'", "'");

                StrRoom      = EV.FromJavaScript(RawHTML, "room", "'", "'");
                StrStartTime = EV.FromJavaScript(RawHTML, "strtTime", "'", "'");
                StrEndTime   = EV.FromJavaScript(RawHTML, "endTime", "'", "'");
                StrDays      = EV.FromJavaScript(RawHTML, "days", "'", "'");
                StrStartDate = EV.FromJavaScript(RawHTML, "strtDate", "'", "'");
                StrTenthDate = EV.FromJavaScript(RawHTML, "tenDay", "'", "'");

                StrOpt1Header  = EV.FromJavaScript(RawHTML, "optHead1", "'", "'");
                StrOpt2Header  = EV.FromJavaScript(RawHTML, "optHead2", "'", "'");
                StrOpt3Header  = EV.FromJavaScript(RawHTML, "optHead3", "'", "'");
                StrOptWlHeader = EV.FromJavaScript(RawHTML, "optWLHead", "'", "'");

                if (SaveOptionHeader)
                {
                    ExcelClassSettings.HeaderNames.Header1        = StrOpt1Header;
                    ExcelClassSettings.HeaderNames.Header2        = StrOpt2Header;
                    ExcelClassSettings.HeaderNames.Header3        = StrOpt3Header;
                    ExcelClassSettings.HeaderNames.WaitListHeader = StrOptWlHeader;
                    SaveOptionHeader = false;
                }

                int Count = Convert.ToInt32(EV.FromJavaScript(RawHTML, "totStu", "'", "'"));
                myStudents = new Student[Count];

                Count      = Convert.ToInt32(EV.FromJavaScript(RawHTML, "totStuWl", "'", "'"));
                myWaitlist = new Student[Count];

                // Extract all students from RawHTML
                ProcessStudentsFromHTML(RawHTML, ExcelClassSettings.HeaderNames);
            }
        }