private void IdentifyCommand(string fileName, string command, List <FileOutputResult> resultList) { string trimmedCommand = command.Trim().Replace(Constants.SpaceString, string.Empty); switch (trimmedCommand[0]) { case 's': ParseAndReplace(fileName, command, trimmedCommand); break; case 'd': ParseAndDelete(fileName, command, trimmedCommand); break; case 'i': ParseAndInsert(fileName, command, trimmedCommand); break; case 'r': ParseAndReverse(fileName, command, trimmedCommand); break; default: throw new InvalidCommand("Invalid command"); //break; } FileOutputResult fileOutputResult = new FileOutputResult(); fileOutputResult.isValid = true; fileOutputResult.message = string.Empty; //fileOutputResult.newContent = ""; resultList.Add(fileOutputResult); }
private void ProcessCommandLineByLine(string fileName, string[] commands, List <FileOutputResult> resultList) { foreach (string command in commands) { try { if (string.IsNullOrEmpty(command.Trim())) { continue; } IdentifyCommand(fileName, command, resultList); } catch (Exception ex) { FileOutputResult fileOutputResult = new FileOutputResult(); fileOutputResult.isValid = false; fileOutputResult.message = "Error in command - " + command; //fileOutputResult.newContent = ""; resultList.Add(fileOutputResult); } } }