-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCSVFileWriter.cs
More file actions
44 lines (38 loc) · 1.06 KB
/
CSVFileWriter.cs
File metadata and controls
44 lines (38 loc) · 1.06 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
using System;
using System.IO;
namespace Capture.WindData
{
public class CSVFileWriter
{
private TextWriter writer;
private FileInfo currentFile;
public CSVFileWriter()
{
CreateFile();
}
internal void WriteData(WindData windData)
{
writer.WriteLine(DateTime.Now + ", " + windData.ResultTime + ", " + windData.Speed + ", " + windData.Direction);
writer.Flush();
CheckFile();
}
private void CheckFile()
{
if (currentFile.Length > 5000000)
{
CreateFile();
}
}
private void CreateFile()
{
var fileName = "c:\\temp\\" + DateTime.Now.ToString("yyyyMMddhhmmss") + ".txt";
writer = File.CreateText(fileName);
currentFile = new FileInfo(fileName);
WriteHeader();
}
private void WriteHeader()
{
writer.WriteLine("System Time, Result Time, Wind Speed, Wind Direction");
}
}
}