示例#1
0
        /// <summary>
        /// Determines was all the segments from range been downloaded
        /// </summary>
        /// <param name="startPos">File position from wich bytes should be read</param>
        /// <param name="count"></param>
        /// <param name="makeRequest">If true the not-finished segments will be marked as High-Priority segments</param>
        /// <returns></returns>
        protected bool CanRead(long startPos, int count, bool makeRequest = true)
        {
            if (!StorageContainer.Available)
            {
                return(false);
            }

            var startIndex = GetSegmentIndex(startPos, SegmentLength);
            var endIndex   = GetSegmentIndex(startPos + count - 1, SegmentLength);

            lock (SyncRoot)
            {
                for (int i = startIndex; i <= endIndex; i++)
                {
                    if (!StorageContainer.CanReadSegment(i) || !_downloadedSegments[i])
                    {
                        if (makeRequest)
                        {
                            if (!HighPrioritySegments.Contains(i))
                            {
                                Logger.Info("Add high priority segment {0}", i);
                                HighPrioritySegments.Add(i);
                            }
                        }
                        return(false);
                    }
                }
                return(true);
            }
        }