Projekt

Obecné

Profil

« Předchozí | Další » 

Revize e6a01bd8

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

re #9712 Added documentation of the newly implemented methods + refactoring

Zobrazit rozdíly:

ld_client/LDClient/detection/T32RemFetcher.cs
1
using System.Diagnostics;
2
using LDClient.utils;
3
using LDClient.utils.loggers;
1
namespace LDClient.detection; 
4 2

  
5
namespace LDClient.detection {
3
public class T32RemFetcher : AInfoFetcher{
6 4

  
7
    public class T32RemFetcher : AInfoFetcher{
5
    /// <summary>
6
    /// Path to the t32rem.exe file which is used to send commands to the debugger.
7
    /// </summary>
8
    private readonly string _f32RemExecutable;
8 9

  
9
        /// <summary>
10
        /// Path to the t32rem.exe file which is used to send commands to the debugger.
11
        /// </summary>
12
        private readonly string _f32RemExecutable;
10
    /// <summary>
11
    /// Arguments (commands) sent to the debugger in order to generate a .txt file
12
    /// containing all the desired information.
13
    /// </summary>
14
    private readonly string[] _f32RemArguments;
13 15

  
14
        /// <summary>
15
        /// Arguments (commands) sent to the debugger in order to generate a .txt file
16
        /// containing all the desired information.
17
        /// </summary>
18
        private readonly string[] _f32RemArguments;
16
    /// <summary>
17
    /// Status code indicating a successful termination of t32rem.exe
18
    /// </summary>
19
    private readonly int _f32SuccessExitCode;
19 20

  
20
        /// <summary>
21
        /// Status code indicating a successful termination of t32rem.exe
22
        /// </summary>
23
        private readonly int _f32SuccessExitCode;
24 21

  
22
    /// <summary>
23
    /// Timeout used when waiting for the t32rem.exe to finish.
24
    /// </summary>
25
    private readonly int _f32WaitTimeoutMs;
25 26

  
26
        /// <summary>
27
        /// Timeout used when waiting for the t32rem.exe to finish.
28
        /// </summary>
29
        private readonly int _f32WaitTimeoutMs;
27
    /// <summary>
28
    /// Instance of ProcessUtils which encapsulates common functionality
29
    /// when it comes to dealing with processes (limited by the needs of this application).
30
    /// </summary>
31
    public IProcessUtils ProcessUtils;
30 32

  
31
        /// <summary>
32
        /// Instance of ProcessUtils which encapsulates common functionality
33
        /// when it comes to dealing with processes (limited by the needs of this application).
34
        /// </summary>
35
        public IProcessUtils ProcessUtils;
33
    /// <summary>
34
    /// Creates an instance of this class.
35
    /// </summary>
36
    /// <param name="maxAttempts">Maximum number of attempts to locate and parse the .txt file</param>
37
    /// <param name="waitPeriodMs">Period (how often) the application tries to locate and parse the .txt file</param>
38
    /// <param name="infoFilePath">Path to the .txt file which is generated from the debugger</param>
39
    /// <param name="f32RemExecutable">Path to the t32rem.exe file which is used to send commands to the debugger</param>
40
    /// <param name="f32RemArguments">Arguments (commands) sent to the debugger in order to generate a .txt file containing all the desired information.</param>
41
    /// <param name="f32SuccessExitCode">Status code indicating a successful termination of t32rem.exe</param>
42
    /// <param name="f32WaitTimeoutMs">Timeout used when waiting for the t32rem.exe to finish</param>
43
    public T32RemFetcher(uint maxAttempts, uint waitPeriodMs, string infoFilePath, string f32RemExecutable,
44
        string[] f32RemArguments, int f32SuccessExitCode, int f32WaitTimeoutMs) : base(maxAttempts, waitPeriodMs, infoFilePath) {
45
        _f32RemExecutable = f32RemExecutable;
46
        _f32RemArguments = f32RemArguments;
47
        _f32SuccessExitCode = f32SuccessExitCode;
48
        _f32WaitTimeoutMs = f32WaitTimeoutMs;
49
        ProcessUtils = new ProcessUtils();
36 50

  
37
        /// <summary>
38
        /// Creates an instance of this class.
39
        /// </summary>
40
        /// <param name="maxAttempts">Maximum number of attempts to locate and parse the .txt file</param>
41
        /// <param name="waitPeriodMs">Period (how often) the application tries to locate and parse the .txt file</param>
42
        /// <param name="infoFilePath">Path to the .txt file which is generated from the debugger</param>
43
        /// <param name="f32RemExecutable">Path to the t32rem.exe file which is used to send commands to the debugger</param>
44
        /// <param name="f32RemArguments">Arguments (commands) sent to the debugger in order to generate a .txt file containing all the desired information.</param>
45
        /// <param name="f32SuccessExitCode">Status code indicating a successful termination of t32rem.exe</param>
46
        /// <param name="f32WaitTimeoutMs">Timeout used when waiting for the t32rem.exe to finish</param>
47

  
48
        public T32RemFetcher(uint maxAttempts, uint waitPeriodMs, string infoFilePath, string f32RemExecutable,
49
            string[] f32RemArguments, int f32SuccessExitCode, int f32WaitTimeoutMs) : base(maxAttempts, waitPeriodMs, infoFilePath) {
50
            _f32RemExecutable = f32RemExecutable;
51
            _f32RemArguments = f32RemArguments;
52
            _f32SuccessExitCode = f32SuccessExitCode;
53
            _f32WaitTimeoutMs = f32WaitTimeoutMs;
54
            ProcessUtils = new ProcessUtils();
51
    }
55 52

  
53
    /// <summary>
54
    /// Method tries to fetch the data from the trace32 application
55
    /// via defined executable 
56
    /// </summary>
57
    /// <returns>true upon success</returns>
58
    protected override bool FetchData() {
59
        if (_f32RemArguments == null) {
60
            Program.DefaultLogger.Error($"Failed to run {_f32RemExecutable} - no parameters were given");
61
            return false;
56 62
        }
57

  
58
        protected override bool FetchData() {
59
            if (_f32RemArguments == null) {
60
                Program.DefaultLogger.Error($"Failed to run {_f32RemExecutable} - no parameters were given");
63
        // Execute one all arguments (commands) one by one.
64
        foreach (var argument in _f32RemArguments) {
65
            if (!ProcessUtils.ExecuteNewProcess(_f32RemExecutable, argument, _f32WaitTimeoutMs, _f32SuccessExitCode)) {
61 66
                return false;
62 67
            }
63
            // Execute one all arguments (commands) one by one.
64
            foreach (var argument in _f32RemArguments) {
65
                if (!ProcessUtils.ExecuteNewProcess(_f32RemExecutable, argument, _f32WaitTimeoutMs, _f32SuccessExitCode)) {
66
                    return false;
67
                }
68
            }
69
            return true;
70 68
        }
69
        return true;
71 70
    }
72 71
}

Také k dispozici: Unified diff