Creating a custom PiecePicker
Example 1 Creating a picker to prioritise the first piece in a file

Example 1

 1 public class MyPicker : PiecePicker {
 2     public MyPicker (PiecePicker basePicker)
 3         : base (basePicker)
 4     {
 5 
 6     }
 7 
 8     public override MessageBundle PickPiece(PeerId id, BitField peerBitfield, List<PeerId> otherPeers, int count, int startIndex, int endIndex)
 9     {
10     // If we do not have the first piece and the other peer does have it
11         if (!HaveFirstPieceAlready && peerBitfield[0] == true) {
12             BitField bf = new BitField (peerBitfield.Length);
13             bf [0] = true;
14             MessageBundle msg = base.PickPiece (id, bf, otherPeers, count, startIndex, endIndex);
15             if (msg != null)
16                 return msg;
17         }
18         return base.PickPiece (id, peerBitfield, otherPeers, count, startIndex, endIndex);
19     }
20 }
21 
22 // This picker can then be added to the default picking pipeline by doing:
23 torrentManager.ChangePicker (new MyPicker (torrentManager.CreateDefaultPicker ()));