예제 #1
0
 public StoredItem(uint magic, T item, DiskBlockPos position)
 {
     _BlockPosition   = position;
     _Item            = item;
     _Header.Magic    = magic;
     _Header.ItemSize = (uint)item.GetSerializedSize();
 }
예제 #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="headersOnly"></param>
        /// <param name="blockStart">Inclusive block count</param>
        /// <param name="blockEnd">Exclusive block count</param>
        /// <returns></returns>
        public IEnumerable <StoredBlock> Enumerate(bool headersOnly, int blockCountStart, int count = 999999999)
        {
            int          blockCount = 0;
            DiskBlockPos start      = null;

            foreach (var block in Enumerate(true, null))
            {
                if (blockCount == blockCountStart)
                {
                    start = block.BlockPosition;
                }
                blockCount++;
            }
            if (start == null)
            {
                yield break;
            }


            int i = 0;

            foreach (var result in Enumerate(headersOnly, new DiskBlockPosRange(start)))
            {
                if (i >= count)
                {
                    break;
                }
                yield return(result);

                i++;
            }
        }
예제 #3
0
        protected override StoredBlock ReadStoredItem(Stream stream, DiskBlockPos pos)
        {
            StoredBlock block = new StoredBlock(Network, pos);

            block.ParseSkipBlockContent = headerOnly;
            block.ReadWrite(stream, false);
            return(block);
        }
예제 #4
0
 protected DiskBlockPos SeekEnd(FileLock @lock)
 {
     if (_last != null)
     {
         return(_last);
     }
     _last = SeekEnd();
     return(_last);
 }
예제 #5
0
        protected override StoredItem <BlockUndo> CreateStoredItem(BlockUndo item, DiskBlockPos position)
        {
            var stored = new StoredItem <BlockUndo>(Network.Magic, item, position);

            stored.HasChecksum = true;
            if (item.CalculatedChecksum == null)
            {
                throw new InvalidOperationException("A block undo should have an calculated checksum with ComputeChecksum");
            }
            stored.Checksum = item.CalculatedChecksum;
            return(stored);
        }
예제 #6
0
 public DiskBlockPos Append(TItem item)
 {
     using (var @lock = CreateLock(FileLockType.ReadWrite))
     {
         DiskBlockPos position = SeekEnd(@lock);
         if (position.Position > MaxFileSize)
         {
             position = new DiskBlockPos(position.File + 1, 0);
         }
         var stored = CreateStoredItem(item, position);
         Write(stored);
         position = new DiskBlockPos(position.File, position.Position + stored.GetStorageSize());
         _last    = position;
         return(stored.BlockPosition);
     }
 }
예제 #7
0
 /// <summary>
 /// Represent a disk block range
 /// </summary>
 /// <param name="begin">Beginning of the range (included)</param>
 /// <param name="end">End of the range (excluded)</param>
 public DiskBlockPosRange(DiskBlockPos begin = null, DiskBlockPos end = null)
 {
     if (begin == null)
     {
         begin = DiskBlockPos.Begin;
     }
     if (end == null)
     {
         end = DiskBlockPos.End;
     }
     _Begin = begin;
     _End   = end;
     if (end <= begin)
     {
         throw new ArgumentException("End should be more than begin");
     }
 }
예제 #8
0
 protected abstract TStoredItem ReadStoredItem(Stream stream, DiskBlockPos pos);
예제 #9
0
 protected abstract TStoredItem CreateStoredItem(TItem item, DiskBlockPos position);
예제 #10
0
        protected override StoredItem <BlockUndo> ReadStoredItem(System.IO.Stream stream, DiskBlockPos pos)
        {
            StoredItem <BlockUndo> item = new StoredItem <BlockUndo>(Network, pos);

            item.HasChecksum = true;
            item.ReadWrite(stream, false);
            item.Item.CalculatedChecksum = item.Checksum;
            return(item);
        }
예제 #11
0
 protected override StoredBlock CreateStoredItem(Block item, DiskBlockPos position)
 {
     return(new StoredBlock(Network.Magic, item, position));
 }
예제 #12
0
 public StoredItem(Network expectedNetwork, DiskBlockPos position)
 {
     _Header        = new StoredHeader(expectedNetwork);
     _BlockPosition = position;
 }
예제 #13
0
 public bool InRange(DiskBlockPos pos)
 {
     return(Begin <= pos && pos < End);
 }
예제 #14
0
 public StoredBlock(uint magic, Block block, DiskBlockPos blockPosition)
     : base(magic, block, blockPosition)
 {
 }
예제 #15
0
 public StoredBlock(Network expectedNetwork, DiskBlockPos position)
     : base(expectedNetwork, position)
 {
 }