18 using System.Collections;
19 using System.Collections.Generic;
22 using System.Threading.Tasks;
32 public class MapFile : IEnumerable<MapFileRow>
34 private readonly List<MapFileRow> _data;
59 public MapFile(
string permtick, IEnumerable<MapFileRow> data)
61 if (
string.IsNullOrEmpty(permtick))
63 throw new ArgumentNullException(nameof(permtick),
"Provided ticker is null or empty");
67 _data = data.Distinct().OrderBy(row => row.Date).ToList();
82 if (
char.IsDigit(firstTicker.Last()))
84 var dotIndex = firstTicker.LastIndexOf(
".", StringComparison.Ordinal);
88 var number = firstTicker.AsSpan(dotIndex + 1);
89 if (
int.TryParse(number, out value))
91 firstTicker = firstTicker.Substring(0, dotIndex);
108 var mappedSymbol = defaultReturnValue;
110 for (var i = 0; i < _data.Count; i++)
113 if (row.Date < searchDate || row.DataMappingMode.HasValue && row.DataMappingMode != dataMappingMode)
117 mappedSymbol = row.MappedSymbol;
129 if (_data.Count == 0)
148 return _data.Select(mapRow => mapRow.ToCsv());
159 var fileDir = Path.GetDirectoryName(filePath);
161 if (!Directory.Exists(fileDir))
163 Directory.CreateDirectory(fileDir);
164 Log.
Trace($
"Created directory for map file: {fileDir}");
178 return Invariant($
"{securityType.SecurityTypeToLower()}/{market}/map_files");
181 #region Implementation of IEnumerable
192 return _data.GetEnumerator();
202 IEnumerator IEnumerable.GetEnumerator()
219 var mapFiles =
new List<MapFile>();
220 Parallel.ForEach(Directory.EnumerateFiles(mapFileDirectory), file =>
222 if (file.EndsWith(
".csv"))
224 var permtick = Path.GetFileNameWithoutExtension(file);
225 var fileRead = SafeMapFileRowRead(file, market, securityType, dataProvider);
226 var mapFile = new MapFile(permtick, fileRead);
230 mapFiles.Add(mapFile);
240 private static List<MapFileRow> SafeMapFileRowRead(
string file,
string market,
SecurityType securityType,
IDataProvider dataProvider)
244 return MapFileRow.Read(file, market, securityType, dataProvider).ToList();
246 catch (Exception err)
249 return new List<MapFileRow>();