public async Task <IndexResponse> PostMatch(MatchModel match) { var asyncIndexResponse = await client.IndexDocumentAsync(match); if (asyncIndexResponse.IsValid) { await DiscordLogger.PostMessageToDiscordAsync($"New match posted: Match date: '{match.MatchDate}' with '{match.MatchMVP}' as the MVP!"); return(asyncIndexResponse); } else { await DiscordLogger.PostMessageToDiscordAsync($"Match data: '{match.Id}' could NOT posted to elastic"); return(asyncIndexResponse); } }
public async Task <IndexResponse> PostPlayer(PlayerSignupModel player) { var asyncIndexResponse = await client.IndexDocumentAsync(player); if (asyncIndexResponse.IsValid) { await DiscordLogger.PostMessageToDiscordAsync($"Signup data: Name: '{player.Name}' with Code: '{player.QuakeLoginCode}' and ID: '{player.QuakeId}' posted to elastic"); return(asyncIndexResponse); } else { await DiscordLogger.PostMessageToDiscordAsync($"Signup data: Name: '{player.Name}' with Code: '{player.QuakeLoginCode}' and ID: '{player.QuakeId}' NOT posted to elastic"); return(asyncIndexResponse); } }
public static async Task <IActionResult> Run( [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req, [Queue("outqueue"), StorageAccount("AzureWebJobsStorage")] ICollector <string> msg, ILogger log) { log.LogInformation("C# HTTP trigger function processed a request."); // pull out body text string requestBody = await new StreamReader(req.Body).ReadToEndAsync(); // deserialize //dynamic data = JsonConvert.DeserializeObject(requestBody); dynamic data = requestBody; // store message in data queue if (string.IsNullOrEmpty(data.ToString()) || string.IsNullOrWhiteSpace(data.ToString()) || data == null) { return(new BadRequestObjectResult("Your match stats payload was empty. Please send correct payload.")); } // Add a message to the output collection. msg.Add(data.ToString()); CrmodStatParser parser = null; try { parser = new CrmodStatParser(log); parser.SplitMatchStats(requestBody); parser.ProcessMatchInfo(); parser.ProcessTeamStats(); parser.ProcessPlayerStats(); parser.ProcessQuadStats(); parser.ProcessBadStats(); parser.ProcessEfficiencyStats(); parser.ProcessKillStats(); } catch (Exception e) { await DiscordLogger.PostMessageToDiscordAsync("Error parsing CRMOD match results payload. Error: " + e.Message); return(new BadRequestObjectResult("Unable to parse CRMOD match results payload. Error: " + e.Message)); } var esClient = new ElasticService(); // some horrible stuff going on here. I'm lazy to fix it but the purpose is to make the elastic->javascript parsing much easier... for my brain. var matchToPost = mapToMatchModel(parser.MatchResults); // Post match data in entirety to elastic var asyncMatchIndexResponse = await esClient.PostMatch(matchToPost); if (asyncMatchIndexResponse.IsValid) { log.LogInformation($"Match data: '{parser.MatchResults.Id}' posted to elastic"); } else { log.LogError($"Match data: '{parser.MatchResults.Id}' could NOT be posted to elastic"); } // upload all player stats foreach (var player in parser.MatchResults.ListOfPlayers) { if (int.TryParse(player.Key, out int statId)) { if (statId > 0) { var asyncPlayerIndexResponse = await esClient.PostPlayerStats(player.Value); if (asyncPlayerIndexResponse.IsValid) { log.LogInformation($"Player: '{player.Key}' for match '{player.Value.MatchId}' posted to elastic"); } else { log.LogError($"Player: '{player.Key}' for match '{player.Value.MatchId}' could NOT posted to elastic"); } } } else { log.LogError($"Int32.TryParse could not parse '{player.Key}' to an int. In match '{player.Value.MatchId}'"); } } return(data != null ? (ActionResult) new OkObjectResult("Match Stats Received.") : new BadRequestObjectResult("Your match stats payload was empty. Please send correct payload.")); }