예제 #1
0
 /// <summary>
 /// 读取或写入区块
 /// </summary>
 /// <param name="BlockIndex">区块序号</param>
 public FileBlock this[int BlockIndex]
 {
     get
     {
         FileBlock output;
         if (_EnabledIOBuffer)
         {
             bool IsInBuf;
             lock (_IOBuffer)
                 IsInBuf = _IOBuffer.TryGetValue(BlockIndex, out output);
             if (IsInBuf)
             {
                 return(output);
             }
             else
             {
                 output = new FileBlock(_task, BlockIndex, true);
                 BeginFillIOBuffer(BlockIndex + 1, null, null);
             }
         }
         else
         {
             output = new FileBlock(_task, BlockIndex, true);
         }
         return(output);
     }
     set
     {
         if (BlockIndex != value.Index)
         {
             throw new FileBlockException("Bad Index!", FileBlockException.ErrorCode.BadIndex);
         }
         Write(value);
     }
 }
예제 #2
0
 /// <summary>
 /// 写入区块
 /// </summary>
 /// <param name="value">区块对象</param>
 public void Write(FileBlock value)
 {
     if (_EnabledIOBuffer)
     {
         if (_IOBuffer.Count >= _IOBufferSize)
         {
             WriteAllBlock();
         }
         lock (_IOBuffer)
             _IOBuffer.Add(value.Index, value);
     }
     else
     {
         value.Write();
     }
 }