示例#1
0
        public StoredItem(Network expectedNetwork, DiskBlockPos position)
        {
#pragma warning disable CS0612 // Type or member is obsolete
            _Header = new StoredHeader(expectedNetwork);
#pragma warning restore CS0612 // Type or member is obsolete
            _BlockPosition = position;
        }
示例#2
0
 public StoredItem(uint magic, T item, DiskBlockPos position)
 {
     _BlockPosition   = position;
     _Item            = item;
     _Header.Magic    = magic;
     _Header.ItemSize = (uint)item.GetSerializedSize();
 }
示例#3
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;

#pragma warning disable CS0612 // Type or member is obsolete
            foreach (var result in Enumerate(headersOnly, new DiskBlockPosRange(start)))
#pragma warning restore CS0612 // Type or member is obsolete
            {
                if (i >= count)
                {
                    break;
                }
                yield return(result);

                i++;
            }
        }
示例#4
0
        protected override StoredBlock ReadStoredItem(Stream stream, DiskBlockPos pos)
        {
            StoredBlock block = new StoredBlock(Network, pos);

            block.ParseSkipBlockContent = headerOnly;
            block.ReadWrite(stream, false);
            return(block);
        }
示例#5
0
 protected DiskBlockPos SeekEnd(FileLock @lock)
 {
     if (_last != null)
     {
         return(_last);
     }
     _last = SeekEnd();
     return(_last);
 }
        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);
        }
示例#7
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);
     }
 }
示例#8
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");
     }
 }
        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);
        }
示例#10
0
 protected abstract TStoredItem ReadStoredItem(Stream stream, DiskBlockPos pos);
示例#11
0
 protected abstract TStoredItem CreateStoredItem(TItem item, DiskBlockPos position);
示例#12
0
 public bool InRange(DiskBlockPos pos)
 {
     return(Begin <= pos && pos < End);
 }
示例#13
0
 public StoredBlock(uint magic, Block block, DiskBlockPos blockPosition)
     : base(magic, block, blockPosition)
 {
 }
示例#14
0
 public StoredBlock(Network expectedNetwork, DiskBlockPos position)
     : base(expectedNetwork, position)
 {
 }
示例#15
0
 protected override StoredBlock CreateStoredItem(Block item, DiskBlockPos position)
 {
     return(new StoredBlock(Network.Magic, item, position));
 }