/// <summary> /// Called when piece has completed. /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">The event arguments.</param> private void OnPieceCompleted(object sender, PieceCompletedEventArgs e) { sender.CannotBeNull(); e.CannotBeNull(); if (this.PieceCompleted != null) { this.PieceCompleted(sender, e); } }
/// <summary> /// Handles the Completed event of the Piece control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="PieceCompletedEventArgs"/> instance containing the event data.</param> private void Piece_Completed(object sender, PieceCompletedEventArgs e) { lock (this.locker) { // only pieces not yet downloaded can be checked in if (this.BitField[e.PieceIndex] == PieceStatus.Missing || this.BitField[e.PieceIndex] == PieceStatus.CheckedOut) { this.BitField[e.PieceIndex] = PieceStatus.Present; this.presentPiecesCount++; this.CompletedPercentage = (decimal)this.presentPiecesCount / (decimal)this.piecesCount; if (this.checkouts.ContainsKey(e.PieceIndex)) { this.checkouts.Remove(e.PieceIndex); } this.OnPieceCompleted(this, new PieceCompletedEventArgs(e.PieceIndex, e.PieceData)); } } }