Exemple #1
0
        internal sealed override void ApplyInternal <TEvent>(TEvent eventEnvelope, bool addToStream)
        {
            base.ApplyInternal(eventEnvelope, addToStream);

            if (Parent != null)
            {
                trySetChildMethodCache.Invoke(null, Parent, this);
            }
            else
            {
                CachedParentActions.Add(parent => trySetChildMethodCache.Invoke(null, Parent, this));
            }
        }
Exemple #2
0
        public void ReconstituteAggregate(IEnumerable <IParcelVisionEventEnvelope> eventStream, int concurrencyId)
        {
            foreach (var eventEnvelope in eventStream)
            {
                var envelopeWithSourceId = eventEnvelope as IParcelVisionEventEnvelope <TId>;

                if (eventEnvelope.SourceEntityType == GetType() || envelopeWithSourceId?.SourceId.Equals(Id) == true)
                {
                    ReconstituteFrom(eventEnvelope);

                    var childContainer = new ConcurrentDictionary <TId, IPersistThroughEvents>(1, 1);
                    childContainers[Id.GetType()] = childContainer;
                    childContainer[Id]            = this;
                }
                else
                {
                    var asHasIdTypes = eventEnvelope as IHaveSourceAndParentIdTypes;

                    if (asHasIdTypes == null)
                    {
                        //This should not happen since there is only one sealed implementation of the event envelope.
                        throw new Exception($"Event envelope of type {eventEnvelope.GetType().FullName} does not implement {nameof(IHaveSourceAndParentIdTypes)}");
                    }

                    reconstituteMethodCache.Invoke(this, eventEnvelope);
                }
            }

            ConcurrencyId = concurrencyId;
        }
Exemple #3
0
 void IPersistThroughEvents.ReconstituteFrom <TEvent>(TEvent @event)
 {
     if (typeof(TEvent) == @event.GetType())
     {
         ApplyInternal(@event, false);
     }
     else
     {
         applyInternalMethodCache.Invoke(this, @event, false);
     }
 }