private async void PostScoreUpdate(Cod2Event cod2Event) { var client = new HttpClient(); var uri = new Uri("http://localhost:3000/api/Cod2Scoreboard"); await client.PostAsync(uri, new StringContent(JsonConvert.SerializeObject(cod2Event), Encoding.UTF8, "application/json")); client.Dispose(); }
private async Task HandleTimer() { try { var status = SendCommand("status"); Console.WriteLine(status); var resultObject = ParseResult(status); lock (_StatusLock) { if (!_LastStatus.MapName.Equals(resultObject.MapName, StringComparison.OrdinalIgnoreCase) || _LastStatus == null) { //New state foreach (var playerScore in resultObject.PlayerScores) { var cod2event = new Cod2Event() { AddedScore = playerScore.Score, Game = "cod2", Event = "addScore", Adress = playerScore.Address, Guid = playerScore.Guid, Timestamp = DateTimeOffset.UtcNow.ToUnixTimeSeconds().ToString(), }; PostScoreUpdate(cod2event); } } else { //TODO //Old state foreach (var playerScore in resultObject.PlayerScores) { var score = playerScore.Score; var existing = _LastStatus.PlayerScores.Where(a => a.Guid.Equals(playerScore.Guid)); if (existing.Any()) { var existingScore = existing.First().Score; score = playerScore.Score - existingScore; } if (score > 0) { var cod2event = new Cod2Event() { AddedScore = playerScore.Score, Game = "cod2", Event = "addScore", Adress = playerScore.Address, Guid = playerScore.Guid, Timestamp = DateTimeOffset.UtcNow.ToUnixTimeSeconds().ToString(), }; PostScoreUpdate(cod2event); } } } _LastStatus = resultObject; } } catch (Exception ex) { Console.WriteLine(ex.Message); } }