Ejemplo n.º 1
0
 /// <summary>
 ///     Unload currently loaded file. To load another file
 ///     it can be found with <see cref="SeekDataFile"/> and opened
 ///     with <see cref="LoadNextFile"/> or use <see cref="Seek"/>
 ///     do do it all at once.
 /// </summary>
 public void Unload()
 {
     if (this.IsDataLoaded)
     {
         _listReader = null;
         LoadedFile  = null;
     }
     Util.Check.Ensure(!this.IsDataLoaded);
     Util.Check.Ensure(this.LoadedFile == null);
 }
Ejemplo n.º 2
0
        /// <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);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        ///		Loads the specified file and positions at the first data item.
        /// </summary>
        /// <exception cref="System.IO.FileNotFoundException">
        ///		The <paramref name="dataFile"/> does not exist on disk.
        /// </exception>
        private void ReadFile(IRepositoryFile dataFile)
        {
            // passing null for equally timestamped items comparer, data items are read in the same
            // order as they were written; no sorting when reading by design
            IDataFileAccessor accessor = GetAccessor(dataFile);

            // will throw exception if file not found or failed to read
            accessor.ReadFromFile();

            IList <IDataItem> dataList = accessor.GetAllItems();

            if (Backwards)
            {
                _listReader = new BackwardListReader <IDataItem>(dataList);
            }
            else
            {
                _listReader = new ForwardListReader <IDataItem>(dataList);
            }
            this.LoadedFile = dataFile;

            Check.Ensure(_listReader.HasItem);
            Check.Ensure(CurrentItem != null);
        }