public async Task <LoginResponse> LoginAsync(string username, string password) { MessageListener <LoginResponse> loginResponseListener = new MessageListener <LoginResponse>(); loginResponseListener.Subscribe(_messageProcessor); LoginRequest loginRequest = new LoginRequest(Guid.NewGuid(), username, password); await _networkConnector.SendMessageAsync(loginRequest, CancellationToken.None); LoginResponse loginResponse = await loginResponseListener.ReceiveMessageAsync(); loginResponseListener.Unsubscribe(); return(loginResponse); }
public async Task <JoinLobbyResponse> JoinLobby(string lobbyName) { MessageListener <JoinLobbyResponse> joinLobbyResponseListener = new MessageListener <JoinLobbyResponse>(); joinLobbyResponseListener.Subscribe(_messageProcessor); JoinLobbyRequest joinLobbyRequest = new JoinLobbyRequest(Guid.NewGuid(), _loggedInUser, lobbyName); await _networkConnector.SendMessageAsync(joinLobbyRequest, CancellationToken.None); JoinLobbyResponse joinLobbyResponse = await joinLobbyResponseListener.ReceiveMessageAsync(); joinLobbyResponseListener.Unsubscribe(); return(joinLobbyResponse); }
public async void StartGame() { StartGameRequest startGameRequest = new StartGameRequest(); await networkConnector.SendMessageAsync(startGameRequest, CancellationToken.None); scene.ChangeScene(Scenes.GAME); }
/// <inheritdoc cref="IService{TDto}.CreateAsync(TDto)"/> public override Task <(bool success, Guid id)> CreateAsync(ServiceDto dto) { return(base.CreateAsync(dto) .ContinueWith(task => { if (task.Result.success && _networkConnector.IsRunning) { AddServiceCommand addServiceCommand = new AddServiceCommand() { Id = Guid.NewGuid(), DateTime = dto.Start, Service = new Messages.Dtos.ServiceDto() { Id = dto.Id, Host = dto.Host, Port = dto.Port, Name = dto.Name } }; Task.Run(async() => await _networkConnector.SendMessageAsync(addServiceCommand, CancellationToken.None)); } return task.Result; })); }
/// <inheritdoc cref="IServiceConnector.StartPublishingAsync(CancellationToken)" /> public async Task StartPublishingAsync(CancellationToken cancellationToken) { while (!cancellationToken.IsCancellationRequested) { await TaskEx.WaitUntil(() => _networkConnectors.Count != 0, cancellationToken : cancellationToken); cancellationToken.ThrowIfCancellationRequested(); IMessage message = await _messageQueue.DequeueAsync(cancellationToken); INetworkConnector networkConnector = null; while (networkConnector == null) { networkConnector = GetNetworkConnector(); cancellationToken.ThrowIfCancellationRequested(); } _ = Task.Run(() => networkConnector.SendMessageAsync(message, cancellationToken), cancellationToken); } }
private static async Task SendMessageToClientAsync(IMessage message, INetworkConnector clientNetworkConnector) { await clientNetworkConnector.SendMessageAsync(message, CancellationToken.None); }
public async Task MoveTankAsync(Tank tank) { TankMovementCommand tankMovementCommand = new TankMovementCommand(Guid.NewGuid(), _userLobbyObject.GetJoinedLobby().Name, tank, _userLobbyObject.GetLoggedInUser().Id); await _networkConnector.SendMessageAsync(tankMovementCommand, CancellationToken.None); }