public void readStoredEventsFile() { var filePath = pathToStoredEventsFile(); //values for an event string name, source; int month, day, hour, minute, second; bool visible; //read in stored events from text file string text, entryType, entryValue; if (!System.IO.File.Exists(filePath)) { resetStoredEventsFile(); } string[] reader = System.IO.File.ReadAllLines(filePath); int i = 0; while (i < reader.Length) { //values for an event name = ""; source = ""; month = 1; day = 1; hour = 0; minute = 0; second = 0; visible = false; text = convertEntry(reader[i]); switch (text) { case "Event": i++; text = convertEntry(reader[i]); while (!text.Equals("/Event")) { entryType = getEntryType(text); entryValue = getEntryValue(text); switch (entryType) { case "Name": name = entryValue; break; case "Source": source = entryValue; break; case "Month": month = Int32.Parse(entryValue); break; case "Day": day = Int32.Parse(entryValue); break; case "Hour": hour = Int32.Parse(entryValue); break; case "Visible": visible = bool.Parse(entryValue); break; } i++; text = convertEntry(reader[i]); } //add the new event to list(s) //2016 used to prevent impossible date due to leap day, the year value will be reset anyhow Event newEvent = new Event(name, new DateTime(2016, month, day, hour, minute, second), visible); GlobalVariables.resetEvent(newEvent); GlobalVariables.storedEvents.Add(newEvent); break; } i++; } }