private List <Course> ParseCSV(string fileLocation) { List <Course> tempCourses = new List <Course>(); foreach (string line in System.IO.File.ReadLines(fileLocation)) { if (string.IsNullOrWhiteSpace(line)) { continue; } // NAME, SECTION, START DATE, DAY, START, FINISH, LOCATION, PROFESSOR(S), SCHEDULING NOTES // Each line represent one time slot of a course; Double quotes inside quotes shoube be escaped by using """ // Parse string[] parameters = line.Split(new string[] { "\",\"" }, StringSplitOptions.None).Select(item => item.Trim(new char[] { '"' })).ToArray(); if (parameters.Length != 9) { continue; } // Get parameters string courseCode = parameters[0]; string sectionCode = parameters[1]; string startDate = parameters[2]; // Not used string day = parameters[3]; string startTime = parameters[4]; string finishTime = parameters[5]; string location = parameters[6]; string profs = parameters[7]; string notes = parameters[8]; #region Further Processing // Further processing: section string sectionTypeString, sectionCodeValue; TimeSlot.BreakSectionCode(sectionCode, out sectionTypeString, out sectionCodeValue); TimeslotType sectionType = TimeslotType.Lecture; switch (sectionTypeString.ToUpper()) { case "LEC": sectionType = TimeslotType.Lecture; break; case "TUT": sectionType = TimeslotType.Tutorial; break; case "PRA": sectionType = TimeslotType.Practice; break; default: sectionType = TimeslotType.Lecture; break; } // Further processing: day Day dayEnum = Day.Monday; switch (day.ToUpper()) { case "MON": dayEnum = Day.Monday; break; case "TUE": dayEnum = Day.Tuesday; break; case "WED": dayEnum = Day.Wednesday; break; case "THU": dayEnum = Day.Thursday; break; case "FRI": dayEnum = Day.Friday; break; default: break; } // Further processing: time; Ignore minute section int startTimeValue = int.Parse(startTime.Substring(0, startTime.IndexOf(':'))); int finishTimeValue = int.Parse(finishTime.Substring(0, finishTime.IndexOf(':'))); // Further processing: availability char lastChar = courseCode.ToUpper().Last(); Availability availability = (lastChar == 'S' || lastChar == 'W') ? Availability.Winter : Availability.Fall; #endregion // Find existing: if it exists then it would be the last per design so we don't need to search if (tempCourses.Count == 0 || tempCourses.Last().CourseCode != courseCode) { // Add new tempCourses.Add(new Course(courseCode, "", 0, new CEABAU())); } // Merge tempCourses.Last().TimeSlots.Add(new TimeSlot(dayEnum, startTimeValue, finishTimeValue - startTimeValue, sectionType, availability, sectionCodeValue, location, profs, notes)); } return(tempCourses); }