5 changed files with 64 additions and 44 deletions
@ -0,0 +1,41 @@ |
|||
using LINGYUN.Abp.RealTime.Localization; |
|||
using Newtonsoft.Json; |
|||
using Volo.Abp.DependencyInjection; |
|||
|
|||
namespace LINGYUN.Abp.Notifications; |
|||
|
|||
[Dependency(TryRegister = true)] |
|||
public class DefaultNotificationDataSerializer : INotificationDataSerializer, ISingletonDependency |
|||
{ |
|||
public NotificationData Serialize(NotificationData source) |
|||
{ |
|||
if (source != null) |
|||
{ |
|||
if (source.NeedLocalizer()) |
|||
{ |
|||
// 潜在的空对象引用修复
|
|||
if (source.ExtraProperties.TryGetValue("title", out var title) && title != null) |
|||
{ |
|||
var titleObj = JsonConvert.DeserializeObject<LocalizableStringInfo>(title.ToString()); |
|||
source.TrySetData("title", titleObj); |
|||
} |
|||
if (source.ExtraProperties.TryGetValue("message", out var message) && message != null) |
|||
{ |
|||
var messageObj = JsonConvert.DeserializeObject<LocalizableStringInfo>(message.ToString()); |
|||
source.TrySetData("message", messageObj); |
|||
} |
|||
|
|||
if (source.ExtraProperties.TryGetValue("description", out var description) && description != null) |
|||
{ |
|||
var descriptionObj = JsonConvert.DeserializeObject<LocalizableStringInfo>(description.ToString()); |
|||
source.TrySetData("description", descriptionObj); |
|||
} |
|||
} |
|||
} |
|||
else |
|||
{ |
|||
source = new NotificationData(); |
|||
} |
|||
return source; |
|||
} |
|||
} |
|||
@ -0,0 +1,5 @@ |
|||
namespace LINGYUN.Abp.Notifications; |
|||
public interface INotificationDataSerializer |
|||
{ |
|||
NotificationData Serialize(NotificationData source); |
|||
} |
|||
@ -1,39 +0,0 @@ |
|||
using LINGYUN.Abp.RealTime.Localization; |
|||
using Newtonsoft.Json; |
|||
|
|||
namespace LINGYUN.Abp.Notifications |
|||
{ |
|||
public class NotificationDataConverter |
|||
{ |
|||
public static NotificationData Convert(NotificationData notificationData) |
|||
{ |
|||
if (notificationData != null) |
|||
{ |
|||
if (notificationData.NeedLocalizer()) |
|||
{ |
|||
// 潜在的空对象引用修复
|
|||
if (notificationData.ExtraProperties.TryGetValue("title", out object title) && title != null) |
|||
{ |
|||
var titleObj = JsonConvert.DeserializeObject<LocalizableStringInfo>(title.ToString()); |
|||
notificationData.TrySetData("title", titleObj); |
|||
} |
|||
if (notificationData.ExtraProperties.TryGetValue("message", out object message) && message != null) |
|||
{ |
|||
var messageObj = JsonConvert.DeserializeObject<LocalizableStringInfo>(message.ToString()); |
|||
notificationData.TrySetData("message", messageObj); |
|||
} |
|||
|
|||
if (notificationData.ExtraProperties.TryGetValue("description", out object description) && description != null) |
|||
{ |
|||
notificationData.TrySetData("description", JsonConvert.DeserializeObject<LocalizableStringInfo>(description.ToString())); |
|||
} |
|||
} |
|||
} |
|||
else |
|||
{ |
|||
notificationData = new NotificationData(); |
|||
} |
|||
return notificationData; |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue