Exemplo n.º 1
0
        public IObservable <IQuery <TObject, TKey> > Run()
        {
            return(Observable.Create <IQuery <TObject, TKey> >(observer =>
            {
                var locker = new object();
                var cache = new Cache <TObject, TKey>();
                var query = new AnonymousQuery <TObject, TKey>(cache);

                if (_itemChangedTrigger != null)
                {
                    return _source.Publish(shared =>
                    {
                        var inlineChange = shared.MergeMany(_itemChangedTrigger)
                                           .Synchronize(locker)
                                           .Select(_ => query);

                        var sourceChanged = shared
                                            .Synchronize(locker)
                                            .Do(changes => cache.Clone(changes))
                                            .Select(changes => query);

                        return sourceChanged.Merge(inlineChange);
                    }).SubscribeSafe(observer);
                }
                else
                {
                    return _source.Do(changes => cache.Clone(changes))
                    .Select(changes => query)
                    .SubscribeSafe(observer);
                }
            }));
        }
Exemplo n.º 2
0
        public IObservable <IChangeSet <TObject, TKey> > Run()
        {
            return(Observable.Create <IChangeSet <TObject, TKey> >(observer =>
            {
                var allData = new Cache <TObject, TKey>();
                var filteredData = new ChangeAwareCache <TObject, TKey>();
                var updater = new FilteredUpdater <TObject, TKey>(filteredData, x => false);

                var locker = new object();

                var evaluate = _refilterObservable.
                               Synchronize(locker)
                               .Select(_ => Reevaluate(updater, allData.KeyValues));

                var predicateChanged = _predicateChanged
                                       .Synchronize(locker)
                                       .Select(predicate =>
                {
                    updater = new FilteredUpdater <TObject, TKey>(filteredData, predicate);
                    return Reevaluate(updater, allData.KeyValues);
                });

                var dataChanged = _source
                                  .Finally(observer.OnCompleted)
                                  .Synchronize(locker)
                                  .Select(changes =>
                {
                    allData.Clone(changes);
                    return updater.Update(changes);
                });

                return predicateChanged.Merge(evaluate).Merge(dataChanged).NotEmpty().SubscribeSafe(observer);
            }));
        }
Exemplo n.º 3
0
        public IObservable <IChangeSet <TDestination, TKey> > Run()
        {
            return(Observable.Create <IChangeSet <TDestination, TKey> >(observer =>
            {
                var locker = new object();
                var shared = _source.Synchronize(locker).Publish();

                //capture all items so we can apply a forced transform
                var cache = new Cache <TSource, TKey>();
                var cacheLoader = shared.Subscribe(changes => cache.Clone(changes));

                //create change set of items where force refresh is applied
                var refresher = _forceTransform.Synchronize(locker)
                                .Select(selector => CaptureChanges(cache, selector))
                                .Select(changes => new ChangeSet <TSource, TKey>(changes))
                                .NotEmpty();

                var sourceAndRefreshes = shared.Merge(refresher);

                //do raw transform
                var transform = new Transform <TDestination, TSource, TKey>(sourceAndRefreshes, _transformFactory, _exceptionCallback, true).Run();

                return new CompositeDisposable(cacheLoader, transform.SubscribeSafe(observer), shared.Connect());
            }));
        }
Exemplo n.º 4
0
        public void RegisterForRemoval(IChangeSet <TObject, TKey> changes, Cache <TObject, TKey> cache)
        {
            changes.ForEach(change =>
            {
                switch (change.Reason)
                {
                case ChangeReason.Update:
                    change.Previous.IfHasValue(t => _removeAction(t));
                    break;

                case ChangeReason.Remove:
                    _removeAction(change.Current);
                    break;
                }
            });
            cache.Clone(changes);
        }
Exemplo n.º 5
0
        private void Update(Cache <TObject, TKey> cache, IChangeSet <TObject, TKey> updates)
        {
            IChangeSet <TObject, TKey> notifications;

            lock (_locker)
            {
                //update cache for the individual source
                cache.Clone(updates);

                //update combined
                notifications = UpdateCombined(updates);
            }

            if (notifications.Count != 0)
            {
                _updatedCallback(notifications);
            }
        }
Exemplo n.º 6
0
        private void RegisterForRemoval(IChangeSet <TObject, TKey> changes, Cache <TObject, TKey> cache)
        {
            changes.ForEach(change =>
            {
                switch (change.Reason)
                {
                case ChangeReason.Update:
                    // ReSharper disable once InconsistentlySynchronizedField
                    change.Previous.IfHasValue(t => _removeAction(t));
                    break;

                case ChangeReason.Remove:
                    // ReSharper disable once InconsistentlySynchronizedField
                    _removeAction(change.Current);
                    break;
                }
            });
            cache.Clone(changes);
        }
Exemplo n.º 7
0
        public IObservable <IChangeSet <TObject, TKey> > Run()
        {
            return(Observable.Create <IChangeSet <TObject, TKey> >(observer =>
            {
                var allData = new Cache <TObject, TKey>();
                var filteredData = new ChangeAwareCache <TObject, TKey>();
                Func <TObject, bool> predicate = t => false;

                var locker = new object();

                var refresher = LatestPredicateObservable()
                                .Synchronize(locker)
                                .Select(p =>
                {
                    //set the local predicate
                    predicate = p;

                    //reapply filter using all data from the cache
                    return filteredData.RefreshFilteredFrom(allData, predicate);
                });

                var dataChanged = _source
                                  // .Finally(observer.OnCompleted)
                                  .Synchronize(locker)
                                  .Select(changes =>
                {
                    //maintain all data [required to re-apply filter]
                    allData.Clone(changes);

                    //maintain filtered data
                    filteredData.FilterChanges(changes, predicate);

                    //get latest changes
                    return filteredData.CaptureChanges();
                });

                return refresher
                .Merge(dataChanged)
                .NotEmpty()
                .SubscribeSafe(observer);
            }));
        }
Exemplo n.º 8
0
 public AnonymousQuery(Cache <TObject, TKey> cache)
 {
     _cache = cache.Clone();
 }
Exemplo n.º 9
0
 private void Clone(IChangeSet <TObject, TKey> changes)
 {
     Cache.Clone(changes);
 }