private (string name, string data) GetMessage(AuditDataEvent @event)
        {
            var attribute = @event.GetType().GetCustomAttribute <EventAttribute>();

            if (attribute == null)
            {
                throw new ArgumentException($"{nameof(EventAttribute)} missing on {nameof(@event)}");
            }

            if (string.IsNullOrEmpty(attribute.Name))
            {
                throw new ArgumentNullException(
                          $"{nameof(EventAttribute)}.Name missing on {nameof(@event)}");
            }

            var serializerSettings = new JsonSerializerSettings {
                ContractResolver = new CamelCasePropertyNamesContractResolver()
            };
            var message = new RabbitMqMessage
            {
                Name      = attribute.Name,
                EventData = JsonConvert.SerializeObject(@event, serializerSettings)
            };

            return(attribute.Name, JsonConvert.SerializeObject(message, serializerSettings));
        }
Exemple #2
0
 internal Type GetHandlerType(RabbitMqMessage message)
 {
     return(_eventHandlerConfiguration.Handlers.TryGetValue(message.Name, out var handlerType) ? handlerType : null);
 }