This repository has been archived by the owner on Jul 13, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathProgram.cs
64 lines (52 loc) · 1.9 KB
/
Program.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
using System;
using System.IO;
using Microsoft.Extensions.Configuration;
using Newtonsoft.Json;
using CLIHelpers;
namespace dbc_export
{
class Program
{
static void Main(string[] args)
{
string path = Directory.GetCurrentDirectory() + "/appsettings.json";
/** Check for config */
if (!File.Exists(path))
{
Logger.Danger("Could not find 'appsettings.json'! Exiting.");
Environment.Exit(-1);
}
/** Load Config */
var config = new ConfigurationBuilder()
.AddJsonFile(path, true, true)
.Build();
/** Init DB Connection */
Database db = new Database(
config["DB_HOST"],
Int32.Parse(config["DB_PORT"]),
config["DB_USER"],
config["DB_PASS"],
config["WORLD_DB"]
);
if (!db.Connect())
{
Logger.Danger("Failed to connect to DB! Exiting...");
Environment.Exit(-1);
}
Logger.Success(String.Format("Connected to DB - MySQL {0}\n", db.GetConnection().ServerVersion));
ParsedDefinitions parsedDefinitions;
/** Deserialize definitions from disk */
using (StreamReader file = File.OpenText(Directory.GetCurrentDirectory() + "/definitions.json"))
{
parsedDefinitions = JsonConvert.DeserializeObject<ParsedDefinitions>(file.ReadToEnd());
}
/** Execute Builders */
foreach (Definition definition in parsedDefinitions.definitions)
{
Builder builder = new Builder(db.GetConnection(), definition);
builder.Run();
}
db.Disconnect();
}
}
}