private static bool GetInputFile(out string inputFileName) { inputFileName = IO.ReadLine("Input file: "); if (inputFileName == string.Empty) { IO.WriteLineError("No input file provided."); return(false); } try { new FileInfo(inputFileName); } catch (ArgumentException) { IO.WriteLineError("Invalid file name!"); return(false); } catch (Exception e) { IO.WriteLineError(e.Message); return(false); } return(true); }
private static void AddNewFormat() { string format = IO.ReadLine("Enter a format: ", removeWhiteSpace: false); // [[5]] if (AddNewFormat(format)) { IO.WriteLineSuccess("Format added successfully."); } }
private static bool GetNumberOfExpressionsToGenerate(out int number) { string input = IO.ReadLine("Number of expressions to generate: "); if (!int.TryParse(input, out number)) { IO.WriteLineError("You must enter a number!"); return(false); } return(true); }
private static void ParseInput() { string input = IO.ReadLine("Your choice: "); Action action; if (!_actions.TryGetValue(input, out action)) { IO.WriteLineError("Invalid input!"); return; } action(); }
private static bool GetNumberOfOperands(out int lower, out int upper) { lower = upper = -1; string input = IO.ReadLine("Desired number of operands in each expression (one number for exact number of operands, two numbers for a range): ", removeWhiteSpace: false); var args = input.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries); if (args.Length == 0) { IO.WriteLineError("You must enter at least one number!"); return(false); } else if (args.Length == 1) { int result; if (!int.TryParse(args[0], out result)) { IO.WriteLineError("You must enter a number!"); return(false); } if (result < 2) { IO.WriteLineError("There must be at least two operands!"); return(false); } lower = upper = result; } else if (args.Length == 2) { if (!int.TryParse(args[0], out lower) || !int.TryParse(args[1], out upper)) { IO.WriteLineError("You must enter a number!"); return(false); } if (upper < lower) { MathHelper.Swap(ref lower, ref upper); } if (lower < 2 || upper < 2) { IO.WriteLineError("There must be at least two operands!"); return(false); } } else { IO.WriteLineError("Too many numbers provided!"); return(false); } return(true); }
private static bool GetOutputFile(out string outFileName) { outFileName = IO.ReadLine("Output file (leave blank if you want console output): "); if (outFileName != "") { try { new FileInfo(outFileName); } catch (ArgumentException) { IO.WriteLineError("Invalid file name!"); return(false); } catch (Exception e) { IO.WriteLineError(e.Message); return(false); } } return(true); }
private static void RemoveFormat() { string input = IO.ReadLine("Id of format to remove: "); int id; if (!int.TryParse(input, out id)) { IO.WriteLineError("You must enter a number!"); return; } int removed = _formats.RemoveWhere(x => x.Index == id); //[[12]] if (removed == 0) { IO.WriteLineError("No formats with the specified ID found!"); } else { IO.WriteLineSuccess("Format removed successfully."); } }