Revize 9657d7e0
Přidáno uživatelem Jakub Šilhavý před asi 2 roky(ů)
ld_client/LDClient/utils/ConfigLoader.cs | ||
---|---|---|
3 | 3 |
|
4 | 4 |
namespace LDClient.utils { |
5 | 5 |
|
6 |
/// <summary> |
|
7 |
/// This class loads up the configuration file (appsettingss.json). |
|
8 |
/// </summary> |
|
6 | 9 |
internal class ConfigLoader { |
7 | 10 |
|
11 |
/// <summary> |
|
12 |
/// Status code indicating a successful termination of an application. |
|
13 |
/// </summary> |
|
8 | 14 |
private const int ErrorExitCode = 1; |
15 |
|
|
16 |
/// <summary> |
|
17 |
/// Path to the configuration file. |
|
18 |
/// </summary> |
|
9 | 19 |
private const string ConfigFile = "appsettings.json"; |
20 |
|
|
21 |
/// <summary> |
|
22 |
/// Name of the logging section defined in the config file. |
|
23 |
/// </summary> |
|
10 | 24 |
private const string LoggingSection = "Logging"; |
25 |
|
|
26 |
/// <summary> |
|
27 |
/// Name of the network section defined in the config file. |
|
28 |
/// </summary> |
|
11 | 29 |
private const string NetworkSection = "Network"; |
30 |
|
|
31 |
/// <summary> |
|
32 |
/// Name of the cache section defined in the config file. |
|
33 |
/// </summary> |
|
12 | 34 |
private const string CacheSection = "Cache"; |
35 |
|
|
36 |
/// <summary> |
|
37 |
/// Name of the detection section defined in the config file. |
|
38 |
/// </summary> |
|
13 | 39 |
private const string DdSection = "DebuggerDetection"; |
14 | 40 |
|
15 | 41 |
#region Logger |
16 | 42 |
|
43 |
/// <summary> |
|
44 |
/// Maximum size of the log file (it will start to rotate when this limit is reached). |
|
45 |
/// </summary> |
|
17 | 46 |
public int LogChunkSize { get; private set; } |
47 |
|
|
48 |
/// <summary> |
|
49 |
/// Number of files to be created until there will be zipped up. |
|
50 |
/// </summary> |
|
18 | 51 |
public int LogChunkMaxCount { get; private set; } |
52 |
|
|
53 |
/// <summary> |
|
54 |
/// Maximum number of zip files |
|
55 |
/// </summary> |
|
19 | 56 |
public int LogArchiveMaxCount { get; private set; } |
57 |
|
|
58 |
/// <summary> |
|
59 |
/// Time after which the last logs will be cleaned up. |
|
60 |
/// </summary> |
|
20 | 61 |
public int LogCleanupPeriod { get; private set; } |
62 |
|
|
63 |
/// <summary> |
|
64 |
/// Level of verbosity. |
|
65 |
/// </summary> |
|
21 | 66 |
public LogVerbosity LogVerbosityType { get; private set; } = LogVerbosity.Full; |
67 |
|
|
68 |
/// <summary> |
|
69 |
/// Logger flow type. |
|
70 |
/// </summary> |
|
22 | 71 |
public LogFlow LogFlowType { get; private set; } = LogFlow.Console; |
23 | 72 |
|
24 | 73 |
#endregion |
25 | 74 |
|
26 | 75 |
#region Api |
27 | 76 |
|
77 |
/// <summary> |
|
78 |
/// URL to the API (it can be an IP address or a domain name if a DNS server is being used). |
|
79 |
/// </summary> |
|
28 | 80 |
public string ApiBaseAddress { get; private set; } = null!; |
81 |
|
|
82 |
/// <summary> |
|
83 |
/// Path to the API (e.g. /api/v1/ld-logs). |
|
84 |
/// </summary> |
|
29 | 85 |
public string ApiUsbEndPoint { get; private set; } = null!; |
86 |
|
|
87 |
/// <summary> |
|
88 |
/// Number of the port that the API runs on. |
|
89 |
/// </summary> |
|
30 | 90 |
public uint ApiPort { get; private set; } |
31 | 91 |
|
32 | 92 |
#endregion |
33 | 93 |
|
34 | 94 |
#region Cache |
35 | 95 |
|
96 |
/// <summary> |
|
97 |
/// Name of the cache (a directory of this name will be created). |
|
98 |
/// </summary> |
|
36 | 99 |
public string CacheFileName { get; private set; } = null!; |
100 |
|
|
101 |
/// <summary> |
|
102 |
/// Maximum number of payloads (entries) to be sent to the server at a time. |
|
103 |
/// </summary> |
|
37 | 104 |
public uint MaxRetries { get; private set; } |
105 |
|
|
106 |
/// <summary> |
|
107 |
/// Maximum number of entries that can be stored in the database. |
|
108 |
/// </summary> |
|
38 | 109 |
public uint MaxEntries { get; private set; } |
110 |
|
|
111 |
/// <summary> |
|
112 |
/// Period (how often) a certain number of entries will be resent to the server. |
|
113 |
/// </summary> |
|
39 | 114 |
public uint RetryPeriod { get; private set; } |
40 | 115 |
|
41 | 116 |
#endregion |
42 | 117 |
|
43 | 118 |
#region Detection |
119 |
|
|
120 |
/// <summary> |
|
121 |
/// Name of the process to be detected (the application programmers use to connect to the debugger). |
|
122 |
/// </summary> |
|
44 | 123 |
public string T32ProcessName { get; private set; } = null!; |
124 |
|
|
125 |
/// <summary> |
|
126 |
/// How often the application checks if there is the process (T32ProcessName) running on the PC. |
|
127 |
/// </summary> |
|
45 | 128 |
public uint DetectionPeriod { get; private set; } |
129 |
|
|
130 |
/// <summary> |
|
131 |
/// Location of the generated .txt file containing all information about a debugger. |
|
132 |
/// </summary> |
|
46 | 133 |
public string T32InfoLocation { get; private set; } = null!; |
134 |
|
|
135 |
/// <summary> |
|
136 |
/// Path to the t32rem.exe which is used to send commands to a debugger. |
|
137 |
/// </summary> |
|
47 | 138 |
public string F32RemExecutable { get; private set; } = null!; |
139 |
|
|
140 |
/// <summary> |
|
141 |
/// How many times the application attempts to check if there |
|
142 |
/// has been a .txt file generated containing all the desired information. |
|
143 |
/// </summary> |
|
48 | 144 |
public uint FetchInfoMaxAttempts { get; private set; } |
145 |
|
|
146 |
/// <summary> |
|
147 |
/// Period in milliseconds after which the application tries to locate and parse the .txt file. |
|
148 |
/// </summary> |
|
49 | 149 |
public uint FetchInfoAttemptPeriod { get; private set; } |
150 |
|
|
151 |
/// <summary> |
|
152 |
/// Arguments (commands) sent to the t32rem.exe file. |
|
153 |
/// </summary> |
|
50 | 154 |
public string[] F32RemArguments { get; private set; } = null!; |
155 |
|
|
156 |
/// <summary> |
|
157 |
/// Status code indication successful execution of the t32rem.exe file. |
|
158 |
/// </summary> |
|
51 | 159 |
public int T32RemSuccessExitCode { get; private set; } |
160 |
|
|
161 |
/// <summary> |
|
162 |
/// Timeout of the execution of t32rem.exe (when sending one command). |
|
163 |
/// </summary> |
|
52 | 164 |
public int T32RemWaitTimeoutMs { get; private set; } |
53 | 165 |
|
54 | 166 |
#endregion |
55 | 167 |
|
168 |
/// <summary> |
|
169 |
/// Creates an instance of the class. |
|
170 |
/// </summary> |
|
56 | 171 |
public ConfigLoader() { |
172 |
// Create a new config builder to read the configuration file. |
|
57 | 173 |
var configuration = new ConfigurationBuilder() |
58 | 174 |
.AddJsonFile(ConfigFile) |
59 | 175 |
.Build(); |
60 | 176 |
|
177 |
// Parse the logger section. |
|
61 | 178 |
ReadLoggerSection(configuration); |
179 |
|
|
180 |
// Parse the api section. |
|
62 | 181 |
ReadApiSection(configuration); |
182 |
|
|
183 |
// Parse the cache section. |
|
63 | 184 |
ReadCacheSection(configuration); |
185 |
|
|
186 |
// Parse the detection section. |
|
64 | 187 |
ReadDebuggerSection(configuration); |
65 | 188 |
|
66 | 189 |
Console.WriteLine("Configuration successfully loaded!"); |
67 | 190 |
} |
68 | 191 |
|
192 |
/// <summary> |
|
193 |
/// Parses the logging section of the configuration file. |
|
194 |
/// </summary> |
|
195 |
/// <param name="configuration">configuration</param> |
|
69 | 196 |
private void ReadLoggerSection(IConfiguration configuration) { |
70 | 197 |
try { |
71 | 198 |
var logging = configuration.GetSection(LoggingSection); |
... | ... | |
81 | 208 |
} |
82 | 209 |
} |
83 | 210 |
|
211 |
/// <summary> |
|
212 |
/// Parses the api section of the configuration file. |
|
213 |
/// </summary> |
|
214 |
/// <param name="configuration">configuration</param> |
|
84 | 215 |
private void ReadApiSection(IConfiguration configuration) { |
85 | 216 |
try { |
86 | 217 |
var network = configuration.GetSection(NetworkSection); |
... | ... | |
93 | 224 |
} |
94 | 225 |
} |
95 | 226 |
|
227 |
/// <summary> |
|
228 |
/// Parses the cache section of the configuration file. |
|
229 |
/// </summary> |
|
230 |
/// <param name="configuration">configuration</param> |
|
96 | 231 |
private void ReadCacheSection(IConfiguration configuration) { |
97 | 232 |
try { |
98 | 233 |
var cache = configuration.GetSection(CacheSection); |
... | ... | |
106 | 241 |
} |
107 | 242 |
} |
108 | 243 |
|
244 |
/// <summary> |
|
245 |
/// Parses the detection section of the configuration file. |
|
246 |
/// </summary> |
|
247 |
/// <param name="configuration">configuration</param> |
|
109 | 248 |
private void ReadDebuggerSection(IConfiguration configuration) { |
110 | 249 |
try { |
111 | 250 |
var debugger = configuration.GetSection(DdSection); |
Také k dispozici: Unified diff
re #9570 Commented ConfigLoader.cs, FileUtils.cs, and IFileUtils.cs