Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 2c9a5fda

Přidáno uživatelem Jakub Šilhavý před více než 2 roky(ů)

re #9845 Added an outer loop for information retrieval

Zobrazit rozdíly:

ld_client/LDClient/Program.cs
92 92
            Config.DetectionPeriod,
93 93
            InfoFetcher,
94 94
            DefaultApiClient,
95
            new ProcessUtils()
95
            new ProcessUtils(),
96
            Config.FetchInfoSuperiorMaxAttempts,
97
            Config.FetchInfoSuperiorAttemptPeriod
96 98
        );
97 99
        
98 100
        // Create and start a new thread that periodically
ld_client/LDClient/appsettings.json
64 64
    "FetchInfoMaxAttempts": 15,
65 65
    "FetchInfoAttemptPeriod": 4000,
66 66
    "T32RemSuccessExitCode": 0,
67
    "T32RemWaitTimeoutMs": 2000
67
    "T32RemWaitTimeoutMs": 2000,
68
    "FetchInfoSuperiorMaxAttempts": 5,
69
    "FetchInfoSuperiorAttemptPeriod": 1000
68 70
  }
69 71
}
ld_client/LDClient/detection/ProcessDetection.cs
61 61
    /// Flag used to stop the thread (process detection).
62 62
    /// </summary>
63 63
    public bool DetectionRunning = false;
64

  
65
    /// <summary>
66
    /// Superior number of attempts to fetch the information (outer loop).
67
    /// </summary>
68
    private uint _fetchInfoSuperiorMaxAttempts;
69
    
70
    /// <summary>
71
    /// Period of the superior (outer) loop to fetch the data.
72
    /// </summary>
73
    private uint _fetchInfoSuperiorAttemptPeriod;
64 74
        
65 75
    /// <summary>
66 76
    /// Creates an instance of this class.
......
71 81
    /// <param name="apiClient">Instance of API clients used for sending data off to the server</param>
72 82
    /// <param name="processUtils">Instance of ProcessUtils which encapsulates common functionality when it comes to dealing with processes (limited by the needs of this application)</param>
73 83
    public ProcessDetection(string processName, uint detectionPeriodMs, IInfoFetcher infoFetcher,
74
        IApiClient apiClient, IProcessUtils processUtils) {
84
        IApiClient apiClient, IProcessUtils processUtils, uint fetchInfoSuperiorMaxAttempts, uint fetchInfoSuperiorAttemptPeriod) {
75 85
        _processName = processName;
76 86
        _detectionPeriodMs = detectionPeriodMs;
77 87
        _infoFetcher = infoFetcher;
78 88
        _apiClient = apiClient;
79 89
        _failedToRetrieveData = false;
80 90
        _processUtils = processUtils;
91
        _fetchInfoSuperiorMaxAttempts = fetchInfoSuperiorMaxAttempts;
92
        _fetchInfoSuperiorAttemptPeriod = fetchInfoSuperiorAttemptPeriod;
81 93
    }
82 94

  
83 95
    /// <summary>
......
86 98
    /// <returns>True, if the data was fetched successfully. False, otherwise.</returns>
87 99
    private async Task<bool> RetrieveDataFromDebugger() {
88 100
        // Try to fetch data from the debugger.
89
        var success = await _infoFetcher.FetchDataAsync();
90
            
91
        // If the data was fetched successfully, send a payload off to the server.
92
        if (success) {
93
            _lastConnectedPayload = await SendDataToServerAsync(_infoFetcher.HeadSerialNumber,
94
                _infoFetcher.BodySerialNumber, DatetimeFormat);
101

  
102
        for (var i = 0; i < _fetchInfoSuperiorMaxAttempts; i++) {
103
            var success = await _infoFetcher.FetchDataAsync();
104

  
105
            // If the data was fetched successfully, send a payload off to the server.
106
            if (success) {
107
                _lastConnectedPayload = await SendDataToServerAsync(_infoFetcher.HeadSerialNumber,
108
                    _infoFetcher.BodySerialNumber, DatetimeFormat);
109
                return true;
110
            }
111
            await Task.Delay((int)_fetchInfoSuperiorAttemptPeriod);
95 112
        }
96
        return success;
113
        return false;
97 114
    }
98 115

  
99 116
    /// <summary>
ld_client/LDClient/utils/ConfigLoader.cs
185 185
        /// </summary>
186 186
        public string T32ApiPacketLen { get; private set; } = null!;
187 187

  
188
        /// <summary>
189
        /// Superior number of attempts to fetch the information (outer loop).
190
        /// </summary>
191
        public uint FetchInfoSuperiorMaxAttempts { get; private set; }
192
        
193
        /// <summary>
194
        /// Period of the superior (outer) loop to fetch the data.
195
        /// </summary>
196
        public uint FetchInfoSuperiorAttemptPeriod { get; private set;  }
197

  
188 198
        #endregion
189 199

  
190 200
        /// <summary>
......
283 293
                T32ApiAddress = debugger["T32ApiAddress"];
284 294
                T32ApiPort = debugger["T32ApiPort"];
285 295
                T32ApiPacketLen = debugger["T32ApiPacketLen"];
286
                
296
                FetchInfoSuperiorMaxAttempts = uint.Parse(debugger["FetchInfoSuperiorMaxAttempts"]);
297
                FetchInfoSuperiorAttemptPeriod = uint.Parse(debugger["FetchInfoSuperiorAttemptPeriod"]);
298

  
287 299
            } catch (Exception e) {
288 300
                Console.WriteLine(e);
289 301
                Environment.Exit(ErrorExitCode);

Také k dispozici: Unified diff