Revize f63d5489
Přidáno uživatelem Jakub Šilhavý před asi 2 roky(ů)
ld_client/LDClient/detection/DebuggerInfoParser.cs | ||
---|---|---|
2 | 2 |
|
3 | 3 |
namespace LDClient.detection { |
4 | 4 |
|
5 |
/// <summary> |
|
6 |
/// This class parses the .txt file generated from the debugger. |
|
7 |
/// Its primary interest is to find two serial numbers (head + body). |
|
8 |
/// </summary> |
|
5 | 9 |
public static class DebuggerInfoParser { |
6 | 10 |
|
11 |
/// <summary> |
|
12 |
/// Number of serial numbers expected to be in the .txt file (number of matches - regex). |
|
13 |
/// </summary> |
|
7 | 14 |
private const int ExpectedNumberOfMatches = 2; |
8 | 15 |
|
16 |
/// <summary> |
|
17 |
/// Regular expression used to find the serial numbers. |
|
18 |
/// </summary> |
|
9 | 19 |
private static readonly Regex SerialNumberRegex = new("(?<=Serial Number: )(.*)"); |
10 | 20 |
|
21 |
/// <summary> |
|
22 |
/// Takes the content of a .txt file and tries to find the two serial numbers (head and body). |
|
23 |
/// If it succeed, it will return the two numbers. |
|
24 |
/// </summary> |
|
25 |
/// <param name="dataTxt">the content of a .txt file (generated from the debugger)</param> |
|
26 |
/// <returns>two serial numbers (head and body) of the debugger</returns> |
|
27 |
/// <exception cref="ArgumentException">throws an exception if it fails to find the serial numbers</exception> |
|
11 | 28 |
public static (string headSerialNumber, string bodySerialNumber) Parse(string dataTxt) { |
29 |
// Find all matches in the content of the file that satisfy the regular expression. |
|
12 | 30 |
var matches = SerialNumberRegex.Matches(dataTxt); |
13 | 31 |
|
32 |
// Make sure an exact number of matches has been found. |
|
14 | 33 |
if (matches.Count != ExpectedNumberOfMatches) { |
15 | 34 |
throw new ArgumentException($"Expected {ExpectedNumberOfMatches} matches to be found in the text (actually found: {matches.Count})"); |
16 | 35 |
} |
17 | 36 |
|
37 |
// Return the two serial numbers (head and body). |
|
18 | 38 |
return (matches[1].ToString().Trim(), matches[0].ToString().Trim()); |
19 | 39 |
} |
20 | 40 |
} |
Také k dispozici: Unified diff
re #9570 Commented DebuggerInfoParser.cs, IInfoFetcher.cs, and InfoFetcher.cs