Exemplo n.º 1
0
        public async Task LeaveFromGameTable(LeaveFromGameTableParams @params)
        {
            try
            {
                var gameTableId = _gameTableService.Leave(Context.User.GetUserId());

                await RemoveFromGroup(gameTableId.ToString(), Context.ConnectionId);
                await NotifyAboutPlayerLeaved(gameTableId, Context.User.GetUserId());

                await Clients.Caller.ReceiveLeaveResult(new ReceiveLeaveResultParams()
                {
                    Succeeded = true,
                    RequestId = @params.RequestId
                });
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, $"Ошибка выхода из-за игрового стола. Игрок с Id = {Context.User.GetUserId()}");

                await Clients.Caller.ReceiveLeaveResult(new ReceiveLeaveResultParams()
                {
                    Succeeded = false,
                    RequestId = @params.RequestId
                });
            }
        }
Exemplo n.º 2
0
        public Promise <ReceiveLeaveResultParams> LeaveFromGameTable(LeaveFromGameTableParams @params)
        {
            if (_isDisposed)
            {
                throw new ObjectDisposedException("Ресурсы объекта были освобождены");
            }

            if (_hubConnection == null)
            {
                throw new Exception("Подключение еще не было создано");
            }

            if (_hubConnection.State != HubConnectionState.Connected)
            {
                throw new Exception($"Подключение еще не установлено. Статус - {_hubConnection.State}");
            }

            var promise = new Promise <ReceiveLeaveResultParams>(@params.RequestId, () =>
            {
                _hubConnection.InvokeAsync(nameof(IMainHubApi.LeaveFromGameTable), @params);
            });

            ReceivedLeaveResult += promise.OnCopleted;

            return(promise);
        }