public StrategyBasedReadOnlyCollection(IPagedBackingStoreCollection <TItem> pagedBackingStoreCollection,
                                               ICollectionItemTouchedStrategy touchedStrategy) : base(pagedBackingStoreCollection)
        {
            Guard.NotNull(pagedBackingStoreCollection);
            Guard.NotNull(touchedStrategy);

            _touchedStrategy = touchedStrategy;
        }
Exemple #2
0
        /// <summary>
        /// Create a collection with a specified <see cref="IPagedBackingStoreCollection{TItem}"/> and <see cref="ICollectionItemTouchedStrategy"/>
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="backingStoreCollection"></param>
        /// <param name="collectionTouchedStrategy">If not specified, <see cref="CollectionItemTouchedStrategy{TItem}"/> is used.</param>
        /// <returns></returns>
        public static ReadOnlyCollectionFromBackingStore <T> Create <T>(IPagedBackingStoreCollection <T> backingStoreCollection, ICollectionItemTouchedStrategy collectionTouchedStrategy = null) where T : class
        {
            // the strategy to request page loads in the backing store

            var touched = collectionTouchedStrategy ?? new CollectionItemTouchedStrategy <T>(backingStoreCollection);

            // the actual list we will bind to...

            var collection = new StrategyBasedReadOnlyCollection <T>(backingStoreCollection, touched);

            return(collection);
        }
Exemple #3
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 #4
0
        /// <summary>
        /// Create a collection backed from a <see cref="ReactiveList{T}"/>
        /// </summary>
        /// <typeparam name="TItem">The type of item stored.</typeparam>
        /// <typeparam name="TKey">The key type</typeparam>
        /// <param name="readPageObservable"></param>
        /// <param name="keySelector"></param>
        /// <param name="maxPageSize"></param>
        /// <param name="onException"></param>
        /// <param name="collectionTouchedStrategy"></param>
        /// <returns></returns>
        /// <remarks>Uses a <see cref="KeyedReactiveListBacked{TItem,TKey}"/> using the provided onException and maxPageSize values.</remarks>
        public static ReadOnlyCollectionFromBackingStore <TItem> FromKeyedReactiveListPager <TItem, TKey>(Func <PageReadRequest, IObservable <PageReadResult <TItem> > > readPageObservable, Func <TItem, TKey> keySelector, int maxPageSize = 10, Func <PageReadRequest, Exception, IObservable <bool> > onException = null,
                                                                                                          ICollectionItemTouchedStrategy collectionTouchedStrategy = null)
            where TItem : class
        {
            // create the provider of the changesets
            var provider = KeyedReactiveListBacked.FromObservable(readPageObservable, keySelector, maxPageSize, onException);

            // this is our list which acts as the backing store for the above stuff...
            return(Create(provider, collectionTouchedStrategy));
        }
Exemple #5
0
        /// <summary>
        /// Create a collection backed from a <see cref="SourceCache{TObject,TKey}"/>
        /// </summary>
        /// <typeparam name="T">The type stored in the collection</typeparam>
        /// <typeparam name="TKey">The key type</typeparam>
        /// <param name="readPageObservable">The observable which provides the pages of content</param>
        /// <param name="keySelector">The key selector</param>
        /// <param name="maxPageSize">The maximum size of page to be read, the default being 10</param>
        /// <param name="onException">The observable to be used when errors on paging are seen. Null will result in the default behavior, which is fail.</param>
        /// <param name="collectionTouchedStrategy">The strategy to be used when items in a collection are touched. If null <see cref="CollectionItemTouchedStrategy{TItem}"/> is used.</param>
        /// <param name="backingStoreCollection">The store to be used to back the collection. If null <see cref="SimpleBackingStoreCollection{TItem}" /> is used</param>
        /// <returns></returns>
        public static ReadOnlyCollectionFromBackingStore <T> FromSourceCachePager <T, TKey>(Func <PageReadRequest, IObservable <PageReadResult <T> > > readPageObservable,
                                                                                            Func <T, TKey> keySelector,
                                                                                            int maxPageSize = 10,
                                                                                            Func <PageReadRequest, Exception, IObservable <bool> > onException = null,
                                                                                            ICollectionItemTouchedStrategy collectionTouchedStrategy           = null,
                                                                                            IPagedBackingStoreCollection <T> backingStoreCollection            = null) where T : class
        {
            var provider = SourceCacheBacked <T, TKey> .FromObservable(readPageObservable, keySelector, maxPageSize, onException);

            return(Create(provider, collectionTouchedStrategy));
        }