Example #1
0
        public void New()
        {
            var newPeople = Enumerable.Range(1, 15).Select(i => new Person("Name" + i, i)).ToArray();

            _cache.EditDiff(newPeople, (current, previous) => Person.AgeComparer.Equals(current, previous));

            Assert.AreEqual(15, _cache.Count);
            CollectionAssert.AreEquivalent(newPeople, _cache.Items);
            var lastChange = _result.Messages.Last();

            Assert.AreEqual(5, lastChange.Adds);
        }
        public void New()
        {
            var newPeople = Enumerable.Range(1, 15).Select(i => new Person("Name" + i, i)).ToArray();

            _cache.EditDiff(newPeople, (current, previous) => Person.AgeComparer.Equals(current, previous));

            _cache.Count.Should().Be(15);
            _cache.Items.Should().BeEquivalentTo(newPeople);
            var lastChange = _result.Messages.Last();

            lastChange.Adds.Should().Be(5);
        }
Example #3
0
 /// <summary>
 /// Load chats into observable cache
 /// </summary>
 private IDisposable LoadChats(IChatLoader chatLoader, IAvatarLoader avatarLoader)
 {
     return(chatLoader.LoadChats()
            .Select(GetChatEntryModel)
            .Aggregate(new List <EntryModel>(), (list, model) =>
     {
         model.Order = list.Count;
         list.Add(model);
         return list;
     })
            .Synchronize(_chats)
            .Do(entries =>
     {
         _chats.EditDiff(entries, (m1, m2) => m1.Id == m2.Id);
         _chats.Refresh();
     })
            .SelectMany(entries => entries)
            .SelectMany(entry => LoadAvatar(avatarLoader, entry)
                        .Select(avatar => new
     {
         Entry = entry,
         Avatar = avatar
     }))
            .SubscribeOn(TaskPoolScheduler.Default)
            .ObserveOn(RxApp.MainThreadScheduler)
            .Subscribe(item =>
     {
         var entry = item.Entry;
         var avatar = item.Avatar;
         entry.Avatar = avatar;
     }));
 }
Example #4
0
        public void Amends()
        {
            var newList = Enumerable.Range(5, 3).Select(i => new Person("Name" + i, i + 10)).ToArray();

            _cache.EditDiff(newList, (current, previous) => Person.AgeComparer.Equals(current, previous));

            _cache.Count.Should().Be(3);

            var lastChange = _result.Messages.Last();

            lastChange.Adds.Should().Be(0);
            lastChange.Updates.Should().Be(3);
            lastChange.Removes.Should().Be(7);

            _cache.Items.Should().BeEquivalentTo(newList);
        }
        /// <summary>
        /// Load chats into observable cache
        /// </summary>
        private IDisposable LoadChats()
        {
            return(_chatLoader.LoadChats()
                   .Select(GetChatEntryModel)
                   .Aggregate(new List <EntryModel>(), (list, model) =>
            {
                model.Order = list.Count;
                list.Add(model);
                return list;
            })
                   .Accept(entries =>
            {
                entries.Insert(0, HomeEntryModel.Instance);

                _chats.EditDiff(entries, (m1, m2) => m1.Id == m2.Id);
                _chats.Refresh();
            }));
        }
Example #6
0
 /// <summary>
 /// Load chats into observable cache
 /// </summary>
 private IDisposable LoadChats(
     IChatLoader chatLoader)
 {
     return(chatLoader.LoadChats()
            .Select(GetChatEntryModel)
            .Aggregate(new List <EntryModel>(), (list, model) =>
     {
         model.Order = list.Count;
         list.Add(model);
         return list;
     })
            .Synchronize(_chats)
            .Accept(entries =>
     {
         _chats.EditDiff(entries, (m1, m2) => m1.Id == m2.Id);
         _chats.Refresh();
     }));
 }
Example #7
0
        public DockerService()
        {
            Client = new DockerClientConfiguration().CreateClient();
            Events = new DockerEvents(Client);
            Name   = string.Empty;

            Task.Run(async() =>
            {
                var info = await Client.System.GetSystemInfoAsync();
                Name     = info.Name ?? string.Empty;
            });

            var images = new SourceCache <ImagesListResponse, string>(x => x.ID);

            Images = images;
            void UpdateImagesCache() => Task.Run(async() => images.EditDiff(
                                                     await Client.Images.ListImagesAsync(new ImagesListParameters {
                All = true
            }),
                                                     (i1, i2) => i1.ID == i2.ID
                                                     ));

            UpdateImagesCache();
            Events
            .Where(e => e.Type == DockerEventType.Image)
            .Subscribe(_ => UpdateImagesCache());

            var containers = new SourceCache <ContainerListResponse, string>(x => x.ID);

            Containers = containers;
            void UpdateContainersCache() => Task.Run(async() => containers.EditDiff(
                                                         await Client.Containers.ListContainersAsync(new ContainersListParameters {
                All = true
            }),
                                                         (c1, c2) => c1.ID == c2.ID
                                                         ));

            UpdateContainersCache();
            Events
            .Where(e => e.Type == DockerEventType.Container)
            .Subscribe(_ => UpdateContainersCache());
        }
        public NuGetPackageListViewModel(INavigationService navigationService, INuGetPackageService nugetPackageService)
        {
            _navigationService   = navigationService;
            _nugetPackageService = nugetPackageService;

            PackageDetails = ReactiveCommand.CreateFromTask <NuGetPackageViewModel>(ExecutePackageDetails);
            Refresh        = ReactiveCommand.CreateFromTask(ExecuteRefresh);

            Refresh.ThrownExceptions.Subscribe(exception => this.Log().Warn(exception));
            PackageDetails.ThrownExceptions.Subscribe(exception => this.Log().Warn(exception));

            var nugetChangeSet =
                _nugetCache
                .Connect()
                .RefCount();

            var sortChanged =
                this.WhenAnyValue(x => x.SelectedTag)
                .Where(x => !string.IsNullOrEmpty(x))
                .Select(selectedTag =>
                        SortExpressionComparer <NuGetPackageViewModel>
                        .Ascending(x => x.PackageMetadata.DownloadCount)
                        .ThenByAscending(x => x.PackageMetadata.Tags.Contains(selectedTag)));

            nugetChangeSet
            .Transform(x => new NuGetPackageViewModel(x))
            .Sort(sortChanged)
            .Bind(out _searchResults)
            .DisposeMany()
            .Subscribe()
            .DisposeWith(Disposal);

            _nugetCache
            .CountChanged
            .Select(count => count > 0)
            .ToProperty(this, x => x.HasItems, out _hasItems)
            .DisposeWith(Disposal);

            nugetChangeSet
            .Transform(x => x.Tags.Split(','))
            .RemoveKey()
            .TransformMany(x => x)
            .DistinctValues(x => x)
            .Bind(out _tags)
            .Subscribe()
            .DisposeWith(Disposal);

            Search =
                ReactiveCommand.CreateFromObservable <string, IEnumerable <IPackageSearchMetadata> >(SearchNuGetPackages);

            Search
            .Select(packageSearchMetadata => packageSearchMetadata)
            .Subscribe(packages =>
                       _nugetCache.EditDiff(packages, (first, second) => first.Identity.Id == second.Identity.Id))
            .DisposeWith(Disposal);

            this.WhenAnyValue(x => x.SearchText)
            .Where(x => !string.IsNullOrEmpty(x))
            .Throttle(TimeSpan.FromMilliseconds(750), RxApp.TaskpoolScheduler)
            .Select(term => term.Trim())
            .DistinctUntilChanged()
            .InvokeCommand(this, x => x.Search)
            .DisposeWith(Disposal);

            this.WhenAnyValue(x => x.SearchText)
            .Where(string.IsNullOrEmpty)
            .Subscribe(_ => _nugetCache.Clear())
            .DisposeWith(Disposal);

            this.WhenAnyObservable(x => x.Refresh.IsExecuting)
            .StartWith(false)
            .DistinctUntilChanged()
            .ToProperty(this, x => x.IsRefreshing, out _isRefreshing)
            .DisposeWith(Disposal);
        }
Example #9
0
 public IObservable <Unit> GetThreads(string searchCriteria, int itemsPerPage) =>
 _threadApi.GetClient().FetchThreads(searchCriteria, itemsPerPage).Select(result =>
 {
     _threads.EditDiff(result.Data);
     return(Unit.Default);
 });
Example #10
0
 public IObservable <Unit> GetMovies(string movieName, int itemsPerPage) =>
 _moviesApi.GetClient().FetchMovies(movieName, itemsPerPage).Select(result =>
 {
     _movies.EditDiff(result.Data);
     return(Unit.Default);
 });
Example #11
0
 public IObservable <Unit> GetComments(int threadId, int itemsPerPage) =>
 _commentApi.GetClient().FetchComments(threadId, itemsPerPage).Select(result =>
 {
     _comments.EditDiff(result.Data);
     return(Unit.Default);
 });