private void RegisterToService()
        {
            _server.HubConnection.On("GameRequested", async(string userName) =>
            {
                await System.Windows.Application.Current.Dispatcher.InvokeAsync(
                    () =>
                {
                    GameRequested?.Invoke(this, new UserActionEventArgs(userName));
                });
            });

            _server.HubConnection.On("GameAccepted", async(Guid gameId, string user) =>
            {
                await System.Windows.Application.Current.Dispatcher.InvokeAsync(
                    () =>
                {
                    GameAccepted?.Invoke(this, new GameAcceptedEventArgs(gameId, user));
                });
            });

            _server.HubConnection.On("GameDeclined", async(string userName) =>
            {
                await System.Windows.Application.Current.Dispatcher.InvokeAsync(
                    () =>
                {
                    GameDeclined?.Invoke(this, new UserActionEventArgs(userName));
                });
            });

            _server.HubConnection.On("MoveMade", async(Game game) =>
            {
                await System.Windows.Application.Current.Dispatcher.InvokeAsync(
                    () =>
                {
                    MoveFinished?.Invoke(this, new MoveMadeEventArgs(game));
                });
            });
        }
Beispiel #2
0
        public void Init()
        {
            if (_isInitialized)
            {
                return;
            }
            _isInitialized = true;

            _hubConnection = new HubConnection(Secrets.GoHubUrl);
            _goHub         = _hubConnection.CreateHubProxy("GoHub");

            _goHub.On(nameof(UserConnected), (UserPrefs user) => UserConnected?.Invoke(user));
            _goHub.On(nameof(UserDisconnected), (string user) => UserDisconnected?.Invoke(user));

            _goHub.On(nameof(LobbyPost), (Post post) => LobbyPost?.Invoke(post));
            _goHub.On(nameof(GamePost), (Post post) => GamePost?.Invoke(post));

            _goHub.On(nameof(GameRequested), (string name) => GameRequested?.Invoke(name));
            _goHub.On(nameof(GameRequestDeclined), (string name) => GameRequestDeclined?.Invoke(name));
            _goHub.On(nameof(GameRequestCancelled), (string name) => GameRequestCancelled?.Invoke(name));
            _goHub.On(nameof(GameRequestAccepted), (string name) => GameRequestAccepted?.Invoke(name));

            _goHub.On(nameof(GameAborted), (string name) => GameAborted?.Invoke(name));
        }