Beispiel #1
0
        public ReactiveSamplePanelViewModel(IReactiveSamplePanelAdapter samplePanelAdapter)
        {
            this.adapter = samplePanelAdapter;
            this.adapter.AddTo(this.disposables);

            this.hasId = new ReactivePropertySlim <bool>(false)
                         .AddTo(this.disposables);

            this.Id = this.adapter.Person.Id
                      .ToReactivePropertySlimAsSynchronized(x => x.Value)
                      .AddTo(this.disposables);
            this.Name = this.adapter.Person.Name
                        .ToReactivePropertySlimAsSynchronized(x => x.Value)
                        .AddTo(this.disposables);
            this.BirthDay = this.adapter.Person.BirthDay
                            .ToReactivePropertySlimAsSynchronized(x => x.Value)
                            .AddTo(this.disposables);
            this.Age = this.adapter.Person.Age
                       .ToReadOnlyReactivePropertySlim()
                       .AddTo(this.disposables);

            this.Id.Subscribe(v => this.hasId.Value = v.HasValue);

            this.LoadClick = this.hasId
                             .ToAsyncReactiveCommand()
                             .WithSubscribe(() => this.onLoadClick())
                             .AddTo(this.disposables);

            this.SaveButtonClick = new AsyncReactiveCommand()
                                   .WithSubscribe(async() => await this.adapter.SavePersonAsync())
                                   .AddTo(this.disposables);
        }
        /// <summary>コンストラクタ。</summary>
        /// <param name="samplePanelAdapter">Model呼び出し用のアダプタを表すIReactiveSamplePanelAdapter。(DIコンテナからインジェクションされる)</param>
        public ReactiveSample2ViewModel(IReactiveSamplePanelAdapter samplePanelAdapter)
        {
            this.adapter = samplePanelAdapter;
            this.adapter.AddTo(this.disposables);

            this.SearchResults = this.adapter.SearchResults
                                 .ToReadOnlyReactiveCollection(x => new BleachListItemViewModel(x))
                                 .AddTo(this.disposables);
            this.SelectedCharacterIndex = new ReactivePropertySlim <int>(-1)
                                          .AddTo(this.disposables);

            this.ShowListItemsClick = new AsyncReactiveCommand()
                                      .WithSubscribe(() => this.adapter.SearchCharacterAsync())
                                      .AddTo(this.disposables);

            this.GetItemsClick = this.SelectedCharacterIndex.Select(i => 0 <= i)
                                 .ToAsyncReactiveCommand()
                                 .WithSubscribe(() =>
            {
                return(Task.Run(() =>
                {
                    var selectedItems = this.SearchResults.Where(i => i.IsSelected.Value)
                                        .Select(i => i.SourcePerson)
                                        .ToList();

                    selectedItems.ForEach(i => Debug.WriteLine(i.ToString()));
                }));
            });

            this.SelectItemsClick = this.SearchResults.ObserveProperty(x => x.Count)
                                    .Select(c => 0 < c)
                                    .ToAsyncReactiveCommand()
                                    .WithSubscribe(() =>
            {
                return(Task.Run(() =>
                {
                    this.SearchResults
                    .Where(vm => 40 <= vm.SourcePerson.Age.Value && vm.SourcePerson.Age.Value <= 50)
                    .ToList()
                    .ForEach(vm => vm.IsSelected.Value = true);
                }));
            });
        }
Beispiel #3
0
        /// <summary>コンストラクタ。</summary>
        /// <param name="samplePanelAdapter">ReactiveSamplePanel用アダプタを表すIReactiveSamplePanelAdapter。(DIコンテナからインジェクション。)</param>
        public ReactiveSamplePanelViewModel(IReactiveSamplePanelAdapter samplePanelAdapter)
        {
            this.adapter = samplePanelAdapter;
            this.adapter.AddTo(this.disposables);

            this.hasId = new ReactivePropertySlim <bool>(false)
                         .AddTo(this.disposables);

            this.Id = this.adapter.Person.Id
                      .ToReactivePropertySlimAsSynchronized(x => x.Value)
                      .AddTo(this.disposables);
            this.Name = this.adapter.Person.Name
                        .ToReactivePropertySlimAsSynchronized(x => x.Value)
                        .AddTo(this.disposables);
            this.BirthDay = this.adapter.Person.BirthDay
                            .ToReactivePropertySlimAsSynchronized(x => x.Value)
                            .AddTo(this.disposables);
            this.Zanpakuto = this.adapter.Person.Zanpakuto
                             .ToReactivePropertySlimAsSynchronized(x => x.Value)
                             .AddTo(this.disposables);
            this.Age = this.adapter.Person.Age
                       .ToReadOnlyReactivePropertySlim()
                       .AddTo(this.disposables);

            this.Id.Subscribe((v) => this.hasId.Value = v.HasValue);

            this.SelectedCharacterIndex = new ReactivePropertySlim <int>(-1)
                                          .AddTo(this.disposables);
            this.SelectedCharacterIndex.Where(i => 0 <= i)
            .Subscribe((i) => this.adapter.UpdatePersonFromSearchResults(i));
            this.SelectedCharacter = new ReactivePropertySlim <BleachListItemViewModel>(null)
                                     .AddTo(this.disposables);

            this.SearchResults = this.adapter.SearchResults
                                 .ToReadOnlyReactiveCollection(x => new BleachListItemViewModel(x))
                                 .AddTo(this.disposables);
            this.hasSelectedIndex = this.SelectedCharacterIndex
                                    .Select(i => 0 <= i)
                                    .ToReadOnlyReactivePropertySlim()
                                    .AddTo(this.disposables);

            this.SelectedValue = new ReactiveProperty <string>(string.Empty)
                                 .AddTo(this.disposables);

            this.SelectListBoxButtonClick = new[]
            {
                this.SearchResults.ObserveProperty(x => x.Count).Select(c => 0 < c),
                this.Name.Select(n => 0 < n.Length)
            }
            .CombineLatestValuesAreAllTrue()
            .ToAsyncReactiveCommand()
            .WithSubscribe(async() => this.SelectedCharacterIndex.Value = await this.adapter.GetCharacterIndex())
            .AddTo(this.disposables);

            this.LoadClick = this.hasId
                             .ToAsyncReactiveCommand()
                             .WithSubscribe(() => this.onLoadClick())
                             .AddTo(this.disposables);

            this.SaveButtonClick = new AsyncReactiveCommand()
                                   .WithSubscribe(async() => await this.adapter.SavePersonAsync())
                                   .AddTo(this.disposables);

            this.SearchButtonClick = new AsyncReactiveCommand()
                                     .WithSubscribe(() => this.adapter.SearchCharacterAsync())
                                     .AddTo(this.disposables);

            this.ClearButtonClick = new AsyncReactiveCommand()
                                    .WithSubscribe(() => this.adapter.ClearAllCharactersAsync())
                                    .AddTo(this.disposables);

            this.AddCharacterClick = new AsyncReactiveCommand()
                                     .WithSubscribe(() => this.adapter.AddRandomCharacterAsync())
                                     .AddTo(this.disposables);

            this.InsertButtonClick = this.hasSelectedIndex
                                     .ToAsyncReactiveCommand()
                                     .WithSubscribe(() => this.adapter.InsertRandomCharacterAsync(this.SelectedCharacterIndex.Value))
                                     .AddTo(this.disposables);

            this.RemoveButtonClick = this.hasSelectedIndex
                                     .ToAsyncReactiveCommand()
                                     .WithSubscribe(() => this.removeCharacter())
                                     .AddTo(this.disposables);

            this.MoveUpCharacter = this.SelectedCharacterIndex.Select(v => 0 < v)
                                   .ToAsyncReactiveCommand()
                                   .WithSubscribe(() => this.adapter.MoveCharacterAsync(this.SelectedCharacterIndex.Value, true))
                                   .AddTo(this.disposables);
            this.MoveDownCharacter = this.SelectedCharacterIndex.Select(v => v < this.SearchResults.Count - 1)
                                     .ToAsyncReactiveCommand()
                                     .WithSubscribe(() => this.adapter.MoveCharacterAsync(this.SelectedCharacterIndex.Value, false))
                                     .AddTo(this.disposables);
        }