|
30 | 30 |
|
31 | 31 | using System; |
32 | 32 | using System.Collections.Generic; |
| 33 | +using System.ComponentModel; |
33 | 34 | using System.IO; |
34 | 35 | using System.Net; |
| 36 | +using System.Text; |
35 | 37 | using System.Threading; |
36 | 38 | using Newtonsoft.Json; |
37 | 39 | using Newtonsoft.Json.Linq; |
@@ -168,6 +170,7 @@ public JsonRpcClient(string baseUrl) |
168 | 170 | /// IMPORTANT: the latter may contain sensitive data, so handle it carefully. |
169 | 171 | /// </summary> |
170 | 172 | public event Action<string> RequestEvent; |
| 173 | + public event Action<string> ResponseEvent; |
171 | 174 |
|
172 | 175 | public JsonRpcVersion JsonRpcVersion { get; set; } |
173 | 176 | public string UserAgent { get; set; } |
@@ -218,9 +221,7 @@ private T Rpc<T>(string callName, JToken parameters, JsonSerializer serializer) |
218 | 221 | // from the Stream rather than allocating strings inbetween |
219 | 222 | // therefore the latter will be done only in DEBUG mode |
220 | 223 |
|
221 | | -#if DEBUG |
222 | 224 | var settings = CreateSettings(serializer.Converters); |
223 | | -#endif |
224 | 225 |
|
225 | 226 | using (var str = webRequest.GetRequestStream()) |
226 | 227 | using (var sw = new StreamWriter(str)) |
@@ -257,7 +258,31 @@ private T Rpc<T>(string callName, JToken parameters, JsonSerializer serializer) |
257 | 258 | string json2 = responseReader.ReadToEnd(); |
258 | 259 | var res2 = JsonConvert.DeserializeObject<JsonResponseV2<T>>(json2, settings); |
259 | 260 | #else |
260 | | - var res2 = (JsonResponseV2<T>)serializer.Deserialize(responseReader, typeof(JsonResponseV2<T>)); |
| 261 | + JsonResponseV2<T> res2; |
| 262 | + |
| 263 | + if (callName == "VM.get_record") |
| 264 | + { |
| 265 | + string json2 = responseReader.ReadToEnd(); |
| 266 | + |
| 267 | + var requestProperties = TypeDescriptor.GetProperties(webRequest); |
| 268 | + var requestSb = new StringBuilder("\n*** WebRequest Properties:\n"); |
| 269 | + foreach (PropertyDescriptor prop in requestProperties) |
| 270 | + requestSb.AppendFormat("{0} {1}={2}\n", prop.PropertyType, prop.Name, prop.GetValue(webRequest)); |
| 271 | + |
| 272 | + var responseProperties = TypeDescriptor.GetProperties(webRequest); |
| 273 | + var responseSb = new StringBuilder("*** WebResponse Properties:\n"); |
| 274 | + foreach (PropertyDescriptor prop in responseProperties) |
| 275 | + responseSb.AppendFormat("{0} {1}={2}\n", prop.PropertyType, prop.Name, prop.GetValue(webRequest)); |
| 276 | + |
| 277 | + if (ResponseEvent != null) |
| 278 | + ResponseEvent(string.Format("{0}\n\n{1}\n\n{2}\n\n", requestSb, responseSb, json2)); |
| 279 | + |
| 280 | + res2 = JsonConvert.DeserializeObject<JsonResponseV2<T>>(json2, settings); |
| 281 | + } |
| 282 | + else |
| 283 | + { |
| 284 | + res2 = (JsonResponseV2<T>)serializer.Deserialize(responseReader, typeof(JsonResponseV2<T>)); |
| 285 | + } |
261 | 286 | #endif |
262 | 287 | if (res2.Error != null) |
263 | 288 | { |
|
0 commit comments