/// <summary> /// Validates instruction lines for the load instructions and edit instructions dialogs /// </summary> /// <param name="instructionLines">The list of lines to validate.</param> /// <returns>An empty string if there were no errors, otherwise, the error.</returns> private string ValidateInstructionsFromDialog(List <string> instructionLines) { // Show error if user entered more than MAX_INSTRUCTION_COUNT instructions if (instructionLines.Count > Settings.Default.MemorySize) { return($"Please enter {Settings.Default.MemorySize} or fewer instructions. You entered {instructionLines.Count}."); } else { // Validate each instruction foreach (string instructionLine in instructionLines) { if (string.IsNullOrWhiteSpace(instructionLine)) { return($"Error: Please do not enter any empty lines."); } else if (instructionLine[0] == '#') { if (!ValidationEngine.ValidateStartLocation(instructionLine.Substring(1, instructionLine.Length - 1))) { return($"Error: One of the '#' instructions is referencing an invalid memory location."); } } else { InstructionError instructionError = ValidationEngine.ValidateInstruction(instructionLine); if (instructionError == InstructionError.InvalidLength) { return($"Error: One of the instructions isn't { Settings.Default.InstructionSize } characters in length."); } else if (instructionError == InstructionError.SignMissing) { return("Error: One of the instructions does not start with a '+' or '-' sign."); } else if (instructionError == InstructionError.InvalidCharacters) { return("Error: One of the instructions contains invalid characters."); } } } // End foreach return(string.Empty); } }
/// <summary> /// Gets program starting locations. /// </summary> /// <returns>A list containing one or two starting locations. If program #2's starting location /// was blank, only one starting location (program 1's) /// is returned. If program #1's starting location was blank, 0 is returned for program #1's /// starting location.</returns> private List <int> GetProgramStartingLocations() { List <int> startingLocations = new List <int>(); if (program1StartLocationTextBox.Text == string.Empty) { startingLocations.Add(0); } else { if (ValidationEngine.ValidateStartLocation(program1StartLocationTextBox.Text)) { startingLocations.Add(Convert.ToInt32(program1StartLocationTextBox.Text)); } else { MessageBox.Show($"Please enter a valid starting location for program 1."); } } if (Settings.Default.MultiThreaded) { if (program2StartLocationTextBox.Text == string.Empty) { startingLocations.Add(0); } else { if (ValidationEngine.ValidateStartLocation(program2StartLocationTextBox.Text)) { startingLocations.Add(Convert.ToInt32(program2StartLocationTextBox.Text)); } else { MessageBox.Show($"Please enter a valid starting location for program 2."); } } } return(startingLocations); }