Skip to content
This repository was archived by the owner on Feb 19, 2025. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 28 additions & 3 deletions csharp/autogen/src/JsonRpc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Net;
using System.Text;
using System.Threading;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
Expand Down Expand Up @@ -168,6 +170,7 @@ public JsonRpcClient(string baseUrl)
/// IMPORTANT: the latter may contain sensitive data, so handle it carefully.
/// </summary>
public event Action<string> RequestEvent;
public event Action<string> ResponseEvent;

public JsonRpcVersion JsonRpcVersion { get; set; }
public string UserAgent { get; set; }
Expand Down Expand Up @@ -218,9 +221,7 @@ private T Rpc<T>(string callName, JToken parameters, JsonSerializer serializer)
// from the Stream rather than allocating strings inbetween
// therefore the latter will be done only in DEBUG mode

#if DEBUG
var settings = CreateSettings(serializer.Converters);
#endif

using (var str = webRequest.GetRequestStream())
using (var sw = new StreamWriter(str))
Expand Down Expand Up @@ -257,7 +258,31 @@ private T Rpc<T>(string callName, JToken parameters, JsonSerializer serializer)
string json2 = responseReader.ReadToEnd();
var res2 = JsonConvert.DeserializeObject<JsonResponseV2<T>>(json2, settings);
#else
var res2 = (JsonResponseV2<T>)serializer.Deserialize(responseReader, typeof(JsonResponseV2<T>));
JsonResponseV2<T> res2;

if (callName == "VM.get_record")
{
string json2 = responseReader.ReadToEnd();

var requestProperties = TypeDescriptor.GetProperties(webRequest);
var requestSb = new StringBuilder("\n*** WebRequest Properties:\n");
foreach (PropertyDescriptor prop in requestProperties)
requestSb.AppendFormat("{0} {1}={2}\n", prop.PropertyType, prop.Name, prop.GetValue(webRequest));

var responseProperties = TypeDescriptor.GetProperties(webResponse);
var responseSb = new StringBuilder("*** WebResponse Properties:\n");
foreach (PropertyDescriptor prop in responseProperties)
responseSb.AppendFormat("{0} {1}={2}\n", prop.PropertyType, prop.Name, prop.GetValue(webResponse));

if (ResponseEvent != null)
ResponseEvent(string.Format("{0}\n\n{1}\n\n{2}\n\n", requestSb, responseSb, json2));

res2 = JsonConvert.DeserializeObject<JsonResponseV2<T>>(json2, settings);
}
else
{
res2 = (JsonResponseV2<T>)serializer.Deserialize(responseReader, typeof(JsonResponseV2<T>));
}
#endif
if (res2.Error != null)
{
Expand Down