protected override void Dispose(bool disposing) { _db = null; _dir = null; _file = null; _file_block = null; }
private void ResetProperties() { // Reset properties. _buffer_position = 0; _buffer_start = 0; _buffer_length = 0; _block_index = -1; _file_block = null; }
protected override void Dispose(bool disposing) { if (_isDisposed) { return; } if (disposing) { Flush(); _db = null; _dir = null; _file = null; _file_block = null; } _isDisposed = true; }
private void SwitchBlock() { // Keep oldBlock DbFileBlock oldBlock = null; if (_file_block != null) { _file_block.ComputeSHA(); oldBlock = _file_block; } long maxBlock = _file.BlockSet.Count(); if (_block_index == maxBlock) { // Add a new block. DbFileBlock block = new DbFileBlock(_file.BufferSize); block.Order = _block_index; _file.BlockSet.Add(block); _file_block = block; _db.SaveChanges(); } else if (_block_index >= 0 && _block_index < maxBlock) { // Switch to existed block. _file_block = _file.BlockSet.SingleOrDefault(obj => obj.Order == _block_index); Debug.Assert(_file_block != null); } else { // throw new System.IO.IOException("Failed to write due to invalid file block index."); } // Reset buffer positions, buffer length, ... _buffer_start = _block_index * _file.BufferSize; _buffer_position = 0; _buffer_length = _file_block.Length; if (_file_block != oldBlock && oldBlock != null) { // Let GC have chance to free the memory space of oldBlock. //_db.Detach(oldBlock); oldBlock = null; } }
private void SwitchBlock(bool enforceEOF) { DbFileBlock oldBlock = null; if (_file_block != null) { oldBlock = _file_block; } long maxBlock = _file.BlockSet.Count(); if (_block_index >= maxBlock) { if (enforceEOF) { throw new System.IO.IOException("Read past EOF"); } else { _block_index -= 1; _buffer_length = _file.BufferSize; } } else { _file_block = _file.BlockSet.SingleOrDefault(obj => obj.Order == _block_index); _buffer_start = _block_index * _file.BufferSize; _buffer_position = 0; long bufLen = _file.Length - _buffer_start; _buffer_length = (bufLen > _file.BufferSize) ? _file.BufferSize : bufLen; } if (oldBlock != _file_block && oldBlock != null) { //_db.Detach(oldBlock); oldBlock = null; } }
public void TestDBSchema() { Guid guid = Guid.NewGuid(); using (DbFileContext db = new DbFileContext()) { DbDirectory dir = new DbDirectory() { Name = "a_dir_" + guid.ToString(), }; db.DirectorySet.Add(dir); DbFileInfo file = new DbFileInfo("a_file"); dir.FileSet.Add(file); DbFileBlock block = new DbFileBlock(100); byte[] bytes = Encoding.UTF8.GetBytes("Hello World"); Array.Copy(bytes, block.RawData, bytes.Length); file.BlockSet.Add(block); db.SaveChanges(); } }