Esempio n. 1
0
        public ConnectionViewModel()
        {
            DisconnectCommand = IsConnected.CombineLatest(IsConnecting, (a, b) => a || b).ToAsyncReactiveCommand();
            DisconnectCommand.Subscribe(() => Disconnect()).AddTo(Disposable);

            DisplayText = ConnectionName.CombineLatest(Host, Port, IsConnecting,
                                                       (name, host, port, isConnecting) =>
            {
                var hostport = host + (port == null ? "" : $":{port}");
                var status   = "";
                if (isConnecting)
                {
                    status = $" - {Resources.Connection_ConnectingText}";
                }
                var identity = string.IsNullOrWhiteSpace(name)
                        ? hostport
                        : $"{name} ({hostport})";
                return(identity + status);
            }).ToReactiveProperty();
        }
Esempio n. 2
0
        public MainViewModel()
        {
            // ファイルから読む体で
            userDict.Add("111", new UserModel("111", "社会人P")
            {
                Color = Colors.LightGreen
            });
            userDict.Add("222", new UserModel("222", "八百屋"));

            Comments = model.Comments.ToReadOnlyReactiveCollection(comment =>
            {
                if (!userDict.TryGetValue(comment.ID, out var user))
                {
                    user = new UserModel(comment.ID);
                    userDict.Add(user.ID, user);
                }

                return(new CommentViewModel(comment, user));
            }).AddTo(disposable);

            #region Command
            NameChangeCommand.Subscribe(obj =>
            {
                var menuItem = obj as MenuItem;
                var comment  = menuItem.DataContext as CommentViewModel;
                var ib       = new InputBox
                {
                    DataContext = comment,
                    Text        = comment.Name.Value,
                };

                if (ib.ShowDialog() == true)
                {
                    comment.Name.Value = ib.Text;
                }
            });

            ColorChangeCommand.Subscribe(obj =>
            {
                var menuItem        = obj as MenuItem;
                var comment         = menuItem.DataContext as CommentViewModel;
                comment.Color.Value = (Color)menuItem.Tag;
            });

            ConnectCommand = IsRunning.Select(x => !x).ToAsyncReactiveCommand();
            ConnectCommand.Subscribe(async _ =>
            {
                await model.ConnectAsync("lv1234567");
                IsRunning.Value = true;
            }).AddTo(disposable);

            DisconnectCommand = IsRunning.ToReactiveCommand();
            DisconnectCommand.Subscribe(_ =>
            {
                model.Disconnect();
                IsRunning.Value = false;
            }).AddTo(disposable);
            #endregion

            ConnectCommand.Execute();
        }
        public MainWindowViewModel()
        {
            _commandService       = new PaletteCommandService();
            CommandPaletteCommand = new ReactiveCommand();
            CommandPaletteCommand.Subscribe(
                _ =>
            {
                if (!IsCommandPaletteOpen.Value)
                {
                    IsCommandPaletteOpen.Value = true;
                }
                else
                {
                    IsCommandPaletteOpen.Value = false;
                }
            });
            IsCommandPaletteOpen = new ReactiveProperty <bool>();

            State = new ReactiveProperty <TargetState>();

            TargetList = new ReactiveCollection <string>();
            TargetList.Add(new string("default"));
            TargetList.Add(new string("TargetA"));
            TargetList.Add(new string("TargetB"));
            TargetList.Add(new string("TargetC"));

            ConnectCommand = State
                             .Select(x => x == TargetState.NotConnected)
                             .ToReactiveCommand <string>()
                             .AddTo(Disposable);
            ConnectCommand.Subscribe(
                (target) =>
            {
                State.Value = TargetState.Connected;
            });

            var targetItemList = new List <IPaletteSearchItem>();

            foreach (var target in TargetList)
            {
                var targetItem = PaletteParameterFactory.CreateSearchItem(target, target.ToString());
                targetItemList.Add(targetItem);
            }
            var targetParameter = PaletteParameterFactory.CreateSearchParameter(targetItemList, "Target", "接続先を指定してください");

            _commandService.AddCommand(ConnectCommand,
                                       nameof(ConnectCommand),
                                       "ターゲットと接続します",
                                       (paramList) =>
            {
                return(paramList.First());
            },
                                       targetParameter);

            DisconnectCommand = State
                                .Select(x => x != TargetState.NotConnected)
                                .ToReactiveCommand()
                                .AddTo(Disposable);
            DisconnectCommand.Subscribe(
                _ =>
            {
                State.Value = TargetState.NotConnected;
            });
            _commandService.AddCommand(DisconnectCommand, nameof(DisconnectCommand), "ターゲットとの接続を切断します");
            Volume              = new ReactiveProperty <float>().AddTo(Disposable);
            Volume.Value        = 0.5f;
            ChangeVolumeCommand = new ReactiveCommand <float>();
            ChangeVolumeCommand.Subscribe((volume) =>
            {
                Volume.Value = volume;
            });
            var volumeParameter = PaletteParameterFactory.CreateMinMaxParameter(0.0f, 1.0f, "Volume", "ボリュームを変更します (0.0 - 1.0)");

            _commandService.AddCommand(ChangeVolumeCommand,
                                       nameof(ChangeVolumeCommand),
                                       "プレイバックボリュームを変更します",
                                       (paramList) =>
            {
                return(paramList.First());
            },
                                       volumeParameter);
            RecordingDirectory = new ReactiveProperty <string>().AddTo(Disposable);
            SelectRecordingDirectoryCommand = State
                                              .Select(x => x != TargetState.Recording)
                                              .ToReactiveCommand()
                                              .AddTo(Disposable);
            SelectRecordingDirectoryCommand.Subscribe(
                _ =>
            {
                MessageBox.Show("SelectCommand");
            });
            _commandService.AddCommand(SelectRecordingDirectoryCommand, nameof(SelectRecordingDirectoryCommand), "録音の保存先を選択します");
            StartRecordingCommand = State
                                    .Select(x => x == TargetState.Connected)
                                    .ToReactiveCommand()
                                    .AddTo(Disposable);
            StartRecordingCommand.Subscribe(
                _ =>
            {
                State.Value = TargetState.Recording;
            });
            _commandService.AddCommand(StartRecordingCommand, nameof(StartRecordingCommand), "録音を開始します");
            StopRecordingCommand = State
                                   .Select(x => x == TargetState.Recording)
                                   .ToReactiveCommand()
                                   .AddTo(Disposable);
            StopRecordingCommand.Subscribe(
                _ =>
            {
                State.Value = TargetState.Connected;
            });
            _commandService.AddCommand(StopRecordingCommand, nameof(StopRecordingCommand), "録音を終了します");
        }