first commit
This commit is contained in:
139
QuickTools/Form1.cs
Normal file
139
QuickTools/Form1.cs
Normal file
@@ -0,0 +1,139 @@
|
||||
using Flurl.Http;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace QuickTools
|
||||
{
|
||||
public partial class Form1 : Form
|
||||
{
|
||||
public Form1()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private async void btnEncode_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (txtProtoId.Text.Trim() == string.Empty)
|
||||
{
|
||||
MessageBox.Show("ProtocolID <20><><EFBFBD><EFBFBD>Ϊ<EFBFBD>գ<EFBFBD>", "<22><><EFBFBD><EFBFBD>", MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
||||
return;
|
||||
}
|
||||
int protocolId;
|
||||
try
|
||||
{
|
||||
protocolId = Convert.ToInt32(txtProtoId.Text.Trim());
|
||||
}
|
||||
catch
|
||||
{
|
||||
MessageBox.Show("ProtocolID ֻ<><D6BB>Ϊ<EFBFBD><CEAA><EFBFBD>֣<EFBFBD>", "<22><><EFBFBD><EFBFBD>", MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
||||
return;
|
||||
}
|
||||
var url = "http://localhost:9999/api/v1/emoney/converter/request/encode";
|
||||
try
|
||||
{
|
||||
string r = await url.PostJsonAsync(new
|
||||
{
|
||||
protocolId,
|
||||
protocolBody = txtJson.Text,
|
||||
}).Result.Content.ReadAsStringAsync();
|
||||
if (r != null)
|
||||
{
|
||||
JObject jo = JObject.Parse(r);
|
||||
if (jo["code"].Value<int>() == 0)
|
||||
{
|
||||
txtProto.Text = jo["result"].Value<string>();
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show(jo["msg"].Value<string>(), "<22><><EFBFBD><EFBFBD>", MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Debug.WriteLine(ex.StackTrace);
|
||||
MessageBox.Show($"ת<><D7AA> JSON Ϊ Protobuf <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ִ<EFBFBD><D6B4><EFBFBD><EFBFBD><EFBFBD>{ex.Message}", "<22><><EFBFBD><EFBFBD>", MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
||||
}
|
||||
}
|
||||
|
||||
private async void btnDecode_Click(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
if (txtProtoId.Text.Trim() == string.Empty)
|
||||
{
|
||||
MessageBox.Show("ProtocolID <20><><EFBFBD><EFBFBD>Ϊ<EFBFBD>գ<EFBFBD>", "<22><><EFBFBD><EFBFBD>", MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
||||
return;
|
||||
}
|
||||
int protocolId;
|
||||
try
|
||||
{
|
||||
protocolId = Convert.ToInt32(txtProtoId.Text.Trim());
|
||||
}
|
||||
catch
|
||||
{
|
||||
MessageBox.Show("ProtocolID ֻ<><D6BB>Ϊ<EFBFBD><CEAA><EFBFBD>֣<EFBFBD>", "<22><><EFBFBD><EFBFBD>", MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
||||
return;
|
||||
}
|
||||
var url = "http://localhost:9999/api/v1/emoney/converter/request/decode";
|
||||
try
|
||||
{
|
||||
string r = await url.PostJsonAsync(new
|
||||
{
|
||||
protocolId,
|
||||
protocolBody = txtProto.Text,
|
||||
}).Result.Content.ReadAsStringAsync();
|
||||
if (r != null)
|
||||
{
|
||||
JObject jo = JObject.Parse(r);
|
||||
if (jo["code"].Value<int>() == 0)
|
||||
{
|
||||
txtJson.Text = ClearSizeInfo(jo["result"]).ToString();
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show(jo["msg"].Value<string>(), "<22><><EFBFBD><EFBFBD>", MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Debug.WriteLine(ex.StackTrace);
|
||||
MessageBox.Show($"ת<><D7AA> Protobuf Ϊ JSON <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ִ<EFBFBD><D6B4><EFBFBD><EFBFBD><EFBFBD>{ex.Message}", "<22><><EFBFBD><EFBFBD>", MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
||||
}
|
||||
}
|
||||
|
||||
public static JToken ClearSizeInfo(JToken j)
|
||||
{
|
||||
if (j == null) return null;
|
||||
if (j is JArray ja)
|
||||
{
|
||||
for (int i = 0; i < ja.Count; i++)
|
||||
{
|
||||
ja[i] = ClearSizeInfo(ja[i]);
|
||||
}
|
||||
return ja;
|
||||
}
|
||||
if (j is JObject jo)
|
||||
{
|
||||
if (jo.ContainsKey("cachedSize"))
|
||||
{
|
||||
jo.Remove("cachedSize");
|
||||
}
|
||||
if (jo.ContainsKey("serializedSize"))
|
||||
{
|
||||
jo.Remove("serializedSize");
|
||||
}
|
||||
foreach (var p in jo)
|
||||
{
|
||||
string key = p.Key;
|
||||
JToken val = p.Value;
|
||||
jo[key] = ClearSizeInfo(val);
|
||||
}
|
||||
return jo;
|
||||
}
|
||||
return j;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user