forked from lucaslorentz/minicover
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHitService.cs
32 lines (29 loc) · 881 Bytes
/
HitService.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
using System.Collections.Generic;
using System.IO;
namespace MiniCover
{
public static class HitService
{
private static readonly object lockObject = new object();
private static Dictionary<string, StreamWriter> writers = new Dictionary<string, StreamWriter>();
public static void Init(string fileName)
{
lock (lockObject)
{
if (!writers.ContainsKey(fileName))
{
writers[fileName] = new StreamWriter(File.Open(fileName, FileMode.Append));
}
}
}
public static void Hit(string fileName, int id)
{
lock (lockObject)
{
var streamWriter = writers[fileName];
streamWriter.WriteLine(id);
streamWriter.Flush();
}
}
}
}