Exemplo n.º 1
0
        public static async Task <IActionResult> DeleteGameInstanceById(
            [HttpTrigger(AuthorizationLevel.Function, "delete", Route = null)] HttpRequest req,
            ILogger log)
        {
            int gameInstanceId;

            try
            {
                NameValueCollection queryStringMap = HttpUtility.ParseQueryString(req.QueryString.Value);
                gameInstanceId = int.Parse(queryStringMap["Id"]);
            }
            catch (Exception e)
            {
                log.LogError(e, e.Message);
                return(new BadRequestObjectResult("Request didn't meet syntax requirements (make sure you include everything and have the correct property types)"));
            }



            try
            {
                await GameInstanceProcessor.DeleteGameInstanceByIdAsync(connectionString, gameInstanceId);
            }
            catch (Exception e)
            {
                log.LogError(e, e.Message);
                return(new ConflictObjectResult("Tried to delete row that didn't exist"));
            }
            return(new OkObjectResult("Row successfully deleted"));
        }
Exemplo n.º 2
0
        public static async Task <IActionResult> GetGameInstances(
            [HttpTrigger(AuthorizationLevel.Function, "get", Route = null)] HttpRequest req,
            ILogger log)
        {
            IEnumerable <GameInstanceModel> GameInstances = await GameInstanceProcessor.GetGameInstancesAsync(connectionString);

            return(new OkObjectResult(GameInstances));
        }
Exemplo n.º 3
0
        public static async Task <IActionResult> CreateGameInstanceAndReturnId(
            [HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequest req,
            ILogger log)
        {
            string requestBody = await req.ReadAsStringAsync();

            JsonElement jsonBody = JsonSerializer.Deserialize <JsonElement>(requestBody);

            // get all of the values we need for the GameInstanceProcessor (maybe deserialize json to a GameInstanceModel instead? Or maybe just pass a GameInstanceModel with a null Id to this endpoint)
            int    reqProcessId;
            int    reqGame;
            string reqPort;
            string reqArgs;
            int    reqHostId;

            try
            {
                reqProcessId = jsonBody.GetProperty("ProcessId").GetInt32();
                reqGame      = jsonBody.GetProperty("Game").GetInt32();
                reqPort      = jsonBody.GetProperty("Port").GetString();
                reqArgs      = jsonBody.GetProperty("Args").GetString();
                reqHostId    = jsonBody.GetProperty("HostId").GetInt32();
            }
            catch (Exception e)
            {
                log.LogError(e, e.Message);
                return(new BadRequestObjectResult("Request didn't meet syntax requirements (make sure you include everything and have the correct property types)"));
            }


            // call on the data processor and store the returned Id
            try
            {
                int retVal = await GameInstanceProcessor.CreateGameInstanceAndReturnIdAsync(connectionString, reqProcessId, reqGame, reqPort, reqArgs, reqHostId);

                // Returning a success code means we continue running the newly created game instance process
                return(new OkObjectResult(retVal));
            }
            catch (Exception e)
            {
                log.LogError(e, e.Message);
                return(new ConflictObjectResult("Conflict when inserting into the database"));
            }
        }