Example #1
0
        public override bool GetPiece(int index, int begin, byte[] piece)
        {
            bool          isFind      = false;
            int           pieceLength = piece.Length;
            bool          doIHave;
            ActiveRequest newRequest = new ActiveRequest(index, begin, pieceLength);

            foreach (ActiveRequest request in requests)
            {
                if (request.Equals(newRequest))
                {
                    requests.Remove(request);
                    isFind = true;
                    break;
                }
            }

            if (!isFind)
            {
                return(false);
            }
            last = DateTime.Now;
            measure.UpdateRate(pieceLength);

            if (downloader.MeasureFunction != null)
            {
                downloader.MeasureFunction(pieceLength);
            }

            downloader.DownloadMeasure.UpdateRate(pieceLength);
            downloader.StorageWrapper.PieceCameIn(index, begin, piece);

            doIHave = downloader.StorageWrapper.DoIHave(index);
            if (doIHave)
            {
                downloader.PiecePicker.Complete(index);
            }
            this.FixDownload();
            return(doIHave);
        }