Пример #1
0
        private int CalculateDataBlockNodeSize()
        {
            using var memStream = new MemoryStream();
            var dataBlock = new DataBlockNode(0, 0, 1);

            ZeroFormatterSerializer.Serialize(memStream, dataBlock);
            return(metaInfDataStorage.DataBlockSize - (int)memStream.Length + 1);
        }
Пример #2
0
 public void SaveDataBlock(DataBlockNode block, int offset)
 {
     _fileStream.Seek(offset, SeekOrigin.Begin);
     //using var memStream = new MemoryStream();
     block = new DataBlockNode(block);
     ZeroFormatterSerializer.Serialize(_fileStream, block);
     //memStream.CopyTo(fs);
     _fileStream.Flush(true);
     writeCount++;
 }
Пример #3
0
        public DataBlockNode(DataBlockNode from)
        {
            if (from is null)
            {
                throw new ArgumentNullException(nameof(from));
            }

            CountRealRecords       = from.CountRealRecords;
            CountNotDeletedRecords = from.CountNotDeletedRecords;
            NextBlock = from.NextBlock;
            PrevBlock = from.PrevBlock;
            Data      = from.Data;
        }
Пример #4
0
        public void CreateAndAddDataBlock()
        {
            var           metaInf = metaInfDataStorage;
            DataBlockNode newBlock;

            if (metaInf.HeadDataBlockList != 0)
            {
                var prevBlock = LoadDataBlock(metaInf.HeadDataBlockList);
                newBlock = new DataBlockNode(0, metaInf.HeadDataBlockList, CalculateDataBlockNodeSize());
                metaInf.HeadDataBlockList = (int)_fileStream.Seek(-GetCalculateMetaInfDataStorageSize(), SeekOrigin.End);
                prevBlock.PrevBlock       = metaInf.HeadDataBlockList;
                SaveDataBlock(prevBlock, newBlock.NextBlock);
            }
            else
            {
                newBlock = new DataBlockNode(0, 0, CalculateDataBlockNodeSize());
                metaInf.HeadDataBlockList = (int)_fileStream.Seek(-GetCalculateMetaInfDataStorageSize(), SeekOrigin.End);
            }

            SaveDataBlock(newBlock, metaInf.HeadDataBlockList);
            CreateMetaInfInEnd(metaInf);
        }
Пример #5
0
        public void DeleteBlock(DataBlockNode block)
        {
            var nextBlock   = LoadDataBlock(block.NextBlock);
            var prevBlock   = LoadDataBlock(block.PrevBlock);
            var curBlockOff = prevBlock == null ? metaInfDataStorage.HeadDataBlockList : prevBlock.NextBlock;

            if (nextBlock != null)
            {
                nextBlock.PrevBlock = block.PrevBlock;
                SaveDataBlock(nextBlock, block.NextBlock);
            }

            if (prevBlock != null)
            {
                prevBlock.NextBlock = block.NextBlock;
                SaveDataBlock(prevBlock, block.PrevBlock);
            }
            else
            {
                metaInfDataStorage.HeadDataBlockList = block.NextBlock;
            }

            if (metaInfDataStorage.HeadFreeBlockList == 0)
            {
                metaInfDataStorage.HeadFreeBlockList = curBlockOff;
                block = new DataBlockNode(0, 0, CalculateDataBlockNodeSize());
            }
            else
            {
                var prevDelBlock = LoadDataBlock(metaInfDataStorage.HeadFreeBlockList);
                block = new DataBlockNode(0, metaInfDataStorage.HeadFreeBlockList, CalculateDataBlockNodeSize());
                metaInfDataStorage.HeadFreeBlockList = curBlockOff;
                prevDelBlock.PrevBlock = metaInfDataStorage.HeadFreeBlockList;
                SaveDataBlock(prevDelBlock, block.NextBlock);
            }

            SaveDataBlock(block, metaInfDataStorage.HeadFreeBlockList);
            SaveMetaInfStorage(metaInfDataStorage);
        }
Пример #6
0
 public RecordsInDataBlockNodeEnumarator(DataBlockNode dataBlock, int recordSize)
 {
     _dataBlock  = dataBlock;
     _recordSize = recordSize;
     Reset();
 }