/// <summary> /// Called when piece is requested. /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">The event arguments.</param> private void OnPieceRequested(object sender, PieceRequestedEventArgs e) { sender.CannotBeNull(); e.CannotBeNull(); if (this.PieceRequested != null) { this.PieceRequested(sender, e); } }
/// <summary> /// Gets the piece. /// </summary> /// <param name="pieceIndex">Index of the piece.</param> /// <returns>The piece.</returns> public Piece GetPiece(int pieceIndex) { pieceIndex.MustBeGreaterThanOrEqualTo(0); pieceIndex.MustBeLessThan(this.PieceCount); this.CheckIfObjectIsDisposed(); PieceRequestedEventArgs e = new PieceRequestedEventArgs(pieceIndex); this.OnPieceRequested(this, e); if (e.PieceData != null) { return(new Piece(pieceIndex, this.pieceHashes.ElementAt(pieceIndex), this.PieceLength, this.BlockLength, this.BlockCount)); } else { return(null); } }