SignalR, MessagePack, improvements, fixes
This commit is contained in:
parent
20b1ab4cf2
commit
413fe00c5f
|
|
@ -6,6 +6,10 @@
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="MessagePack" Version="2.5.140" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\AyCode.Core\AyCode.Core.csproj" />
|
<ProjectReference Include="..\AyCode.Core\AyCode.Core.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<PackageReference Include="MessagePack" Version="2.5.140" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="8.0.0" />
|
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="8.0.0" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0" />
|
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0" />
|
||||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,29 @@
|
||||||
|
using AyCode.Core.Interfaces;
|
||||||
|
using MessagePack.Resolvers;
|
||||||
|
using MessagePack;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
|
namespace AyCode.Core.Extensions;
|
||||||
|
|
||||||
|
public static class SerializeObjectExtensions
|
||||||
|
{
|
||||||
|
private static readonly JsonSerializerSettings Options = new()
|
||||||
|
{
|
||||||
|
ReferenceLoopHandling = ReferenceLoopHandling.Ignore,
|
||||||
|
NullValueHandling = NullValueHandling.Ignore
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
public static string ToJson<T>(this T source) where T : class, IAcSerializableToJson => JsonConvert.SerializeObject(source, Options);
|
||||||
|
public static string ToJson<T>(this IQueryable<T> source) where T : class, IAcSerializableToJson => JsonConvert.SerializeObject(source, Options);
|
||||||
|
public static string ToJson<T>(this IEnumerable<T> source) where T : class, IAcSerializableToJson => JsonConvert.SerializeObject(source, Options);
|
||||||
|
|
||||||
|
public static T? JsonTo<T>(this string json) => JsonConvert.DeserializeObject<T>(json, Options);
|
||||||
|
|
||||||
|
|
||||||
|
public static byte[] ToMessagePack(this object message) => MessagePackSerializer.Serialize(message);
|
||||||
|
public static byte[] ToMessagePack(this object message, MessagePackSerializerOptions options) => MessagePackSerializer.Serialize(message, options);
|
||||||
|
|
||||||
|
public static T? MessagePackTo<T>(this byte[] message) => MessagePackSerializer.Deserialize<T>(message);
|
||||||
|
public static T? MessagePackTo<T>(this byte[] message, MessagePackSerializerOptions options) => MessagePackSerializer.Deserialize<T>(message, options);
|
||||||
|
}
|
||||||
|
|
@ -1,22 +0,0 @@
|
||||||
using AyCode.Core.Interfaces;
|
|
||||||
using Newtonsoft.Json;
|
|
||||||
|
|
||||||
namespace AyCode.Core.Extensions;
|
|
||||||
|
|
||||||
public static class SerializeObjectToJsonExtensions
|
|
||||||
{
|
|
||||||
private static string SerializeObjectToJson<T>(T source)
|
|
||||||
{
|
|
||||||
JsonSerializerSettings options = new()
|
|
||||||
{
|
|
||||||
ReferenceLoopHandling = ReferenceLoopHandling.Ignore,
|
|
||||||
NullValueHandling = NullValueHandling.Ignore
|
|
||||||
};
|
|
||||||
|
|
||||||
return JsonConvert.SerializeObject(source, options);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static string ToJson<T>(this T source) where T : class, IAcSerializableToJson => SerializeObjectToJson(source);
|
|
||||||
public static string ToJson<T>(this IQueryable<T> source) where T : class, IAcSerializableToJson => SerializeObjectToJson(source);
|
|
||||||
public static string ToJson<T>(this IEnumerable<T> source) where T : class, IAcSerializableToJson => SerializeObjectToJson(source);
|
|
||||||
}
|
|
||||||
|
|
@ -6,6 +6,6 @@ public interface IAcSignalRHubClient : IAcSignalRHubBase
|
||||||
|
|
||||||
public interface IAcSignalRHubBase
|
public interface IAcSignalRHubBase
|
||||||
{
|
{
|
||||||
Task Get(string user, int messageTag);
|
Task Send(string user, int messageTag, object? message);
|
||||||
Task Post(string user, int messageTag, object? message);
|
Task MessageReceived(string user, int messageTag, byte[]? message);
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue