/// <summary> /// Force the specified direction /// </summary> private void SetDirection(EnumerationDirection direction) { Check.Require(IsReadingSequential, StorageResources.CannotChangeReadingDirectionWhenNonSequential); bool hadData = this.HasItem; _direction = direction; _timeComparison = TimeComparer.GetComparer(direction); if (!Backwards) { _getFirstItemToReadFromFileName = (f) => f.FirstItemTimestamp; _getLastItemToReadFromFileName = (f) => f.LastItemTimestamp; } else { _getFirstItemToReadFromFileName = (f) => f.LastItemTimestamp; _getLastItemToReadFromFileName = (f) => f.FirstItemTimestamp; } if (IsDataLoaded && _listReader.Direction != direction) { _listReader = _listReader.Reverse(); Check.Ensure(_listReader.Direction == Direction); } int moveCount = 0; if (IsDataLoaded) { // in sequential mode and when data is loaded iterator points to the data file to load next, so need to move by 2 // (skipping currently loaded file) moveCount = 2; } else { // data is not loaded; 2 cases: 1) seek found file with data beyond seek time and 2) seek time is contained in the file if (!NextFileFound || IsNextFileToBeReadInFull) { // case 1 moveCount = 1; } // case 2: next file remains valid because will have to read some data from it in the opposite direction } _fileIterator.Backwards = Backwards; for (int n = 0; n < moveCount; ++n) { MoveIteratorToNextFile(); } if (!hadData) { _position.SetEmpty(direction); } }
/// <summary> /// Given first logical (according to direction) item timestamp in file and logical time comparison (again, according /// to direction) determine whether the file is to be read in full when restoring this position /// </summary> /// <param name="firstItemTimestampInFile"> /// First logical item timestamp in the file (of either first or last item when going forward and backwards respectively) /// </param> /// <param name="comparison"> /// Time comparison implementation /// </param> /// <returns> /// <see langword="true"/> if first item in the file represented by <paramref name="firstItemTimestampInFile"/> will have to be read /// <see langword="false"/> otherwise, i.e. when at least 1 item will have to be skipped /// </returns> public bool IsFileToBeReadInFull(DateTime firstItemTimestampInFile, Util.IDirectedTimeComparison comparison) { int cmp = comparison.Compare(firstItemTimestampInFile, Time); return cmp > 0 || (cmp == 0 && NumberOfItemsWithTheTimestampRead == 0); }