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


C# TrackingCollection.AddItem方法代码示例

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


在下文中一共展示了TrackingCollection.AddItem方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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

示例3: NoChangingAfterDisposed1

 public void NoChangingAfterDisposed1()
 {
     var col = new TrackingCollection<Thing>(Observable.Never<Thing>(), OrderedComparer<Thing>.OrderByDescending(x => x.UpdatedAt).Compare);
     col.Dispose();
     Assert.Throws<ObjectDisposedException>(() => col.AddItem(new Thing()));
 }
开发者ID:chris134pravin,项目名称:VisualStudio,代码行数:6,代码来源:TrackingCollectionTests.cs

示例4: 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

示例5: OnlyTimesEqualOrHigherThan3Minutes

    public void OnlyTimesEqualOrHigherThan3Minutes()
    {
        var count = 6;

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

        var col = new TrackingCollection<Thing>(
            Observable.Never<Thing>(),
            OrderedComparer<Thing>.OrderBy(x => x.UpdatedAt).Compare,
            (item, position, list) => item.UpdatedAt >= Now + TimeSpan.FromMinutes(3) && item.UpdatedAt <= Now + TimeSpan.FromMinutes(5));
        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.DebugInternalList);
#endif
        CollectionAssert.AreEqual(col, new List<Thing>() { list1[2], list1[1], list1[0] });
        col.Dispose();
    }
开发者ID:chris134pravin,项目名称:VisualStudio,代码行数:35,代码来源:TrackingCollectionTests.cs

示例6: 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

示例7: 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

示例8: CreateSource

 TrackingCollection<Thing> CreateSource()
 {
     var result = new TrackingCollection<Thing>(Observable.Empty<Thing>());
     result.Subscribe();
     result.AddItem(new Thing(1, "item1", DateTimeOffset.MinValue));
     result.AddItem(new Thing(2, "item2", DateTimeOffset.MinValue));
     result.AddItem(new Thing(3, "item3", DateTimeOffset.MinValue));
     return result;
 }
开发者ID:github,项目名称:VisualStudio,代码行数:9,代码来源:ListenerCollectionTests.cs

示例9: 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

示例10: AddingBeforeSubscribingWorks

    public async void AddingBeforeSubscribingWorks()
    {
        ITrackingCollection<Thing> col = new TrackingCollection<Thing>(Observable.Empty<Thing>());
        ReplaySubject<Thing> done = new ReplaySubject<Thing>();
        col.AddItem(GetThing(1));
        col.AddItem(GetThing(2));
        var count = 0;
        done.OnNext(null);
        col.Subscribe(t =>
        {
            done.OnNext(t);
            if (++count == 2)
                done.OnCompleted();
        }, () => {});

        await Observable.Timeout(done, TimeSpan.FromMilliseconds(500));
        Assert.AreEqual(2, col.Count);
    }
开发者ID:github,项目名称:VisualStudio,代码行数:18,代码来源:TrackingCollectionTests.cs

示例11: AddingWithNoObservableSetThrows

 public void AddingWithNoObservableSetThrows()
 {
     ITrackingCollection<Thing> col = new TrackingCollection<Thing>();
     Assert.Throws<InvalidOperationException>(() => col.AddItem(new Thing()));
 }
开发者ID:github,项目名称:VisualStudio,代码行数:5,代码来源:TrackingCollectionTests.cs

示例12: CopyFromDoesNotLoseAvatar

        public void CopyFromDoesNotLoseAvatar()
        {
            var userImage = AvatarProvider.CreateBitmapImage("pack://application:,,,/GitHub.App;component/Images/default_user_avatar.png");
            var orgImage = AvatarProvider.CreateBitmapImage("pack://application:,,,/GitHub.App;component/Images/default_org_avatar.png");

            var initialBitmapImageSubject = new Subject<BitmapImage>();

            var collectionEvent = new ManualResetEvent(false);
            var avatarPropertyEvent = new ManualResetEvent(false);

            //Creating an initial account with an observable that returns immediately
            const string login = "foo";
            const int initialOwnedPrivateRepositoryCount = 1;

            var initialAccount = new Account(login, true, false, initialOwnedPrivateRepositoryCount, 0, initialBitmapImageSubject);

            //Creating the test collection
            var col = new TrackingCollection<IAccount>(Observable.Empty<IAccount>(), OrderedComparer<IAccount>.OrderByDescending(x => x.Login).Compare);
            col.Subscribe(account =>
            {
                collectionEvent.Set();
            }, () => { });

            //Adding that account to the TrackingCollection
            col.AddItem(initialAccount);

            //Waiting for the collection add the item
            collectionEvent.WaitOne();
            collectionEvent.Reset();

            //Checking some initial properties
            Assert.Equal(login, col[0].Login);
            Assert.Equal(initialOwnedPrivateRepositoryCount, col[0].OwnedPrivateRepos);

            //Demonstrating that the avatar is not yet present
            Assert.Null(col[0].Avatar);

            //Adding a listener to check for the changing of the Avatar property
            initialAccount.Changed.Subscribe(args =>
            {
                if (args.PropertyName == "Avatar")
                {
                    avatarPropertyEvent.Set();
                }
            });

            //Providing the first avatar
            initialBitmapImageSubject.OnNext(userImage);
            initialBitmapImageSubject.OnCompleted();

            //Waiting for the avatar to be added
            avatarPropertyEvent.WaitOne();
            avatarPropertyEvent.Reset();

            //Demonstrating that the avatar is present
            Assert.NotNull(col[0].Avatar);
            Assert.True(BitmapSourcesAreEqual(col[0].Avatar, userImage));
            Assert.False(BitmapSourcesAreEqual(col[0].Avatar, orgImage));

            //Creating an account update
            const int updatedOwnedPrivateRepositoryCount = 2;
            var updatedBitmapImageSubject = new Subject<BitmapImage>();
            var updatedAccount = new Account(login, true, false, updatedOwnedPrivateRepositoryCount, 0, updatedBitmapImageSubject);

            //Updating the account in the collection
            col.AddItem(updatedAccount);

            //Waiting for the collection to process the update
            collectionEvent.WaitOne();
            collectionEvent.Reset();

            //Providing the second avatar
            updatedBitmapImageSubject.OnNext(orgImage);
            updatedBitmapImageSubject.OnCompleted();

            //Waiting for the delayed bitmap image observable
            avatarPropertyEvent.WaitOne();
            avatarPropertyEvent.Reset();

            //Login is the id, so that should be the same
            Assert.Equal(login, col[0].Login);

            //CopyFrom() should have updated this field
            Assert.Equal(updatedOwnedPrivateRepositoryCount, col[0].OwnedPrivateRepos);

            //CopyFrom() should not cause a race condition here
            Assert.NotNull(col[0].Avatar);
            Assert.True(BitmapSourcesAreEqual(col[0].Avatar, orgImage));
            Assert.False(BitmapSourcesAreEqual(col[0].Avatar, userImage));
        }
开发者ID:github,项目名称:VisualStudio,代码行数:90,代码来源:AccountModelTests.cs


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