Exemple #1
0
        /// <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();
            }
        }
Exemple #2
0
 /// <summary>
 /// Maintains the specified collection from the changes
 /// </summary>
 /// <param name="changes">The changes.</param>
 public void Adapt(IChangeSet <T> changes)
 {
     if (changes.TotalChanges - changes.Refreshes > _refreshThreshold || !_loaded)
     {
         using (_collection.SuspendNotifications())
         {
             _collection.Clone(changes);
             _loaded = true;
         }
     }
     else
     {
         _collection.Clone(changes);
     }
 }
Exemple #3
0
        /// <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);
                }
            }
        }
Exemple #4
0
        /// <summary>
        /// Maintains the specified collection from the changes.
        /// </summary>
        /// <param name="changes">The changes.</param>
        public void Adapt(IChangeSet <T> changes)
        {
            if (changes is null)
            {
                throw new ArgumentNullException(nameof(changes));
            }

            if (changes.TotalChanges - changes.Refreshes > _refreshThreshold || !_loaded)
            {
                using (_collection.SuspendNotifications())
                {
                    _collection.Clone(changes);
                    _loaded = true;
                }
            }
            else
            {
                _collection.Clone(changes);
            }
        }
 public IDisposable SuspendNotifications() => _collection?.SuspendNotifications() ?? Disposable.Empty;