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


C# TrackingCollection.Subscribe方法代码示例

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


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

示例1: PullRequestListViewModel

        public PullRequestListViewModel(
            IRepositoryHost repositoryHost,
            ILocalRepositoryModel repository,
            IPackageSettings settings)
        {
            this.repositoryHost = repositoryHost;
            this.repository = repository;
            this.settings = settings;

            Title = Resources.PullRequestsNavigationItemText;

            this.listSettings = settings.UIState
                .GetOrCreateRepositoryState(repository.CloneUrl)
                .PullRequests;

            openPullRequestCommand = ReactiveCommand.Create();
            openPullRequestCommand.Subscribe(_ =>
            {
                VisualStudio.Services.DefaultExportProvider.GetExportedValue<IVisualStudioBrowser>().OpenUrl(repositoryHost.Address.WebUri);
            });

            States = new List<PullRequestState> {
                new PullRequestState { IsOpen = true, Name = "Open" },
                new PullRequestState { IsOpen = false, Name = "Closed" },
                new PullRequestState { Name = "All" }
            };

            trackingAuthors = new TrackingCollection<IAccount>(Observable.Empty<IAccount>(),
                OrderedComparer<IAccount>.OrderByDescending(x => x.Login).Compare);
            trackingAssignees = new TrackingCollection<IAccount>(Observable.Empty<IAccount>(),
                OrderedComparer<IAccount>.OrderByDescending(x => x.Login).Compare);
            trackingAuthors.Subscribe();
            trackingAssignees.Subscribe();

            Authors = trackingAuthors.CreateListenerCollection(EmptyUser, this.WhenAnyValue(x => x.SelectedAuthor));
            Assignees = trackingAssignees.CreateListenerCollection(EmptyUser, this.WhenAnyValue(x => x.SelectedAssignee));

            PullRequests = new TrackingCollection<IPullRequestModel>();
            pullRequests.Comparer = OrderedComparer<IPullRequestModel>.OrderByDescending(x => x.UpdatedAt).Compare;
            pullRequests.NewerComparer = OrderedComparer<IPullRequestModel>.OrderByDescending(x => x.UpdatedAt).Compare;

            this.WhenAny(x => x.SelectedState, x => x.Value)
                .Where(x => PullRequests != null)
                .Subscribe(s => UpdateFilter(s, SelectedAssignee, SelectedAuthor));

            this.WhenAny(x => x.SelectedAssignee, x => x.Value)
                .Where(x => PullRequests != null && x != EmptyUser && IsLoaded)
                .Subscribe(a => UpdateFilter(SelectedState, a, SelectedAuthor));

            this.WhenAny(x => x.SelectedAuthor, x => x.Value)
                .Where(x => PullRequests != null && x != EmptyUser && IsLoaded)
                .Subscribe(a => UpdateFilter(SelectedState, SelectedAssignee, a));

            SelectedState = States.FirstOrDefault(x => x.Name == listSettings.SelectedState) ?? States[0];
        }
开发者ID:github,项目名称:VisualStudio,代码行数:55,代码来源:PullRequestListViewModel.cs

示例2: OrderByUpdatedFilter

    public void OrderByUpdatedFilter()
    {
        var count = 3;
        var col = new TrackingCollection<Thing>(
            Observable.Never<Thing>(),
            OrderedComparer<Thing>.OrderBy(x => x.UpdatedAt).Compare,
            (item, position, list) => true);
        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:chris134pravin,项目名称:VisualStudio,代码行数:44,代码来源:TrackingCollectionTests.cs

示例3: MultipleSortingAndFiltering

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

        var titles1 = Enumerable.Range(1, expectedTotal).Select(x => ((char)('a' + x)).ToString()).ToList();
        var dates1 = Enumerable.Range(1, expectedTotal).Select(x => Now + TimeSpan.FromMinutes(x)).ToList();

        var idstack1 = new Stack<int>(Enumerable.Range(1, expectedTotal).OrderBy(rnd.Next));
        var datestack1 = new Stack<DateTimeOffset>(dates1);
        var titlestack1 = new Stack<string>(titles1.OrderBy(_ => rnd.Next()));

        var titles2 = Enumerable.Range(1, expectedTotal).Select(x => ((char)('c' + x)).ToString()).ToList();
        var dates2 = Enumerable.Range(1, expectedTotal).Select(x => Now + TimeSpan.FromMinutes(x)).ToList();
        var dates2mixed = new List<DateTimeOffset>() {
                dates2[2],  dates2[0],  dates2[1],  dates2[3],  dates2[5],
                dates2[9],  dates2[15], dates2[6],  dates2[7],  dates2[8],
                dates2[13], dates2[10], dates2[16], dates2[11], dates2[12],
                dates2[14], dates2[17], dates2[18], dates2[19], dates2[4],
        };
        var idstack2 = new Stack<int>(Enumerable.Range(1, expectedTotal).OrderBy(rnd.Next));
        var datestack2 = new Stack<DateTimeOffset>(dates2mixed);
        var titlestack2 = new Stack<string>(titles2.OrderBy(_ => rnd.Next()));

        var datestack3 = new Stack<DateTimeOffset>();
        for (int i = 0; i < datestack1.Count; i++)
            datestack3.Push(new DateTimeOffset(Math.Max(dates1[i].Ticks, dates2mixed[i].Ticks), TimeSpan.Zero));

        var list1 = Observable.Defer(() => Enumerable.Range(1, expectedTotal)
            .OrderBy(rnd.Next)
            .Select(x => new Thing(idstack1.Pop(), titlestack1.Pop(), datestack1.Pop()))
            .ToObservable())
            .Replay()
            .RefCount();

        var list2 = Observable.Defer(() => Enumerable.Range(1, expectedTotal)
            .OrderBy(rnd.Next)
            .Select(x => new Thing(idstack2.Pop(), titlestack2.Pop(), datestack2.Pop()))
            .ToObservable())
            .Replay()
            .RefCount();

        ITrackingCollection<Thing> col = new TrackingCollection<Thing>(
            list1.Concat(list2),
            OrderedComparer<Thing>.OrderByDescending(x => x.CreatedAt).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.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.CreatedAt).Compare;
        sortlist = col.ToArray();
        Array.Sort(sortlist, new LambdaComparer<Thing>(OrderedComparer<Thing>.OrderBy(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,代码行数:81,代码来源:TrackingCollectionTests.cs

示例4: NotInitializedCorrectlyThrows2

 public void NotInitializedCorrectlyThrows2()
 {
     var col = new TrackingCollection<Thing>(OrderedComparer<Thing>.OrderByDescending(x => x.UpdatedAt).Compare);
     Assert.Throws<InvalidOperationException>(() => col.Subscribe(_ => { }, () => { }));
 }
开发者ID:chris134pravin,项目名称:VisualStudio,代码行数:5,代码来源:TrackingCollectionTests.cs

示例5: OrderByDescendingNoFilter

    public void OrderByDescendingNoFilter()
    {
        var count = 6;

        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, "Run 2")).ToList());

        var col = new TrackingCollection<Thing>(
            Observable.Never<Thing>(),
            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(6, col.Count);
#if DEBUG
        CollectionAssert.AreEqual(list1, col.DebugInternalList);
#endif
        CollectionAssert.AreEqual(col, list1);

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

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

        Assert.AreEqual(6, col.Count);

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

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

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

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

示例9: ChangingSortingAndUpdatingItemsUpdatesSortCorrectly

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

        ITrackingCollection<Thing> col = new TrackingCollection<Thing>(
            source);
        col.Comparer = OrderedComparer<Thing>.OrderBy(x => x.UpdatedAt).Compare;
        col.NewerComparer = OrderedComparer<Thing>.OrderByDescending(x => x.UpdatedAt).Compare;
        col.Filter = (item, position, list) =>
            position == 2 || position == 3 || position == 5 || position == 7;
        col.ProcessingDelay = TimeSpan.Zero;

        var count = 0;
        var expectedCount = 0;
        var evt = new ManualResetEvent(false);

        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);
//.........这里部分代码省略.........
开发者ID:github,项目名称:VisualStudio,代码行数:101,代码来源:TrackingCollectionTests.cs

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

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

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

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

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

示例15: Run2

        void Run2()
        {
            var count = 10;
            var col = new TrackingCollection<Thing>();
            col.ProcessingDelay = TimeSpan.FromMilliseconds(20);

            col.NewerComparer = OrderedComparer<Thing>.OrderByDescending(x => x.UpdatedAt).Compare;
            list.ItemsSource = col;

            var source = Observable.Merge(
                Observable.Generate(0, i => i < count, i => i + 1, i => i, i => TimeSpan.FromMilliseconds(5))
                    .Select(i => GetThing(i, i, i, "Run 1")),
                Observable.Generate(0, i => i < count, i => i + 1, i => i, i => TimeSpan.FromMilliseconds(7))
                    .Select(i => GetThing(i, i, i + 1, "Run 2"))
            );

            col.Listen(source);
            col.Subscribe();
        }
开发者ID:shana,项目名称:handy-things,代码行数:19,代码来源:MainWindow.xaml.cs


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