protected void ApplyCommittedEvents <TAggregateEvent>(ICommittedEvent <TAggregate, TIdentity, TAggregateEvent> committedEvent) where TAggregateEvent : IAggregateEvent <TAggregate, TIdentity> { var applyMethods = GetEventApplyMethods(committedEvent.AggregateEvent); applyMethods(committedEvent.AggregateEvent); }
protected virtual bool Recover(ICommittedEvent <TAggregateSaga, TIdentity, IAggregateEvent <TAggregateSaga, TIdentity> > committedEvent) { try { Log.Debug("AggregateSaga of Name={0}, Id={1}, and Version={2}, is recovering with CommittedEvent of Type={3}.", Name, Id, Version, committedEvent.GetType().PrettyPrint()); ApplyEvent(committedEvent.AggregateEvent); } catch (Exception exception) { Log.Error(exception, "Aggregate of Name={0}, Id={1}; while recovering with event of Type={2} caused an exception.", Name, Id, committedEvent.GetType().PrettyPrint()); return(false); } return(true); }
protected virtual bool Recover(ICommittedEvent <TAggregate, TIdentity, IAggregateEvent <TAggregate, TIdentity> > committedEvent) { try { Logger.Debug($"Recovering with event of type [{committedEvent.GetType().PrettyPrint()}] "); ApplyEvent(committedEvent.AggregateEvent); } catch (Exception exception) { Logger.Error($"Recovering with event of type [{committedEvent.GetType().PrettyPrint()}] caused an exception {exception.GetType().PrettyPrint()}"); return(false); } return(true); }
protected void ApplyCommittedEvent <TAggregateEvent>(ICommittedEvent <TAggregate, TIdentity, TAggregateEvent> committedEvent) where TAggregateEvent : class, IAggregateEvent <TAggregate, TIdentity> { var applyMethods = GetEventApplyMethods(committedEvent.AggregateEvent); applyMethods(committedEvent.AggregateEvent); Log.Info("Aggregate of Name={0}, and Id={1}; committed and applied an AggregateEvent of Type={2}.", Name, Id, typeof(TAggregateEvent).PrettyPrint()); Version++; var domainEvent = new DomainEvent <TAggregate, TIdentity, TAggregateEvent>(Id, committedEvent.AggregateEvent, committedEvent.Metadata, committedEvent.Timestamp, Version); Publish(domainEvent); ReplyIfAvailable(); if (!SnapshotStrategy.ShouldCreateSnapshot(this)) { return; } var aggregateSnapshot = CreateSnapshot(); if (aggregateSnapshot == null) { return; } _snapshotDefinitionService.Load(aggregateSnapshot.GetType()); var snapshotDefinition = _snapshotDefinitionService.GetDefinition(aggregateSnapshot.GetType()); var snapshotMetadata = new SnapshotMetadata { AggregateId = Id.Value, AggregateName = Name.Value, AggregateSequenceNumber = Version, SnapshotName = snapshotDefinition.Name, SnapshotVersion = snapshotDefinition.Version }; var committedSnapshot = new CommittedSnapshot <TAggregate, TIdentity, IAggregateSnapshot <TAggregate, TIdentity> >( Id, aggregateSnapshot, snapshotMetadata, committedEvent.Timestamp, Version); SaveSnapshot(committedSnapshot); }
protected void ApplyCommittedEvent <TAggregateEvent>(ICommittedEvent <TAggregate, TIdentity, TAggregateEvent> committedEvent) where TAggregateEvent : IAggregateEvent <TAggregate, TIdentity> { var applyMethods = GetEventApplyMethods(committedEvent.AggregateEvent); applyMethods(committedEvent.AggregateEvent); Logger.Info($"[{Name}] With Id={Id} Commited and Applied [{typeof(TAggregateEvent).PrettyPrint()}]"); Version++; var domainEvent = new DomainEvent <TAggregate, TIdentity, TAggregateEvent>(Id, committedEvent.AggregateEvent, committedEvent.Metadata, committedEvent.Timestamp, Version); Publish(domainEvent); ReplyIfAvailable(); if (SnapshotStrategy.ShouldCreateSnapshot(this)) { var aggregateSnapshot = CreateSnapshot(); if (aggregateSnapshot != null) { _snapshotDefinitionService.Load(aggregateSnapshot.GetType()); var snapshotDefinition = _snapshotDefinitionService.GetDefinition(aggregateSnapshot.GetType()); var snapshotMetadata = new SnapshotMetadata { AggregateId = Id.Value, AggregateName = Name.Value, AggregateSequenceNumber = Version, SnapshotName = snapshotDefinition.Name, SnapshotVersion = snapshotDefinition.Version }; var commitedSnapshot = new ComittedSnapshot <TAggregate, TIdentity, IAggregateSnapshot <TAggregate, TIdentity> >( Id, aggregateSnapshot, snapshotMetadata, committedEvent.Timestamp, Version); SaveSnapshot(commitedSnapshot); } } }
protected void ApplyCommittedEvent <TAggregateEvent>(ICommittedEvent <TIdentity, TAggregateEvent> committedEvent) where TAggregateEvent : class, IAggregateEvent <TIdentity> { Log.Info("Aggregate of Name={0}, and Id={1}; committed and applied an AggregateEvent of Type={2}.", Name, Id, typeof(TAggregateEvent).PrettyPrint()); var aggEvent = committedEvent.AggregateEvent; var meta = committedEvent.EventMetadata; var timestamp = committedEvent.Timestamp; var domainEvent = new DomainEvent <TIdentity, TAggregateEvent>(Id, aggEvent, meta, timestamp, Version); if (State != null && State is ITransactionState) { _committedEvents.Add(domainEvent); } else { Publish(domainEvent); ReplyIfAvailable(); } }