diff --git a/AyCode.Core.Server/AyCode.Core.Server.csproj b/AyCode.Core.Server/AyCode.Core.Server.csproj index 66e6116..a113558 100644 --- a/AyCode.Core.Server/AyCode.Core.Server.csproj +++ b/AyCode.Core.Server/AyCode.Core.Server.csproj @@ -6,6 +6,10 @@ enable + + + + diff --git a/AyCode.Core/AyCode.Core.csproj b/AyCode.Core/AyCode.Core.csproj index 3a34c73..045dbf2 100644 --- a/AyCode.Core/AyCode.Core.csproj +++ b/AyCode.Core/AyCode.Core.csproj @@ -11,6 +11,7 @@ + diff --git a/AyCode.Core/Extensions/SerializeObjectExtensions.cs b/AyCode.Core/Extensions/SerializeObjectExtensions.cs new file mode 100644 index 0000000..4607b9b --- /dev/null +++ b/AyCode.Core/Extensions/SerializeObjectExtensions.cs @@ -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(this T source) where T : class, IAcSerializableToJson => JsonConvert.SerializeObject(source, Options); + public static string ToJson(this IQueryable source) where T : class, IAcSerializableToJson => JsonConvert.SerializeObject(source, Options); + public static string ToJson(this IEnumerable source) where T : class, IAcSerializableToJson => JsonConvert.SerializeObject(source, Options); + + public static T? JsonTo(this string json) => JsonConvert.DeserializeObject(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(this byte[] message) => MessagePackSerializer.Deserialize(message); + public static T? MessagePackTo(this byte[] message, MessagePackSerializerOptions options) => MessagePackSerializer.Deserialize(message, options); +} \ No newline at end of file diff --git a/AyCode.Core/Extensions/SerializeObjectToJsonExtensions.cs b/AyCode.Core/Extensions/SerializeObjectToJsonExtensions.cs deleted file mode 100644 index afd90de..0000000 --- a/AyCode.Core/Extensions/SerializeObjectToJsonExtensions.cs +++ /dev/null @@ -1,22 +0,0 @@ -using AyCode.Core.Interfaces; -using Newtonsoft.Json; - -namespace AyCode.Core.Extensions; - -public static class SerializeObjectToJsonExtensions -{ - private static string SerializeObjectToJson(T source) - { - JsonSerializerSettings options = new() - { - ReferenceLoopHandling = ReferenceLoopHandling.Ignore, - NullValueHandling = NullValueHandling.Ignore - }; - - return JsonConvert.SerializeObject(source, options); - } - - public static string ToJson(this T source) where T : class, IAcSerializableToJson => SerializeObjectToJson(source); - public static string ToJson(this IQueryable source) where T : class, IAcSerializableToJson => SerializeObjectToJson(source); - public static string ToJson(this IEnumerable source) where T : class, IAcSerializableToJson => SerializeObjectToJson(source); -} \ No newline at end of file diff --git a/AyCode.Services/SignalRs/IAcSignalRHubBase.cs b/AyCode.Services/SignalRs/IAcSignalRHubBase.cs index 8a0600a..bcd587a 100644 --- a/AyCode.Services/SignalRs/IAcSignalRHubBase.cs +++ b/AyCode.Services/SignalRs/IAcSignalRHubBase.cs @@ -6,6 +6,6 @@ public interface IAcSignalRHubClient : IAcSignalRHubBase public interface IAcSignalRHubBase { - Task Get(string user, int messageTag); - Task Post(string user, int messageTag, object? message); + Task Send(string user, int messageTag, object? message); + Task MessageReceived(string user, int messageTag, byte[]? message); } \ No newline at end of file