diff --git a/DysonNetwork.Shared/Cache/MessagePackCacheSerializer.cs b/DysonNetwork.Shared/Cache/MessagePackCacheSerializer.cs index ace68da..d57d45b 100644 --- a/DysonNetwork.Shared/Cache/MessagePackCacheSerializer.cs +++ b/DysonNetwork.Shared/Cache/MessagePackCacheSerializer.cs @@ -1,4 +1,5 @@ using MessagePack; +using MessagePack.NodaTime; using MessagePack.Resolvers; namespace DysonNetwork.Shared.Cache; @@ -6,7 +7,13 @@ namespace DysonNetwork.Shared.Cache; public class MessagePackCacheSerializer(MessagePackSerializerOptions? options = null) : ICacheSerializer { private readonly MessagePackSerializerOptions _options = options ?? MessagePackSerializerOptions.Standard - .WithResolver(ContractlessStandardResolver.Instance) + .WithResolver(CompositeResolver.Create( + BuiltinResolver.Instance, + AttributeFormatterResolver.Instance, + NodatimeResolver.Instance, + DynamicEnumAsStringResolver.Instance, + ContractlessStandardResolver.Instance + )) .WithCompression(MessagePackCompression.Lz4BlockArray) .WithSecurity(MessagePackSecurity.UntrustedData) .WithOmitAssemblyVersion(true); diff --git a/DysonNetwork.Shared/Models/Account.cs b/DysonNetwork.Shared/Models/Account.cs index 557a9ad..6a34f96 100644 --- a/DysonNetwork.Shared/Models/Account.cs +++ b/DysonNetwork.Shared/Models/Account.cs @@ -1,6 +1,7 @@ using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; using System.Text.Json.Serialization; +using MessagePack; using Microsoft.EntityFrameworkCore; using NodaTime; using NodaTime.Serialization.Protobuf; @@ -26,13 +27,13 @@ public class SnAccount : ModelBase public ICollection Contacts { get; set; } = []; public ICollection Badges { get; set; } = []; - [JsonIgnore] public ICollection AuthFactors { get; set; } = []; - [JsonIgnore] public ICollection Connections { get; set; } = []; - [JsonIgnore] public ICollection Sessions { get; set; } = []; - [JsonIgnore] public ICollection Challenges { get; set; } = []; + [IgnoreMember] [JsonIgnore] public ICollection AuthFactors { get; set; } = []; + [IgnoreMember] [JsonIgnore] public ICollection Connections { get; set; } = []; + [IgnoreMember] [JsonIgnore] public ICollection Sessions { get; set; } = []; + [IgnoreMember] [JsonIgnore] public ICollection Challenges { get; set; } = []; - [JsonIgnore] public ICollection OutgoingRelationships { get; set; } = []; - [JsonIgnore] public ICollection IncomingRelationships { get; set; } = []; + [IgnoreMember] [JsonIgnore] public ICollection OutgoingRelationships { get; set; } = []; + [IgnoreMember] [JsonIgnore] public ICollection IncomingRelationships { get; set; } = []; [NotMapped] public SnSubscriptionReferenceObject? PerkSubscription { get; set; } @@ -217,7 +218,7 @@ public class SnAccountProfile : ModelBase, IIdentifiedResource [Column(TypeName = "jsonb")] public SnCloudFileReferenceObject? Background { get; set; } public Guid AccountId { get; set; } - [JsonIgnore] public SnAccount Account { get; set; } = null!; + [IgnoreMember] [JsonIgnore] public SnAccount Account { get; set; } = null!; public Proto.AccountProfile ToProtoValue() { @@ -331,7 +332,7 @@ public class SnAccountContact : ModelBase [MaxLength(1024)] public string Content { get; set; } = string.Empty; public Guid AccountId { get; set; } - [JsonIgnore] public SnAccount Account { get; set; } = null!; + [IgnoreMember] [JsonIgnore] public SnAccount Account { get; set; } = null!; public Proto.AccountContact ToProtoValue() { diff --git a/DysonNetwork.Shared/Models/Badge.cs b/DysonNetwork.Shared/Models/Badge.cs index 7846228..07a1588 100644 --- a/DysonNetwork.Shared/Models/Badge.cs +++ b/DysonNetwork.Shared/Models/Badge.cs @@ -2,6 +2,7 @@ using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; using System.Text.Json.Serialization; using DysonNetwork.Shared.Proto; +using MessagePack; using NodaTime; using NodaTime.Serialization.Protobuf; @@ -18,7 +19,7 @@ public class SnAccountBadge : ModelBase public Instant? ExpiredAt { get; set; } public Guid AccountId { get; set; } - [JsonIgnore] public SnAccount Account { get; set; } = null!; + [IgnoreMember] [JsonIgnore] public SnAccount Account { get; set; } = null!; public SnAccountBadgeRef ToReference() { diff --git a/DysonNetwork.Shared/Models/ChatRoom.cs b/DysonNetwork.Shared/Models/ChatRoom.cs index 7b7e5d8..b62d7dc 100644 --- a/DysonNetwork.Shared/Models/ChatRoom.cs +++ b/DysonNetwork.Shared/Models/ChatRoom.cs @@ -1,6 +1,7 @@ using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; using System.Text.Json.Serialization; +using MessagePack; using NodaTime; namespace DysonNetwork.Shared.Models; @@ -30,6 +31,7 @@ public class SnChatRoom : ModelBase, IIdentifiedResource [Column(TypeName = "jsonb")] public SnCloudFileReferenceObject? Background { get; set; } + [IgnoreMember] [JsonIgnore] public ICollection Members { get; set; } = new List(); diff --git a/DysonNetwork.Shared/Models/SnLottery.cs b/DysonNetwork.Shared/Models/Lottery.cs similarity index 100% rename from DysonNetwork.Shared/Models/SnLottery.cs rename to DysonNetwork.Shared/Models/Lottery.cs diff --git a/DysonNetwork.Shared/Models/Publisher.cs b/DysonNetwork.Shared/Models/Publisher.cs index fbae9dd..e288871 100644 --- a/DysonNetwork.Shared/Models/Publisher.cs +++ b/DysonNetwork.Shared/Models/Publisher.cs @@ -2,6 +2,8 @@ using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; using System.Text.Json.Serialization; using DysonNetwork.Shared.Proto; +using Google.Protobuf.WellKnownTypes; +using MessagePack; using Microsoft.EntityFrameworkCore; using NodaTime; using NodaTime.Extensions; @@ -29,11 +31,11 @@ public class SnPublisher : ModelBase, IIdentifiedResource [Column(TypeName = "jsonb")] public SnVerificationMark? Verification { get; set; } - [JsonIgnore] public ICollection Posts { get; set; } = []; - [JsonIgnore] public ICollection Polls { get; set; } = []; - [JsonIgnore] public ICollection Collections { get; set; } = []; - [JsonIgnore] public ICollection Members { get; set; } = []; - [JsonIgnore] public ICollection Features { get; set; } = []; + [IgnoreMember] [JsonIgnore] public ICollection Posts { get; set; } = []; + [IgnoreMember] [JsonIgnore] public ICollection Polls { get; set; } = []; + [IgnoreMember] [JsonIgnore] public ICollection Collections { get; set; } = []; + [IgnoreMember] [JsonIgnore] public ICollection Members { get; set; } = []; + [IgnoreMember] [JsonIgnore] public ICollection Features { get; set; } = []; [JsonIgnore] public ICollection Subscriptions { get; set; } = []; @@ -45,7 +47,7 @@ public class SnPublisher : ModelBase, IIdentifiedResource public string ResourceIdentifier => $"publisher:{Id}"; - public static SnPublisher FromProtoValue(Proto.Publisher proto) + public static SnPublisher FromProtoValue(Publisher proto) { var publisher = new SnPublisher { @@ -87,25 +89,25 @@ public class SnPublisher : ModelBase, IIdentifiedResource return publisher; } - public Proto.Publisher ToProtoValue() + public Publisher ToProtoValue() { - var p = new Proto.Publisher() + var p = new Publisher { Id = Id.ToString(), Type = Type == PublisherType.Individual - ? Shared.Proto.PublisherType.PubIndividual - : Shared.Proto.PublisherType.PubOrganizational, + ? Proto.PublisherType.PubIndividual + : Proto.PublisherType.PubOrganizational, Name = Name, Nick = Nick, Bio = Bio, AccountId = AccountId?.ToString() ?? string.Empty, RealmId = RealmId?.ToString() ?? string.Empty, - CreatedAt = Google.Protobuf.WellKnownTypes.Timestamp.FromDateTimeOffset(CreatedAt.ToDateTimeOffset()), - UpdatedAt = Google.Protobuf.WellKnownTypes.Timestamp.FromDateTimeOffset(UpdatedAt.ToDateTimeOffset()) + CreatedAt = Timestamp.FromDateTimeOffset(CreatedAt.ToDateTimeOffset()), + UpdatedAt = Timestamp.FromDateTimeOffset(UpdatedAt.ToDateTimeOffset()) }; if (Picture is not null) { - p.Picture = new Proto.CloudFile + p.Picture = new CloudFile { Id = Picture.Id, Name = Picture.Name, @@ -117,7 +119,7 @@ public class SnPublisher : ModelBase, IIdentifiedResource if (Background is not null) { - p.Background = new Proto.CloudFile + p.Background = new CloudFile { Id = Background.Id, Name = Background.Name, diff --git a/DysonNetwork.Shared/Models/Realm.cs b/DysonNetwork.Shared/Models/Realm.cs index 36231ba..64519fb 100644 --- a/DysonNetwork.Shared/Models/Realm.cs +++ b/DysonNetwork.Shared/Models/Realm.cs @@ -2,6 +2,7 @@ using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; using System.Text.Json.Serialization; using DysonNetwork.Shared.Proto; +using MessagePack; using Microsoft.EntityFrameworkCore; using NodaTime; using NodaTime.Serialization.Protobuf; @@ -23,7 +24,7 @@ public class SnRealm : ModelBase, IIdentifiedResource [Column(TypeName = "jsonb")] public SnVerificationMark? Verification { get; set; } - [JsonIgnore] public ICollection Members { get; set; } = new List(); + [IgnoreMember] [JsonIgnore] public ICollection Members { get; set; } = new List(); public Guid AccountId { get; set; } diff --git a/DysonNetwork.Shared/Models/SnUnpaidAccount.cs b/DysonNetwork.Shared/Models/UnpaidAccount.cs similarity index 100% rename from DysonNetwork.Shared/Models/SnUnpaidAccount.cs rename to DysonNetwork.Shared/Models/UnpaidAccount.cs diff --git a/DysonNetwork.Shared/Models/Wallet.cs b/DysonNetwork.Shared/Models/Wallet.cs index 0692d2b..866f184 100644 --- a/DysonNetwork.Shared/Models/Wallet.cs +++ b/DysonNetwork.Shared/Models/Wallet.cs @@ -1,6 +1,7 @@ using System.ComponentModel.DataAnnotations; using System.Globalization; using System.Text.Json.Serialization; +using MessagePack; using NodaTime; using NodaTime.Serialization.Protobuf; @@ -46,7 +47,7 @@ public class SnWalletPocket : ModelBase public decimal Amount { get; set; } public Guid WalletId { get; set; } - [JsonIgnore] public SnWallet Wallet { get; set; } = null!; + [IgnoreMember] [JsonIgnore] public SnWallet Wallet { get; set; } = null!; public Proto.WalletPocket ToProtoValue() => new() {