Пример #1
0
        public async Task <HttpResponseData> Test(
            [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "players/{idString}/test")] HttpRequestData req,
            string idString)
        {
            // Verify authenticated user is present
            var subject = await authorize.TryGetSubject(req.Headers);

            if (subject == null)
            {
                return(req.CreateResponse(HttpStatusCode.Unauthorized));
            }

            var(player, errorResponse) = await GetSingleOwning(req, idString, subject);

            if (player == null)
            {
                return(errorResponse !);
            }

            try
            {
                await gameClient.GetReadyForGame(player.WebApiUrl, 1, player.ApiKey);

                await gameClient.PlaySingleMoveInRandomGame(player.WebApiUrl, player.ApiKey);
            }
            catch (Exception ex)
            {
                var errorMessage = ex.GetFullDescription();
                await playerLogTable.AddException(player.RowKey, player.WebApiUrl, errorMessage);

                return(await CreateDependencyError(req, errorMessage));
            }

            await playerLogTable.Add(new(player.RowKey, player.WebApiUrl, $"Successfully tested player"));

            return(req.CreateResponse(HttpStatusCode.OK));
        }