Ejemplo n.º 1
0
 protected virtual void Upsert(DomainEvent domainEvent)
 {
     if (ThisRecordHasBeenInserted(domainEvent))
         Update(domainEvent);
     else
         Insert(domainEvent);
 }
Ejemplo n.º 2
0
 private static IDomainEventMessage CreateDomainEventMessage(DomainEvent domainEvent)
 {
     var domainEventMessageType = typeof(DomainEventMessage<>).MakeGenericType(domainEvent.GetType());
     var message = (IDomainEventMessage)Activator.CreateInstance(domainEventMessageType);
     message.DomainEvent = domainEvent;
     return message;
 }
Ejemplo n.º 3
0
        public void PublishEvent(DomainEvent domainEvent)
        {
            if(!eventHandlerInvokers.ContainsKey(domainEvent.GetType())) return;

            var eventHandlerInvoker = eventHandlerInvokers[domainEvent.GetType()];
            eventHandlerInvoker.Publish(domainEvent);
        }
Ejemplo n.º 4
0
 public void Apply(DomainEvent domainEvent)
 {
     domainEvent.Sequence = ++LastEventSequence;
     ApplyEventToInternalState(domainEvent);
     domainEvent.AggregateRootId = Id;
     domainEvent.EventDate = DateTime.Now;
     uncommittedEvents.Enqueue(domainEvent);
 }
Ejemplo n.º 5
0
        private void ApplyEventToEntities(DomainEvent domainEvent)
        {
            var entityDomainEvent = domainEvent as EntityDomainEvent;
            if (entityDomainEvent == null) return;

            var list = _entities.Where(entity => entity.Id == entityDomainEvent.EntityId).ToList();
            list.ForEach(entity => entity.ApplyHistoricalEvents(entityDomainEvent));
        }
Ejemplo n.º 6
0
 private static Dictionary<string, object> BuildADataObjectThatHasAllUpdatableData(DomainEvent domainEvent,
     IEnumerable<string> tableColumnsToUpdate)
 {
     var dictionary = new Dictionary<string, object>();
     foreach (var property in tableColumnsToUpdate)
         dictionary[property] = GetValue(domainEvent, property);
     dictionary["Id"] = domainEvent.AggregateRootId;
     return dictionary;
 }
 public string Serialize(DomainEvent domainEvent) {
     var formatter = new BinaryFormatter();
     using (var stream = new MemoryStream()) {
         formatter.Serialize(stream, domainEvent);
         stream.Flush();
         stream.Position = 0;
         return Convert.ToBase64String(stream.ToArray());
     }
 }
Ejemplo n.º 8
0
 public void Publish(DomainEvent domainEvent)
 {
     var handleMethod = typeof(IHandleDomainEvents<>).MakeGenericType(domainEventType).GetMethod("Handle");
     foreach (var eventHandlerType in eventHandlerTypes)
     {
         var eventHandler = eventHandlerFactory.Create(eventHandlerType);
         handleMethod.Invoke(eventHandler, new object[] {domainEvent});
     }
 }
        public void PublishEvent(DomainEvent domainEvent)
        {
            var domainEventType = domainEvent.GetType();
            var invokers = (from entry in eventHandlerInvokers
                           where  entry.Key.IsAssignableFrom(domainEventType)
                           select entry.Value).ToList();

            invokers.ForEach(i => i.Publish(domainEvent));
        }
Ejemplo n.º 10
0
        public void PublishEvent(DomainEvent domainEvent)
        {
            while (eventConverters.ContainsKey(domainEvent.GetType()))
                domainEvent = ((dynamic)eventConverterFactory.Create(eventConverters[domainEvent.GetType()])).Convert((dynamic)domainEvent);

            if(!eventHandlerInvokers.ContainsKey(domainEvent.GetType())) return;

            var eventHandlerInvoker = eventHandlerInvokers[domainEvent.GetType()];
            eventHandlerInvoker.Publish(domainEvent);
        }
Ejemplo n.º 11
0
        private void ApplyEventToInternalState(DomainEvent domainEvent)
        {
            var domainEventType = domainEvent.GetType();
            var domainEventTypeName = domainEventType.Name;
            var aggregateRootType = GetType();

            var methodInfo = aggregateRootType.GetMethod(GetEventHandlerMethodName(domainEventTypeName),
                                                         BindingFlags.Instance | BindingFlags.Public |
                                                         BindingFlags.NonPublic, null, new[] {domainEventType}, null);

            if(methodInfo == null || !EventHandlerMethodInfoHasCorrectParameter(methodInfo, domainEventType)) return;

            methodInfo.Invoke(this, new[] {domainEvent});
        }
Ejemplo n.º 12
0
        private void ApplyEventToInternalState(DomainEvent domainEvent)
        {
            //
            // TODO: cache handler method
            //
            var domainEventType = domainEvent.GetType();
            var domainEventTypeName = domainEventType.Name;
            var aggregateRootType = GetType();

            var eventHandlerMethodName = GetEventHandlerMethodName(domainEventTypeName);
            var methodInfo = aggregateRootType.GetMethod(eventHandlerMethodName,
                BindingFlags.Instance | BindingFlags.Public |
                BindingFlags.NonPublic, null, new[] {domainEventType}, null);

            if (methodInfo != null && EventHandlerMethodInfoHasCorrectParameter(methodInfo, domainEventType))
            {
                methodInfo.Invoke(this, new[] {domainEvent});
            }

            ApplyEventToEntities(domainEvent);
        }
Ejemplo n.º 13
0
            public void Publish(DomainEvent domainEvent)
            {
                var exceptionList = new List<Exception>();

                var handleMethod = typeof(IHandleDomainEvents<>).MakeGenericType(domainEventType).GetMethod("Handle");
                foreach(var eventHandlerType in eventHandlerTypes)
                {
                    try
                    {
                        var eventHandler = eventHandlerFactory.Create(eventHandlerType);
                        handleMethod.Invoke(eventHandler, new object[] {domainEvent});
                    }
                    catch(Exception exception)
                    {
                        logger.Error(string.Format("An exception occured while handling event of type '{0}'\nMessage: {1}", domainEvent.GetType(), exception.Message), exception);
                        exceptionList.Add(exception);
                    }
                }

                if(exceptionList.Count > 0)
                    throw new AggregateException(exceptionList);
            }
Ejemplo n.º 14
0
 private bool ThisRecordHasBeenInserted(DomainEvent domainEvent)
 {
     return (bool) TheDatabaseTable.FindAllById(domainEvent.AggregateRootId).Any();
 }
 public string Serialize(DomainEvent domainEvent)
 {
     return JsonSerializer.SerializeToString(domainEvent, domainEvent.GetType());
 }
Ejemplo n.º 16
0
 public static void Modify(DomainEvent e)
 {
     if (Modification != null)
         Modification.Apply(e);
 }
Ejemplo n.º 17
0
 public void PublishEvent(DomainEvent domainEvent)
 {
     Bus.Publish<IDomainEventMessage>(message => message.DomainEvent = domainEvent);
 }
Ejemplo n.º 18
0
        protected virtual void Insert(DomainEvent domainEvent)
        {
            var data = GetTheDataToUpdateInTheTable(domainEvent);

            TheDatabaseTable.Insert(data);
        }
 public EventStoreConcurrencyException(int latestVersion, DomainEvent domainEvent, List<DomainEvent> domainEventsList)
 {
     LatestVersion = latestVersion;
     DomainEventInstance = domainEvent;
     DomainEventsList = domainEventsList;
 }
Ejemplo n.º 20
0
 private IDictionary<string, object> GetTheDataToUpdateInTheTable(DomainEvent domainEvent)
 {
     return (updateValuesBuilder.GetTheDataToUpdateInTheTable(domainEvent, tableName));
 }
Ejemplo n.º 21
0
 public void PublishEvent(DomainEvent domainEvent)
 {
     serviceBus.Notify(domainEvent);
 }
Ejemplo n.º 22
0
 public async Task PublishEvent(SimpleCqrs.Eventing.DomainEvent domainEvent)
 {
     await _serviceBus.PublishAsync((IEvent)domainEvent).ConfigureAwait(false);
 }
Ejemplo n.º 23
0
 private IEnumerable<string> GetTheTableColumnsThatNeedToBeUpdated(DomainEvent domainEvent, string tableName)
 {
     return domainEvent.GetType().GetProperties()
         .Select(x => x.Name)
         .Where(property => GetTheColumnsInTheTable(tableName).Contains(property));
 }
Ejemplo n.º 24
0
 protected void Delete(DomainEvent domainEvent)
 {
     TheDatabaseTable.DeleteById(domainEvent.AggregateRootId);
 }
Ejemplo n.º 25
0
 public void Apply(DomainEvent e)
 {
     if (e is EventForModificationTestEvent)
         ((EventForModificationTestEvent)e).ModifiedValue = ModifyValueTo;
 }
Ejemplo n.º 26
0
        public IDictionary<string, object> GetTheDataToUpdateInTheTable(DomainEvent domainEvent, string tableName)
        {
            var tableColumnsToUpdate = GetTheTableColumnsThatNeedToBeUpdated(domainEvent, tableName);

            return BuildADataObjectThatHasAllUpdatableData(domainEvent, tableColumnsToUpdate);
        }
Ejemplo n.º 27
0
        protected virtual void Update(DomainEvent domainEvent)
        {
            var data = GetTheDataToUpdateInTheTable(domainEvent);

            TheDatabaseTable.UpdateById(data);
        }
Ejemplo n.º 28
0
 public void PublishEvent(DomainEvent domainEvent)
 {
     _bus.Publish(domainEvent);
 }
Ejemplo n.º 29
0
 private static object GetValue(DomainEvent domainEvent, string column)
 {
     return GetThePropertyOnThisObject(domainEvent, column).GetValue(domainEvent, null);
 }