Revize 4dcc6c07
Přidáno uživatelem Jakub Šilhavý před téměř 3 roky(ů)
ld_client/LDClient/Program.cs | ||
---|---|---|
21 | 21 |
Config.FetchInfoAttemptPeriod, |
22 | 22 |
Config.T32InfoLocation, |
23 | 23 |
Config.F32RemExecutable, |
24 |
Config.F32RemArguments |
|
24 |
Config.F32RemArguments, |
|
25 |
Config.T32RemSuccessExitCode, |
|
26 |
Config.T32RemWaitTimeoutMs |
|
25 | 27 |
); |
26 | 28 |
|
27 | 29 |
public static int Main() { |
ld_client/LDClient/appsettings.json | ||
---|---|---|
26 | 26 |
"CacheFileName": "cache" |
27 | 27 |
}, |
28 | 28 |
"DebuggerDetection": { |
29 |
"F32RemArguments" : [ |
|
30 |
"localhost port=20000 printer.filetype ASCIIE", |
|
31 |
"localhost port=20000 printer.open C:\\Users\\pulta\\Desktop\\testResult.txt", |
|
32 |
"localhost port=20000 WinPrint.version.hardware", |
|
33 |
"localhost port=20000 printer.close" |
|
34 |
], |
|
29 | 35 |
"F32RemExecutable": "/home/silhavyj/School/KIV-ASWI/aswi2022bug-thugs/ld_client/Mock/t32rem/build/t32rem_mock", |
30 |
"F32RemArguments": "localhost port=20000 VERSION.HARDWARE", |
|
31 | 36 |
"T32ProcessName": "ld_mock", |
32 |
"T32InfoLocation": "ldResult.txt",
|
|
37 |
"T32InfoLocation": "C:\\Users\\pulta\\Desktop\\testResult.txt",
|
|
33 | 38 |
"DetectionPeriod": 5000, |
34 | 39 |
"FetchInfoMaxAttempts": 5, |
35 |
"FetchInfoAttemptPeriod": 1000 |
|
40 |
"FetchInfoAttemptPeriod": 1000, |
|
41 |
"T32RemSuccessExitCode": 0, |
|
42 |
"T32RemWaitTimeoutMs": 2000 |
|
36 | 43 |
} |
37 | 44 |
} |
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 |
} |
ld_client/LDClient/utils/ConfigLoader.cs | ||
---|---|---|
44 | 44 |
public uint DetectionPeriod { get; private set; } |
45 | 45 |
public string T32InfoLocation { get; private set; } |
46 | 46 |
public string F32RemExecutable { get; private set; } |
47 |
public string F32RemArguments { get; private set; } |
|
48 | 47 |
public uint FetchInfoMaxAttempts { get; private set; } |
49 | 48 |
public uint FetchInfoAttemptPeriod { get; private set; } |
50 |
|
|
49 |
public string[] F32RemArguments { get; private set; } |
|
50 |
public int T32RemSuccessExitCode { get; private set; } |
|
51 |
public int T32RemWaitTimeoutMs { get; private set; } |
|
52 |
|
|
51 | 53 |
#endregion |
52 | 54 |
|
53 | 55 |
public ConfigLoader() { |
... | ... | |
85 | 87 |
T32InfoLocation = debugger["T32InfoLocation"]; |
86 | 88 |
DetectionPeriod = uint.Parse(debugger["DetectionPeriod"]); |
87 | 89 |
F32RemExecutable = debugger["F32RemExecutable"]; |
88 |
F32RemArguments = debugger["F32RemArguments"]; |
|
89 | 90 |
FetchInfoMaxAttempts = uint.Parse(debugger["FetchInfoMaxAttempts"]); |
90 | 91 |
FetchInfoAttemptPeriod = uint.Parse(debugger["FetchInfoAttemptPeriod"]); |
92 |
T32RemSuccessExitCode = int.Parse(debugger["T32RemSuccessExitCode"]); |
|
93 |
T32RemWaitTimeoutMs = int.Parse(debugger["T32RemWaitTimeoutMs"]); |
|
94 |
F32RemArguments = configuration.GetSection($"{DdSection}:F32RemCommands").GetChildren().Select(key => key.Value).ToArray(); |
|
91 | 95 |
|
92 | 96 |
Console.WriteLine("Configuration successfully loaded!"); |
93 | 97 |
} catch (FormatException e) { |
Také k dispozici: Unified diff
re #9568 Added all 4 commands (arguments) to be sent to the debugger into the configuration file.