-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEngine.cs
More file actions
51 lines (42 loc) · 1.25 KB
/
Engine.cs
File metadata and controls
51 lines (42 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
namespace ListProcessing
{
using System;
using Interfaces;
public class Engine
{
private const string EndCommand = "END";
private ICommandInterpreter Interpreter;
public Engine(ICommandInterpreter interpreter)
{
this.Interpreter = interpreter;
}
public void Listen()
{
string commandInput = ConsoleManager.Read();
while (commandInput != EndCommand)
{
try
{
this.ParseCommand(commandInput);
}
catch (ArgumentException ex)
{
ConsoleManager.WriteLine(ex.Message);
}
commandInput = ConsoleManager.Read();
}
}
private void ParseCommand(string commandInput)
{
var commandTokens = commandInput.Split(new[] {' '}, StringSplitOptions.RemoveEmptyEntries);
try
{
this.Interpreter.InterpretCommand(commandTokens).Execute();
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
}
}
}