Esempio n. 1
0
        /// <summary>
        ///		Seek with position not loading data immediately.
        /// </summary>
        /// <param name="position">
        ///		The position to restore
        /// </param>
        /// <returns>
        ///		Success boolean flag; whether a data file to be read was found. It may not be exact match for the position, however.
        /// </returns>
        /// <remarks>
        ///		The position is saved and completely restored when <see cref="LoadNextFile"/> is called; issues are reported
        ///		via <see cref="IRepositoryReader.SeekStatusCallback"/>, success is not reported, only warnings
        ///		, <see cref="FolderSeekStatus.PositionStatus"/>.
        ///		Note that you cannot change reading direction after the call to this method until you load the file and restore
        ///		the reading position.
        /// </remarks>
        public bool SeekDataFile(IFolderReadingPosition position)
        {
            // save position copy
            _position.FromSeek(position);

            bool retval = null != _fileIterator.Seek(position.Time, Backwards);

            if (position.IsExact && (!retval || !_fileIterator.Current.Name.IsCovering(position.Time)))
            {
                _log.WarnFormat("Seek on folder {0} have not found data file containing item referenced in the position: {1}"
                                , position.FolderKey
                                , position.Time);

                MasterReader.SeekStatusCallback(new FolderSeekStatus(TargetFolder.FolderKey, FolderSeekStatus.PositionStatus.FileNotFound));
            }

            if (retval)
            {
                DateTime firstTimeInFile = _getFirstItemToReadFromFileName(NextDataFile.Name);
                if (_timeComparison.Compare(position.Time, firstTimeInFile) > 0)
                {
                    // file starts before the seek time, so will need to skip some items in it
                    firstTimeInFile = _position.Time;
                }
                NextFileFirstTimestampToRead = firstTimeInFile;
            }

            WasPositioned    = true;
            LastSeekTime     = position.Time;
            SoughtFileLoaded = false;

            return(retval);
        }
 /// <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);
 }