Пример #1
0
        public TweetsListViewModel()
        {
            TweetTiles = Tweets.CreateDerivedCollection(
                x => new TweetTileViewModel()
            {
                Model = x
            },
                x => true,
                (x, y) => x.Model.CreatedAt.CompareTo(y.Model.CreatedAt));

            VisibleTiles = TweetTiles.CreateDerivedCollection(
                x => x,
                x => !x.IsHidden);
        }
Пример #2
0
        public GamesViewModel(IDependencyResolver resolver)
        {
            var menuManager = resolver.GetService <IPinballXManager>();
            var gameManager = resolver.GetService <IGameManager>();

            // create platforms, filtered and sorted
            Systems = menuManager.Systems.CreateDerivedCollection(
                system => new SystemItemViewModel(this, system),
                system => system.Enabled,
                (x, y) => string.Compare(x.System.Name, y.System.Name, StringComparison.OrdinalIgnoreCase)
                );

            // this is the list we only create once
            _allGameViewModels = gameManager.AggregatedGames.CreateDerivedCollection(
                game => new GameItemViewModel(game, resolver)
            {
                IsVisible = IsGameVisible(game)
            }
                );

            // this is the list that gets filtered
            Games = _allGameViewModels.CreateDerivedCollection(
                gameViewModel => gameViewModel,
                gameViewModel => gameViewModel.IsVisible,
                (x, y) => string.Compare(Path.GetFileName(x.Game.FileId), Path.GetFileName(y.Game.FileId), StringComparison.OrdinalIgnoreCase)
                );
            _allGameViewModels.ChangeTrackingEnabled = true;

            // update platform filter when platforms change
            Systems.Changed
            .Select(_ => Unit.Default)
            .StartWith(Unit.Default)
            .Subscribe(x => UpdateSystems());

            menuManager.GamesUpdated.Subscribe(x => RefreshGameVisibility());
            this.WhenAnyValue(vm => vm.ShowDisabled, vm => vm.ShowHidden).Subscribe(x => RefreshGameVisibility());
            this.WhenAnyValue(vm => vm.StatusFilter).Subscribe(x => RefreshGameVisibility());
        }
Пример #3
0
        public GamesViewModel(IDependencyResolver resolver)
        {
            _platformManager = resolver.GetService<IPlatformManager>();
            var gameManager = resolver.GetService<IGameManager>();

            // setup init listener
            gameManager.Initialized.Subscribe(_ => SetupTracking());

            // create platforms, filtered and sorted
            Platforms = _platformManager.Platforms.CreateDerivedCollection(
                platform => platform,
                platform => platform.IsEnabled,
                (x, y) => string.Compare(x.Name, y.Name, StringComparison.Ordinal)
            );

            // push all games into AllGames as view models and sorted
            _allGames = gameManager.Games.CreateDerivedCollection(
                game => new GameItemViewModel(game, resolver) { IsVisible = IsGameVisible(game) },
                gameViewModel => true,
                (x, y) => string.Compare(x.Game.Id, y.Game.Id, StringComparison.Ordinal)
            );

            // push filtered game view models into Games
            Games = _allGames.CreateDerivedCollection(
                gameViewModel => gameViewModel,
                gameViewModel => gameViewModel.IsVisible);

            // todo check if we can simplify this.
            IdentifyAll.Subscribe(_ => {

                /*
                Games
                    .ToObservable()
                    .Where(g => g.ShowIdentifyButton)
                    .StepInterval(TimeSpan.FromMilliseconds(200)) // don't DOS the server...
                    .Select(g => Observable.DeferAsync(async token =>
                        Observable.Return(await System.Windows.Application.Current. // must be on main thread
                            Dispatcher.Invoke(async () => new { game = g, result = await g.IdentifyRelease.ExecuteAsyncTask() }))))
                    .Merge(1)
                    .Subscribe(x => {
                        if (x.result.Count == 0) {
                            System.Windows.Application.Current.Dispatcher.Invoke(delegate {
                                x.game.CloseResults.Execute(null);
                            });
                        }
                    });*/

                Games
                    .ToObservable()
                    .Where(g => !g.HasExecuted && !g.Game.HasRelease && !g.IsExecuting)
                    .StepInterval(TimeSpan.FromMilliseconds(200)) // don't DOS the server...
                    .Subscribe(g => {
                        System.Windows.Application.Current.Dispatcher.Invoke(async () => {
                            var result = await g.IdentifyRelease.ExecuteAsyncTask();
                            if (result.Count == 0) {
                                g.CloseResults.Execute(null);
                            }
                        });
                    });
            });
        }