Projekt

Obecné

Profil

Stáhnout (1.77 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 30c849e4 silhavyj
    public static ConfigLoader Config { get; } = new();
14 4b0f0b36 Pultak
    public static ALogger DefaultLogger { get; } = ALogger.Current;
15 30c849e4 silhavyj
    private static IApiClient? DefaultApiClient { get; set; }
16
    
17 f281acac silhavyj
    private static readonly InfoFetcher InfoFetcher = new(
18
        5,
19
        1000,
20
        "output.txt"
21
    );
22
    
23 30c849e4 silhavyj
    public static int Main() {
24
        var exists = GetProcessesByName(Path.GetFileNameWithoutExtension(GetEntryAssembly()?.Location)).Length > 1;
25
        if (exists) {
26
            DefaultLogger.Error("Another instance of the application is already running");
27
            return 1;
28
        }
29
        
30
        DefaultApiClient = new ApiClient(
31
            Config.ApiBaseAddress,
32
            Config.ApiPort, 
33
            Config.ApiUsbEndPoint, 
34
            Config.RetryPeriod, Config.MaxEntries,
35
            Config.MaxRetries, 
36
            Config.CacheFileName
37
        );
38
        
39 f281acac silhavyj
        IProcessDetection processProcessDetection = new ProcessProcessDetection(
40
            Config.T32ProcessName,
41
            Config.DetectionPeriod,
42
            InfoFetcher,
43
            DefaultApiClient
44
        );
45
        
46 30c849e4 silhavyj
        DefaultLogger.Debug("Main -> starting the ApiClient");
47 aaad9ad4 Pultak
        var apiClientThread = new Thread(DefaultApiClient.Run) {
48
            IsBackground = true
49
        };
50
        apiClientThread.Start();
51
52 f281acac silhavyj
        var processThread = new Thread(processProcessDetection.RunPeriodicDetection) {
53
            IsBackground = true
54
        };
55
        processThread.Start();
56 aaad9ad4 Pultak
57 f281acac silhavyj
        while (true) {
58
            Thread.Sleep(10 * 1000);
59 f5a08dd5 Pultak
        }
60 30c849e4 silhavyj
        return 0;
61 aaad9ad4 Pultak
    }
62 c318a92c Pultak
}