Exemple #1
0
        public void RemoveAll()
        {               //****************************************
            var MySeed   = Environment.TickCount;
            var MyRandom = new Random(MySeed);

            var MyDictionary = new SortedList <int, int>(1024);

            //****************************************

            for (var Index = 0; Index < 1024; Index++)
            {
                int Key, Value;

                do
                {
                    Key = MyRandom.Next();
                } while (MyDictionary.ContainsKey(Key));

                Value = MyRandom.Next();

                MyDictionary.Add(Key, Value);
            }

            var MyRecords = new ObservableSortedList <int, int>(MyDictionary);

            //****************************************

            MyRecords.RemoveAll((pair) => { if (MyRandom.Next() > int.MaxValue / 2)
                                            {
                                                return(MyDictionary.Remove(pair.Key));
                                            }
                                            return(false); });

            //****************************************

            CollectionAssert.AreEquivalent(MyDictionary, MyRecords, "Collections don't match. Bad Seed was {0}", MySeed);

            foreach (var MyPair in MyDictionary)
            {
                Assert.IsTrue(MyRecords.TryGetValue(MyPair.Key, out var Value));
                Assert.AreEqual(MyPair.Value, Value);
            }

            Thread.Sleep(1);
        }
        private void HandlePageCollectionChanges(object sender, NotifyDictionaryChangedEventArgs <string, TaggedPage> e)
        {
            Action a = null;

            switch (e.Action)
            {
            case NotifyDictionaryChangedAction.Add:
                a = () => _pages.AddAll(from i in e.Items select new HitHighlightedPageLinkModel(i, _highlighter, OneNoteApp));
                break;

            case NotifyDictionaryChangedAction.Remove:
                a = () => _pages.RemoveAll(from i in e.Items select i.Key);
                break;

            case NotifyDictionaryChangedAction.Reset:
                a = () => _pages.Clear();
                break;
            }
            if (a != null)
            {
                Dispatcher.Invoke(new Action(() => { a(); fireNotifyPropertyChanged(PAGE_COUNT); }));
            }
        }