add common json options
This commit is contained in:
@@ -4,6 +4,7 @@ using System.Text.Encodings.Web;
|
||||
using System.Text.Json;
|
||||
using System.Text.Unicode;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using SimApi.Helpers;
|
||||
|
||||
namespace SimApi;
|
||||
|
||||
@@ -16,11 +17,7 @@ public partial class Synapse
|
||||
|
||||
private void FireEvent(string eventName, object param)
|
||||
{
|
||||
var paramJson = JsonSerializer.Serialize(param, new JsonSerializerOptions
|
||||
{
|
||||
Encoder = JavaScriptEncoder.Create(UnicodeRanges.All),
|
||||
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
|
||||
});
|
||||
var paramJson = JsonSerializer.Serialize(param, SimApiUtil.JsonOption);
|
||||
var router = $"event.{Options.AppName}.{eventName}";
|
||||
var props = EventClientChannel.CreateBasicProperties();
|
||||
props.AppId = Options.AppId;
|
||||
|
||||
@@ -5,6 +5,7 @@ using System.Text.Json;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using RabbitMQ.Client.Events;
|
||||
using SimApi.Helpers;
|
||||
|
||||
namespace SimApi;
|
||||
|
||||
@@ -35,13 +36,7 @@ public partial class Synapse
|
||||
{
|
||||
mt.Invoke(callClass, pt == typeof(string)
|
||||
? new object[] { reqBody }
|
||||
: new[]
|
||||
{
|
||||
JsonSerializer.Deserialize(reqBody, pt, new JsonSerializerOptions
|
||||
{
|
||||
PropertyNamingPolicy = JsonNamingPolicy.CamelCase
|
||||
})
|
||||
});
|
||||
: new[] { JsonSerializer.Deserialize(reqBody, pt, SimApiUtil.JsonOption) });
|
||||
EventServerChannel.BasicAck(ea.DeliveryTag, false);
|
||||
}
|
||||
catch (Exception e)
|
||||
|
||||
+2
-10
@@ -38,11 +38,7 @@ public partial class Synapse
|
||||
|
||||
private object FireRpc(string app, string action, object param)
|
||||
{
|
||||
var paramJson = JsonSerializer.Serialize(param, new JsonSerializerOptions
|
||||
{
|
||||
Encoder = JavaScriptEncoder.Create(UnicodeRanges.All),
|
||||
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
|
||||
});
|
||||
var paramJson = JsonSerializer.Serialize(param, SimApiUtil.JsonOption);
|
||||
var router = $"server.{app}";
|
||||
SimApiBaseResponse response;
|
||||
var props = RpcClientChannel.CreateBasicProperties();
|
||||
@@ -65,11 +61,7 @@ public partial class Synapse
|
||||
if (ResponseCache.TryGetValue(props.MessageId, out var value))
|
||||
{
|
||||
response = JsonSerializer.Deserialize<SimApiBaseResponse<object>>(
|
||||
Encoding.UTF8.GetString(value), new JsonSerializerOptions
|
||||
{
|
||||
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
|
||||
Encoder = JavaScriptEncoder.Create(UnicodeRanges.All)
|
||||
});
|
||||
Encoding.UTF8.GetString(value), SimApiUtil.JsonOption);
|
||||
ResponseCache.Remove(props.MessageId);
|
||||
break;
|
||||
}
|
||||
|
||||
+4
-11
@@ -4,6 +4,7 @@ using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Text.Encodings.Web;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using System.Text.Unicode;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
@@ -48,10 +49,7 @@ public partial class Synapse
|
||||
}
|
||||
else
|
||||
{
|
||||
var paramObj = JsonSerializer.Deserialize(reqBody, pt, new JsonSerializerOptions
|
||||
{
|
||||
PropertyNamingPolicy = JsonNamingPolicy.CamelCase
|
||||
});
|
||||
var paramObj = JsonSerializer.Deserialize(reqBody, pt, SimApiUtil.JsonOption);
|
||||
param = new[] { paramObj };
|
||||
}
|
||||
var ret = mt.Invoke(callClass, param);
|
||||
@@ -59,9 +57,8 @@ public partial class Synapse
|
||||
}
|
||||
catch (TargetInvocationException e)
|
||||
{
|
||||
if (e.InnerException is SimApiException)
|
||||
if (e.InnerException is SimApiException ie)
|
||||
{
|
||||
var ie = e.InnerException as SimApiException;
|
||||
Logger.LogDebug("RPC调用错误: {Err}", ie.Message);
|
||||
res = new SimApiBaseResponse(ie.Code, ie.Message);
|
||||
}
|
||||
@@ -77,11 +74,7 @@ public partial class Synapse
|
||||
}
|
||||
}
|
||||
|
||||
var returnJson = JsonSerializer.Serialize((object)res, new JsonSerializerOptions
|
||||
{
|
||||
Encoder = JavaScriptEncoder.Create(UnicodeRanges.All),
|
||||
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
|
||||
});
|
||||
var returnJson = JsonSerializer.Serialize((object)res, SimApiUtil.JsonOption);
|
||||
var reply = $"client.{ea.BasicProperties.ReplyTo}.{ea.BasicProperties.AppId}";
|
||||
var props = RpcServerChannel.CreateBasicProperties();
|
||||
props.AppId = Options.AppId;
|
||||
|
||||
Reference in New Issue
Block a user