public List <TaskDetails> convertStringIntoTaskDetails(List <String> ListOfCompletedEvents) { try { List <TaskDetails> listOfTasksInFile = new List <TaskDetails>(); for (int j = 0; j < ListOfCompletedEvents.Count(); j++) { String line = ListOfCompletedEvents[j]; int i = j + 1; string[] eventParameters = line.Split(';'); TaskDetails task = new TaskDetails(); task.setEventname(eventParameters[0]); task.setlocation(eventParameters[1]); task.setStartDate(eventParameters[2]); task.setEndDate(eventParameters[3]); task.setStartTime(eventParameters[4]); task.setEndTime(eventParameters[5]); task.setDuration(eventParameters[6]); task.setPriority(eventParameters[7]); task.setReminder(eventParameters[8]); task.setID(i.ToString()); listOfTasksInFile.Add(task); } return(listOfTasksInFile); } catch (Exception e) { StreamWriter loggingWriter = new StreamWriter("Logging.txt"); loggingWriter.WriteLine(System.DateTime.Now + e.Message + "\n"); loggingWriter.Close(); return(null); } }
public List <TaskDetails> readFromFile() { // Create an instance of StreamReader to read from a file. // The using statement also closes the StreamReader. List <TaskDetails> listOfTasksInFile = new List <TaskDetails>(); using (StreamReader sr = new StreamReader(filename)) { Debug.Assert(sr != null); String line; int i = 1; int j = 1; // Read and display lines from the file until the end of // the file is reached. while ((line = sr.ReadLine()) != null) { //Console.WriteLine(line); if (!(line.Contains("*******")) && line.CompareTo("") != 0) { j++; string[] eventParameters = line.Split(';'); TaskDetails task = new TaskDetails(); task.setEventname(eventParameters[0]); task.setlocation(eventParameters[1]); task.setStartDate(eventParameters[2]); task.setEndDate(eventParameters[3]); task.setStartTime(eventParameters[4]); task.setEndTime(eventParameters[5]); task.setDuration(eventParameters[6]); task.setPriority(eventParameters[7]); task.setReminder(eventParameters[8]); task.setID(i.ToString()); i++; listOfTasksInFile.Add(task); } else { listOfTasksInFile.RemoveRange(0, listOfTasksInFile.Count()); } } sr.Close(); } return(listOfTasksInFile); }
public List <TaskDetails> readFromFile() { List <TaskDetails> listOfTasksInFile = new List <TaskDetails>(); using (StreamReader sr = new StreamReader(this.filename)) { string line; int i = 1; int j = 1; while ((line = sr.ReadLine()) != null) { if (!(line.Contains("*******") || (line.CompareTo("") == 0))) { j++; string[] eventParameters = line.Split(new char[] { ';' }); TaskDetails task = new TaskDetails(); task.setEventname(eventParameters[0]); task.setlocation(eventParameters[1]); task.setStartDate(eventParameters[2]); task.setEndDate(eventParameters[3]); task.setStartTime(eventParameters[4]); task.setEndTime(eventParameters[5]); task.setDuration(eventParameters[6]); task.setPriority(eventParameters[7]); task.setReminder(eventParameters[8]); task.setID(i.ToString()); i++; listOfTasksInFile.Add(task); } else { listOfTasksInFile.RemoveRange(0, listOfTasksInFile.Count <TaskDetails>()); } } sr.Close(); } return(listOfTasksInFile); }
public List <TaskDetails> convertStringIntoTaskDetails(List <string> ListOfCompletedEvents) { List <TaskDetails> listOfTasksInFile = new List <TaskDetails>(); for (int j = 0; j < ListOfCompletedEvents.Count <string>(); j++) { string line = ListOfCompletedEvents[j]; int i = j + 1; string[] eventParameters = line.Split(new char[] { ';' }); TaskDetails task = new TaskDetails(); task.setEventname(eventParameters[0]); task.setlocation(eventParameters[1]); task.setStartDate(eventParameters[2]); task.setEndDate(eventParameters[3]); task.setStartTime(eventParameters[4]); task.setEndTime(eventParameters[5]); task.setDuration(eventParameters[6]); task.setPriority(eventParameters[7]); task.setReminder(eventParameters[8]); task.setID(i.ToString()); listOfTasksInFile.Add(task); } return(listOfTasksInFile); }