public async Task <bool> StartGuessingGame(StartGuessingGameRequest songInfo) { try { var result = await _guessingGameClient.PostAsync("StartGuessingGame", HttpClientHelper.GetJsonData(songInfo)); return(result.IsSuccessStatusCode); } catch (Exception e) { return(HttpClientHelper.LogError <bool>(_logger, e, new object[] { songInfo })); } }
public IActionResult StartGuessingGame([FromBody] StartGuessingGameRequest songInfo) { try { bool isGameInProgress; lock (timerLock) { // Check guessing game state isGameInProgress = _guessingGameService.IsGuessingGameInProgress(); } if (!isGameInProgress) { _guessingGameService.GuessingGameStart(songInfo.SongName, songInfo.SongLengthSeconds); } return(Ok()); } catch (Exception e) { _logger.LogError(e, "Error in StartGuessingGame"); return(BadRequest()); } }
private async Task CheckRocksnifferFiles() { var songDetailsLocation = _rocksnifferDirectory + "song_details.txt"; var songTimerLocation = _rocksnifferDirectory + "song_timer.txt"; // split on / left is current time, right is total. var songAccuracyLocation = _rocksnifferDirectory + "accuracy.txt"; //TempWriteToFile($"SongDetails: {GetFileContents(songDetailsLocation)}"); //TempWriteToFile($"SongTimer: {GetFileContents(songTimerLocation)}"); //TempWriteToFile($"SongAccuracy: {GetFileContents(songAccuracyLocation)}"); var timerText = GetFileContents(songTimerLocation); var songName = GetFileContents(songDetailsLocation); var finalPercentage = GetFileContents(songAccuracyLocation).Trim('%'); if (string.IsNullOrWhiteSpace(timerText)) { return; } var timer = timerText.Split("/"); var runningTimeInSeconds = ConvertTimerToSeconds(timer[0]); var songInfoModel = new StartGuessingGameRequest { SongName = songName, SongLengthSeconds = ConvertTimerToSeconds(timer[1]) }; if (runningTimeInSeconds != 0) { if (!hasGameStarted && !hasGameBeenCompleted) { // send request to start guessing game hasGameStarted = true; hasGameBeenCompleted = false; var success = await _guessingGameApiClient.StartGuessingGame(songInfoModel); if (!success) { return; } totalTime = ConvertTimerToSeconds(timer[1]); return; } // Need hasGameBeenCompleted flag as the file remains on full time for a few seconds, allowing us to grab the final score. if (runningTimeInSeconds != totalTime || hasGameBeenCompleted) { return; } // send percentage to server and finish game decimal.TryParse(finalPercentage, out var finalPercentageDecimal); var completedResult = await _guessingGameApiClient.FinishGuessingGame(finalPercentageDecimal); if (!completedResult) { return; } hasGameStarted = false; hasGameBeenCompleted = true; return; } hasGameStarted = false; hasGameBeenCompleted = false; }