public void Add(VirtualizingObservableCollectionSource <Item> collection)
 {
     for (var i = 0; i < Iterations; i++)
     {
         collection.Add(_data[i]);
     }
 }
コード例 #2
0
        public void OnAppendTest()
        {
            var i0  = new Item(0);
            var i1  = new Item(1);
            var voc = new VirtualizingObservableCollectionSource <Item>();
            var r0  = voc.OnAppend(i0, DateTime.Now);

            Assert.IsTrue(r0 == 0);
            var r1 = voc.OnAppend(i1, DateTime.Now);

            Assert.IsTrue(r1 == 1);
        }
コード例 #3
0
        public void GetCountTest()
        {
            var i0  = new Item(0);
            var i1  = new Item(1);
            var voc = new VirtualizingObservableCollectionSource <Item>();

            Assert.IsTrue(voc.Count == 0);
            voc.Add(i0);
            Assert.IsTrue(voc.Count == 1);
            voc.Add(i1);
            Assert.IsTrue(voc.Count == 2);
        }
        public void IterationLong(VirtualizingObservableCollectionSource <Item> collection)
        {
            var j = 0;

            foreach (var item in collection)
            {
                j++;
                if (j > 1000)
                {
                    break;
                }
            }
        }
コード例 #5
0
        public void OnRemoveTest()
        {
            var i0  = new Item(0);
            var i1  = new Item(1);
            var voc = new VirtualizingObservableCollectionSource <Item>
            {
                i0, i1
            };

            Assert.IsTrue(voc.Count == 2);
            voc.OnRemove(0, i0, DateTime.Now);
            Assert.IsTrue(voc.Count == 1);
        }
コード例 #6
0
        public void OnResetTest()
        {
            var i0  = new Item(0);
            var i1  = new Item(1);
            var voc = new VirtualizingObservableCollectionSource <Item>
            {
                i0, i1
            };

            Assert.IsTrue(voc.Count == 2);
            voc.OnReset(0);
            Assert.IsTrue(voc.Count == 0);
        }
 private void RemoveRandom(VirtualizingObservableCollectionSource <Item> collection)
 {
     while (!this.IsRandomCanceled)
     {
         Thread.Sleep(10);
         try
         {
             var removed = collection[1] as Item;
             this.RemovedObjects.Add(removed);
             collection.Remove(removed);
         }
         catch (ArgumentOutOfRangeException) { }
     }
 }
コード例 #8
0
        public void OnInsertTest()
        {
            var i0  = new Item(0);
            var i1  = new Item(1);
            var i2  = new Item(2);
            var voc = new VirtualizingObservableCollectionSource <Item>()
            {
                i0, i1
            };

            voc.OnInsert(0, i2, DateTime.Now);

            Assert.IsTrue(voc.GetAt(0, voc, false) == i2);
            Assert.IsTrue(voc.GetAt(1, voc, false) == i0);
            Assert.IsTrue(voc.GetAt(2, voc, false) == i1);
        }
コード例 #9
0
        public void GetAtTest()
        {
            var i0  = new Item(0);
            var i1  = new Item(1);
            var voc = new VirtualizingObservableCollectionSource <Item>
            {
                i0, i1
            };

            Assert.IsTrue(voc.Count == 2);
            var r0 = voc.GetAt(0, voc, false);
            var r1 = voc.GetAt(1, voc, false);

            Assert.IsTrue(i0 == r0);
            Assert.IsTrue(i1 == r1);
        }
        public void VirtualizingObservableCollectionSource()
        {
            var currentMethodName = this.GetCurrentMethodName();
            var collection        = new VirtualizingObservableCollectionSource <Item>();

            this._testStopwatch.Start($"{currentMethodName} iterative add with notifications");
            for (var i = 0; i < Iterations; i++)
            {
                collection.Add(_data[i]);
            }
            this._testStopwatch.Stop();
            this.CheckDataConsistency(collection);
            collection.Clear();

            this._testStopwatch.Start($"{currentMethodName} iterative add without notifications");
            //collection.SuppressChangeNotifications();
            for (var i = 0; i < Iterations; i++)
            {
                collection.Add(_data[i]);
            }
            //collection.Reset();
            this._testStopwatch.Stop();
            this.CheckDataConsistency(collection);
            collection.Clear();

            //this._testStopwatch.Start($"{currentMethodName} bulk add");
            //collection.AddRange(_data);
            //this._testStopwatch.Stop();
            //collection.Clear();

            this._testStopwatch.Start($"{currentMethodName} parallel add with notifications");
            Parallel.ForEach(_data, item => { collection.Add(item); });
            this._testStopwatch.Stop();
            this.CheckDataConsistency(collection);
            collection.Clear();

            this._testStopwatch.Start($"{currentMethodName} parallel add without notifications");
            //collection.SuppressChangeNotifications();
            Parallel.ForEach(_data, item => { collection.Add(item); });
            //collection.Reset();
            this._testStopwatch.Stop();
            this.CheckDataConsistency(collection);
            collection.Clear();

            collection.Clear();
            this._testStopwatch.Start($"{currentMethodName} parallel add int without interlocked");
            Parallel.ForEach(_data, item => { collection.Add(item); });
            this._testStopwatch.Stop();
            this.CheckDataConsistency(collection);
            collection.Clear();

            this._testStopwatch.Start($"{currentMethodName} Iterative add  with parallel read");
            Parallel.Invoke(() => this.Add(collection), () => this.Iteration(collection));
            this.CheckDataConsistency(collection);
            this._testStopwatch.Stop();
            this.CheckDataConsistency(collection);
            collection.Clear();

            this._testStopwatch.Start($"{currentMethodName} Iterative add  with parallel read and remove");
            var task = Task.Factory.StartNew(() => this.RemoveRandom(collection));

            Parallel.Invoke(() => this.Add(collection), () => this.Iteration(collection));
            this._testStopwatch.Stop();
            this.IsRandomCanceled = true;
            task.Wait();
            this.CheckDataConsistency(collection);
            this.RemovedObjects.Clear();
            collection.Clear();

            this._testStopwatch.Start($"{currentMethodName} Iterative add  with parallel long read and remove");
            task = Task.Factory.StartNew(() => this.RemoveRandom(collection));
            Parallel.Invoke(() => this.Add(collection), () => this.IterationLong(collection));
            this._testStopwatch.Stop();
            this.IsRandomCanceled = true;
            task.Wait();
            this.CheckDataConsistency(collection);
            this.RemovedObjects.Clear();
            collection.Clear();
        }