当前位置: 首页>>代码示例>>C#>>正文


C# TrackingCollection.Dispose方法代码示例

本文整理汇总了C#中TrackingCollection.Dispose方法的典型用法代码示例。如果您正苦于以下问题:C# TrackingCollection.Dispose方法的具体用法?C# TrackingCollection.Dispose怎么用?C# TrackingCollection.Dispose使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在TrackingCollection的用法示例。


在下文中一共展示了TrackingCollection.Dispose方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: OrderByUpdatedNoFilter

    public void OrderByUpdatedNoFilter()
    {
        var count = 6;
        ITrackingCollection<Thing> col = new TrackingCollection<Thing>(
            Observable.Never<Thing>(),
            OrderedComparer<Thing>.OrderBy(x => x.UpdatedAt).Compare);
        col.NewerComparer = OrderedComparer<Thing>.OrderByDescending(x => x.UpdatedAt).Compare;
        col.ProcessingDelay = TimeSpan.Zero;

        var list1 = new List<Thing>(Enumerable.Range(1, count).Select(i => GetThing(i, i, count - i, "Run 1")).ToList());
        var list2 = new List<Thing>(Enumerable.Range(1, count).Select(i => GetThing(i, i, i + count, "Run 2")).ToList());

        var evt = new ManualResetEvent(false);
        col.Subscribe(t =>
        {
            if (++count == list1.Count)
                evt.Set();
        }, () => { });

        count = 0;
        // add first items
        foreach (var l in list1)
            col.AddItem(l);

        evt.WaitOne();
        evt.Reset();

        Assert.AreEqual(list1.Count, col.Count);
        list1.Sort(new LambdaComparer<Thing>(OrderedComparer<Thing>.OrderByDescending(x => x.CreatedAt).Compare));
        CollectionAssert.AreEqual(col, list1);

        count = 0;
        // replace items
        foreach (var l in list2)
            col.AddItem(l);

        evt.WaitOne();
        evt.Reset();

        Assert.AreEqual(list2.Count, col.Count);
        CollectionAssert.AreEqual(col, list2);

        col.Dispose();
    }
开发者ID:shana,项目名称:handy-things,代码行数:44,代码来源:TrackingCollectionTests.cs

示例2: RemovingItemsFromCollectionManuallyThrows2

    public void RemovingItemsFromCollectionManuallyThrows2()
    {
        var source = new Subject<Thing>();
        var col = new TrackingCollection<Thing>(source) { ProcessingDelay = TimeSpan.Zero };
        var count = 0;
        var expectedCount = 2;
        var evt = new ManualResetEvent(false);

        col.Subscribe(t =>
        {
            if (++count == expectedCount)
                evt.Set();
        }, () => { });

        Add(source, GetThing(1, 1));
        Add(source, GetThing(2, 2));
        evt.WaitOne();
        evt.Reset();
        Assert.Throws<InvalidOperationException>(() => col.RemoveAt(0));
        col.Dispose();
    }
开发者ID:chris134pravin,项目名称:VisualStudio,代码行数:21,代码来源:TrackingCollectionTests.cs

示例3: InsertingItemsIntoCollectionManuallyThrows

 public void InsertingItemsIntoCollectionManuallyThrows()
 {
     var col = new TrackingCollection<Thing>(Observable.Empty<Thing>());
     Assert.Throws<InvalidOperationException>(() => col.Insert(0, GetThing(1)));
     col.Dispose();
 }
开发者ID:chris134pravin,项目名称:VisualStudio,代码行数:6,代码来源:TrackingCollectionTests.cs

示例4: ChangingSortUpdatesCollection

    public void ChangingSortUpdatesCollection()
    {
        var source = new Subject<Thing>();
        var col = new TrackingCollection<Thing>(
            source,
            OrderedComparer<Thing>.OrderBy(x => x.UpdatedAt).Compare,
            (item, position, list) => item.UpdatedAt < Now + TimeSpan.FromMinutes(10))
            { ProcessingDelay = TimeSpan.Zero };

        var count = 0;
        var evt = new ManualResetEvent(false);
        var list1 = new List<Thing> {
            GetThing(1, 1),
            GetThing(2, 2),
            GetThing(3, 3),
            GetThing(4, 4),
            GetThing(5, 5),
            GetThing(6, 6),
            GetThing(7, 7),
            GetThing(8, 8),
            GetThing(9, 9),
        };

        col.Subscribe(t =>
        {
            if (++count == list1.Count)
                evt.Set();
        }, () => { });


        foreach (var l in list1)
            Add(source, l);
        evt.WaitOne();
        evt.Reset();
        CollectionAssert.AreEqual(col, list1);

        col.SetComparer(OrderedComparer<Thing>.OrderByDescending(x => x.UpdatedAt).Compare);

        CollectionAssert.AreEqual(col, list1.Reverse<Thing>().ToArray());
        col.Dispose();
    }
开发者ID:chris134pravin,项目名称:VisualStudio,代码行数:41,代码来源:TrackingCollectionTests.cs

示例5: RemovingFirstItemWithFilterWorks

    public void RemovingFirstItemWithFilterWorks()
    {
        var source = new Subject<Thing>();

        ITrackingCollection<Thing> col = new TrackingCollection<Thing>(
            Observable.Range(0, 5).Select(x => GetThing(x, x)),
            OrderedComparer<Thing>.OrderBy(x => x.UpdatedAt).Compare,
            (item, position, list) => true);
        col.ProcessingDelay = TimeSpan.Zero;

        var count = 0;
        var expectedCount = 5;
        var evt = new ManualResetEvent(false);
        col.Subscribe(t =>
        {
            if (++count == expectedCount)
                evt.Set();
        }, () => { });

        Assert.True(evt.WaitOne(40));
        evt.Reset();

        expectedCount = 6;
        col.RemoveItem(GetThing(0));

        Assert.True(evt.WaitOne(40));
        evt.Reset();

        CollectionAssert.AreEqual(col, Enumerable.Range(1, 4).Select(x => GetThing(x, x)));

        col.Dispose();

    }
开发者ID:github,项目名称:VisualStudio,代码行数:33,代码来源:TrackingCollectionTests.cs

示例6: OrderByMatchesOriginalOrder

    public void OrderByMatchesOriginalOrder()
    {
        var count = 0;
        var total = 1000;

        var list1 = new List<Thing>(Enumerable.Range(1, total).Select(i => GetThing(i, i, total - i, "Run 1")).ToList());
        var list2 = new List<Thing>(Enumerable.Range(1, total).Select(i => GetThing(i, i, total - i, "Run 2")).ToList());

        var col = new TrackingCollection<Thing>(
            list1.ToObservable(),
            OrderedComparer<Thing>.OrderByDescending(x => x.UpdatedAt).Compare,
            (item, position, list) => item.Title.Equals("Run 2"));
        col.ProcessingDelay = TimeSpan.Zero;

        count = 0;
        var evt = new ManualResetEvent(false);
        col.Subscribe(t =>
        {
            if (++count == list1.Count)
                evt.Set();
        }, () => { });

        evt.WaitOne();
        evt.Reset();

        Assert.AreEqual(total, count);
        Assert.AreEqual(0, col.Count);

        count = 0;

        // add new items
        foreach (var l in list2)
            col.AddItem(l);

        evt.WaitOne();
        evt.Reset();

        Assert.AreEqual(total, count);
        Assert.AreEqual(total, col.Count);
        CollectionAssert.AreEqual(col, list2);

        col.Dispose();
    }
开发者ID:chris134pravin,项目名称:VisualStudio,代码行数:43,代码来源:TrackingCollectionTests.cs

示例7: ProcessingDelayPingsRegularly

    public void ProcessingDelayPingsRegularly()
    {
        int count, total;
        count = total = 400;

        var list1 = new List<Thing>(Enumerable.Range(1, count).Select(i => GetThing(i, i, count - i)).ToList());

        var col = new TrackingCollection<Thing>(
            list1.ToObservable().Delay(TimeSpan.FromMilliseconds(10)),
            OrderedComparer<Thing>.OrderByDescending(x => x.UpdatedAt).Compare);
        col.ProcessingDelay = TimeSpan.FromMilliseconds(10);

        var sub = new Subject<Thing>();
        var times = new List<DateTimeOffset>();
        sub.Subscribe(t =>
        {
            times.Add(DateTimeOffset.UtcNow);
        });

        count = 0;

        var evt = new ManualResetEvent(false);
        col.Subscribe(t =>
        {
            sub.OnNext(t);
            if (++count == list1.Count)
            {
                sub.OnCompleted();
                evt.Set();
            }
        }, () => { });


        evt.WaitOne();
        evt.Reset();

        Assert.AreEqual(total, col.Count);

        CollectionAssert.AreEqual(col, list1);

        long totalTime = 0;

        for (var j = 1; j < times.Count; j++)
            totalTime += (times[j] - times[j - 1]).Ticks;
        var avg = TimeSpan.FromTicks(totalTime / times.Count).TotalMilliseconds;
        Assert.GreaterOrEqual(avg, 9);
        Assert.LessOrEqual(avg, 12);
        col.Dispose();
    }
开发者ID:chris134pravin,项目名称:VisualStudio,代码行数:49,代码来源:TrackingCollectionTests.cs

示例8: DisposingThrows

 public void DisposingThrows()
 {
     var col = new TrackingCollection<Thing>(Observable.Empty<Thing>());
     col.Dispose();
     Assert.Throws<ObjectDisposedException>(() => col.SetFilter(null));
     Assert.Throws<ObjectDisposedException>(() => col.SetComparer(null));
     Assert.Throws<ObjectDisposedException>(() => col.Subscribe());
     Assert.Throws<ObjectDisposedException>(() => col.AddItem(GetThing(1)));
     Assert.Throws<ObjectDisposedException>(() => col.RemoveItem(GetThing(1)));
 }
开发者ID:chris134pravin,项目名称:VisualStudio,代码行数:10,代码来源:TrackingCollectionTests.cs

示例9: OrderByDoesntMatchOriginalOrderTimings

    public void OrderByDoesntMatchOriginalOrderTimings()
    {
        var count = 0;
        var total = 1000;

        var list1 = new List<Thing>(Enumerable.Range(1, total).Select(i => GetThing(i, i, i, "Run 1")).ToList());
        var list2 = new List<Thing>(Enumerable.Range(1, total).Select(i => GetThing(i, i, i, "Run 2")).ToList());

        ITrackingCollection<Thing> col = new TrackingCollection<Thing>(
            list1.ToObservable(),
            OrderedComparer<Thing>.OrderByDescending(x => x.UpdatedAt).Compare,
            (item, position, list) => item.Title.Equals("Run 2"));
        col.NewerComparer = OrderedComparer<Thing>.OrderByDescending(x => x.UpdatedAt).Compare;
        col.ProcessingDelay = TimeSpan.Zero;

        var evt = new ManualResetEvent(false);
        var start = DateTimeOffset.UtcNow;

        col.Subscribe(t =>
        {
            if (++count == list1.Count)
                evt.Set();
        }, () => { });

        evt.WaitOne();
        var time = (DateTimeOffset.UtcNow - start).TotalMilliseconds;
        Assert.LessOrEqual(time, 100);
        evt.Reset();

        Assert.AreEqual(total, count);
        Assert.AreEqual(0, col.Count);

        count = 0;

        start = DateTimeOffset.UtcNow;
        // add new items
        foreach (var l in list2)
            col.AddItem(l);

        evt.WaitOne();
        time = (DateTimeOffset.UtcNow - start).TotalMilliseconds;
        Assert.LessOrEqual(time, 200);
        evt.Reset();

        Assert.AreEqual(total, count);
        Assert.AreEqual(total, col.Count);
        CollectionAssert.AreEqual(col, list2.Reverse<Thing>());

        col.Dispose();
    }
开发者ID:shana,项目名称:handy-things,代码行数:50,代码来源:TrackingCollectionTests.cs

示例10: OnlyIndexes2To4

    public void OnlyIndexes2To4()
    {
        var count = 6;

        var list1 = new List<Thing>(Enumerable.Range(1, count).Select(i => GetThing(i, i, count - i, "Run 1")).ToList());

        ITrackingCollection<Thing> col = new TrackingCollection<Thing>(
            Observable.Never<Thing>(),
            OrderedComparer<Thing>.OrderBy(x => x.UpdatedAt).Compare,
            (item, position, list) => position >= 2 && position <= 4);
        col.NewerComparer = OrderedComparer<Thing>.OrderByDescending(x => x.UpdatedAt).Compare;
        col.ProcessingDelay = TimeSpan.Zero;

        var evt = new ManualResetEvent(false);
        col.Subscribe(t =>
        {
            if (++count == list1.Count)
                evt.Set();
        }, () => { });

        count = 0;
        // add first items
        foreach (var l in list1)
            col.AddItem(l);

        evt.WaitOne();
        evt.Reset();

        Assert.AreEqual(3, col.Count);

#if DEBUG
        CollectionAssert.AreEqual(list1.Reverse<Thing>(), (col as TrackingCollection<Thing>).DebugInternalList);
#endif

        CollectionAssert.AreEqual(col, new List<Thing>() { list1[3], list1[2], list1[1] });

        col.Dispose();
    }
开发者ID:shana,项目名称:handy-things,代码行数:38,代码来源:TrackingCollectionTests.cs

示例11: AddingItemsToCollectionManuallyThrows

 public void AddingItemsToCollectionManuallyThrows()
 {
     ITrackingCollection<Thing> col = new TrackingCollection<Thing>(Observable.Empty<Thing>());
     Assert.Throws<InvalidOperationException>(() => col.Add(GetThing(1)));
     col.Dispose();
 }
开发者ID:shana,项目名称:handy-things,代码行数:6,代码来源:TrackingCollectionTests.cs

示例12: ChangingSortingAndUpdatingItemsUpdatesSortCorrectly


//.........这里部分代码省略.........

        col.Subscribe(t =>
        {
            if (++count == expectedCount)
                evt.Set();
        }, () => { });

        expectedCount = 9;
        Enumerable.Range(0, expectedCount)
            .Select(x => GetThing(x, x))
            .ForEach(x => Add(source, x));

        evt.WaitOne();
        evt.Reset();
        CollectionAssert.AreEqual(new List<Thing> {
            GetThing(2, 2),
            GetThing(3, 3),
            GetThing(5, 5),
            GetThing(7, 7),
        }, col);

        expectedCount = 10;
        Add(source, GetThing(3, 3, 2));
        evt.WaitOne();
        evt.Reset();
        CollectionAssert.AreEqual(new List<Thing> {
            GetThing(2, 2),
            GetThing(3, 3),
            GetThing(5, 5),
            GetThing(7, 7),
        }, col);

        expectedCount = 11;
        Add(source, GetThing(3, 3, 4));
        evt.WaitOne();
        evt.Reset();
        CollectionAssert.AreEqual(new List<Thing> {
            GetThing(2, 2),
            GetThing(3, 3, 4),
            GetThing(5, 5),
            GetThing(7, 7),
        }, col);

        expectedCount = 12;
        Add(source, GetThing(3, 3, 6));
        evt.WaitOne();
        evt.Reset();
        CollectionAssert.AreEqual(new List<Thing> {
            GetThing(2, 2),
            GetThing(4, 4),
            GetThing(3, 3, 6),
            GetThing(7, 7),
        }, col);

        col.Comparer = OrderedComparer<Thing>.OrderByDescending(x => x.UpdatedAt).Compare;
        CollectionAssert.AreEqual(new List<Thing> {
            GetThing(3, 3, 6),
            GetThing(6, 6),
            GetThing(4, 4),
            GetThing(1, 1),
        }, col);

        expectedCount = 13;
        Add(source, GetThing(4, 4));
        evt.WaitOne();
        evt.Reset();

        CollectionAssert.AreEqual(new List<Thing> {
            GetThing(3, 3, 6),
            GetThing(6, 6),
            GetThing(4, 4),
            GetThing(1, 1),
        }, col);

        expectedCount = 14;
        Add(source, GetThing(4, 4, 6));
        evt.WaitOne();
        evt.Reset();

        CollectionAssert.AreEqual(new List<Thing> {
            GetThing(3, 3, 6),
            GetThing(6, 6),
            GetThing(5, 5),
            GetThing(1, 1),
        }, col);

        expectedCount = 15;
        Add(source, GetThing(5, 5, 6));
        evt.WaitOne();
        evt.Reset();

        CollectionAssert.AreEqual(new List<Thing> {
            GetThing(3, 3, 6),
            GetThing(6, 6),
            GetThing(5, 5, 6),
            GetThing(1, 1),
        }, col);

        col.Dispose();
    }
开发者ID:github,项目名称:VisualStudio,代码行数:101,代码来源:TrackingCollectionTests.cs

示例13: DoesUpdateThingIfTimeIsNewer

    public void DoesUpdateThingIfTimeIsNewer()
    {
        ITrackingCollection<Thing> col = new TrackingCollection<Thing>(
            Observable.Never<Thing>(),
            OrderedComparer<Thing>.OrderBy(x => x.UpdatedAt).Compare);
        col.NewerComparer = OrderedComparer<Thing>.OrderByDescending(x => x.UpdatedAt).Compare;
        col.ProcessingDelay = TimeSpan.Zero;

        var evt = new ManualResetEvent(false);
        col.Subscribe(t =>
        {
            evt.Set();
        }, () => { });

        var createdAndUpdatedTime = DateTimeOffset.Now;
        var newerUpdateTime = createdAndUpdatedTime.Add(TimeSpan.FromMinutes(1));

        const string originalTitle = "Original Thing";

        var originalThing = new Thing(1, originalTitle, createdAndUpdatedTime, createdAndUpdatedTime);
        col.AddItem(originalThing);

        evt.WaitOne();
        evt.Reset();

        Assert.AreEqual(originalTitle, col[0].Title);

        const string updatedTitle = "Updated Thing";

        var updatedThing = new Thing(1, updatedTitle, createdAndUpdatedTime, newerUpdateTime);
        col.AddItem(updatedThing);

        evt.WaitOne();
        evt.Reset();

        Assert.AreEqual(updatedTitle, col[0].Title);

        col.Dispose();
    }
开发者ID:github,项目名称:VisualStudio,代码行数:39,代码来源:TrackingCollectionTests.cs

示例14: MultipleSortingAndFiltering

    public async Task MultipleSortingAndFiltering()
    {
        var expectedTotal = 20;
        var rnd = new Random(214748364);

        var updatedAtMinutesStack = new Stack<int>(Enumerable.Range(1, expectedTotal).OrderBy(rnd.Next));

        var list1 = Observable.Defer(() => Enumerable.Range(1, expectedTotal)
            .OrderBy(rnd.Next)
            .Select(x => GetThing(x, x, x, ((char)('a' + x)).ToString()))
            .ToObservable())
            .Replay()
            .RefCount();

        var list2 = Observable.Defer(() => Enumerable.Range(1, expectedTotal)
            .OrderBy(rnd.Next)
            .Select(x => GetThing(x, x, updatedAtMinutesStack.Pop(), ((char)('c' + x)).ToString()))
            .ToObservable())
            .Replay()
            .RefCount();

        ITrackingCollection<Thing> col = new TrackingCollection<Thing>(
            list1.Concat(list2),
            OrderedComparer<Thing>.OrderByDescending(x => x.UpdatedAt).Compare,
            (item, idx, list) => idx < 5
        );
        col.NewerComparer = OrderedComparer<Thing>.OrderByDescending(x => x.UpdatedAt).Compare;
        col.Subscribe();

        await col.OriginalCompleted;

        // it's initially sorted by date, so id list should not match
        CollectionAssert.AreNotEqual(list1.Select(x => x.Number).ToEnumerable(), list2.Select(x => x.Number).ToEnumerable());

        var sortlist = col.ToArray();
        Array.Sort(sortlist, new LambdaComparer<Thing>(OrderedComparer<Thing>
            .OrderByDescending(x => x.UpdatedAt)
            .ThenByDescending(x => x.CreatedAt).Compare));
        CollectionAssert.AreEqual(sortlist.Take(5), col);

        col.Comparer = OrderedComparer<Thing>.OrderBy(x => x.Number).Compare;
        sortlist = col.ToArray();
        Array.Sort(sortlist, new LambdaComparer<Thing>(OrderedComparer<Thing>.OrderBy(x => x.Number).Compare));
        CollectionAssert.AreEqual(sortlist.Take(5), col);

        col.Comparer = OrderedComparer<Thing>.OrderBy(x => x.UpdatedAt).Compare;
        sortlist = col.ToArray();
        Array.Sort(sortlist, new LambdaComparer<Thing>(OrderedComparer<Thing>
            .OrderBy(x => x.UpdatedAt)
            .ThenBy(x => x.CreatedAt).Compare));
        CollectionAssert.AreEqual(sortlist.Take(5), col);

        col.Comparer = OrderedComparer<Thing>.OrderByDescending(x => x.Title).Compare;
        sortlist = col.ToArray();
        Array.Sort(sortlist, new LambdaComparer<Thing>(OrderedComparer<Thing>.OrderByDescending(x => x.Title).Compare));
        CollectionAssert.AreEqual(sortlist.Take(5), col);

        col.Comparer = OrderedComparer<Thing>.OrderBy(x => x.Title).Compare;
        sortlist = col.ToArray();
        Array.Sort(sortlist, new LambdaComparer<Thing>(OrderedComparer<Thing>.OrderBy(x => x.Title).Compare));
        CollectionAssert.AreEqual(sortlist.Take(5), col);

        col.Dispose();
    }
开发者ID:github,项目名称:VisualStudio,代码行数:64,代码来源:TrackingCollectionTests.cs

示例15: ChangingComparers

    public void ChangingComparers()
    {
        var source = new Subject<Thing>();

        var col = new TrackingCollection<Thing>(source, OrderedComparer<Thing>.OrderBy(x => x.CreatedAt).Compare) { ProcessingDelay = TimeSpan.Zero };

        var count = 0;
        var evt = new ManualResetEvent(false);
        var list1 = new List<Thing> {
            GetThing(1, 1, 9),
            GetThing(2, 2, 8),
            GetThing(3, 3, 7),
            GetThing(4, 4, 6),
            GetThing(5, 5, 5),
            GetThing(6, 6, 4),
            GetThing(7, 7, 3),
            GetThing(8, 8, 2),
            GetThing(9, 9, 1),
        };

        col.Subscribe(t =>
        {
            if (++count == list1.Count)
                evt.Set();
        }, () => { });

        foreach (var l in list1)
            Add(source, l);

        evt.WaitOne();
        evt.Reset();
        CollectionAssert.AreEqual(col, list1);
        col.SetComparer(null);
        CollectionAssert.AreEqual(col, list1.Reverse<Thing>().ToArray());
        col.Dispose();
    }
开发者ID:chris134pravin,项目名称:VisualStudio,代码行数:36,代码来源:TrackingCollectionTests.cs


注:本文中的TrackingCollection.Dispose方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。