public static void LoadMenus(Ruleset ruleset) { _elements = new Dictionary <string, List <MenuElement> >(); var filePath = Utils.GetFilePath("Menu.txt", ruleset.Paths); TextFileParser.ParseFile(filePath, new Menu()); }
public static Dictionary <string, List <string> > LoadCityNames(IEnumerable <string> paths) { var filePath = Utils.GetFilePath("city.txt", paths); var loader = new NameLoader(); TextFileParser.ParseFile(filePath, loader); return(loader.CityNames); }
public static void UpdateLabels(Ruleset rules) { var labelPath = rules != null?Utils.GetFilePath("labels.txt", rules.Paths) : Utils.GetFilePath("labels.txt"); if (labelPath == _currentPath) { return; } _currentPath = labelPath; TextFileParser.ParseFile(labelPath, new LabelLoader()); }
static void Main(string[] args) { try { string fileText = string.Empty; Console.WriteLine("Please enter the file to parse with the complete path"); string filePath = Console.ReadLine(); Console.WriteLine("Parsing File"); IFileParser fileParser = new TextFileParser(new FileSystem()); fileText = fileParser.ParseFile(filePath); Console.WriteLine("File parsed. Counting the number of words"); IWordCounter wordCounter = new WordCounterLogic(); var wordCounterOutput = wordCounter.CountWord(fileText); ITextFormatter textFormatter = new TextFormatter.TextFormatter(); Console.WriteLine("Here is the output"); Console.WriteLine(textFormatter.FormatText(wordCounterOutput)); Console.Read(); } catch (ArgumentNullException ex) { Console.WriteLine(ex.Message); } catch (FileNotFoundException ex) { Console.WriteLine(ex.Message); } catch (FileFormatException ex) { Console.WriteLine(ex.Message); } catch (Exception ex) { //Ideally we should not catch the Base exception class and should not allow the application to run //since in case of OutOfMemory or StackOverFlowexception the application/system might not be in a position to run/ //The Application might be in a corrupted state and should not be allowed to run. Console.WriteLine(ex.Message); } }
private static void Main(string[] args) { if (args?.Any() == false) { return; } var lineage = new Lineage(); var family = lineage.Family; var fileParser = new TextFileParser(); fileParser.ParseFile(args?[0]); if (fileParser.Inputs.Count == 0) { return; } foreach (var input in fileParser.Inputs) { try { switch (input.Item1) { case Command.ADD_CHILD: AddChildOperation(input); break; case Command.GET_RELATIONSHIP: GetRelationshipOperation(input); break; default: throw new Exception("Invalid Action"); } } catch (Exception e) { Console.WriteLine(e.Message + Environment.NewLine); //Console.WriteLine(e.StackTrace); } } void AddChildOperation(Tuple <Command, string, string, string> input) { Enum.TryParse(input.Item4, true, out Gender gender); lineage.AddChild(input.Item2, input.Item3, gender); Console.WriteLine("CHILD_ADDITION_SUCCEEDED"); } void GetRelationshipOperation(Tuple <Command, string, string, string> input) { var members = family.FindRelatedMembers(input.Item2, input.Item3); if (members == null || !members.Any()) { Console.WriteLine("None"); } else { foreach (var person in members) { Console.Write($"{person.Name} "); } Console.WriteLine(); } } }