private void Upsert(DictionaryModification <TKey, TValue> modification)
            {
                TValue existingValue;

                if (_dictionary._state.TryGetValue(modification.Key, out existingValue))
                {
                    try
                    {
                        var newValue = _dictionary._updateFunction(modification.Key, existingValue, modification.Value);

                        _dictionary._state[modification.Key] = newValue;
                        _dictionary._subject.OnNext(DictionaryNotification.Updated(modification.Key, newValue,
                                                                                   modification.Value, existingValue));
                    }
                    catch (Exception ex)
                    {
                        _dictionary._error = ex;
                        _dictionary._subject.OnError(
                            new ObservableDictionaryUpdateException("Exception thrown when updating " + modification, ex));
                    }
                }
                else
                {
                    _dictionary._state[modification.Key] = modification.Value;
                    _dictionary._subject.OnNext(DictionaryNotification.Inserted(modification.Key, modification.Value));
                }
            }
Esempio n. 2
0
            private void Upsert(DictionaryModification <TKey, TValue> modification)
            {
                TValue existingValue;

                if (_dictionary._state.TryGetValue(modification.Key, out existingValue))
                {
                    try
                    {
                        // TODO Check order is correct here.
                        var newValue = _dictionary._updateFunction.Invoke(modification.Key, existingValue,
                                                                          modification.Value);

                        _dictionary._state[modification.Key] = newValue;
                        _dictionary._subject.OnNext(DictionaryNotification.Updated(modification.Key, newValue,
                                                                                   modification.Value, existingValue));
                    }
                    catch (Exception ex)
                    {
                        // TODO Check that this errors the whole stream.
                        _dictionary._error = ex;
                        _dictionary._subject.OnError(
                            new ObservableDictionaryUpdateException("Exception thrown when updating " + modification, ex));
                    }
                }
                else
                {
                    _dictionary._state[modification.Key] = modification.Value;
                    _dictionary._subject.OnNext(DictionaryNotification.Inserted(modification.Key, modification.Value));
                }
            }