private string AskUser(KeysForPhrases question = KeysForPhrases.ExitKey, bool isUserSupposedToEnterNumber = false) { string userInput = "empty"; for (InputCheckResult i = InputCheckResult.Invalid; i != InputCheckResult.Valid;) { if (question != KeysForPhrases.ExitKey)// ExitKey used as flag for execution without question { inputOutputModule.ClearMenu(); inputOutputModule.WriteOutput(phraseProvider.GetPhrase(gameSettings.LangPackName, question)); } userInput = inputOutputModule.ReadInput(); i = ValidateUserInput(userInput, isUserSupposedToEnterNumber); } return(userInput); }
public string GetPhrase(KeysForPhrases phraseKey, string langPackName) { var resourceFile = new FileInfo($"Resources/{langPackName}.json"); if (!resourceFile.Exists) { throw new ArgumentException( $"Can't find language file. Trying to find it here: {resourceFile}"); } var resourceFileContent = File.ReadAllText(resourceFile.FullName); try { var resourceData = JsonConvert.DeserializeObject <Dictionary <string, string> >(resourceFileContent); return(resourceData[phraseKey.ToString()]); } catch (Exception ex) { throw new ArgumentException( $"Can't extract phrase value {phraseKey.ToString()}", ex); } }