From e1f9e1748d356b91b4bdf5980110e8ed115c86da Mon Sep 17 00:00:00 2001 From: Loretta Date: Thu, 18 Jul 2024 19:21:19 +0200 Subject: [PATCH] json fix --- TIAM.Entities/Products/ProductBase.cs | 5 +++++ TIAM.Entities/Users/UserProductMapping.cs | 3 +++ TIAMWebApp/Server/Services/DevAdminSignalRhub.cs | 13 ++++++++++--- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/TIAM.Entities/Products/ProductBase.cs b/TIAM.Entities/Products/ProductBase.cs index d6d71708..b1f074d6 100644 --- a/TIAM.Entities/Products/ProductBase.cs +++ b/TIAM.Entities/Products/ProductBase.cs @@ -1,6 +1,7 @@ using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; using AyCode.Interfaces.TimeStampInfo; +using Newtonsoft.Json; using TIAM.Core.Enums; using TIAM.Entities.Profiles; @@ -23,6 +24,10 @@ public abstract class ProductBase : IProductBase, ITimeStampInfo public string Name { get; set; } public string Description { get; set; } public float Price { get; set; } + + [NotMapped] + [JsonIgnore] + [System.Text.Json.Serialization.JsonIgnore] public string? JsonDetails { get; set; } public DateTime Created { get; set; } diff --git a/TIAM.Entities/Users/UserProductMapping.cs b/TIAM.Entities/Users/UserProductMapping.cs index 1184e919..968d291e 100644 --- a/TIAM.Entities/Users/UserProductMapping.cs +++ b/TIAM.Entities/Users/UserProductMapping.cs @@ -2,6 +2,7 @@ using System.ComponentModel.DataAnnotations.Schema; using AyCode.Interfaces.Entities; using AyCode.Interfaces.TimeStampInfo; +using Newtonsoft.Json; using TIAM.Entities.Drivers; using TIAM.Entities.Products; @@ -27,6 +28,8 @@ public class UserProductMapping : IEntityGuid, IUserRelation, IProductRelation, //[Column("JsonDetailModel")] [NotMapped] + [JsonIgnore] + [System.Text.Json.Serialization.JsonIgnore] public UserProductJsonDetailModel? JsonDetailModel { get; set; } = null; public DateTime Created { get; set; } diff --git a/TIAMWebApp/Server/Services/DevAdminSignalRhub.cs b/TIAMWebApp/Server/Services/DevAdminSignalRhub.cs index b24475dc..9d402896 100644 --- a/TIAMWebApp/Server/Services/DevAdminSignalRhub.cs +++ b/TIAMWebApp/Server/Services/DevAdminSignalRhub.cs @@ -215,7 +215,13 @@ public class DevAdminSignalRHub : Hub, IAcSignalRHubServe } else _logger.Debug($"{logText}(); {tagName}"); - await ResponseToCaller(messageTag, new SignalResponseJsonMessage(messageTag, SignalResponseStatus.Success, methodInfoModel.MethodInfo.InvokeMethod(methodsByDeclaringObject.InstanceObject, paramValues)), requestId); + var responseDataJson = new SignalResponseJsonMessage(messageTag, SignalResponseStatus.Success, methodInfoModel.MethodInfo.InvokeMethod(methodsByDeclaringObject.InstanceObject, paramValues)); + var responseDataJsonKiloBytes = System.Text.Encoding.Unicode.GetByteCount(responseDataJson.ResponseData!) / 1024; + + //File.WriteAllText(Path.Combine("h:", $"{requestId}.json"), responseDataJson.ResponseData); + + _logger.Info($"[{responseDataJsonKiloBytes}kb] responseData serialized to json"); + await ResponseToCaller(messageTag, responseDataJson, requestId); return; } @@ -309,9 +315,10 @@ public class DevAdminSignalRHub : Hub, IAcSignalRHubServe protected async Task SendMessageToClient(ISignalRHubItemServer sendTo, int messageTag, ISignalRMessage message, int? requestId = null) { - _logger.Info($"Server SendMessageToClient; {nameof(requestId)}: {requestId}; ConnectionId: {Context.ConnectionId}; {ConstHelper.NameByValue(messageTag)}"); + var responseDataMessagePack = message.ToMessagePack(ContractlessStandardResolver.Options); + _logger.Info($"[{(responseDataMessagePack.Length/1024)}kb] Server sending responseDataMessagePack to client; {nameof(requestId)}: {requestId}; ConnectionId: {Context.ConnectionId}; {ConstHelper.NameByValue(messageTag)}"); - await sendTo.OnReceiveMessage(messageTag, message.ToMessagePack(ContractlessStandardResolver.Options), requestId); + await sendTo.OnReceiveMessage(messageTag, responseDataMessagePack, requestId); } public async Task SendMessageToGroup(string groupId, int messageTag, string message)