Example #1
0
 public BlockWriteState Init(BlockWrittenDelegate callback, int remaining, Block block, object state)
 {
     Callback  = callback;
     State     = state;
     Remaining = remaining;
     Block     = block;
     return(this);
 }
Example #2
0
 public void AddBlock(Block block, BlockWrittenDelegate callback, object state)
 {
     try
     {
         var parts    = GetParts(block.Info.Index, block.Info.Offset, block.Info.Length, true);
         var totalLen = parts.Sum(p => p.Length);
         var data     = _writeCache.Get().Init(callback, (int)totalLen, block, state);
         //Console.WriteLine(parts.Any());
         foreach (var part in parts)
         {
             DiskIo.QueueWrite(part.FileStream, block.Data, part.FileOffset, part.DataOffset, part.Length,
                               EndAddBlock, data);
         }
     }
     catch (Exception e)
     {
         OnRaisedException(new TorrentException(e.Message, e));
         callback(false, state);
     }
 }
Example #3
0
 public void AddBlock(Block block, BlockWrittenDelegate callback, object state)
 {
     try
     {
         IEnumerable<BlockPartInfo> parts = GetParts(block.Info.Index, block.Info.Offset, block.Info.Length, true);
         var totalLen = parts.Sum(p => p.Length);
         BlockWriteState data = writeCache.Get().Init(callback, (int)totalLen, block, state);
         Trace.Assert(parts.Any());
         foreach(BlockPartInfo part in parts)
         {
             DiskIO.QueueWrite(part.FileStream, block.Data, part.FileOffset, part.DataOffset, part.Length,
                               EndAddBlock, data);
         }
     }
     catch(Exception e)
     {
         OnRaisedException(new TorrentException(e.Message, e));
         callback(false, state);
     }
 }
Example #4
0
 public void AddBlock(Block block, BlockWrittenDelegate callback, object state)
 {
     try
     {
         IEnumerable <BlockPartInfo> parts = GetParts(block.Info.Index, block.Info.Offset, block.Info.Length, true);
         var             totalLen          = parts.Sum(p => p.Length);
         BlockWriteState data = writeCache.Get().Init(callback, (int)totalLen, block, state);
         Trace.Assert(parts.Any());
         foreach (BlockPartInfo part in parts)
         {
             DiskIO.QueueWrite(part.FileStream, block.Data, part.FileOffset, part.DataOffset, part.Length,
                               EndAddBlock, data);
         }
     }
     catch (Exception e)
     {
         OnRaisedException(new TorrentException(e.Message, e));
         callback(false, state);
     }
 }
Example #5
0
 public BlockWriteState Init(BlockWrittenDelegate callback, int remaining, Block block, object state)
 {
     Callback = callback;
     State = state;
     Remaining = remaining;
     Block = block;
     return this;
 }