コード例 #1
0
 private void AnySegmentProgressDisposed(SegmentProgress prog)
 {
     prog.ProgressChanged -= AnySegmentProgressChanged;
     prog.Disposed        -= AnySegmentProgressDisposed;
     lock (segmentProgressesLock)
     {
         segmentProgresses.Remove(prog);
         if (prog.DownloadedSize != 0)
         {
             coveredRanges.Add(new Range(
                                   prog.Offset, prog.Offset + prog.DownloadedSize));
         }
     }
 }
コード例 #2
0
        /// <summary>
        /// Create a SegmentProgress in this CompositeProgress.
        /// Dispose a SegmentProgress to remove it from CompositeProgress
        /// and stablize its downloaded range into previouslv covered ranges.
        ///
        /// See <see cref="CompositeProgress"/>.
        /// </summary>
        /// <param name="offset">Offset of the SegmentProgress created.</param>
        /// <param name="totalSize">TotalSize of the SegmentProgress created.</param>
        /// <returns>SegmentProgress created.</returns>
        public SegmentProgress NewSegmentProgress(long offset, long totalSize)
        {
            var targetRange = new Range(offset, offset + totalSize);
            var res         = new SegmentProgress(this, offset, totalSize);

            lock (segmentProgressesLock)
            {
                Ensure.That(coveredRanges.All(covered => !targetRange.IsIntersectWith(covered))).IsTrue();
                Ensure.That(segmentProgresses.All(progress => !targetRange.IsIntersectWith(new Range(progress.Offset, progress.Offset + progress.TotalSize)))).IsTrue();

                res.ProgressChanged += AnySegmentProgressChanged;
                res.Disposed        += AnySegmentProgressDisposed;
                segmentProgresses.Add(res);
            }

            return(res);
        }