-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathQEngine.cs
48 lines (44 loc) · 1.42 KB
/
QEngine.cs
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
//*****************************************************************************
// QEngine.cs - Entry point of the application.
//*****************************************************************************
using System;
using System.IO;
namespace QEngine
{
class QEngine
{
static void Main(string[] args)
{
try
{
Run(args[0], args[1]);
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
}
/// <summary>
/// Loads the given file and executes commands continuously untill user quits.
/// </summary>
/// <param name="filePath">CSV file which is to be represented as database</param>
/// <param name="tableName">Name of the database table</param>
static void Run(string filePath, string tableName)
{
var lines = File.ReadLines(filePath);
var db = Data.CreateDB(lines, tableName);
while (true)
{
Console.Write(">> ");
var cmd = Console.ReadLine();
if (cmd == "exit" || cmd == "quit") return;
var result = db.ProcessCommand(cmd);
foreach (var item in result)
{
Console.WriteLine(item);
}
Console.WriteLine();
}
}
}
}