Exemple #1
0
        /// <summary>
        /// Create an instance from a specified change set provider and a collection touched strategy
        /// </summary>
        /// <typeparam name="TItem"></typeparam>
        /// <param name="provider"></param>
        /// <param name="collectionTouchedStrategy"></param>
        /// <returns></returns>
        ///
        public static ReadOnlyCollectionFromBackingStore <TItem> Create <TItem>(IChangeSetPagedDataProvider <TItem> provider, ICollectionItemTouchedStrategy collectionTouchedStrategy = null) where TItem : class
        {
            // create a backing store...
            var backingStore = new SimpleBackingStoreCollection <TItem>(provider);

            return(Create(backingStore, collectionTouchedStrategy));
        }
Exemple #2
0
        /// <summary>
        /// Create a collection
        /// </summary>
        /// <param name="changeSetProvider"></param>
        /// <param name="scheduler">The scheduler on which data set changes are to be observed</param>
        public SimpleBackingStoreCollection(IChangeSetPagedDataProvider <TItem> changeSetProvider, IScheduler scheduler = null)
        {
            Guard.NotNull(changeSetProvider);

            // record the change set provider
            _changeSetProvider = changeSetProvider;

            // bind to the backing collection
            _backingCollection = new ObservableCollectionExtended <TItem>();

            _subscriptionDisposable.Disposable = changeSetProvider.Changes.
                                                 ObserveOn(scheduler ?? RxApp.MainThreadScheduler).
                                                 Bind(_backingCollection).
                                                 Subscribe();
        }
        /// <summary>
        /// Create an enumeration of offsets required to read up to a specified offset.
        /// </summary>
        /// <typeparam name="TResultItem"></typeparam>
        /// <param name="changeSetProvider"></param>
        /// <param name="total"></param>
        /// <param name="offset"></param>
        /// <returns></returns>
        public static IEnumerable <int> CreateOffsetsUpTo <TResultItem>(this IChangeSetPagedDataProvider <TResultItem> changeSetProvider, int?total, int offset)
        {
            var maxPageSize = changeSetProvider.MaxPageSize;

            if (maxPageSize != int.MaxValue)
            {
                // at most a single read
                if (!total.HasValue || offset < total)
                {
                    yield return(offset);
                }
                {
                    var alignedOffset = ((int)Math.Round(((float)offset) / maxPageSize)) * maxPageSize;

                    if (!total.HasValue || offset < total)
                    {
                        while (alignedOffset < offset)
                        {
                            yield return(alignedOffset);

                            alignedOffset += maxPageSize;
                        }
                    }
                }
            }
            else
            {
                if (!total.HasValue || offset < total)
                {
                    yield return(offset);
                }
                {
                    if (total.HasValue)
                    {
                        yield return(Math.Min(offset, total.Value));
                    }
                    else
                    {
                        yield return(offset);
                    }
                }
            }
        }