Пример #1
0
        /// <summary>
        /// Tells if the area is in cache
        /// </summary>
        /// <param name="start">start file position in bytes</param>
        /// <param name="length">area length in bytes</param>
        /// <returns></returns>
        public bool IsAreaCached(long start, long length)
        {
            if (Complete)
            {
                return(true);
            }

            if (length < 0)
            {
                throw new ArgumentException("length could not be less than zero");
            }

            if (start < 0)
            {
                throw new ArgumentException("start could not be less than zero");
            }

            if (start + length > Magnet.Size)
            {
                throw new ArgumentException("The area is out of file space");
            }

            var ind   = DownloadItem.GetSegmentIndex(start, SegmentLength);
            var total = DownloadItem.SegmentsCount(length, SegmentLength);

            return(CachedSegments.FirstFalse(ind, total) == -1);
        }
Пример #2
0
        public List <ISnapSegment> FindOrCacheSegments(SceneObject so)
        {
            if (enable_snap_segments == false)
            {
                return(null);
            }
            if (SegmentsCache.ContainsKey(so))
            {
                CachedSegments c = SegmentsCache[so];
                if (c.timestamp == so.Timestamp)
                {
                    return(c.segments);
                }

                // un-cache
                if (c.segments != null)
                {
                    foreach (ISnapSegment pt in c.segments)
                    {
                        pt.Destroy();
                    }
                }
                SegmentsCache.Remove(so);
            }

            List <ISnapSegment> vSegments = null;

            foreach (ISnapGenerator gen in Generators)
            {
                if (gen.CanGenerate(so))
                {
                    List <ISnapSegment> v = gen.GenerateSegments(so);
                    if (v != null && v.Count > 0)
                    {
                        if (vSegments == null)
                        {
                            vSegments = v;
                        }
                        else
                        {
                            vSegments.AddRange(v);
                        }
                    }
                }
            }

            SegmentsCache[so] = new CachedSegments()
            {
                segments = vSegments, timestamp = so.Timestamp
            };
            return(vSegments);
        }