-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSetup.cs
56 lines (47 loc) · 1.55 KB
/
Setup.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
using System.Xml;
using Piano.Extensions;
using Piano.Objects;
using Piano.Utils;
namespace Piano;
public class Setup {
private const string AppConfigName = "app_config.xml";
private static readonly XmlWriterSettings XmlWriterSettings = new() {
Indent = true,
IndentChars = "\t",
CloseOutput = true,
OmitXmlDeclaration = true
};
public static AppConfig GetAppConfig => new() {
MssqlConfig = MssqlConfig,
PianoConfig = PianoConfig
};
public static void SetAppConfig(AppConfig appConfig) {
MssqlConfig = appConfig.MssqlConfig;
PianoConfig = appConfig.PianoConfig;
}
public static PianoConfig PianoConfig = new() {
Port = 80,
IsDevelopment = false,
SecureCode = RandomUtils.GetRandomString(12)
};
public static MssqlConfig MssqlConfig = new() {
Server = "localhost",
Database = "Piano",
User = "sa",
Password = "SaPassword",
Port = 1433
};
public static void OnStart() {
if(!File.Exists(AppConfigName)) {
using (var writer = XmlWriter.Create(AppConfigName, XmlWriterSettings)) {
AppConfig.XmlSerializer.Serialize(writer, GetAppConfig);
}
Console.WriteLine("Please restart your application.");
Environment.Exit(0);
}
using (var reader = XmlReader.Create(AppConfigName)) {
var appConfig = AppConfig.XmlSerializer.Deserialize(reader)!.To<AppConfig>();
SetAppConfig(appConfig);
}
}
}