Ejemplo n.º 1
0
            public bool Merge(DirtyRange range)
            {
                DirtyRange r = this;

                if (range.Start <= Start + Length &&
                    Start <= range.Start + range.Length)
                {
                    int end = Math.Max(Start + Length, range.Start + range.Length);
                    Start  = Math.Min(Start, range.Start);
                    Length = end - Start;
                    return(true);
                }
                return(false);
            }
Ejemplo n.º 2
0
            public bool Merge(DirtyRange range)
            {
                DirtyRange r = this;

                if (range.start <= start + length &&
                    start <= range.start + range.length)
                {
                    int end = Math.Max(this.start + this.length, range.start + range.length);
                    this.start  = Math.Min(this.start, range.start);
                    this.length = end - this.start;
                    return(true);
                }
                return(false);
            }
Ejemplo n.º 3
0
        public void AddDirtyRange(int startIndex, int count, Type sourceType, bool fillEntireRange)
        {
            if ((startIndex < 0 || count <= 0) && !fillEntireRange)
            {
                throw new ArgumentException("Invalid range specified");
            }

            IEnumerable <DataType> data = _data;

            //if (data == null)
            //    throw new InvalidOperationException("Cannot set a dirty region when source data has been garbage collected");

            _isList = true;

            if (data is IList == false)
            {
                if (data is ICollection == false || !(startIndex == 0 && count == (data as ICollection).Count && !fillEntireRange))
                {
                    if (!(data is ICollection == false && data is IEnumerable && fillEntireRange))
                    {
                        throw new InvalidOperationException(sourceType.Name + "<" + sourceType.GetGenericArguments()[0].Name + "> source data must implement the IList<" + sourceType.GetGenericArguments()[0].Name + "> interface to set a dirty subrange");
                    }
                }
                else
                {
                    if (data is ICollection && (startIndex == 0 && count == (data as ICollection).Count))
                    {
                        fillEntireRange = true;
                    }
                }
                _isList = false;
            }

            IList dataList = data as IList;

            if (!fillEntireRange && ((startIndex + count) > dataList.Count))
            {
                throw new ArgumentException("Invalid range specified");
            }

            if (_dirtyRanges == null)
            {
                _dirtyRanges = new List <DirtyRange>();
            }

            if (fillEntireRange)
            {
                _dirtyRanges.Clear();
                if (data is ICollection)
                {
                    _dirtyRanges.Add(new DirtyRange(0, (data as ICollection).Count));
                }
                else
                {
                    _dirtyRanges.Add(new DirtyRange(0, -1));//special case as length is not yet known
                }
            }
            else
            {
                DirtyRange range = new DirtyRange(startIndex, count);

                for (int i = 0; i < _dirtyRanges.Count; i++)
                {
                    if (_dirtyRanges[i].Merge(range))
                    {
                        return;
                    }
                }

                _dirtyRanges.Add(range);
            }
        }