19 using System.Threading;
33 static private int _curFileCount = 0;
34 private string _zipPath;
35 private string _entryPath;
40 private string _dataDirectory;
42 private DateTime _referenceDate;
43 private static string[] _windowsRestrictedNames =
45 "con",
"prn",
"aux",
"nul"
55 if (_entryPath ==
null)
61 set { _entryPath = value; }
73 _zipPath = Path.Combine(_dataDirectory, SafeName(
LeanData.
GenerateRelativeZipFilePath(Safe(_symbol), _referenceDate, _resolution, _tickType).Replace(
".zip",
string.Empty))) +
".zip";
77 set { _zipPath = value; }
85 get {
return _symbol; }
93 get {
return _resolution; }
102 get {
return _tickType; }
103 set { _tickType = value; }
124 _symbol = Safe(symbol);
125 _tickType = tickType;
126 _referenceDate = date;
127 _resolution = resolution;
128 _dataDirectory = dataDirectory;
151 var path =
ZipPath.Replace(
".zip",
string.Empty);
152 Directory.CreateDirectory(path);
154 var file = Path.Combine(path,
EntryPath);
160 catch (Exception err)
163 Log.
Error(
"File: {0} Err: {1} Source: {2} Stack: {3}", file, err.Message, err.Source, err.StackTrace);
164 var newRandomizedName = (file +
"-" + Math.Abs(file.GetHashCode()).ToStringInvariant()).Replace(
".csv",
string.Empty) +
".csv";
167 Log.
Trace(
"Changing name from {0} to {1}", file, newRandomizedName);
177 Interlocked.Add(ref _curFileCount, 1);
178 if (_curFileCount % 1000 == 0)
180 Log.
Trace(
"Opened more files: {0}", _curFileCount);
195 _consolidator.
Update(data);
206 _consolidator.
Scan(frontierTime);
216 _streamWriter.
Flush();
217 _streamWriter.
Close();
218 _streamWriter =
null;
220 Interlocked.Add(ref _curFileCount, -1);
221 if (_curFileCount % 1000 == 0)
223 Log.
Trace(
"Closed some files: {0}", _curFileCount);
237 if (_windowsRestrictedNames.Contains(symbol.
Value.ToLowerInvariant()))
244 private static string SafeName(
string fileName)
248 foreach (var name
in _windowsRestrictedNames)
251 var restrictedFilePath = Path.DirectorySeparatorChar + name;
252 var safeFilePath = Path.DirectorySeparatorChar +
"_" + name;
253 fileName = fileName.Replace(restrictedFilePath, safeFilePath);