Example #1
0
        public async Task <StopGameResponse> StopGameAsync(StopGameRequest request)
        {
            LogInfo($"Stop game: ConnectionId = {CurrentRequest.RequestContext.ConnectionId}");

            // fetch game record from table
            var gameRecord = await _table.GetAsync <GameRecord>(request.GameId);

            if (gameRecord == null)
            {
                LogInfo("No game found to stop");

                // game is already stopped, nothing further to do
                return(new StopGameResponse());
            }

            // check if game state machine needs to be stopped
            if (gameRecord.GameLoopArn != null)
            {
                LogInfo($"Stopping Step Function: Name = {gameRecord.GameLoopArn}");
                try {
                    await _stepFunctionsClient.StopExecutionAsync(new StopExecutionRequest {
                        ExecutionArn = gameRecord.GameLoopArn,
                        Cause        = "user requested game to be stopped"
                    });
                } catch (Exception e) {
                    LogErrorAsInfo(e, "unable to stop state-machine");
                }
            }

            // delete game record
            LogInfo($"Deleting game record: ID = {request.GameId}");
            await _table.DeleteAsync <GameRecord>(request.GameId);

            // update game state to indicated it was stopped
            gameRecord.Game.Status = GameStatus.Finished;
            ++gameRecord.Game.TotalTurns;
            gameRecord.Game.Messages.Add(new Message {
                GameTurn = gameRecord.Game.TotalTurns,
                Text     = "Game stopped."
            });

            // return final game state
            return(new StopGameResponse {
                Game = gameRecord.Game
            });
        }
 private Amazon.StepFunctions.Model.StopExecutionResponse CallAWSServiceOperation(IAmazonStepFunctions client, Amazon.StepFunctions.Model.StopExecutionRequest request)
 {
     Utils.Common.WriteVerboseEndpointMessage(this, client.Config, "AWS Step Functions", "StopExecution");
     try
     {
         #if DESKTOP
         return(client.StopExecution(request));
         #elif CORECLR
         return(client.StopExecutionAsync(request).GetAwaiter().GetResult());
         #else
                 #error "Unknown build edition"
         #endif
     }
     catch (AmazonServiceException exc)
     {
         var webException = exc.InnerException as System.Net.WebException;
         if (webException != null)
         {
             throw new Exception(Utils.Common.FormatNameResolutionFailureMessage(client.Config, webException.Message), webException);
         }
         throw;
     }
 }