49 lines
1.9 KiB
C#
Raw Normal View History

using System;
using System.Collections.Generic;
using System.Text;
using Newtonsoft.Json;
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events;
using System.Linq;
using System.ComponentModel.DataAnnotations.Schema;
using System.Reflection;
2019-08-06 16:10:39 +02:00
using Microsoft.Extensions.Logging;
using Microsoft.eShopOnContainers.BuildingBlocks.IntegrationEventLogEF.Services;
namespace Microsoft.eShopOnContainers.BuildingBlocks.IntegrationEventLogEF
{
public class IntegrationEventLogEntry
{
private IntegrationEventLogEntry() { }
2019-08-06 16:10:39 +02:00
public IntegrationEventLogEntry(IntegrationEvent @event, Guid transactionId, ILogger<IntegrationEventLogService> logger)
{
EventId = @event.Id;
CreationTime = @event.CreationDate;
EventTypeName = @event.GetType().FullName;
Content = JsonConvert.SerializeObject(@event);
State = EventStateEnum.NotPublished;
TimesSent = 0;
TransactionId = transactionId.ToString();
2019-08-06 16:10:39 +02:00
}
public Guid EventId { get; private set; }
public string EventTypeName { get; private set; }
[NotMapped]
public string EventTypeShortName => EventTypeName.Split('.')?.Last();
[NotMapped]
public IntegrationEvent IntegrationEvent { get; private set; }
public EventStateEnum State { get; set; }
public int TimesSent { get; set; }
public DateTime CreationTime { get; private set; }
public string Content { get; private set; }
public string TransactionId { get; private set; }
2019-08-06 16:10:39 +02:00
public IntegrationEventLogEntry DeserializeJsonContent(Type type, ILogger<IntegrationEventLogService> logger)
{
2019-08-06 16:10:39 +02:00
logger.LogInformation("----- DeserializeJsonContent {Content} {Type}", Content, type);
IntegrationEvent = JsonConvert.DeserializeObject(Content, type) as IntegrationEvent;
return this;
}
}
}