コード例 #1
0
        public void DoNotThrowAWobblyWhenRemovingaMutatedValue()
        {

            var pageController = new PageController();
            var sortController = new SortController<TestVm>(SortExpressionComparer<TestVm>.Ascending(t => t.DateFavorited ?? DateTime.MinValue));
            var filterController = new FilterController<TestVm>(myVm => myVm.Id != 0);
            var items = new ObservableCollectionExtended<TestVm>();
            var itemCache = new SourceCache<TestVm, int>(myVm => myVm.Id);

            var item1 = new TestVm(1) { DateFavorited = DateTime.Now };
            var item2 = new TestVm(2) { DateFavorited = DateTime.Now };

            itemCache.AddOrUpdate(item1);
            itemCache.AddOrUpdate(item2);

            bool error = false;
            itemCache.Connect()
                .Filter(filterController)
                .Sort(sortController)
                .Page(pageController)//error doesnt occur with paging disabled
                .Bind(items)
                .Subscribe(changes => { }, ex => error = true);

            pageController.Change(new PageRequest(1, 100));

            //NB: never errored if it was the first item which was removed
            item2.DateFavorited = null;
            itemCache.Remove(item2); //ERROR!

            Assert.IsFalse(error, "Error has been thrown");
        }
コード例 #2
0
		public void Initialise()
		{
			_sortController = new SortController<Person>(_originalComparer);
			_source = new SourceCache<Person, string>(p => p.Key);
			_pageController = new PageController(new PageRequest(1, 25));
			_aggregators = new PagedChangeSetAggregator<Person, string>
				(
				_source.Connect()
					.Sort(_sortController)
					.Page(_pageController)
				);
		}
コード例 #3
0
        public void Initialise()
        {
            _comparer = SortExpressionComparer<Person>.Ascending(p => p.Name).ThenByAscending(p => p.Age);

            _source = new SourceCache<Person, string>(p=>p.Key);
            _pageController = new PageController(new PageRequest(1,25));
            _aggregators = new PagedChangeSetAggregator<Person, string>
                (
                    _source.Connect()
                    .Sort(_comparer)
                    .Page(_pageController)
                );
        }
コード例 #4
0
        public PagedDataViewer(ILogger logger, ITradeService tradeService, ISchedulerProvider schedulerProvider)
        {
            _logger = logger;

            //watch for filter changes and change filter 
            var filterController = new FilterController<Trade>(trade => true);
            var filterApplier = this.ObservePropertyValue(t => t.SearchText)
                .Throttle(TimeSpan.FromMilliseconds(250))
                .Select(propargs => BuildFilter(propargs.Value))
                .Subscribe(filterController.Change);

            //watch for changes to sort and apply when necessary
            var sortContoller = new SortController<TradeProxy>(SortExpressionComparer<TradeProxy>.Ascending(proxy=>proxy.Id));
            var sortChange = SortParameters.ObservePropertyValue(t => t.SelectedItem).Select(prop=>prop.Value.Comparer)
                    .ObserveOn(schedulerProvider.TaskPool)
                    .Subscribe(sortContoller.Change);
            
            //watch for page changes and change filter 
            var pageController = new PageController();
            var currentPageChanged = PageParameters.ObservePropertyValue(p => p.CurrentPage).Select(prop => prop.Value);
            var pageSizeChanged = PageParameters.ObservePropertyValue(p => p.PageSize).Select(prop => prop.Value);
            var pageChanger = currentPageChanged.CombineLatest(pageSizeChanged,(page, size) => new PageRequest(page, size))
                                .DistinctUntilChanged()
                                .Sample(TimeSpan.FromMilliseconds(100))
                                .Subscribe(pageController.Change);

            // filter, sort, page and bind to loaded data
            var loader = tradeService.All .Connect() 
                .Filter(filterController) // apply user filter
                .Transform(trade => new TradeProxy(trade), new ParallelisationOptions(ParallelType.Ordered, 5))
                .Sort(sortContoller, SortOptimisations.ComparesImmutableValuesOnly)
                .Page(pageController)
                .ObserveOn(schedulerProvider.MainThread)
                .Do(changes => _pageParameters.Update(changes.Response))
                .Bind(_data)     // update observable collection bindings
                .DisposeMany()   //since TradeProxy is disposable dispose when no longer required
                .Subscribe();

            _cleanUp = new CompositeDisposable(loader, filterController, filterApplier, sortChange,sortContoller, pageChanger, pageController);
        }
コード例 #5
0
 public void Initialise()
 {
     _source = new SourceList<Person>();
     _controller = new PageController(new PageRequest(1,25));
     _results = _source.Connect().Page(_controller).AsAggregator();
 }