/// <summary>
        ///		Find a place for data item with the specified timestamp
        /// </summary>
        /// <exception cref="System.IO.FileNotFoundException">
        ///		File found in the data file container was not found on disk, by virtue of <see cref="RepositoryFileAccessor.ReadFromFile"/>.
        ///		Possible concurrent update; better shut down.
        /// </exception>
        private void Seek(DateTime seekTimestamp)
        {
            if (null == _currentFolder ||
                !IsCovering(_currentFolder, seekTimestamp))
            {
                // need to change current leaf data folder
                _currentFolder = _targetFolder.RootDataFolder.GetLeafFolder(seekTimestamp, true);
            }

            IRepositoryFileName targetFile;
            IRepositoryFileName predecessor;
            IRepositoryFileName successor;

            _currentFolder.DataFileBrowser.GetDataFiles(seekTimestamp, out predecessor, out targetFile, out successor);

            bool openingExistingFile = targetFile != null;

            if (!openingExistingFile)
            {
                // new file needed
                targetFile = _targetFolder.Repository.ObjectFactory.CreateNewFile(_targetFolder);
            }

            _currentAccessor = GetAccessor(targetFile);

            if (openingExistingFile)
            {
                // will throw exception if file was not found or failed to read
                _currentAccessor.ReadFromFile();
            }

            _currentAccessor.Encryptor = this.Encryptor;

            // set timestamp limits
            if (null != predecessor)
            {
                _currentAccessor.MinTimestampToAccept = predecessor.LastItemTimestamp.AddTicks(1);
            }
            else
            {
                _currentAccessor.MinTimestampToAccept = _currentFolder.Start;
            }

            if (null != successor)
            {
                _currentAccessor.MaxTimestampToAccept = successor.FirstItemTimestamp.AddTicks(-1);
            }
            else
            {
                _currentAccessor.MaxTimestampToAccept = _currentFolder.End.AddTicks(-1);
            }

            Check.Ensure(null != _currentAccessor);
        }
 private void CloseAccessor()
 {
     if (null != _currentAccessor)
     {
         Flush();
         _currentAccessor.Close();
         _currentAccessor = null;
     }
     else
     {
         DropUnsavedItems();
     }
 }
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);
        }