Exemple #1
0
        private bool ReadToStream(Stream stream)
        {
            var e = new DownloadProgressArgs {Size = Length};

            var buffer = new byte[BufferSize];
            using (Stream responseStream = _response.GetResponseStream())
            {
                if (responseStream == null) return false;

                do
                {
                    if (_cancellationPending)
                        break;

                    _bytesRead = responseStream.Read(buffer, 0, buffer.Length);
                    stream.Write(buffer, 0, (int) _bytesRead);
                    _bytesWritten += _bytesRead;
                    e.BytesRead = _bytesRead;
                    e.BytesWritten = _bytesWritten;
                    e.PercentComplete = (_bytesWritten / (float) Length - _rangeFrom) * 100f;
                    OnDownloadProgress(e);
                }
                while (_bytesRead > 0L);
            }
            return true;
        }
Exemple #2
0
 private void DownloaderProgress(object sender, DownloadProgressArgs e)
 {
     Trace.WriteLine(e.PercentComplete);
 }
Exemple #3
0
 private void OnDownloadProgress(DownloadProgressArgs e)
 {
     if (DownloadProgress != null)
     {
         DownloadProgress(this, e);
     }
 }