Esempio n. 1
0
        private async Task SendScoreEventAndLogErrors(ScorePostRequestModel request)
        {
            //try
            //{
            //    await _analyticsIntegrationClient.SendGameEventAsync(new ScoreEvent()
            //    {
            //        //GamerTag = gamertag,
            //        ClientUtcTime = DateTime.UtcNow,
            //        GameSessionId = "unknowngamesession",
            //        Score = request.Score
            //    });
            //}
            //catch (Exception ex)
            //{
            //    _logger.LogError("Error sending analytics ScoreEvent: {0}", ex);
            //    _appMonitor.LogError(ex, properties: new Dictionary<string, string> {
            //        { "Score", request.Score.ToString() }
            //    });
            //}

            // Temporary disabling sending of Scores to Nether Analytics, since that message is currently not supported.
            // Will be enabled again once, we start supporting that message type again.

            return;
        }
Esempio n. 2
0
        public async Task <IActionResult> Post([FromBody] ScorePostRequestModel request)
        {
            //TODO: Make validation more sophisticated, perhaps some games want/need negative scores
            // Validate input
            if (request.Score < 0)
            {
                _logger.LogError("score is negative ({0})", request.Score);
                return(this.ValidationFailed(new ErrorDetail("score", "Score cannot be negative")));
            }

            //TODO: Handle exceptions and retries
            var gamertag = User.GetGamerTag();

            if (string.IsNullOrWhiteSpace(gamertag))
            {
                _logger.LogError("user has no gamertag: '{0}'", User.GetId());
                return(this.ValidationFailed(new ErrorDetail("gamertag", "The user doesn't have a gamertag")));
            }

            // Save score and call analytics in parallel
            await Task.WhenAll(
                _store.SaveScoreAsync(new GameScore
            {
                Gamertag  = gamertag,
                Country   = request.Country,
                CustomTag = request.CustomTag,
                Score     = request.Score
            }),
                SendScoreEventAndLogErrors(request));

            // Return result
            return(Ok());
        }
Esempio n. 3
0
 private async Task SendScoreEventAndLogErrors(ScorePostRequestModel request)
 {
     try
     {
         await _analyticsIntegrationClient.SendGameEventAsync(new ScoreEvent()
         {
             //GamerTag = gamertag,
             ClientUtcTime = DateTime.UtcNow,
             GameSessionId = "unknowngamesession",
             Score         = request.Score
         });
     }
     catch (Exception ex)
     {
         _logger.LogError("Error sending analytics ScoreEvent: {0}", ex);
     }
 }
Esempio n. 4
0
 private async Task SendScoreEventAndLogErrors(ScorePostRequestModel request)
 {
     try
     {
         await _analyticsIntegrationClient.SendGameEventAsync(new ScoreEvent()
         {
             //GamerTag = gamertag,
             ClientUtcTime = DateTime.UtcNow,
             GameSessionId = "unknowngamesession",
             Score         = request.Score
         });
     }
     catch (Exception ex)
     {
         _logger.LogError("Error sending analytics ScoreEvent: {0}", ex);
         _appMonitor.LogError(ex, properties: new Dictionary <string, string> {
             { "Score", request.Score.ToString() }
         });
     }
 }
Esempio n. 5
0
        public async Task <ActionResult> Post([FromBody] ScorePostRequestModel request)
        {
            //TODO: Make validation more sophisticated, perhaps some games want/need negative scores
            // Validate input
            if (request.Score < 0)
            {
                _logger.LogError("score is negative ({0})", request.Score);
                return(BadRequest()); //TODO: return error info in body
            }

            //TODO: Handle exceptions and retries
            var gamertag = User.GetGamerTag();

            if (string.IsNullOrWhiteSpace(gamertag))
            {
                _logger.LogError("user has no gamertag: '{0}'", User.GetId());
                return(BadRequest()); //TODO: return error info in body
            }

            // Save score and call analytics in parallel
            await Task.WhenAll(
                _store.SaveScoreAsync(new GameScore
            {
                Gamertag  = gamertag,
                Country   = request.Country,
                CustomTag = request.CustomTag,
                Score     = request.Score
            }),
                _analyticsIntegrationClient.SendGameEventAsync(new ScoreEvent()
            {
                //GamerTag = gamertag,
                ClientUtcTime = DateTime.UtcNow,
                GameSessionId = "unknowngamesession",
                Score         = request.Score
            }));

            // Return result
            return(Ok());
        }