using ConsoleUI.Models; using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Runtime.CompilerServices; using System.Text; using System.Threading.Tasks; namespace ConsoleUI.WithoutGenerics { public class OriginalTextFileProcessor { public static List LoadPeople(string filePath) { List output = new List(); Person p; var lines = System.IO.File.ReadAllLines(filePath).ToList(); // remove the header row lines.RemoveAt(0); foreach (var line in lines) { var vals = line.Split(';'); p = new Person(); p.FirstName = vals[0]; p.IsAlive = bool.Parse(vals[1]); p.LastName = vals[2]; output.Add(p); } return output; } public static List LoadLogs(string filePath) { List output = new List(); LogEntry log; var lines = System.IO.File.ReadAllLines(filePath).ToList(); // remove the header row lines.RemoveAt(0); foreach (var line in lines) { var vals = line.Split(';'); log = new LogEntry(); log.ErrorCode= int.Parse(vals[0]); log.Message = vals[1]; log.TimeOfEvent = DateTime.Parse(vals[2]); output.Add(log); } return output; } public static void SavePeople(List people, string filePath) { List lines = new List(); //Add a header row lines.Add("FirstName,IsAlive,LastName"); foreach(var p in people) { lines.Add($"{p.FirstName};{p.IsAlive};{p.LastName}"); } System.IO.File.WriteAllLines(filePath, lines); } public static void SaveLogs(List logs, string filePath) { List lines = new List(); //Add a header row lines.Add("ErrorCode,Message,TimeOfEvent"); foreach (var l in logs) { lines.Add($"{l.ErrorCode};{l.Message};{l.TimeOfEvent}"); } System.IO.File.WriteAllLines(filePath, lines); } } }