public async Task <ISuccessOrErrors <Common.BoardState> > JoinGame(SeatII seat, Guid playerId) { seat.State.PlayerId = playerId; seat.State.ETag = Guid.NewGuid().ToString(); await seat.WriteStateAsync(); var game = seat.GrainFactory.GetGrain <IGame> (seat.GetPrimaryKey()); var boardState = await game.GetBoardState(); var provider = seat.GetStreamProvider(seat.PlayerSeatStreamProvider); var stream = provider.GetStream <PlayerTookSeatII> (seat.GetPrimaryKey(), nameof(PlayerTookSeatII)); await stream.OnNextAsync(new PlayerTookSeatII (playerId)); var result = new Success <Common.BoardState> (new Common.BoardState(boardState)); return(result); }
public async Task <ISuccessOrErrors <Common.BoardState> > LeaveGame(SeatII seat) { var playerId = seat.State.PlayerId.GetValueOrDefault(); seat.State.PlayerId = null; seat.State.ETag = Guid.NewGuid().ToString(); await seat.WriteStateAsync(); var game = seat.GrainFactory.GetGrain <IGame> (seat.GetPrimaryKey()); var boardState = await game.GetBoardState(); var provider = seat.GetStreamProvider(seat.PlayerSeatStreamProvider); var stream = provider.GetStream <PlayerLeftSeatII> (seat.GetPrimaryKey(), nameof(PlayerLeftSeatII)); await stream.OnNextAsync(new PlayerLeftSeatII (playerId)); return(new Success <Common.BoardState> (new Common.BoardState(boardState))); }