Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 4dcc6c07

Přidáno uživatelem Jakub Šilhavý před asi 2 roky(ů)

re #9568 Added all 4 commands (arguments) to be sent to the debugger into the configuration file.

Zobrazit rozdíly:

ld_client/LDClient/detection/InfoFetcher.cs
7 7
        private const string UndefinedSerialNumber = "number";
8 8

  
9 9
        private readonly string _f32RemExecutable;
10
        private readonly string _f32RemArguments;
10
        private readonly string[] _f32RemArguments;
11
        private readonly int _f32SuccessExitCode;
12
        private readonly int _f32WaitTimeoutMs;
11 13
        
12 14
        private readonly uint _maxAttempts;
13 15
        private readonly uint _waitPeriodMs;
......
16 18
        public string HeadSerialNumber { get; private set; } = UndefinedSerialNumber;
17 19
        public string BodySerialNumber { get; private set; } = UndefinedSerialNumber;
18 20

  
19
        public InfoFetcher(uint maxAttempts, uint waitPeriodMs, string infoFilePath, string f32RemExecutable, string f32RemArguments) {
21
        public InfoFetcher(uint maxAttempts, uint waitPeriodMs, string infoFilePath, string f32RemExecutable, string[] f32RemArguments, int f32SuccessExitCode, int f32WaitTimeoutMs) {
20 22
            _maxAttempts = maxAttempts;
21 23
            _waitPeriodMs = waitPeriodMs;
22 24
            _infoFilePath = infoFilePath;
23 25
            _f32RemExecutable = f32RemExecutable;
24 26
            _f32RemArguments = f32RemArguments;
27
            _f32SuccessExitCode = f32SuccessExitCode;
28
            _f32WaitTimeoutMs = f32WaitTimeoutMs;
25 29
        }
26 30

  
27 31
        public async Task<bool> FetchDataAsync() {
28 32
            Program.DefaultLogger.Info("Fetching data from the debugger.");
29
            var success = await SendRetrieveInfoCommandAsync(_f32RemExecutable, _f32RemArguments);
33
            var success = SendRetrieveInfoCommands(_f32RemExecutable, _f32RemArguments, _f32SuccessExitCode, _f32WaitTimeoutMs);
30 34
            if (!success) {
31 35
                Program.DefaultLogger.Error("Failed to fetch data from the debugger.");
32 36
                return false;
......
57 61
            return true;
58 62
        }
59 63

  
60
        private static async Task<bool> SendRetrieveInfoCommandAsync(string executableFile, string arguments) {
61
            var t32RemProcess = new Process();
62
            t32RemProcess.StartInfo.FileName = executableFile;
63
            t32RemProcess.StartInfo.Arguments = arguments;
64
            try {
65
                t32RemProcess.Start();
66
                await t32RemProcess.WaitForExitAsync();
67
            } catch (Exception exception) {
68
                Program.DefaultLogger.Error($"Failed to run {executableFile}. {exception.Message}");
64
        private static bool SendRetrieveInfoCommands(string executableFile, IReadOnlyList<string>? arguments, int successExitCode, int waitTimeoutMs) {
65
            if (arguments == null) {
66
                Program.DefaultLogger.Error($"Failed to run {executableFile} - no parameters were given");
69 67
                return false;
70 68
            }
69
            foreach (var argument in arguments) {
70
                var t32RemProcess = new Process();
71
                t32RemProcess.StartInfo.FileName = executableFile;
72
                t32RemProcess.StartInfo.Arguments = argument;
73
                try {
74
                    t32RemProcess.Start();
75
                    t32RemProcess.WaitForExit(waitTimeoutMs);
76
                    if (t32RemProcess.ExitCode != successExitCode) {
77
                        return false;
78
                    }
79
                } catch (Exception exception) {
80
                    Program.DefaultLogger.Error($"Failed to run {executableFile} {argument}. {exception.Message}");
81
                    return false;
82
                }
83
            }
71 84
            return true;
72 85
        }
73 86
    }

Také k dispozici: Unified diff