예제 #1
0
            private IVirtualChangeSet <TObject, TKey> Virtualise(ISortedChangeSet <TObject, TKey> updates = null)
            {
                if (_isLoaded == false)
                {
                    return(null);
                }

                var previous   = _current;
                var virualised = _all.Skip(_parameters.StartIndex)
                                 .Take(_parameters.Size)
                                 .ToList();

                _current = new KeyValueCollection <TObject, TKey>(virualised, _all.Comparer, updates?.SortedItems.SortReason ?? SortReason.DataChanged, _all.Optimisations);

                ////check for changes within the current virtualised page.  Notify if there have been changes or if the overall count has changed
                var notifications = _changedCalculator.Calculate(_current, previous, updates);

                if (notifications.Count == 0 && (previous.Count != _current.Count))
                {
                    return(null);
                }

                var response = new VirtualResponse(_parameters.Size, _parameters.StartIndex, _all.Count);

                return(new VirtualChangeSet <TObject, TKey>(notifications, _current, response));
            }
예제 #2
0
            private IPagedChangeSet <TObject, TKey>?Paginate(ISortedChangeSet <TObject, TKey>?updates = null)
            {
                if (_isLoaded == false)
                {
                    return(null);
                }

                var previous = _current;

                int pages = CalculatePages();
                int page  = _request.Page > pages ? pages : _request.Page;
                int skip  = _request.Size * (page - 1);

                var paged = _all.Skip(skip).Take(_request.Size).ToList();

                _current = new KeyValueCollection <TObject, TKey>(paged, _all.Comparer, updates?.SortedItems.SortReason ?? SortReason.DataChanged, _all.Optimisations);

                // check for changes within the current virtualised page.  Notify if there have been changes or if the overall count has changed
                var notifications = FilteredIndexCalculator <TObject, TKey> .Calculate(_current, previous, updates);

                if (notifications.Count == 0 && (previous.Count != _current.Count))
                {
                    return(null);
                }

                var response = new PageResponse(_request.Size, _all.Count, page, pages);

                return(new PagedChangeSet <TObject, TKey>(_current, notifications, response));
            }