This repository has been archived by the owner on Dec 7, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 224
/
Copy pathSettings.cs
95 lines (82 loc) · 3.05 KB
/
Settings.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
using Microsoft.Extensions.Configuration;
using Neo.Network.P2P;
using System.Threading;
namespace Neo
{
public class Settings
{
public StorageSettings Storage { get; }
public P2PSettings P2P { get; }
public UnlockWalletSettings UnlockWallet { get; }
public string PluginURL { get; }
static Settings _default;
static bool UpdateDefault(IConfiguration configuration)
{
var settings = new Settings(configuration.GetSection("ApplicationConfiguration"));
return null == Interlocked.CompareExchange(ref _default, settings, null);
}
public static bool Initialize(IConfiguration configuration)
{
return UpdateDefault(configuration);
}
public static Settings Default
{
get
{
if (_default == null)
{
UpdateDefault(Utility.LoadConfig("config"));
}
return _default;
}
}
public Settings(IConfigurationSection section)
{
this.Storage = new StorageSettings(section.GetSection("Storage"));
this.P2P = new P2PSettings(section.GetSection("P2P"));
this.UnlockWallet = new UnlockWalletSettings(section.GetSection("UnlockWallet"));
this.PluginURL = section.GetSection("PluginURL").Value;
}
}
public class StorageSettings
{
public string Engine { get; }
public StorageSettings(IConfigurationSection section)
{
this.Engine = section.GetSection("Engine").Value;
}
}
public class P2PSettings
{
public ushort Port { get; }
public ushort WsPort { get; }
public int MinDesiredConnections { get; }
public int MaxConnections { get; }
public int MaxConnectionsPerAddress { get; }
public P2PSettings(IConfigurationSection section)
{
this.Port = ushort.Parse(section.GetSection("Port").Value);
this.WsPort = ushort.Parse(section.GetSection("WsPort").Value);
this.MinDesiredConnections = section.GetValue("MinDesiredConnections", Peer.DefaultMinDesiredConnections);
this.MaxConnections = section.GetValue("MaxConnections", Peer.DefaultMaxConnections);
this.MaxConnectionsPerAddress = section.GetValue("MaxConnectionsPerAddress", 3);
}
}
public class UnlockWalletSettings
{
public string Path { get; }
public string Password { get; }
public bool StartConsensus { get; }
public bool IsActive { get; }
public UnlockWalletSettings(IConfigurationSection section)
{
if (section.Exists())
{
this.Path = section.GetSection("Path").Value;
this.Password = section.GetSection("Password").Value;
this.StartConsensus = bool.Parse(section.GetSection("StartConsensus").Value);
this.IsActive = bool.Parse(section.GetSection("IsActive").Value);
}
}
}
}