public void OnNext(DictionaryModification <TKey, TValue> value)
            {
                if (DictionaryModification <TKey, TValue> .Initialised == value)
                {
                    _dictionary._subject.OnNext(DictionaryNotification.Initialised <TKey, TValue>());
                }
                else
                {
                    switch (value.Type)
                    {
                    case DictionaryModificationType.Upsert:
                        Upsert(value);
                        break;

                    case DictionaryModificationType.Replace:
                        Replace(value);
                        break;

                    case DictionaryModificationType.Remove:
                        Remove(value);
                        break;

                    case DictionaryModificationType.Clear:
                        Clear();
                        break;

                    default:
                        throw new ArgumentOutOfRangeException();
                    }
                }
            }
        public IDisposable Subscribe(IObserver <DictionaryNotification <TKey, TValue> > observer)
        {
            var futureDisposable = new SingleAssignmentDisposable();

            var scheduledWorkDisposable = _scheduler.Schedule(() =>
            {
                if (_isDisposed)
                {
                    futureDisposable.Disposable =
                        Observable.Throw <DictionaryNotification <TKey, TValue> >(
                            new ObjectDisposedException(this.GetType().Name)).Subscribe(observer);
                }

                if (_error != null)
                {
                    futureDisposable.Disposable = Observable.Throw <DictionaryNotification <TKey, TValue> >(_error).Subscribe(observer);
                }

                var existingValues = _state.ToList();

                foreach (var existingValue in existingValues)
                {
                    observer.OnNext(DictionaryNotification.Existing(existingValue.Key, existingValue.Value));
                }
                observer.OnNext(DictionaryNotification.Initialised <TKey, TValue>());

                futureDisposable.Disposable = new CompositeDisposable(_subject.Subscribe(observer), Connect());
            });

            return(new CompositeDisposable(scheduledWorkDisposable, futureDisposable));
        }
예제 #3
0
        public IDisposable Subscribe(IObserver <DictionaryNotification <TKey, TValue> > observer)
        {
            lock (_lock)
            {
                if (_isDisposed)
                {
                    return
                        (Observable.Throw <DictionaryNotification <TKey, TValue> >(
                             new ObjectDisposedException(this.GetType().Name)).Subscribe(observer));
                }

                if (_error != null)
                {
                    return(Observable.Throw <DictionaryNotification <TKey, TValue> >(_error).Subscribe(observer));
                }

                var existingValues = _state.ToList();

                foreach (var existingValue in existingValues)
                {
                    observer.OnNext(DictionaryNotification.Existing(existingValue.Key, existingValue.Value));
                }
                observer.OnNext(DictionaryNotification.Initialised <TKey, TValue>());

                return(new CompositeDisposable(_subject.Subscribe(observer), Connect()));
            }
        }