Example #1
0
        public OverlayWindowViewModel(IReactionHubProxy reactionHubProxy,
                                      IDisplayControlService displayControl,
                                      IUsersActivity usersActivity)
        {
            this.ReactionHub    = reactionHubProxy;
            this.DisplayControl = displayControl;
            this.UsersActivity  = usersActivity;

            this.DisplayTime = this.DisplayControl.DisplayTime
                               .ToReactiveProperty()
                               .AddTo(this.Disposable);
            this.MaxOpacity = this.DisplayControl.MaxOpacity
                              .ToReactiveProperty()
                              .AddTo(this.Disposable);
            this.Scale = this.DisplayControl.Scale
                         .ToReactiveProperty()
                         .AddTo(this.Disposable);
            this.MoveMethod = this.DisplayControl.MoveMethod
                              .ToReactiveProperty()
                              .AddTo(this.Disposable);
            this.OpacityCurve = this.DisplayControl.OpacityCurve
                                .ToReactiveProperty()
                                .AddTo(this.Disposable);
            this.Message = this.UsersActivity
                           .SelectedUser
                           .Select(x => x?.Name ?? "川原's System.")
                           .ToReactiveProperty()
                           .AddTo(this.Disposable);

            this.ReactionHub.Connected += async() =>
            {
                //リアクションの受信設定
                this.ReactionHub.OnReceiveReaction()
                .Subscribe(x => this.OnInteraction(x.Item1, x.Item2))
                .AddTo(this.Disposable);

                //リスナー登録
                var ret = await this.ReactionHub.AddListener();

                if (ret.ResultTypes == eResultTypes.Failed)
                {
                    throw new ArgumentException(ret.Message);
                }
            };
            this.ReactionHub.Open();
        }
        public UsersActivity(IReactionHubProxy reactionHubProxy, IUsersStore usersStore)
        {
            this.ReactionHubProxy = reactionHubProxy;
            this.UsersStore       = usersStore;

            this.ReactionHubProxy.Connected += () =>
            {
                this.ReactionHubProxy
                .OnReceiveReaction()
                .Subscribe(x =>
                {
                    var user = this.SelectedUser.Value;
                    if (user == null)
                    {
                        return;
                    }
                    lock ( user ) {
                        switch (x.Item1)
                        {
                        case Models.eReactionType.Good:
                            user.GoodCount++;
                            break;

                        case Models.eReactionType.Nice:
                            user.NiceCount++;
                            break;

                        case Models.eReactionType.Fun:
                            user.FunCount++;
                            break;
                        }
                    }
                })
                .AddTo(this.Disposable);
            };

            this.SelectedUser = new ReactivePropertySlim <IUser>();
            this.Users        = new ReactiveCollection <IUser>();

            this.Load();
        }
        public ConnectionControlViewModel(IReactionHubProxy reactionHubProxy, IConnectionService connectionService)
        {
            this.ReactionHub       = reactionHubProxy;
            this.ConnectionService = connectionService;

            this.ServerURL = Observable.FromEvent <string>(
                handler => this.ReactionHub.ServerURLChanged += handler,
                handler => this.ReactionHub.ServerURLChanged -= handler)
                             .Select(x => x ?? "N/A")
                             .ToReactiveProperty(Properties.Settings.Default.LastServerURL.NotEmptyOrDefault("N/A"))
                             .AddTo(this.Disposable);
            this.ServerURL
            .Where(x => x != "N/A")
            .Select(x => string.IsNullOrWhiteSpace(x) ? null : x)
            .Subscribe(x => this.ReactionHub.ServerURL = x)
            .AddTo(this.Disposable);

            this.PresentationID = Observable.FromEvent <Action <string, string>, string>(
                handler => (newValue, oldValue) => handler(newValue),
                handler => this.ReactionHub.PresentationIDChanged += handler,
                handler => this.ReactionHub.PresentationIDChanged -= handler)
                                  .Select(x => x ?? "N/A")
                                  .ToReactiveProperty(Properties.Settings.Default.LastPresentationID.NotEmptyOrDefault("N/A"))
                                  .AddTo(this.Disposable);
            this.PresentationID
            .Where(x => x != "N/A")
            .Select(x => string.IsNullOrWhiteSpace(x) ? null : x)
            .Subscribe(x => this.ReactionHub.PresentationID = x)
            .AddTo(this.Disposable);

            this.ConnectionState = Observable.FromEvent <bool>(
                handler => this.ConnectionService.HasConnectionChanged += handler,
                handler => this.ConnectionService.HasConnectionChanged -= handler)
                                   .Select(x => x ? "接続完了" : "切断")
                                   .ToReadOnlyReactiveProperty(this.ConnectionService.HasConnection ? "接続完了" : "切断")
                                   .AddTo(this.Disposable);

            this.SettingChangeCommand = new ReactiveCommand();
            this.SettingChangeCommand
            .Subscribe(_ =>
            {
                var inputSetting = new InputSettingNotification {
                    Title = "通信設定 ・ 変更"
                };
                this.InputSettingRequest.Raise(inputSetting);

                if (inputSetting.Confirmed)
                {
                    this.ReactionHub.PresentationID = inputSetting.InputPresentationID;

                    try {
                        this.ReactionHub.ServerURL = inputSetting.InputServerURL;
                    } catch (InvalidOperationException ex) {
                        inputSetting.InputServerURL = this.ReactionHub.ServerURL;

                        this.ExceptionNotificationRequest.Raise(
                            new Notification {
                            Title   = "ERROR",
                            Content = ex.Message
                        });
                    }
                }
            })
            .AddTo(this.Disposable);

            this.InputSettingRequest          = new InteractionRequest <InputSettingNotification>();
            this.ExceptionNotificationRequest = new InteractionRequest <Notification>();

            this.Title.Value = "Connection";
        }