Exemplo n.º 1
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++;
            }
        }
Exemplo n.º 2
0
 public StoredItem(uint magic, T item, DiskBlockPos position)
 {
     _BlockPosition   = position;
     _Item            = item;
     _Header.Magic    = magic;
     _Header.ItemSize = (uint)item.GetSerializedSize();
 }
Exemplo n.º 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);
        }
Exemplo n.º 4
0
 protected DiskBlockPos SeekEnd(FileLock @lock)
 {
     if (_last != null)
     {
         return(_last);
     }
     _last = SeekEnd();
     return(_last);
 }
Exemplo n.º 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);
        }
Exemplo n.º 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);
     }
 }
Exemplo n.º 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");
     }
 }
Exemplo n.º 8
0
 public StoredItem(Network expectedNetwork, DiskBlockPos position)
 {
     _Header        = new StoredHeader(expectedNetwork);
     _BlockPosition = position;
 }
Exemplo n.º 9
0
 protected override StoredBlock CreateStoredItem(Block item, DiskBlockPos position)
 {
     return(new StoredBlock(Network.Magic, item, position));
 }
Exemplo n.º 10
0
 public bool InRange(DiskBlockPos pos)
 {
     return(Begin <= pos && pos < End);
 }
Exemplo n.º 11
0
 public StoredBlock(uint magic, Block block, DiskBlockPos blockPosition)
     : base(magic, block, blockPosition)
 {
 }
Exemplo n.º 12
0
 public StoredBlock(Network expectedNetwork, DiskBlockPos position)
     : base(expectedNetwork, position)
 {
 }
Exemplo n.º 13
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);
        }
Exemplo n.º 14
0
 protected abstract TStoredItem ReadStoredItem(Stream stream, DiskBlockPos pos);
Exemplo n.º 15
0
 protected abstract TStoredItem CreateStoredItem(TItem item, DiskBlockPos position);