Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 0932a9e2

Přidáno uživatelem Pultak před více než 2 roky(ů)

re #9443 refactoring of detection classes

Zobrazit rozdíly:

ld_client/LDClient/detection/ProcessDetection.cs
4 4

  
5 5
namespace LDClient.detection {
6 6
   
7
	 public sealed class ProcessProcessDetection : IProcessDetection {
7
	 public sealed class ProcessDetection : IProcessDetection {
8 8
        
9 9
        private const string DatetimeFormat = "yyyy-MM-dd hh:mm:ss";
10 10

  
11 11
        private readonly string _processName;
12 12
        private readonly uint _detectionPeriodMs;
13
        private readonly InfoFetcher _infoFetcher;
13
        private readonly IInfoFetcher _infoFetcher;
14 14
        private readonly IApiClient _apiClient;
15
        
15
        private readonly IProcessUtils _processUtils;
16

  
16 17
        private bool _processIsActive;
17 18
        private bool _failedToRetrieveData;
18 19
        private Payload? _lastConnectedPayload;
19 20

  
20
        public ProcessProcessDetection(string processName, uint detectionPeriodMs, InfoFetcher infoFetcher, IApiClient apiClient) {
21
        public bool DetectionRunning = false;
22

  
23
        public ProcessDetection(string processName, uint detectionPeriodMs, IInfoFetcher infoFetcher, IApiClient apiClient, IProcessUtils processUtils) {
21 24
            _processName = processName;
22 25
            _detectionPeriodMs = detectionPeriodMs;
23 26
            _infoFetcher = infoFetcher;
24 27
            _apiClient = apiClient;
25 28
            _failedToRetrieveData = false;
29
            _processUtils = processUtils;
26 30
        }
27 31

  
28 32
        private async Task<bool> RetrieveDataFromDebugger() {
......
43 47
        }
44 48

  
45 49
        private async Task DetectProcessAsync() {
46
            var processExists = Process.GetProcessesByName(_processName).Length > 0;
50
            var processExists = _processUtils.IsProcessRunning(_processName);
47 51

  
48 52
            if (processExists && !_processIsActive) {
49 53
                Program.DefaultLogger.Info($"Process started: {_processName}");
......
77 81
        
78 82
        public async void RunPeriodicDetection() {
79 83
            Program.DefaultLogger.Info("Process periodic detector has started");
80
            while (true) {
84
            DetectionRunning = true;
85
            while (DetectionRunning) {
81 86
                await DetectProcessAsync();
82 87
                Thread.Sleep((int)_detectionPeriodMs);
83 88
            }
84
            // ReSharper disable once FunctionNeverReturns
85 89
        }
86 90
    }
87 91
}

Také k dispozici: Unified diff