Revize 625c7c2e
Přidáno uživatelem Jakub Šilhavý před téměř 3 roky(ů)
ld_client/LDClient/network/data/ConnectionStatus.cs | ||
---|---|---|
2 | 2 |
|
3 | 3 |
namespace LDClient.network.data { |
4 | 4 |
|
5 |
/// <summary> |
|
6 |
/// This enumeration defines different states in |
|
7 |
/// which a debugger can be. |
|
8 |
/// </summary> |
|
5 | 9 |
public enum ConnectionStatus { |
6 | 10 |
|
11 |
/// <summary> |
|
12 |
/// Debugger is connected |
|
13 |
/// </summary> |
|
7 | 14 |
[EnumMember(Value = "connected")] |
8 | 15 |
Connected, |
16 |
|
|
17 |
/// <summary> |
|
18 |
/// Debugger is disconnected |
|
19 |
/// </summary> |
|
9 | 20 |
[EnumMember(Value = "disconnected")] |
10 | 21 |
Disconnected |
11 | 22 |
} |
ld_client/LDClient/network/data/DebuggerInfo.cs | ||
---|---|---|
1 | 1 |
using System.Text.Json.Serialization; |
2 | 2 |
|
3 | 3 |
namespace LDClient.network.data { |
4 |
|
|
5 |
/// <summary> |
|
6 |
/// This class holds all the information about |
|
7 |
/// a specific part of a debugger (head/body). |
|
8 |
/// </summary> |
|
4 | 9 |
public class DebuggerInfo { |
5 | 10 |
|
11 |
/// <summary> |
|
12 |
/// Serial number of the part of a debugger. |
|
13 |
/// </summary> |
|
6 | 14 |
[JsonPropertyName("serial_number")] |
7 | 15 |
public string? SerialNumber { get; set; } |
8 | 16 |
} |
ld_client/LDClient/network/data/Payload.cs | ||
---|---|---|
5 | 5 |
|
6 | 6 |
namespace LDClient.network.data { |
7 | 7 |
|
8 |
/// <summary> |
|
9 |
/// This class represents a single payload that is sent to the server. |
|
10 |
/// </summary> |
|
8 | 11 |
[JsonObject(MemberSerialization.OptIn)] |
9 | 12 |
public class Payload { |
10 | 13 |
|
14 |
/// <summary> |
|
15 |
/// Username of the currently logged user. |
|
16 |
/// </summary> |
|
11 | 17 |
[JsonPropertyName("username")] |
12 | 18 |
public string? UserName { get; set; } |
13 | 19 |
|
20 |
/// <summary> |
|
21 |
/// Hostname of the pc. |
|
22 |
/// </summary> |
|
14 | 23 |
[JsonPropertyName("hostname")] |
15 | 24 |
public string? HostName { get; set; } |
16 | 25 |
|
26 |
/// <summary> |
|
27 |
/// Timestamp (when a debugger was plugged/unplugged). |
|
28 |
/// </summary> |
|
17 | 29 |
[JsonPropertyName("timestamp")] |
18 | 30 |
public string? TimeStamp { get; set; } |
19 | 31 |
|
32 |
/// <summary> |
|
33 |
/// Information about the head of the debugger. |
|
34 |
/// </summary> |
|
20 | 35 |
[JsonPropertyName("head_device")] |
21 | 36 |
public DebuggerInfo? HeadDevice { get; set; } |
22 | 37 |
|
23 |
|
|
38 |
/// <summary> |
|
39 |
/// Information about the body of the debugger. |
|
40 |
/// </summary> |
|
24 | 41 |
[JsonPropertyName("body_device")] |
25 | 42 |
public DebuggerInfo? BodyDevice { get; set; } |
26 | 43 |
|
44 |
/// <summary> |
|
45 |
/// Status of the debugger (connected/disconnected). |
|
46 |
/// </summary> |
|
27 | 47 |
[JsonPropertyName("status")] |
28 | 48 |
public ConnectionStatus Status { get; set; } |
29 |
|
|
30 |
|
|
49 |
|
|
50 |
/// <summary> |
|
51 |
/// Returns a string representation of the payload. |
|
52 |
/// </summary> |
|
53 |
/// <returns></returns> |
|
31 | 54 |
public override string ToString() { |
32 | 55 |
return ParseToJson(this); |
33 | 56 |
} |
34 | 57 |
|
58 |
/// <summary> |
|
59 |
/// Parses (converts) the payload into JSON format. |
|
60 |
/// </summary> |
|
61 |
/// <returns></returns> |
|
35 | 62 |
public string ParseToJson() { |
36 | 63 |
return Payload.ParseToJson(this); |
37 | 64 |
} |
38 | 65 |
|
66 |
/// <summary> |
|
67 |
/// Serializes a given payload into JSON format. |
|
68 |
/// </summary> |
|
69 |
/// <param name="payload">payload to be serialized into JSON</param> |
|
70 |
/// <returns></returns> |
|
39 | 71 |
public static string ParseToJson(Payload payload) { |
72 |
// Create options for serialization. |
|
40 | 73 |
var options = new JsonSerializerOptions { |
41 | 74 |
Converters = { |
42 | 75 |
new JsonStringEnumConverter(JsonNamingPolicy.CamelCase) |
43 | 76 |
} |
44 | 77 |
}; |
45 |
|
|
78 |
// Serialize the payload and return it. |
|
46 | 79 |
return JsonSerializer.Serialize(payload, options); |
47 | 80 |
} |
48 | 81 |
} |
Také k dispozici: Unified diff
re #9570 Commented ConnectionStatus.cs, DebuggerInfo.cs, and Payload.cs