示例#1
0
    public bool IsSameEntityEventRecord(UnitOfWorkEventRecord record1, UnitOfWorkEventRecord record2)
    {
        if (record1.EventType != record2.EventType)
        {
            return(false);
        }

        var record1OriginalEntity = record1.Properties.GetOrDefault(UnitOfWorkEventRecordEntityPropName) as IEntity;
        var record2OriginalEntity = record2.Properties.GetOrDefault(UnitOfWorkEventRecordEntityPropName) as IEntity;

        if (record1OriginalEntity == null || record2OriginalEntity == null)
        {
            return(false);
        }

        return(EntityHelper.EntityEquals(record1OriginalEntity, record2OriginalEntity));
    }
示例#2
0
    protected virtual void TriggerEventWithEntity(
        IEventBus eventPublisher,
        Type genericEventType,
        object entityOrEto,
        object originalEntity)
    {
        var entityType = ProxyHelper.UnProxy(entityOrEto).GetType();
        var eventType  = genericEventType.MakeGenericType(entityType);
        var eventData  = Activator.CreateInstance(eventType, entityOrEto);
        var currentUow = UnitOfWorkManager.Current;

        if (currentUow == null)
        {
            Logger.LogWarning("UnitOfWorkManager.Current is null! Can not publish the event.");
            return;
        }

        var eventRecord = new UnitOfWorkEventRecord(eventType, eventData, EventOrderGenerator.GetNext())
        {
            Properties =
            {
                { UnitOfWorkEventRecordEntityPropName, originalEntity },
            }
        };

        /* We are trying to eliminate same events for the same entity.
         * In this way, for example, we don't trigger update event for an entity multiple times
         * even if it is updated multiple times in the current UOW.
         */

        if (eventPublisher == DistributedEventBus)
        {
            currentUow.AddOrReplaceDistributedEvent(
                eventRecord,
                otherRecord => IsSameEntityEventRecord(eventRecord, otherRecord)
                );
        }
        else
        {
            currentUow.AddOrReplaceLocalEvent(
                eventRecord,
                otherRecord => IsSameEntityEventRecord(eventRecord, otherRecord)
                );
        }
    }
示例#3
0
 public virtual void AddOrReplaceEvent(
     List <UnitOfWorkEventRecord> eventRecords,
     UnitOfWorkEventRecord eventRecord,
     Predicate <UnitOfWorkEventRecord> replacementSelector = null)
 {
     if (replacementSelector == null)
     {
         eventRecords.Add(eventRecord);
     }
     else
     {
         var foundIndex = eventRecords.FindIndex(replacementSelector);
         if (foundIndex < 0)
         {
             eventRecords.Add(eventRecord);
         }
         else
         {
             eventRecords[foundIndex] = eventRecord;
         }
     }
 }
 protected override void AddToUnitOfWork(IUnitOfWork unitOfWork, UnitOfWorkEventRecord eventRecord)
 {
     unitOfWork.AddOrReplaceDistributedEvent(eventRecord);
 }
示例#5
0
 public void AddOrReplaceDistributedEvent(
     UnitOfWorkEventRecord eventRecord,
     Predicate <UnitOfWorkEventRecord> replacementSelector = null)
 {
     _parent.AddOrReplaceDistributedEvent(eventRecord, replacementSelector);
 }
示例#6
0
 protected abstract void AddToUnitOfWork(IUnitOfWork unitOfWork, UnitOfWorkEventRecord eventRecord);
示例#7
0
 public virtual void AddOrReplaceDistributedEvent(
     UnitOfWorkEventRecord eventRecord,
     Predicate <UnitOfWorkEventRecord> replacementSelector = null)
 {
     AddOrReplaceEvent(DistributedEvents, eventRecord, replacementSelector);
 }