Projekt

Obecné

Profil

Stáhnout (1.91 KB) Statistiky
| Větev: | Tag: | Revize:
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
    private const int MainLoopDelayMs = 30000; 
14

    
15
    public static ConfigLoader Config { get; } = new();
16
    public static ALogger DefaultLogger { get; } = ALogger.Current;
17
    private static IApiClient? DefaultApiClient { get; set; }
18
    
19
    private static readonly InfoFetcher InfoFetcher = new(
20
        Config.FetchInfoMaxAttempts,
21
        Config.FetchInfoAttemptPeriod,
22
        Config.T32InfoLocation,
23
        Config.F32RemExecutable,
24
        Config.F32RemArguments,
25
        Config.T32RemSuccessExitCode,
26
        Config.T32RemWaitTimeoutMs
27
    );
28
    
29
    public static int Main() {
30
        if (GetProcessesByName(Path.GetFileNameWithoutExtension(GetEntryAssembly()?.Location)).Length > 1) {
31
            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
        IProcessDetection processProcessDetection = new ProcessProcessDetection(
45
            Config.T32ProcessName,
46
            Config.DetectionPeriod,
47
            InfoFetcher,
48
            DefaultApiClient
49
        );
50
        
51
        var apiClientThread = new Thread(DefaultApiClient.Run) {
52
            IsBackground = true
53
        };
54
        apiClientThread.Start();
55

    
56
        var processThread = new Thread(processProcessDetection.RunPeriodicDetection) {
57
            IsBackground = true
58
        };
59
        processThread.Start();
60

    
61
        while (true) {
62
            Thread.Sleep(MainLoopDelayMs);
63
        }
64
    }
65
}
(2-2/3)