public Task DeleteTimetableCellAsync(TimetableCell cell) { return(_database.DeleteAsync(cell, true)); }
/// <summary> /// Return the List of Lecture Items from the Academic Office website xlsx file. This is where the cleanup of the streamed data happends /// </summary> /// <returns>Lecture Items List</returns> public static List <Lecture> LecturesList() { var lectures = new List <Lecture>(); var timeTableCells = new List <TimetableCell>(); //get the uri that has the lecture timetables in xlsx file var lectureTimetableuri = GetLinksFromMainPage("03")[0]; //get the xlsx file in the given link as a memory stream var timetableMemoryStream = GetTimetableAsMemStream(lectureTimetableuri); var dayOfWeekFull = new Dictionary <string, string> { { "月/Mon.", "Monday" }, { "火/Tue.", "Tuesday" }, { "水/Wed.", "Wednesday" }, { "木/Thu.", "Thursday" }, { "金/Fri.", "Friday" } }; var periodStartTime = new Dictionary <string, string> { { "1st Period", "08:45" }, { "2nd Period", "10:35" }, { "3rd Period", "12:25" }, { "4th Period", "14:15" }, { "5th Period", "16:05" }, { "6th Period", "17:55" }, { "T.B.A.", "T.B.A." } }; //loop through the links that has the xlsx file foreach (var i in timetableMemoryStream) { //loop through all the raw strings in the xlsx cell row by row foreach (var n in ReadRawXlsxFileStream(i)) { //split the string with the delimiter, making it to an array var lectureArray = n.Split(delimiter); //only add the items that has a proper subject id if (lectureArray[5] != "NA" && lectureArray[5] != "講義CD/Subject CD") { //split the semester and curriculum string into two and declare them string[] semesterOrCurr = lectureArray[lectureArray.Length - 1].Split('('); string semester = semesterOrCurr[0].Replace("Timetable", "").Replace(" Semester", "").Trim(); string curriculum = semesterOrCurr[1].Replace("For ", "").Replace(" Curriculum students)", ""); string buildingFloor = lectureArray[4]; //change building format to a more readable one if (lectureArray[4] != "T.B.A.") { buildingFloor = lectureArray[4].Replace("-", " building ").Replace("Ⅱ", "II"); buildingFloor = buildingFloor.Remove(buildingFloor.Length - 1, 1) + OrderedNumber(lectureArray[4].Remove(0, lectureArray[4].Length - 1)) + " floor"; } //change day of week format only if it's not "Session" string dayOfWeek = lectureArray[1].Contains("Session") ? "Session" : dayOfWeekFull[lectureArray[1]]; string classPeriod = lectureArray[2].Contains("T.B.A.") ? "T.B.A." : OrderedNumber(lectureArray[2].Normalize(System.Text.NormalizationForm.FormKC)) + " Period"; string grade = OrderedNumber(lectureArray[12].Remove(1, 2)) + " Year"; string term = lectureArray[0]; if (lectureArray[0].Contains("Session")) { term = "Session"; } else if (lectureArray[0].Contains("Semester")) { term = "Semester"; } else { term = lectureArray[0].Contains("2Q") ? "2nd Quarter" : "1st Quarter"; } //setup the current lecture item var thisLecture = new Lecture { Term = term, Classroom = lectureArray[3].Replace("Ⅱ", "II "), BuildingFloor = buildingFloor, SubjectId = lectureArray[5], SubjectNameJP = lectureArray[6], SubjectNameEN = lectureArray[7], InstructorJP = lectureArray[8], InstructorEN = lectureArray[9], GradeEval = lectureArray[10], Language = lectureArray[11], Grade = grade, Field = lectureArray[13], APS = lectureArray[14], APM = lectureArray[15], Semester = semester, Curriculum = curriculum }; //check if the list already has this lecture if (!lectures.Contains(thisLecture)) { lectures.Add(thisLecture); } //start instantiating objects. Add all the time cells without filtering timeTableCells.Add(TimetableCell.Parse(thisLecture, dayOfWeek, classPeriod, periodStartTime[classPeriod])); } } } //add all the timetable cells to all the lectures AddTimetableCellsToList(lectures, timeTableCells); return(lectures); }
//save the given timetable to the database public Task SaveTimetableCellAsync(TimetableCell cell) { Console.WriteLine("[DataStore]Inserting new item " + cell.Period + " - " + cell.DayOfWeek); return(_database.InsertOrReplaceWithChildrenAsync(cell, recursive: true)); }