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/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>

Také k dispozici: Unified diff