2021-01-15 14:45:24 +05:30
|
|
|
|
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events;
|
|
|
|
|
using System;
|
2021-05-03 16:36:31 +05:30
|
|
|
|
using System.Text.Json;
|
2018-10-11 17:16:31 +02:00
|
|
|
|
using System.ComponentModel.DataAnnotations.Schema;
|
2021-01-15 14:45:24 +05:30
|
|
|
|
using System.Linq;
|
2017-03-14 09:47:36 +01:00
|
|
|
|
|
2017-03-22 16:10:46 +01:00
|
|
|
|
namespace Microsoft.eShopOnContainers.BuildingBlocks.IntegrationEventLogEF
|
2017-03-14 09:47:36 +01:00
|
|
|
|
{
|
2017-03-15 18:42:47 -07:00
|
|
|
|
public class IntegrationEventLogEntry
|
2017-03-14 09:47:36 +01:00
|
|
|
|
{
|
2017-03-23 13:24:17 +01:00
|
|
|
|
private IntegrationEventLogEntry() { }
|
2019-08-07 17:06:20 +02:00
|
|
|
|
public IntegrationEventLogEntry(IntegrationEvent @event, Guid transactionId)
|
2017-03-14 09:47:36 +01:00
|
|
|
|
{
|
2021-01-15 14:45:24 +05:30
|
|
|
|
EventId = @event.Id;
|
2017-03-28 12:02:30 +02:00
|
|
|
|
CreationTime = @event.CreationDate;
|
2021-05-03 16:36:31 +05:30
|
|
|
|
EventTypeName = @event.GetType().FullName;
|
|
|
|
|
Content = JsonSerializer.Serialize(@event, @event.GetType(), new JsonSerializerOptions
|
|
|
|
|
{
|
|
|
|
|
WriteIndented = true
|
|
|
|
|
});
|
2017-03-15 18:42:47 -07:00
|
|
|
|
State = EventStateEnum.NotPublished;
|
2017-03-14 09:47:36 +01:00
|
|
|
|
TimesSent = 0;
|
2019-05-07 21:29:37 +01:00
|
|
|
|
TransactionId = transactionId.ToString();
|
2019-08-06 16:10:39 +02:00
|
|
|
|
}
|
2017-03-14 09:47:36 +01:00
|
|
|
|
public Guid EventId { get; private set; }
|
|
|
|
|
public string EventTypeName { get; private set; }
|
2018-10-11 17:16:31 +02:00
|
|
|
|
[NotMapped]
|
|
|
|
|
public string EventTypeShortName => EventTypeName.Split('.')?.Last();
|
|
|
|
|
[NotMapped]
|
|
|
|
|
public IntegrationEvent IntegrationEvent { get; private set; }
|
2017-03-14 09:47:36 +01:00
|
|
|
|
public EventStateEnum State { get; set; }
|
|
|
|
|
public int TimesSent { get; set; }
|
|
|
|
|
public DateTime CreationTime { get; private set; }
|
|
|
|
|
public string Content { get; private set; }
|
2019-05-07 21:29:37 +01:00
|
|
|
|
public string TransactionId { get; private set; }
|
2018-10-11 17:16:31 +02:00
|
|
|
|
|
2019-08-07 17:06:20 +02:00
|
|
|
|
public IntegrationEventLogEntry DeserializeJsonContent(Type type)
|
2021-05-03 16:36:31 +05:30
|
|
|
|
{
|
|
|
|
|
IntegrationEvent = JsonSerializer.Deserialize(Content, type, new JsonSerializerOptions() { PropertyNameCaseInsensitive = true }) as IntegrationEvent;
|
2018-10-12 15:30:22 +02:00
|
|
|
|
return this;
|
2018-10-11 17:16:31 +02:00
|
|
|
|
}
|
2017-03-14 09:47:36 +01:00
|
|
|
|
}
|
|
|
|
|
}
|