static void Main(string[] args) { if (args.Length == 0) { // No argument given... print help and error out. System.Console.WriteLine(":: NameSorter ::"); System.Console.WriteLine(NameSorter.ProgramUsageText()); Environment.Exit(-1); } SortInterface name_sorter = null; InputInterface name_source = new FileInput(); string[] name_list = null; // process flags if (args.Any("--desc".Contains)) { name_sorter = new NameSorterReverse(); } else { name_sorter = new NameSorter(); } if (args.Any("--ifile".Contains)) { string file_name = args[Array.IndexOf(args, "--ifile") + 1]; name_list = name_source.GetNames(file_name); } // catch origional program behaviour if (name_list == null) { name_list = name_source.GetNames(args[0]); } string[] sorted_names = name_sorter.SortNames(name_list); System.Console.WriteLine(String.Join(Platform.Delimiter, sorted_names)); System.IO.File.WriteAllLines(@"sorted-names-list.txt", sorted_names); //old and crusty now if (args.Length == 1 && System.IO.File.Exists(args[0])) { } else { // This should be in output module: // System.Console.WriteLine(":: NameSorter ::"); // System.Console.WriteLine(NameSorter.ProgramUsageText()); // System.Console.WriteLine($" The file '{args[0]}' was not found!"); // Environment.Exit(-1); } Environment.Exit(0); }
public static void Main(string[] args) { //Get Input file name string inputFileName = NameSorter.GetInputFileName(args); //Read Input txt file ArrayList unSortedList = NameSorter.ReadInputFile(inputFileName); //Sort the names ArrayList getSortedList = NameSorter.SortNameList(unSortedList); //Writing sorted list in txt file NameSorter.WritingResults(getSortedList); }
static void Main(string[] args) { // Define Input & Output objects FileReader InputFile = new FileReader(); FileWriter OutputFile = new FileWriter("sorted-names-list.txt"); ScreenPrinter screen = new ScreenPrinter(); // Define PersonName Objects and List. NameSorter nameSorter = new NameSorter(); PersonNameConverter personNameConverter = new PersonNameConverter(); List <PersonName> personNameList = new List <PersonName>(); // only execute the program if an input file was specified. if (args.Length > 0) { // load the list of raw unsorted names to a string array. string[] rawNames = InputFile.LoadStringArray(args[0]); // convert the string array to a list of PersonNames personNameList = personNameConverter.StringArrayToPersonNameList(rawNames); // Perform the sort operation. personNameList = nameSorter.SortByLastNameThenFirstName(personNameList); // convert the PersonName list back to a raw string array rawNames = personNameConverter.PersonNameListToStringArray(personNameList); // print the list of names to the screen screen.PrintArray(rawNames); // the sorted name list can now be saved to file OutputFile.PrintArray(rawNames); } else { screen.Print("Please specify a file to sort."); } }
static void Main(string[] args) { //Filepaths String readPath = "unsorted-names-list.txt"; String writePath = "sorted-names-list.txt"; //Initialise NameSorter sorter = new NameSorter(); FileHandler file = new FileHandler(); List <Person> unorderedPersons = new List <Person>(); List <Person> orderedPersons = new List <Person>(); //Get names from file and process them unorderedPersons = ProcessNames(" ", file.ReadLinesFromFile(readPath)); //Sort names orderedPersons = sorter.SortLastThenFirst(unorderedPersons); //Print to screen Console.WriteLine("Original list: "); foreach (Person p in unorderedPersons) { Console.WriteLine(p.FirstLastNameString()); } Console.WriteLine("---------------------------"); Console.WriteLine("Ordered list: "); foreach (Person p in orderedPersons) { Console.WriteLine(p.FirstLastNameString()); } //Write names to file file.WriteLinesToFile(writePath, NamesToArray(orderedPersons)); Console.ReadKey(); }
public SorterProgram(String fileName) { FileParser = new FileParser(fileName); FileWriter = new FileWriter(fileName); NameSorter = new NameSorter(); }