diff --git a/src/wfh-log-wpf/Entity/LogEntry.cs b/src/wfh-log-wpf/Entity/LogEntry.cs index 9cbfa68..524e51d 100644 --- a/src/wfh-log-wpf/Entity/LogEntry.cs +++ b/src/wfh-log-wpf/Entity/LogEntry.cs @@ -4,9 +4,9 @@ namespace wfh_log_wpf.Models { public class LogEntry { - public string ConnectedNetwork { get; set; } - public bool IsWorkingFromHome { get; set; } = false; public DateTime Time { get; set; } = DateTime.Now.ToLocalTime(); + public bool IsWorkingFromHome { get; set; } = false; + public string ConnectedNetwork { get; set; } // needed for csv helper to load headers public LogEntry() { } diff --git a/src/wfh-log-wpf/Entity/LogEntryPretty.cs b/src/wfh-log-wpf/Entity/LogEntryPretty.cs index 94985e2..75ee38e 100644 --- a/src/wfh-log-wpf/Entity/LogEntryPretty.cs +++ b/src/wfh-log-wpf/Entity/LogEntryPretty.cs @@ -15,11 +15,9 @@ public class LogEntryPretty public LogEntryPretty(LogEntry entry) { - IsWorkingFromHome = entry.IsWorkingFromHome - ? " " + entry.IsWorkingFromHome.ToString() + " " - : " " + entry.IsWorkingFromHome.ToString(); - ConnectedNetwork = " " + entry.ConnectedNetwork.ToString(); Time = entry.Time; + IsWorkingFromHome = "\t" + entry.IsWorkingFromHome.ToString(); + ConnectedNetwork = "\t\t\t" + entry.ConnectedNetwork.ToString(); } } } diff --git a/src/wfh-log-wpf/Logger/LogReader.cs b/src/wfh-log-wpf/Logger/LogReader.cs index e619ab9..4045aeb 100644 --- a/src/wfh-log-wpf/Logger/LogReader.cs +++ b/src/wfh-log-wpf/Logger/LogReader.cs @@ -1,4 +1,5 @@ using CsvHelper; +using CsvHelper.Configuration; using System.Collections.Generic; using System.Globalization; using System.IO; @@ -11,20 +12,32 @@ public class LogReader : BaseLog { public LogReader() { + var config = new CsvConfiguration(CultureInfo.InvariantCulture) + { + HasHeaderRecord = false, + ShouldQuote = (args) => false + }; + if (!File.Exists(AbsoluteFilePath)) { using (var writer = new StreamWriter(AbsoluteFilePath)) using (var csv = new CsvWriter(writer, CultureInfo.InvariantCulture)) { - csv.WriteHeader(); - csv.NextRecord(); + writer.WriteLine("Time\t\t\tIsWorkingFromHome\tNetwork"); } - } - - using (var reader = new StreamReader(AbsoluteFilePath)) - using (var csv = new CsvReader(reader, CultureInfo.InvariantCulture)) + } + else { - _logs = csv.GetRecords().ToList(); + using (var reader = new StreamReader(AbsoluteFilePath)) + using (var csv = new CsvReader(reader, config)) + { + csv.Read(); + + while(csv.Read()) + { + _logs.Add(csv.GetRecord()); + } + } } } diff --git a/src/wfh-log-wpf/Logger/LogWriter.cs b/src/wfh-log-wpf/Logger/LogWriter.cs index 98c7821..e76e215 100644 --- a/src/wfh-log-wpf/Logger/LogWriter.cs +++ b/src/wfh-log-wpf/Logger/LogWriter.cs @@ -17,7 +17,7 @@ public void Log(bool isWorkingFromHome, string connectedNetworkName) var config = new CsvConfiguration(CultureInfo.InvariantCulture) { - HasHeaderRecord = false, // don't write the header twice + HasHeaderRecord = false, ShouldQuote = (args) => false };