Пример #1
0
 /// <summary>
 /// Returns the Current Sop.DataBlock with option not to put it on cache
 /// </summary>
 /// <param name="getForRemoval"></param>
 /// <returns></returns>
 protected internal Sop.DataBlock GetCurrentDataBlock(bool getForRemoval)
 {
     if (currentDataBlock == null || DataBlockDriver.GetId(currentDataBlock) == -1)
     {
         currentDataBlock = DataBlockDriver.ReadBlockFromDisk(this, getForRemoval);
     }
     return(currentDataBlock);
 }
Пример #2
0
        /// <summary>
        /// Clear contents of this Collection.
        /// Changes will be saved right after clearing the contents.
        /// </summary>
        public virtual void Clear()
        {
            if (HeaderData.OccupiedBlocksHead != null && HeaderData.OccupiedBlocksTail != null)
            {
                HeaderData.DiskBuffer.IsDirty              = true;
                HeaderData.OccupiedBlocksTail.DataAddress  =
                    HeaderData.NextAllocatableAddress      =
                        HeaderData.StartAllocatableAddress = HeaderData.OccupiedBlocksHead.DataAddress;

                int segmentSize = File.GetSegmentSize();
                if (HeaderData.OccupiedBlocksHead.DataAddress + segmentSize != HeaderData.EndAllocatableAddress)
                {
                    //**** add to File.DeletedCollections the next _region for reuse...
                    //** read next segment of deleted collection
                    var           dbi = new DeletedBlockInfo();
                    Sop.DataBlock db;
                    db = DataBlockDriver.ReadBlockFromDisk(this,
                                                           HeaderData.OccupiedBlocksHead.DataAddress + segmentSize -
                                                           (int)File.DataBlockSize, true);
                    if (db.InternalNextBlockAddress >= 0)
                    {
                        dbi.StartBlockAddress = db.InternalNextBlockAddress;
                        dbi.EndBlockAddress   = db.InternalNextBlockAddress + segmentSize;

                        if (File.DeletedCollections != null)
                        {
                            bool oc = ((CollectionOnDisk)File.DeletedCollections).ChangeRegistry;
                            ((CollectionOnDisk)File.DeletedCollections).ChangeRegistry = ChangeRegistry;
                            File.DeletedCollections.Add(dbi);
                            ((CollectionOnDisk)File.DeletedCollections).ChangeRegistry = oc;
                        }

                        HeaderData.EndAllocatableAddress = HeaderData.OccupiedBlocksHead.DataAddress + segmentSize;
                    }
                }
            }
            HeaderData.Count = 0;
            if (HeaderData.diskBuffer != null)
            {
                HeaderData.diskBuffer.ClearData();
            }
            if (deletedBlocks != null)
            {
                deletedBlocks.Clear();
            }
            //if (MruManager != null)
            //    MruManager.Clear();
            //if (this.DataBlockDriver != null)
            //    this.DataBlockDriver.MruManager.Clear();
            //Blocks.Clear();
            currentDataBlock         = null;
            currentEntry             = null;
            _currentEntryDataAddress = -1;
            RegisterChange();
            Flush();
        }
Пример #3
0
        /// <summary>
        /// Add 'Value' to the Collection
        /// </summary>
        public long Add(object value)
        {
            var o = new LinkedItemOnDisk(this.DataBlockSize)
            {
                Data = value
            };

            WriteToDisk(o, false);
            UpdateCount(UpdateCountType.Increment);
            //*** update Current, Last & First
            if (LastItem.DiskBuffer.DataAddress != -1)
            {
                o.PreviousItemAddress = LastItem.DiskBuffer.DataAddress;
                WriteToDisk(o, false);
                LinkedItemOnDisk biod = CurrentItem;
                biod.NextItemAddress = o.DiskBuffer.DataAddress;
                Sop.DataBlock db = DataBlockDriver.ReadBlockFromDisk(this, LastItem.DiskBuffer.DataAddress, true);
                if (CurrentItem.DiskBuffer.DataAddress != LastItem.DiskBuffer.DataAddress)
                {
                    biod = (LinkedItemOnDisk)ReadFromBlock(db);
                    biod.NextItemAddress = o.DiskBuffer.DataAddress;
                }
                else
                {
                    PurifyMeta(biod, db);
                    if (db.SizeOccupied > 0)
                    {
                        biod.DiskBuffer = db;
                    }
                }
                WriteToDisk(biod, false);
            }
            else
            {
                FirstItem.DiskBuffer.DataAddress = o.DiskBuffer.DataAddress;
            }

            currentEntry                    = null;
            CurrentItem                     = o;
            CurrentEntryDataAddress         = o.DiskBuffer.DataAddress;
            currentDataBlock                = o.DiskBuffer;
            LastItem.DiskBuffer.DataAddress = o.DiskBuffer.DataAddress;

            MruManager.Add(CurrentEntryDataAddress, o);

            //** update the header
            RegisterChange(true);
            //IsDirty = true;

            return(o.DiskBuffer.DataAddress);
        }
Пример #4
0
 /// <summary>
 /// MoveFirst makes the first entry in the Collection the current one
 /// </summary>
 public override bool MoveFirst()
 {
     if (Count > 0 && CurrentItem != null)
     {
         if (FirstItem.DiskBuffer.DataAddress != CurrentEntryDataAddress ||
             FirstItem.DiskBuffer.DataAddress != CurrentItem.DiskBuffer.DataAddress)
         {
             CurrentEntryDataAddress = -1;
             this.DataBlockDriver.MoveTo(this, FirstItem.DiskBuffer.DataAddress);
             Sop.DataBlock db = DataBlockDriver.ReadBlockFromDisk(this, FirstItem.DiskBuffer.DataAddress, false);
             this.currentDataBlock = db;
             CurrentItem           = (LinkedItemOnDisk)ReadFromBlock(db);
         }
         return(true);
     }
     return(false);
 }
Пример #5
0
 /// <summary>
 /// OnRead gets called to read Object from Disk
 /// </summary>
 /// <param name="address">Address of Object on disk</param>
 /// <returns></returns>
 protected internal virtual object OnRead(long address)
 {
     //** read Node including Keys
     Sop.DataBlock d = DataBlockDriver.ReadBlockFromDisk(this, address, false);
     return(ReadFromBlock(d));
 }