Projekt

Obecné

Profil

Stáhnout (1.87 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
    );
26
    
27
    public static int Main() {
28
        if (GetProcessesByName(Path.GetFileNameWithoutExtension(GetEntryAssembly()?.Location)).Length > 1) {
29
            DefaultLogger.Error("Another instance of the application is already running");
30
            return 1;
31
        }
32
        
33
        DefaultApiClient = new ApiClient(
34
            Config.ApiBaseAddress,
35
            Config.ApiPort, 
36
            Config.ApiUsbEndPoint, 
37
            Config.RetryPeriod, Config.MaxEntries,
38
            Config.MaxRetries, 
39
            Config.CacheFileName
40
        );
41
        
42
        IProcessDetection processProcessDetection = new ProcessProcessDetection(
43
            Config.T32ProcessName,
44
            Config.DetectionPeriod,
45
            InfoFetcher,
46
            DefaultApiClient
47
        );
48
        
49
        var apiClientThread = new Thread(DefaultApiClient.Run) {
50
            IsBackground = true
51
        };
52
        apiClientThread.Start();
53

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

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