Projekt

Obecné

Profil

Stáhnout (1.98 KB) Statistiky
| Větev: | Tag: | Revize:
1
using DiskQueue;
2
using LDClient.detection;
3
using LDClient.network;
4
using LDClient.utils;
5
using LDClient.utils.loggers;
6

    
7
using static System.Diagnostics.Process;
8
using static System.Reflection.Assembly;
9

    
10
namespace LDClient;
11

    
12
internal static class Program {
13

    
14
    private const int MainLoopDelayMs = 30000; 
15

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

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

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