private void downloadDataReceived(DownloadDataReceivedEventArgs args)
        {
            var  download       = args.Download;
            var  count          = args.Count;
            var  data           = args.Data;
            long previousOffset = 0;

            lock (this.monitor)
            {
                if (this.currentDownload == download)
                {
                    if (this.DoStopIfNecessary())
                    {
                        return;
                    }

                    previousOffset = this.currentOffset;

                    this.lastHeartbeat   = DateTime.Now;
                    this.currentOffset  += count;
                    this.sumOfBytesRead += count;
                }
            }

            this.OnDataReceived(new DownloadDataReceivedEventArgs(this, data, previousOffset, count));
        }
Example #2
0
 protected virtual void OnDataReceived(DownloadDataReceivedEventArgs args)
 {
     if (this.DataReceived != null)
     {
         this.DataReceived(args);
     }
 }
 private void downloadDataReceived(DownloadDataReceivedEventArgs args)
 {
     lock (this.monitor)
     {
         this.WriteToFile(args.Data, args.Offset, args.Count);
     }
 }
Example #4
0
        private void downloadDataReceived(DownloadDataReceivedEventArgs args)
        {
            this.AddSample(args.Count);
            var waitingTime = this.CalculateWaitingTime();

            if (waitingTime > 0)
            {
                Thread.Sleep(waitingTime);
            }
        }
Example #5
0
        private void OnDownloadDataReceived(DownloadDataReceivedEventArgs args)
        {
            lock (this.monitor)
            {
                if (!alreadyDownloadedSizes.ContainsKey(args.Download))
                {
                    this.alreadyDownloadedSizes[args.Download] = 0;
                }

                this.alreadyDownloadedSizes[args.Download] += args.Count;
            }
        }
        private void downloadDataReceived(DownloadDataReceivedEventArgs args)
        {
            var offset = args.Offset;
            var count  = args.Count;
            var data   = args.Data;

            lock (this.monitor)
            {
                var justDownloadedRange = new DownloadRange(offset, count);

                var todoRange = this.ToDoRanges.Single(r => downloadRangeHelper.RangesCollide(r, justDownloadedRange));
                this.ToDoRanges.Remove(todoRange);
                var differences = downloadRangeHelper.RangeDifference(todoRange, justDownloadedRange);
                this.ToDoRanges.AddRange(differences);

                var alreadyDoneRange = this.AlreadyDownloadedRanges.FirstOrDefault(r => r.End + 1 == justDownloadedRange.Start);

                if (alreadyDoneRange == null)
                {
                    alreadyDoneRange = justDownloadedRange;
                    this.AlreadyDownloadedRanges.Add(alreadyDoneRange);
                }
                else
                {
                    alreadyDoneRange.Length += justDownloadedRange.Length;
                }

                var neighborRange = this.AlreadyDownloadedRanges.FirstOrDefault(r => r.Start == alreadyDoneRange.End + 1);

                if (neighborRange != null)
                {
                    this.AlreadyDownloadedRanges.Remove(alreadyDoneRange);
                    this.AlreadyDownloadedRanges.Remove(neighborRange);
                    var combinedRange = new DownloadRange(alreadyDoneRange.Start, alreadyDoneRange.Length + neighborRange.Length);
                    this.AlreadyDownloadedRanges.Add(combinedRange);
                }
            }

            this.OnDataReceived(new DownloadDataReceivedEventArgs(this, data, offset, count));
        }
 private void downloadDataReceived(DownloadDataReceivedEventArgs args)
 {
     AddSample(args.Count);
 }