static void Main(string[] args) { ServiceProvider = RegisterServices(); ConsoleWriter = ServiceProvider.GetService <IUIPresenter>(); DisplayIntro(); var command = ""; while (command != InputCommands.Exit) { var input = Console.ReadLine(); if (string.IsNullOrEmpty(input)) { continue; } if (input.ToLowerInvariant() == InputCommands.Exit) { command = InputCommands.Exit; continue; } ReadInstructions(input); ConsoleWriter.WriteLine(""); ConsoleWriter.WriteLine("Enter a file name or exit"); } DisposeServices(); }
public static void ReadInstructions(string filename) { var converter = ServiceProvider.GetService <IInstructionConverter>(); var calculator = ServiceProvider.GetService <ICalculator>(); var reader = ServiceProvider.GetService <IReader>(); try { var rawFileContent = reader.ReadAsStringLines(filename); var listOfinstructions = converter.ConvertIntoListOfInstructions(rawFileContent); var result = calculator.Calculate(listOfinstructions); ConsoleWriter.WriteLine(result.ToString(CultureInfo.InvariantCulture)); } catch (Exception ex) { ConsoleWriter.WriteLine(ex.Message); } }