Skip to content

Commit

Permalink
feat: align IsWorkingFromHome column in output
Browse files Browse the repository at this point in the history
  • Loading branch information
dylan-george-field committed Aug 20, 2023
1 parent 52d97a4 commit bb9c66f
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 5 deletions.
7 changes: 4 additions & 3 deletions src/wfh-log-wpf/Entity/LogEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ namespace wfh_log_wpf.Models
{
public class LogEntry
{
public DateTime Time { get; set; } = DateTime.Now.ToLocalTime();
public bool IsWorkingFromHome { get; set; } = false;
public string ConnectedNetwork { get; set; }
public bool IsWorkingFromHome { get; set; } = false;
public DateTime Time { get; set; } = DateTime.Now.ToLocalTime();

public LogEntry() { } // for csv helper
// needed for csv helper to load headers
public LogEntry() { }

public LogEntry(bool isWorkingFromHome, string connectedNetwork)
{
Expand Down
25 changes: 25 additions & 0 deletions src/wfh-log-wpf/Entity/LogEntryPretty.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System;

namespace wfh_log_wpf.Models
{
/// <summary>
/// The same as LogEntry.cs but with strings.
/// Used to change log output by adding tabs
/// before properties to make it look pretty
/// </summary>
public class LogEntryPretty
{
public DateTime Time { get; set; }
public string IsWorkingFromHome { get; set; }
public string ConnectedNetwork { get; set; }

public LogEntryPretty(LogEntry entry)
{
IsWorkingFromHome = entry.IsWorkingFromHome
? entry.IsWorkingFromHome.ToString() + " "
: entry.IsWorkingFromHome.ToString();
ConnectedNetwork = entry.ConnectedNetwork.ToString();
Time = entry.Time;
}
}
}
6 changes: 4 additions & 2 deletions src/wfh-log-wpf/Logger/LogWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,16 @@ public void Log(bool isWorkingFromHome, string connectedNetworkName)

var config = new CsvConfiguration(CultureInfo.InvariantCulture)
{
HasHeaderRecord = false // don't write header again
HasHeaderRecord = false, // don't write the header twice
ShouldQuote = (args) => false
};

using (var stream = File.Open(AbsoluteFilePath, FileMode.Append))
using (var writer = new StreamWriter(stream))
using (var csv = new CsvWriter(writer, config))
{
csv.WriteRecords(new List<LogEntry>() { entry });
var prettyEntry = new LogEntryPretty(entry);
csv.WriteRecords(new List<LogEntryPretty>() { prettyEntry });
}
}
}
Expand Down

0 comments on commit bb9c66f

Please sign in to comment.