public static bool VerifySequentiality(string filePath) { DateTime previousDateTime = DateTime.MinValue; DateTime dateTime; for (int i = 0; i < 10; i++) { try { using (StreamReader reader = File.OpenText(filePath)) { while (QuotesConverter.GetQuoteDateTimeFromStreamReader(reader, out dateTime)) { if (dateTime < previousDateTime) { return(false); } } } } catch (IOException ioe) { Console.WriteLine(ioe.Message); Thread.Sleep(1000); } } return(true); }
/// <summary> /// Entrega el siguiente sample considerando el período definido en la construcción de esta instancia. /// </summary> /// <param name="dateTime"></param> /// <param name="ask"></param> /// <param name="bid"></param> /// <returns></returns> public bool Next(out DateTime dateTime, out decimal ask, out decimal bid) { if (!QuotesConverter.GetQuoteFromBinaryReader(_reader, out dateTime, out ask, out bid)) { if (_paths.Count == 0) { dateTime = default(DateTime); ask = bid = default(decimal); return(false); } if (_reader != null) { _reader.Close(); } string path = _paths.Dequeue(); while (!File.Exists(path)) { if (_paths.Count > 0) { path = _paths.Dequeue(); } else { return(false); } } _reader = new BinaryReader(File.OpenRead(path)); if (!QuotesConverter.GetQuoteFromBinaryReader(_reader, out dateTime, out ask, out bid)) { throw new Exception("Empty file found."); } } while (dateTime < _begin) { if (!Next(out dateTime, out ask, out bid)) { return(false); } } if (dateTime > _end) { return(false); } return(true); }
public void ImportQuotes(string sourceFilePath, IQuotesProcessor quotesProcessor, DateTime begin, DateTime end) { using (StreamReader reader = File.OpenText(sourceFilePath)) { string line; bool endOfSearchSpaceReached = false; while (!endOfSearchSpaceReached && (line = reader.ReadLine()) != null) { DateTime currentDateTime = QuotesConverter.GetQuoteDateTimeFromString(line); if (currentDateTime > end) { endOfSearchSpaceReached = true; } else if (currentDateTime >= begin) { quotesProcessor.StoreQuoteFromString(line); } } } }
public void StoreQuoteFromString(string text) { long time; DateTime dateTime; decimal ask, bid; QuotesConverter.GetQuoteFromString(text, out dateTime, out time, out ask, out bid); if (_dayOfYear != dateTime.DayOfYear) { if (_writer != null) { _writer.Close(); } string folderPath; string filePath; PathBuilder.CreatePaths(_rootFolder, dateTime, out folderPath, out filePath); Directory.CreateDirectory(folderPath); _writer = new BinaryWriter(File.Create(filePath)); _dayOfYear = dateTime.DayOfYear; } _writer.Write((Int64)time); _writer.Write(ask); _writer.Write(bid); }