private byte[] FindBlockHA(DateTime dateTime, RecordCollection cache) { byte[] result = null; while (true) { Record nearest = cache.GetNearestRecordHA(dateTime); int steps = CalculateStepsHA(dateTime, nearest); Address newAddress = nearest.Address.GetNextAddressHA(steps); Record newRecord = ReadRecord(newAddress); if (newRecord == null || DriverHelper.IsValidRecord(newRecord) == false) { break; } if (DriverHelper.IsValidRecord(newRecord)) { cache.Add(newRecord); } if (newRecord.Block1.DateTime == dateTime) { result = newRecord.Block1.Bytes; break; } if (newRecord.Block2.DateTime == dateTime) { result = newRecord.Block2.Bytes; break; } if (cache.IsRecordExist(dateTime)) { var record = cache.ExistRecord(dateTime); if (dateTime == record.Block1.DateTime) { result = newRecord.Block1.Bytes; break; } if (dateTime == record.Block2.DateTime) { result = newRecord.Block2.Bytes; break; } break; } } return(result); }
public override SurveyResultData ReadHourlyArchive(IEnumerable <DateTime> dates) { var result = new List <Data>(); var cache = new RecordCollection(); if (!Connect()) { return(null); } var firstRecord = ReadRecord(Address.GetFirstHourAddress()); if (firstRecord != null) { cache.Add(firstRecord); } var presentRecord = FindPresentRecordHA(firstRecord); if (presentRecord != null) { cache.Add(presentRecord); } foreach (var dateTime in dates) { var records = ParseHA((FindBlockHA(dateTime, cache)), dateTime); if (records != null) { result.AddRange(records); } } return(new SurveyResultData { Records = result, State = result.Any() ? SurveyResultState.Success : SurveyResultState.PartialyRead }); }