improvements, fixes, etc...
This commit is contained in:
parent
8d9ec4df7a
commit
60b53a217a
|
|
@ -2,6 +2,8 @@
|
|||
using MessagePack.Resolvers;
|
||||
using MessagePack;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace AyCode.Core.Extensions;
|
||||
|
||||
|
|
@ -18,7 +20,12 @@ public static class SerializeObjectExtensions
|
|||
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 T? JsonTo<T>(this string json)
|
||||
{
|
||||
if (json.StartsWith("\"") && json.EndsWith("\"")) json = Regex.Unescape(json).TrimStart('"').TrimEnd('"');
|
||||
|
||||
return JsonConvert.DeserializeObject<T>(json, Options);
|
||||
}
|
||||
|
||||
|
||||
public static byte[] ToMessagePack(this object message) => MessagePackSerializer.Serialize(message);
|
||||
|
|
|
|||
|
|
@ -16,6 +16,8 @@ public abstract class AcUserToCompany<TUser, TCompany> : IAcUserToCompany<TUser,
|
|||
public Guid UserId { get; set; }
|
||||
public Guid ServiceProviderId { get; set; }
|
||||
|
||||
public int Permissions { get; set; }
|
||||
|
||||
public virtual TUser User { get; set; }
|
||||
[ForeignKey("ServiceProviderId")] //COMPANY_RENAME - J.
|
||||
public virtual TCompany Company { get; set; }
|
||||
|
|
|
|||
|
|
@ -6,4 +6,5 @@ namespace AyCode.Interfaces.Users;
|
|||
|
||||
public interface IAcUserToCompanyBase : IEntityGuid, IAcUserForeignKey, IAcCompanyForeignKey, ITimeStampInfo
|
||||
{
|
||||
public int Permissions { get; set; }
|
||||
}
|
||||
|
|
@ -6,19 +6,31 @@ using System.Text.RegularExpressions;
|
|||
namespace AyCode.Services.SignalRs;
|
||||
|
||||
[MessagePackObject]
|
||||
public class SignalPostJsonDataMessage : ISignalPostMessage<string>
|
||||
public class SignalPostJsonDataMessage<TPostDataType> : ISignalPostMessage<TPostDataType> where TPostDataType : class
|
||||
{
|
||||
[IgnoreMember]
|
||||
private string _postData;
|
||||
private TPostDataType? _postData;
|
||||
|
||||
[Key(0)]
|
||||
public string PostData
|
||||
[IgnoreMember]
|
||||
public TPostDataType PostData
|
||||
{
|
||||
get => _postData;
|
||||
set => _postData = Regex.Unescape(value).TrimStart('"').TrimEnd('"');
|
||||
get
|
||||
{
|
||||
return _postData ??= PostDataJson.JsonTo<TPostDataType>()!;
|
||||
}
|
||||
private init
|
||||
{
|
||||
_postData = value;
|
||||
PostDataJson = _postData.ToJson();
|
||||
}
|
||||
}
|
||||
|
||||
public SignalPostJsonDataMessage(object postData) => PostData = postData.ToJson();
|
||||
[Key(0)]
|
||||
public string PostDataJson { get; set; }
|
||||
|
||||
public SignalPostJsonDataMessage(){}
|
||||
public SignalPostJsonDataMessage(TPostDataType postData) => PostData = postData;
|
||||
public SignalPostJsonDataMessage(string postDataJson) => PostDataJson = postDataJson;
|
||||
}
|
||||
|
||||
[MessagePackObject]
|
||||
|
|
@ -28,7 +40,7 @@ public class SignalPostMessage<TPostData>(TPostData postData) : ISignalPostMessa
|
|||
public TPostData? PostData { get; set; } = postData;
|
||||
}
|
||||
|
||||
public interface ISignalPostMessage<out TPostData> : ISignalRMessage
|
||||
public interface ISignalPostMessage<TPostData> : ISignalRMessage
|
||||
{
|
||||
TPostData? PostData { get; }
|
||||
}
|
||||
|
|
@ -49,6 +61,27 @@ public interface ISignalRMessage
|
|||
{ }
|
||||
|
||||
|
||||
[MessagePackObject]
|
||||
public sealed class SignalResponseJsonMessage : ISignalResponseMessage<string>
|
||||
{
|
||||
[Key(0)]
|
||||
public SignalResponseStatus Status { get; set; }
|
||||
|
||||
[Key(1)]
|
||||
public string? ResponseData { get; set; }
|
||||
|
||||
public SignalResponseJsonMessage(){}
|
||||
|
||||
public SignalResponseJsonMessage(SignalResponseStatus status, object responseData) : this(status, responseData.ToJson())
|
||||
{ }
|
||||
|
||||
public SignalResponseJsonMessage(SignalResponseStatus status, string responseDataJson)
|
||||
{
|
||||
Status = status;
|
||||
ResponseData = responseDataJson;
|
||||
}
|
||||
}
|
||||
|
||||
[MessagePackObject]
|
||||
public sealed class SignalResponseMessage<TResponseData>(SignalResponseStatus status, TResponseData? responseData) : ISignalResponseMessage<TResponseData>
|
||||
{
|
||||
|
|
|
|||
|
|
@ -0,0 +1,10 @@
|
|||
namespace AyCode.Services.SignalRs;
|
||||
|
||||
public class SignalMessageTagAttribute(Type requestMessageType, Type responseMessageType, Type controllerType, params Type[] parameters) : Attribute
|
||||
{
|
||||
public Type RequestMessageType { get; } = requestMessageType;
|
||||
public Type ResponseMessageType { get; } = responseMessageType;
|
||||
|
||||
public Type ControllerType { get; } = controllerType;
|
||||
public Type[] Parameters { get; } = parameters;
|
||||
}
|
||||
Loading…
Reference in New Issue