public async Task <IActionResult> SignInGithub() { if (this.TryGetNameIdentifierClaim(out var githubId)) { try { await this.Repository.GetUserByGithubId(githubId); } catch (EntityNotFound) { await ComputeAllUserGlobalRanksMutex.WaitAsync(); try { using (var transaction = await this.Repository.CreateTransaction()) { var userName = await this.GetUniqueUserName(); await this.Repository.AddUser(githubId, userName); await this.Repository.UpdateAllUserGlobalRanks(); await transaction.CommitAsync(); } } finally { ComputeAllUserGlobalRanksMutex.Release(); } } } return(this.RedirectToAction("Index", "Account")); }
public async Task <IActionResult> AddGameResult([FromBody] ApiGameResult gameResult) { if (!this.ModelState.IsValid) { return(this.BadRequest(GetAllErrors(this.ModelState))); } GameHistory gameHistory; try { gameHistory = JsonSerializer.Deserialize <GameHistory>(gameResult.SerializedHistory); if (gameHistory == null) { throw new Exception("JSON game result parsing returned null"); } } catch (Exception ex) { return(this.BadRequest("Not a valid JSON game result: " + ex)); } gameHistory.Summary.StandardOutput = gameResult.StandardOutput ?? string.Empty; gameHistory.Summary.StandardError = gameResult.StandardError ?? string.Empty; if (gameResult.PlayerBotIds != null) { foreach (var(playerIndex, playerBotIdStr) in gameResult.PlayerBotIds) { if (Guid.TryParse(playerBotIdStr, out var playerBotId) && gameHistory.Summary.Players.TryGetValue(playerIndex, out var playerSummary)) { playerSummary.BotId = playerBotId; } } } await ComputeAllUserGlobalRanksMutex.WaitAsync(); try { using (var transaction = await this.Repository.CreateTransaction()) { if (gameResult.Origin == GameOrigin.RankedMatchmaking) { gameHistory = await this.ComputeNewUserPoints(gameHistory); } var currentSeason = await this.Repository.GetCurrentSeason(); var gameId = await this.Repository.AddGame(gameHistory.Summary, gameResult.Origin, currentSeason.Id); if (gameResult.Origin == GameOrigin.RankedMatchmaking) { await this.Repository.UpdateAllUserGlobalRanks(); } var jsonGameHistoryStream = SerializeGameHistoryToJsonStream(gameHistory); await this.Storage.UploadGameResult(gameId, jsonGameHistoryStream); await transaction.CommitAsync(); } } finally { ComputeAllUserGlobalRanksMutex.Release(); } return(this.Ok()); }