-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWdIndoorRecord.cs
64 lines (53 loc) · 1.57 KB
/
WdIndoorRecord.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
using System.Globalization;
namespace ImportWD
{
internal class WdIndoorRecord
{
// Uses space separated fields
// 0 - day
// 1 - month
// 2 - year
// 3 - hour
// 4 - minute
// 5 - temperature
// 6 - humidity
public DateTime? Timestamp { get; set; }
public double? Temp { get; private set; }
public int? Hum { get; private set; }
public WdIndoorRecord(string entry)
{
var arr = entry.Split(' ', StringSplitOptions.RemoveEmptyEntries);
try
{
Timestamp = new DateTime(int.Parse(arr[2]), int.Parse(arr[1]), int.Parse(arr[0]), int.Parse(arr[3]), int.Parse(arr[4]), 0, DateTimeKind.Local);
}
catch (Exception ex)
{
Program.LogMessage(" Error parsing date/time fields: " + ex.Message);
Program.LogMessage(" Error line: " + entry);
Program.LogConsole(" Error parsing date/time fields: " + ex.Message, ConsoleColor.Red);
return;
}
if (double.TryParse(arr[5], CultureInfo.InvariantCulture, out double temp))
{
Temp = Program.WdConfigTemp == "c" ? ConvertUnits.TempCToUser(temp) : ConvertUnits.TempFToUser(temp);
}
else
{
Program.LogMessage(" Error parsing field 6 (temperature})");
Program.LogMessage(" Error line: " + entry);
Program.LogConsole(" Error parsing field 6 (temperature})", ConsoleColor.Red);
}
if (int.TryParse(arr[6], out int hum))
{
Hum = hum;
}
else
{
Program.LogMessage(" Error parsing field 6 (humidity})");
Program.LogMessage(" Error line: " + entry);
Program.LogConsole(" Error parsing field 6 (humidity})", ConsoleColor.Red);
}
}
}
}