Пример #1
0
 private void downloadDataReceived(DownloadDataReceivedEventArgs args)
 {
     lock (this.monitor)
     {
         this.WriteToFile(args.Data, args.Offset, args.Count);
     }
 }
Пример #2
0
        private void downloadDataReceived(DownloadDataReceivedEventArgs args)
        {
            var download = args.Download;
            var count = args.Count;
            var data = args.Data;
            int 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));
        }
Пример #3
0
        private void downloadDataReceived(DownloadDataReceivedEventArgs args)
        {
            this.AddSample(args.Count);
            var waitingTime = this.CalculateWaitingTime();

            if (waitingTime > 0)
            {
                Thread.Sleep(waitingTime);
            }
        }
Пример #4
0
 private void downloadDataReceived(DownloadDataReceivedEventArgs args)
 {
     AddSample(args.Count);
 }
Пример #5
0
 protected virtual void OnDataReceived(DownloadDataReceivedEventArgs args)
 {
     if (this.DataReceived != null)
     {
         this.DataReceived(args);
     }
 }
Пример #6
0
        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));
        }