Projekt

Obecné

Profil

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