예제 #1
0
        internal static int SizeOfMetaData(IInternalPersistent parent)
        {
            if (parent == null)
            {
                throw new ArgumentNullException("parent");
            }
            if (!(parent is CollectionOnDisk))
            {
                throw new ArgumentException("Parent is not CollectionOnDisk type.");
            }

            if (Encoding != ((CollectionOnDisk)parent).File.Server.Encoding)
            {
                Encoding = ((CollectionOnDisk)parent).File.Server.Encoding;
                _sizeOf  = 0;
            }
            if (_sizeOf == 0)
            {
                var o = new LinkedItemOnDisk
                {
                    DiskBuffer = ((CollectionOnDisk)parent).DataBlockDriver.
                                 CreateBlock(((CollectionOnDisk)parent).File.DataBlockSize),
                    Data = new byte[0]
                };
                var w = new OnDiskBinaryWriter(Encoding)
                {
                    DataBlock = o.DiskBuffer
                };
                WritePersistentData(parent, o, w);
                _sizeOf = (int)w.BaseStream.Position;
                w.Close();
            }
            return(_sizeOf);
        }
예제 #2
0
 /// <summary>
 /// protected virtual dispose.
 /// Closes this Collection on disk, its deleted blocks and Mru Segments.
 /// Sets the data block driver to null.
 /// </summary>
 protected internal virtual void InternalDispose()
 {
     if (FileStream != null)
     {
         Close();
     }
     if (deletedBlocks != null)
     {
         deletedBlocks.Dispose();
         deletedBlocks = null;
     }
     Parent = null;
     if (DataBlockDriver != null)
     {
         if (!IsCloned)
         {
             DataBlockDriver.Dispose();
         }
         DataBlockDriver = null;
     }
     if (OnDiskBinaryReader != null)
     {
         OnDiskBinaryReader.Close();
         OnDiskBinaryReader = null;
     }
     if (OnDiskBinaryWriter != null)
     {
         OnDiskBinaryWriter.Close();
         OnDiskBinaryWriter = null;
     }
     _instanceTransaction     = null;
     _parentTransactionLogger = null;
     File = null;
 }
예제 #3
0
        /// <summary>
        /// protected virtual dispose.
        /// Closes this Collection on disk, its deleted blocks and Mru Segments.
        /// Sets the data block driver to null.
        /// </summary>
        protected internal virtual void InternalDispose()
        {
            // note: SOP's Dispose pattern is created to provide way to do early
            // garbage collection of the "graph" objects, simply. Not for freeing up unmanaged
            // resources, thus, no finalizer/SafeHandle "patterns". All members are "virtualized"
            // objects and they have custom Dispose for the same.
            if (isDisposed)
            {
                return;
            }
            isDisposed = true;
            // FileStream is a wrapper, not the .Net FileStream.
            if (FileStream != null)
            {
                Close();
            }
            if (deletedBlocks != null)
            {
                deletedBlocks.Dispose();
                deletedBlocks = null;
            }
            Parent = null;
            if (DataBlockDriver != null)
            {
                //if (!IsCloned)
                DataBlockDriver.Dispose();
                DataBlockDriver = null;
            }
            if (OnDiskBinaryReader != null)
            {
                OnDiskBinaryReader.Close();
                OnDiskBinaryReader = null;
            }
            if (OnDiskBinaryWriter != null)
            {
                OnDiskBinaryWriter.Close();
                OnDiskBinaryWriter = null;
            }
            _instanceTransaction     = null;
            _parentTransactionLogger = null;
            File   = null;
            Blocks = null;
            var locker = _syncRoot as IDisposable;

            if (locker != null)
            {
                locker.Dispose();
            }
        }
예제 #4
0
        public override void Close()
        {
            if (!IsOpen)
            {
                return;
            }
            base.Close();
            if (OnDiskBinaryWriter != null)
            {
                OnDiskBinaryWriter.Close();
                OnDiskBinaryWriter = null;
            }
            if (OnDiskBinaryReader != null)
            {
                OnDiskBinaryReader.Close();
                OnDiskBinaryReader = null;
            }

            FirstItem        = new LinkedItemOnDisk(File.DataBlockSize);
            this.CurrentItem = FirstItem;
            LastItem         = new LinkedItemOnDisk(File.DataBlockSize);
        }
예제 #5
0
        /// <summary>
        /// Close the Collection
        /// </summary>
        public virtual void Close()
        {
            bool miscCollsClosed = false;

            if (IsOpen)
            {
                if (!IsCloned)
                {
                    OnCommit();
                }
                if (IsDirty && !IsCloned && DataAddress >= 0 && Count > 0)
                {
                    Flush();
                }
                if (deletedBlocks != null)
                {
                    deletedBlocks.Close();
                }
                miscCollsClosed = true;
                if (DataBlockDriver != null)
                {
                    if (!IsCloned)
                    {
                        //DataBlocksPool.RemoveFromPool(this.DataBlockDriver.MruManager);
                        //this.DataBlockDriver.MruManager.Clear();
                        DataBlockDriver.HeaderData.Clear();
                    }
                }
                if (Parent == null)
                {
                    if (OnDiskBinaryWriter != null)
                    {
                        OnDiskBinaryWriter.Close();
                        OnDiskBinaryWriter = null;
                    }
                    if (OnDiskBinaryReader != null)
                    {
                        OnDiskBinaryReader.Close();
                        OnDiskBinaryReader = null;
                    }
                }
                if (Blocks != null)
                {
                    Blocks.Clear();
                }
                currentDataBlock         = null;
                currentEntry             = null;
                _currentEntryDataAddress = -1;
                isOpen = false;
            }
            if (_fileStream != null)
            {
                _fileStream.Close();
                _fileStream = null;
            }
            if (!miscCollsClosed)
            {
                if (deletedBlocks != null)
                {
                    deletedBlocks.Close();
                }
            }
            if (_isUnloading)
            {
                _isUnloading = false;
            }
            long da = DiskBuffer.DataAddress;

            DiskBuffer.Initialize();
            DiskBuffer.DataAddress = da;
        }