-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathFishTimeDataStorage.cs
More file actions
48 lines (41 loc) · 1.36 KB
/
FishTimeDataStorage.cs
File metadata and controls
48 lines (41 loc) · 1.36 KB
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
using System;
using System.IO;
using System.Collections.Generic;
namespace FishTime
{
class FishTimeDataStorage
{
static FishTimeDataStorage instance = new FishTimeDataStorage();
public static FishTimeDataStorage Instance
{
get
{
return instance;
}
}
private string GetFile(DateTime timestamp)
{
string filename = timestamp.ToString("yyyyMMdd") + ".csv";
filename = Path.Combine(GlobalConfig.Instance.StorageDir, filename);
if (!File.Exists(filename))
{
File.WriteAllText(filename, @"""Window"", ""Process"", ""TimeStamp""" + Environment.NewLine);
}
return filename;
}
private string CSVEncode(string input)
{
return @"""" + input.Replace(@"""", @"""""") + @"""";
}
public bool AppendRecord(FishData fishData)
{
string file = GetFile(fishData.TimeStamp);
string toAppend = CSVEncode(fishData.WindowTitle) + ","
+ CSVEncode(fishData.ProcessName) + ","
+ CSVEncode((fishData.TimeStamp - new DateTime(1970, 1, 1)).TotalSeconds.ToString())
+ Environment.NewLine;
File.AppendAllText(file, toAppend);
return true;
}
}
}