Ejemplo n.º 1
0
            public void MultipleActionsWithoutSuspendingNotifications()
            {
                var counter = 0;

                var fastCollection = new FastObservableCollection <int>();

                fastCollection.AutomaticallyDispatchChangeNotifications = false;
                fastCollection.CollectionChanged += (sender, e) => counter++;

                fastCollection.Add(0);
                fastCollection.Add(1);

                fastCollection.Remove(0);
                fastCollection.Remove(1);

                fastCollection.AddRange(new[] { 1, 2 });

                fastCollection[0] = 5;

                fastCollection.Move(0, 1);

                fastCollection.Clear();

                Assert.AreEqual(9, counter);
            }
Ejemplo n.º 2
0
            public void RemovingItemsInRemovingMode()
            {
                var counter   = 0;
                var eventArgs = (NotifyCollectionChangedEventArgs)null;

                var fastCollection = new FastObservableCollection <int> {
                    1, 2, 3, 4, 5
                };

                fastCollection.AutomaticallyDispatchChangeNotifications = false;
                fastCollection.CollectionChanged += (sender, e) =>
                {
                    counter++;
                    eventArgs = e;
                };

                using (fastCollection.SuspendChangeNotifications(SuspensionMode.Removing))
                {
                    fastCollection.Remove(1);
                    fastCollection.Remove(2);
                    fastCollection.Remove(3);
                    fastCollection.Remove(4);
                    fastCollection.Remove(5);
                }

                Assert.AreEqual(1, counter);
                Assert.AreEqual(NotifyCollectionChangedAction.Remove, eventArgs.Action);
                CollectionAssert.AreEqual(eventArgs.OldItems, new[] { 1, 2, 3, 4, 5 });
            }
Ejemplo n.º 3
0
            public void SuspendsValidationWhileAddingAndRemovingItems()
            {
                var counter = 0;

                var fastCollection = new FastObservableCollection <int>();

                fastCollection.AutomaticallyDispatchChangeNotifications = false;
                fastCollection.CollectionChanged += (sender, e) => counter++;

                using (fastCollection.SuspendChangeNotifications())
                {
                    fastCollection.Add(1);
                    fastCollection.Add(2);
                    fastCollection.Add(3);
                    fastCollection.Add(4);
                    fastCollection.Add(5);

                    fastCollection.Remove(5);
                    fastCollection.Remove(4);
                    fastCollection.Remove(3);
                    fastCollection.Remove(2);
                    fastCollection.Remove(1);
                }

                Assert.AreEqual(0, counter);
            }
        /// <summary>
        /// Updates the entries (via Remove and Add) in the ALL items collection
        /// with the entries in the <param name="viewModels"/> array parameter.
        /// </summary>
        /// <param name="viewModels"></param>
        private void UpdateAllEntries(params VM[] viewModels)
        {
            Logger.InfoFormat("_");

            _All.SuspendCollectionChangeNotification();
            try
            {
                var removeItems = _All.Where(vm => !viewModels.Contains(vm)).ToList();
                var addItems    = viewModels.Where(vm => !_All.Contains(vm)).ToList();

                foreach (var vm in removeItems)
                {
                    _All.Remove(vm);
                }

                foreach (var vm in addItems)
                {
                    _All.Add(vm);
                }
            }
            finally
            {
                _All.NotifyChanges();

                if (this.EntriesChanged != null)
                {
                    this.EntriesChanged(this, EventArgs.Empty);
                }
            }
        }
Ejemplo n.º 5
0
        private void updateEntries(params VM[] viewModels)
        {
            FastObservableCollection <VM> all = All as FastObservableCollection <VM>;

            all.SuspendCollectionChangeNotification();

            var removeItems = all.Where(vm => !viewModels.Contains(vm)).ToList();
            var addItems    = viewModels.Where(vm => !all.Contains(vm)).ToList();

            if (addItems.Count == 0 && removeItems.Count == 0)
            {
                return; //nothing to do here
            }
            foreach (var vm in removeItems)
            {
                all.Remove(vm);
            }

            foreach (var vm in addItems)
            {
                all.Add(vm);
            }

            _subItemList = all.ToArray().ToList();
            all.NotifyChanges();

            EntriesChanged?.Invoke(this, EventArgs.Empty);
        }
Ejemplo n.º 6
0
        private void updateEntries(params VM[] viewModels)
        {
            FastObservableCollection <VM> all = All as FastObservableCollection <VM>;

            all.SuspendCollectionChangeNotification();

            var removeItems = all.Where(vm => !viewModels.Contains(vm)).ToList();
            var addItems    = viewModels.Where(vm => !all.Contains(vm)).ToList();

            foreach (var vm in removeItems)
            {
                all.Remove(vm);
            }

            foreach (var vm in addItems)
            {
                all.Add(vm);
            }

            _subItemList = all.ToArray().ToList();
            all.NotifyChanges();

            if (EntriesChanged != null)
            {
                EntriesChanged(this, EventArgs.Empty);
            }
        }
Ejemplo n.º 7
0
 public static void MoveItemToTop <T>(this FastObservableCollection <T> collection, T item)
 {
     using (collection.SuspendChangeNotifications())
     {
         collection.Remove(item);
         collection.Insert(0, item);
     }
 }
Ejemplo n.º 8
0
            public void ThrowsInvalidOperationExceptionForRemovingInAddingMode()
            {
                var fastCollection = new FastObservableCollection <int> {
                    0
                };

                using (fastCollection.SuspendChangeNotifications(SuspensionMode.Adding))
                {
                    Assert.Throws <InvalidOperationException>(() => fastCollection.Remove(0));
                }
            }
Ejemplo n.º 9
0
            public void SuspendsValidationWhileAddingAndRemovingItems()
            {
                int counter = 0;

                var fastCollection = new FastObservableCollection<int>();
                fastCollection.AutomaticallyDispatchChangeNotifications = false;
                fastCollection.CollectionChanged += (sender, e) => counter++;

                using (fastCollection.SuspendChangeNotifications())
                {
                    fastCollection.Add(1);
                    fastCollection.Add(2);
                    fastCollection.Add(3);
                    fastCollection.Add(4);
                    fastCollection.Add(5);

                    fastCollection.Remove(5);
                    fastCollection.Remove(4);
                    fastCollection.Remove(3);
                    fastCollection.Remove(2);
                    fastCollection.Remove(1);
                }

                Assert.AreEqual(1, counter);
            }