17 using System.Collections.Generic;
19 using System.Threading.Tasks;
31 private const int TicksPerFlush = 50;
32 private static readonly
object DirectoryCreateSync =
new object();
34 private readonly
string _dataDirectory;
37 private readonly Dictionary<Symbol, Writer> _writers;
47 _dataDirectory = dataDirectory;
48 _resolution = resolution;
50 _writers =
new Dictionary<Symbol, Writer>();
60 if (!_writers.TryGetValue(data.
Symbol, out writer))
62 writer = CreateTextWriter(data);
63 _writers[data.
Symbol] = writer;
67 if (++writer.ProcessCount%TicksPerFlush == 0)
69 writer.TextWriter.Flush();
73 writer.TextWriter.WriteLine(line);
81 foreach (var kvp
in _writers)
83 kvp.Value.TextWriter.Dispose();
90 private Writer CreateTextWriter(
IBaseData data)
94 .Replace(
".zip",
string.Empty);
95 var path = Path.Combine(Path.Combine(_dataDirectory, relativePath), entry);
96 var directory =
new FileInfo(path).Directory.FullName;
97 if (!Directory.Exists(directory))
100 lock (DirectoryCreateSync)
if (!Directory.Exists(directory)) Directory.CreateDirectory(directory);
103 return new Writer(path,
new StreamWriter(path));
107 private sealed
class Writer
109 public readonly
string Path;
110 public readonly TextWriter TextWriter;
111 public int ProcessCount;
112 public Writer(
string path, TextWriter textWriter)
115 TextWriter = textWriter;