public void TestMethod1() { string content = File.ReadAllText("C:\\Users\\renme_000\\Downloads\\run_results.json"); dynamic allCourseData = JsonConvert.DeserializeObject(content); List <UTCourse> allCourses = new List <UTCourse>(); foreach (dynamic category in allCourseData.categorydata) { foreach (dynamic course in category.course) { UTCourse courseObj = new UTCourse(); string code = course.code; courseObj.Code = code.Substring(0, 6); string secstring = course.section; if (code.Length > 8) { courseObj.Semester = code.Substring(9, 1); } else { courseObj.Semester = secstring.Substring(0, 1); } courseObj.SemesterPrefix = code.Substring(6, 2); courseObj.Name = course.name; Trace.Write(courseObj.Abbr); try { foreach (dynamic activity in course.activities) { CourseSection section = new CourseSection(); section.Name = activity.name; Trace.Write(" " + section.Name); List <CourseSectionTimeSpan> meetTimes = new List <CourseSectionTimeSpan>(); foreach (dynamic time in activity.times) { string day = time.dayofweek; string timeFrom = time.time_from; string timeTo = time.time_to; CourseSectionTimeSpan timespan; timespan.Day = ((DayOfWeek)Enum.Parse(typeof(DayOfWeek), day)); timespan.Start = (byte)(Convert.ToInt32(timeFrom.Substring(0, 2)) * 4 + Convert.ToInt32(timeFrom.Substring(3, 2))); timespan.End = (byte)(Convert.ToInt32(timeTo.Substring(0, 2)) * 4 + Convert.ToInt32(timeTo.Substring(3, 2))); meetTimes.Add(timespan); } section.Time = new CourseSectionTime(meetTimes).ToString(); courseObj.Sections.Add(section); } } catch (NullReferenceException e) { Trace.WriteLine(e.ToString()); continue; } Trace.WriteLine(""); allCourses.Add(courseObj); } } Trace.WriteLine(string.Format("Total number of courses: {0}", allCourses.Count)); }
public Course Get(uint id) { if (!(bool)HttpContext.Current.Application["Updating"]) { IIndexableCollection <Course> courses = (IIndexableCollection <Course>)HttpContext.Current.Application["Courses"]; Course result; if (courses.TryGetItem(id, out result)) { if (result is UTCourse) { UTCourse utResult = result as UTCourse; utResult.Prerequisites = ReplaceCourseCode(utResult.Prerequisites); utResult.Corequisites = ReplaceCourseCode(utResult.Corequisites); utResult.Exclusions = ReplaceCourseCode(utResult.Exclusions); return(utResult); } } } return(null); }
public bool TryAddCourse(uint courseId, string courseString, string sectionCode, iCalendar calendar) { IIndexableCollection <Course> courses = (IIndexableCollection <Course>)HttpContext.Current.Application["Courses"]; Course course; if (courses.TryGetItem(courseId, out course)) { if (!courseString.StartsWith(course.Abbr)) { return(false); } foreach (CourseSection section in course.Sections) { if (section.Name == sectionCode) { UTCourseSection utSection = section as UTCourseSection; UTCourse utCourse = course as UTCourse; if (utSection != null && utCourse != null) { int order = 0; foreach (CourseSectionTimeSpan timeSpan in utSection.ParsedTime.MeetTimes) { if (utCourse.SemesterDetail == "Fall" || utCourse.SemesterDetail == "Year") { Event courseEvent = calendar.Create <Event>(); if (utCourse.Faculty == "Engineering") { courseEvent.Start = new iCalDateTime(this.ConvertDateTime(new DateTime(2020, 9, 1), timeSpan.Day, timeSpan.Start), "America/Toronto"); courseEvent.End = new iCalDateTime(this.ConvertDateTime(new DateTime(2020, 9, 1), timeSpan.Day, timeSpan.End), "America/Toronto"); courseEvent.RecurrenceRules.Add(new RecurrencePattern(FrequencyType.Weekly) { //Count = 13 Until = new DateTime(2020, 12, 15) }); } else { courseEvent.Start = new iCalDateTime(this.ConvertDateTime(new DateTime(2018, 9, 6), timeSpan.Day, timeSpan.Start), "America/Toronto"); courseEvent.End = new iCalDateTime(this.ConvertDateTime(new DateTime(2018, 9, 6), timeSpan.Day, timeSpan.End), "America/Toronto"); courseEvent.RecurrenceRules.Add(new RecurrencePattern(FrequencyType.Weekly) { //Count = 13 Until = new DateTime(2020, 12, 15) }); } courseEvent.Summary = utCourse.Abbr + ": " + utCourse.Name + " " + utSection.Name; try { courseEvent.Location = utSection.Location.Split(' ')[order]; } catch { } } if (utCourse.SemesterDetail == "Winter" || utCourse.SemesterDetail == "Year") { Event courseEvent = calendar.Create <Event>(); if (utCourse.Faculty == "Engineering") { courseEvent.Start = new iCalDateTime(this.ConvertDateTime(new DateTime(2021, 1, 3), timeSpan.Day, timeSpan.Start), "America/Toronto"); courseEvent.End = new iCalDateTime(this.ConvertDateTime(new DateTime(2021, 1, 3), timeSpan.Day, timeSpan.End), "America/Toronto"); courseEvent.RecurrenceRules.Add(new RecurrencePattern(FrequencyType.Weekly) { Until = new DateTime(2021, 4, 10) //Count = 13 }); } else { courseEvent.Start = new iCalDateTime(this.ConvertDateTime(new DateTime(2021, 1, 3), timeSpan.Day, timeSpan.Start), "America/Toronto"); courseEvent.End = new iCalDateTime(this.ConvertDateTime(new DateTime(2021, 1, 3), timeSpan.Day, timeSpan.End), "America/Toronto"); courseEvent.RecurrenceRules.Add(new RecurrencePattern(FrequencyType.Weekly) { Until = new DateTime(2021, 4, 10) //Count = 13 }); } courseEvent.Summary = utCourse.Abbr + ": " + utCourse.Name + " " + utSection.Name; try { courseEvent.Location = utSection.Location.Split(' ')[order]; } catch { } } order++; } } return(true); } } } return(false); }