示例#1
0
        public IEnumerable <UTCourse> FetchItems()
        {
            IItemFetcher <UTCourse> fallCourseFetcher   = new UTEngCourseInfoFetcher(WebUrlConstants.EngTimetableFall);
            IItemFetcher <UTCourse> winterCourseFetcher = new UTEngCourseInfoFetcher(WebUrlConstants.EngTimetableWinter);
            IEnumerable <UTCourse>  allCourses          = fallCourseFetcher.FetchItems().Concat <UTCourse>(winterCourseFetcher.FetchItems());
            IEnumerable <UTCourse>  coursesDetail       = new UTEngCourseDetailFetcher(WebUrlConstants.EngCalendar).FetchItems();

            // Merge course info and course detail
            allCourses = allCourses.GroupJoin(coursesDetail,
                                              (x => x.Abbr),
                                              (x => x.Abbr),
                                              ((x, y) => this.CombineInfoDetail(x, y.FirstOrDefault())),
                                              new UTCourseAbbrComparer());

            UTEngHssCsChecker checker = new UTEngHssCsChecker();

            foreach (UTCourse course in allCourses)
            {
                course.Faculty = "Engineering";

                if (checker.CheckEngCs(course.Code))
                {
                    course.AddCategory("cs");
                }

                if (!CoursesCollection.ContainsKey(course.Abbr))
                {
                    CoursesCollection.Add(course.Abbr, course);
                }
            }


            // Match the prerequisites to postrequisites
            foreach (UTCourse course in CoursesCollection.Values)
            {
                if (!String.IsNullOrEmpty(course.Prerequisites))
                {
                    foreach (Match match in CodeRegex.Matches(course.Prerequisites))
                    {
                        string abbr = match.Value;
                        TryMatchPreq(this.CoursesCollection, course.Abbr, abbr, "F");
                        TryMatchPreq(this.CoursesCollection, course.Abbr, abbr, "S");
                        TryMatchPreq(this.CoursesCollection, course.Abbr, abbr, "Y");
                    }
                }
            }

            return(CoursesCollection.Values);
        }
示例#2
0
        public IEnumerable <UTCourse> FetchItems()
        {
            IItemFetcher <UTCourse> fallCourseFetcher   = new UTEngCourseInfoFetcher(WebUrlConstants.EngTimetableFall);
            IItemFetcher <UTCourse> winterCourseFetcher = new UTEngCourseInfoFetcher(WebUrlConstants.EngTimetableWinter);
            IEnumerable <UTCourse>  allCourses          = fallCourseFetcher.FetchItems().Concat <UTCourse>(winterCourseFetcher.FetchItems());

            //IEnumerable<UTCourse> courseDetail = new UTEngCourseDetailFetcher(WebUrlConstants.EngCalendar).FetchItems();
            List <UTCourse> courseDetail = new List <UTCourse>();

            Parallel.ForEach <UTCourse>(allCourses, new ParallelOptions()
            {
                MaxDegreeOfParallelism = Environment.ProcessorCount
            }, delegate(UTCourse course)
            {
                string session;
                if (String.Equals(course.Semester, "S"))
                {
                    session = WebUrlConstants.ArtsciSessionWinter;
                }
                else
                {
                    session = WebUrlConstants.ArtsciSession;
                }
                IEnumerable <UTCourse> courseDetail_ = new UTCourseDetailFetcher(String.Format(WebUrlConstants.CourseFinderCourse, course.Abbr, session)).FetchItems();
                lock (this)
                {
                    if (courseDetail_.Count() > 0)
                    {
                        UTCourse course_ = courseDetail_.First();
                        courseDetail.Add(course_);
                        Console.WriteLine("Engineering Course Detail: {0} | {1}", course_.Abbr, course.Abbr);
                    }
                    else
                    {
                        Console.WriteLine("Engineering Course Detail Not Found: {0}", course.Abbr);
                    }
                }
            });

            // Merge course info and course detail
            allCourses = allCourses.GroupJoin(courseDetail,
                                              (x => x.Abbr),
                                              (x => x.Abbr),
                                              ((x, y) => this.CombineInfoDetail(x, y.FirstOrDefault())),
                                              new UTCourseAbbrComparer());

            UTEngHssCsChecker checker = new UTEngHssCsChecker();

            foreach (UTCourse course in allCourses)
            {
                course.Faculty = "Engineering";

                if (checker.CheckEngCs(course.Code))
                {
                    course.AddCategory("cs");
                }

                if (!CoursesCollection.ContainsKey(course.Abbr))
                {
                    CoursesCollection.Add(course.Abbr, course);
                }
            }

            // Match the prerequisites to postrequisites
            foreach (UTCourse course in CoursesCollection.Values)
            {
                if (!String.IsNullOrEmpty(course.Prerequisites))
                {
                    foreach (Match match in CodeRegex.Matches(course.Prerequisites))
                    {
                        string abbr = match.Value;
                        TryMatchPreq(this.CoursesCollection, course.Abbr, abbr, "F");
                        TryMatchPreq(this.CoursesCollection, course.Abbr, abbr, "S");
                        TryMatchPreq(this.CoursesCollection, course.Abbr, abbr, "Y");
                    }
                }
            }
            return(CoursesCollection.Values);
        }