-
Notifications
You must be signed in to change notification settings - Fork 49
/
Copy pathLogItem.cs
43 lines (34 loc) · 1.01 KB
/
LogItem.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HearthstoneAI.LogWatcher
{
class LogItem
{
private LogItem(DateTime time, string content)
{
Time = time;
Content = content;
}
public static LogItem Parse(string line)
{
if (!line.StartsWith("D ")) throw new Exception("wrong format");
DateTime time;
if (line.Length < 19) throw new Exception("wrong format");
if (DateTime.TryParse(line.Substring(2, 16), out time) == false)
{
throw new Exception("wrong format");
}
string content = line.Substring(19);
return new LogItem(time, content);
}
public DateTime Time { get; }
public string Content { get; set; }
public override string ToString()
{
return "[" + Time.ToLongTimeString() + "] " + Content;
}
}
}