/// <summary> /// Maintains the specified collection from the changes /// </summary> /// <param name="changes">The changes.</param> /// <param name="collection">The collection.</param> public void Adapt(ISortedChangeSet <TObject, TKey> changes, IObservableCollection <TObject> collection) { switch (changes.SortedItems.SortReason) { case SortReason.InitialLoad: { if (changes.Count > _refreshThreshold()) { using (collection.SuspendNotifications()) { collection.Load(changes.SortedItems.Select(kv => kv.Value)); } } else { using (collection.SuspendCount()) { DoUpdate(changes, collection); } } } break; case SortReason.ComparerChanged: case SortReason.Reset: using (collection.SuspendNotifications()) { collection.Load(changes.SortedItems.Select(kv => kv.Value)); } break; case SortReason.DataChanged: if (changes.Count > _refreshThreshold()) { using (collection.SuspendNotifications()) { collection.Load(changes.SortedItems.Select(kv => kv.Value)); } } else { using (collection.SuspendCount()) { DoUpdate(changes, collection); } } break; case SortReason.Reorder: //Updates will only be moves, so appply logic using (collection.SuspendCount()) { DoUpdate(changes, collection); } break; default: throw new ArgumentOutOfRangeException(); } }
/// <summary> /// Maintains the specified collection from the changes /// </summary> /// <param name="changes">The changes.</param> /// <param name="collection">The collection.</param> public void Adapt(IChangeSet <TObject, TKey> changes, IObservableCollection <TObject> collection) { _cache.Clone(changes); if (changes.Count > _refreshThreshold || !_loaded) { _loaded = true; using (collection.SuspendNotifications()) { collection.Load(_cache.Items); } } else { using (collection.SuspendCount()) { DoUpdate(changes, collection); } } }