1
|
using LDClient.detection;
|
2
|
using LDClient.network;
|
3
|
using LDClient.utils;
|
4
|
using LDClient.utils.loggers;
|
5
|
|
6
|
using static System.Diagnostics.Process;
|
7
|
using static System.Reflection.Assembly;
|
8
|
|
9
|
namespace LDClient;
|
10
|
|
11
|
internal static class Program {
|
12
|
|
13
|
public static ConfigLoader Config { get; } = new();
|
14
|
public static ALogger DefaultLogger { get; } = ALogger.Current;
|
15
|
private static IApiClient? DefaultApiClient { get; set; }
|
16
|
|
17
|
private static readonly InfoFetcher InfoFetcher = new(
|
18
|
5,
|
19
|
1000,
|
20
|
"output.txt"
|
21
|
);
|
22
|
|
23
|
public static int Main() {
|
24
|
var exists = GetProcessesByName(Path.GetFileNameWithoutExtension(GetEntryAssembly()?.Location)).Length > 1;
|
25
|
if (exists) {
|
26
|
DefaultLogger.Error("Another instance of the application is already running");
|
27
|
return 1;
|
28
|
}
|
29
|
|
30
|
DefaultApiClient = new ApiClient(
|
31
|
Config.ApiBaseAddress,
|
32
|
Config.ApiPort,
|
33
|
Config.ApiUsbEndPoint,
|
34
|
Config.RetryPeriod, Config.MaxEntries,
|
35
|
Config.MaxRetries,
|
36
|
Config.CacheFileName
|
37
|
);
|
38
|
|
39
|
IProcessDetection processProcessDetection = new ProcessProcessDetection(
|
40
|
Config.T32ProcessName,
|
41
|
Config.DetectionPeriod,
|
42
|
InfoFetcher,
|
43
|
DefaultApiClient
|
44
|
);
|
45
|
|
46
|
DefaultLogger.Debug("Main -> starting the ApiClient");
|
47
|
var apiClientThread = new Thread(DefaultApiClient.Run) {
|
48
|
IsBackground = true
|
49
|
};
|
50
|
apiClientThread.Start();
|
51
|
|
52
|
var processThread = new Thread(processProcessDetection.RunPeriodicDetection) {
|
53
|
IsBackground = true
|
54
|
};
|
55
|
processThread.Start();
|
56
|
|
57
|
while (true) {
|
58
|
Thread.Sleep(10 * 1000);
|
59
|
}
|
60
|
return 0;
|
61
|
}
|
62
|
}
|