-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathHostConfig.cs
32 lines (26 loc) · 834 Bytes
/
HostConfig.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
using System.IO;
using Newtonsoft.Json;
namespace MqttBrokerWithDashboard
{
public class HostConfig
{
public static string Filename = $"{nameof(HostConfig)}.json";
public bool HideConfigPanel = false;
public int TcpPort = 1883;
public int HttpPort = 5000;
public static HostConfig LoadFromFile()
{
if (File.Exists(Filename))
{
using var file = File.OpenText(Filename);
return (HostConfig)new JsonSerializer().Deserialize(file, typeof(HostConfig));
}
return new HostConfig();
}
public void SaveToFile()
{
using var file = File.CreateText(Filename);
new JsonSerializer { Formatting = Formatting.Indented }.Serialize(file, this);
}
}
}