Projekt

Obecné

Profil

Stáhnout (1.98 KB) Statistiky
| Větev: | Tag: | Revize:
1 fa084fc4 Pultak
using DiskQueue;
2 f5a08dd5 Pultak
using LDClient.detection;
3 aaad9ad4 Pultak
using LDClient.network;
4 4b0f0b36 Pultak
using LDClient.utils;
5 74bd1e40 Pultak
using LDClient.utils.loggers;
6 c318a92c Pultak
7 30c849e4 silhavyj
using static System.Diagnostics.Process;
8
using static System.Reflection.Assembly;
9
10 f5a08dd5 Pultak
namespace LDClient;
11 c318a92c Pultak
12 30c849e4 silhavyj
internal static class Program {
13 c318a92c Pultak
14 6dab0250 silhavyj
    private const int MainLoopDelayMs = 30000; 
15
16 30c849e4 silhavyj
    public static ConfigLoader Config { get; } = new();
17 4b0f0b36 Pultak
    public static ALogger DefaultLogger { get; } = ALogger.Current;
18 30c849e4 silhavyj
    private static IApiClient? DefaultApiClient { get; set; }
19
    
20 f281acac silhavyj
    private static readonly InfoFetcher InfoFetcher = new(
21 6dab0250 silhavyj
        Config.FetchInfoMaxAttempts,
22
        Config.FetchInfoAttemptPeriod,
23
        Config.T32InfoLocation,
24
        Config.F32RemExecutable,
25 4dcc6c07 silhavyj
        Config.F32RemArguments,
26
        Config.T32RemSuccessExitCode,
27
        Config.T32RemWaitTimeoutMs
28 f281acac silhavyj
    );
29
    
30 30c849e4 silhavyj
    public static int Main() {
31 6dab0250 silhavyj
        if (GetProcessesByName(Path.GetFileNameWithoutExtension(GetEntryAssembly()?.Location)).Length > 1) {
32 30c849e4 silhavyj
            DefaultLogger.Error("Another instance of the application is already running");
33
            return 1;
34
        }
35
        
36
        DefaultApiClient = new ApiClient(
37
            Config.ApiBaseAddress,
38
            Config.ApiPort, 
39
            Config.ApiUsbEndPoint, 
40
            Config.RetryPeriod, Config.MaxEntries,
41
            Config.MaxRetries, 
42 fa084fc4 Pultak
            new PersistentQueue(Config.CacheFileName)
43 30c849e4 silhavyj
        );
44
        
45 afafbc22 Pultak
        IProcessDetection processProcessDetection = new ProcessDetection(
46 f281acac silhavyj
            Config.T32ProcessName,
47
            Config.DetectionPeriod,
48
            InfoFetcher,
49 afafbc22 Pultak
            DefaultApiClient,
50
            new ProcessUtils()
51 f281acac silhavyj
        );
52
        
53 aaad9ad4 Pultak
        var apiClientThread = new Thread(DefaultApiClient.Run) {
54
            IsBackground = true
55
        };
56
        apiClientThread.Start();
57
58 f281acac silhavyj
        var processThread = new Thread(processProcessDetection.RunPeriodicDetection) {
59
            IsBackground = true
60
        };
61
        processThread.Start();
62 aaad9ad4 Pultak
63 f281acac silhavyj
        while (true) {
64 6dab0250 silhavyj
            Thread.Sleep(MainLoopDelayMs);
65 f5a08dd5 Pultak
        }
66 aaad9ad4 Pultak
    }
67 c318a92c Pultak
}