public virtual CommittedEvent <TIdentity, TAggregateEvent> From <TAggregateEvent>(TAggregateEvent aggregateEvent, Int64 version, IEventMetadata metadata = null) where TAggregateEvent : class, IAggregateEvent <TIdentity> { if (aggregateEvent == null) { throw new ArgumentNullException(nameof(aggregateEvent)); } var eventDefinition = _eventDefinitionService.GetDefinition(aggregateEvent.GetType()); var aggregateSequenceNumber = version + 1; var eventId = EventId.NewDeterministic( GuidFactories.Deterministic.Namespaces.Events, $"{Id.Value}-v{aggregateSequenceNumber}"); var now = DateTimeOffset.UtcNow; var eventMetadata = new EventMetadata { Timestamp = now, AggregateSequenceNumber = aggregateSequenceNumber, AggregateName = Name.Value, AggregateId = Id.Value, EventId = eventId, EventName = eventDefinition.Name, EventVersion = eventDefinition.Version }; eventMetadata.AddOrUpdateValue(MetadataKeys.TimestampEpoch, now.ToUnixTime().ToString()); if (metadata != null) { eventMetadata.AddRange(metadata); } var committedEvent = new CommittedEvent <TIdentity, TAggregateEvent>(Id, aggregateEvent, eventMetadata, now, aggregateSequenceNumber); return(committedEvent); }
private void Signal <TAggregateEvent>(TAggregateEvent aggregateEvent, IEventMetadata metadata = null) where TAggregateEvent : class, IAggregateEvent <TestAggregateId> { if (aggregateEvent == null) { throw new ArgumentNullException(nameof(aggregateEvent)); } var aggregateSequenceNumber = Version; var eventId = EventId.NewDeterministic(GuidFactories.Deterministic.Namespaces.Events, $"{Id.Value}-v{aggregateSequenceNumber}"); var now = DateTimeOffset.UtcNow; var eventMetadata = new EventMetadata { Timestamp = now, AggregateSequenceNumber = aggregateSequenceNumber, AggregateName = Name.Value, AggregateId = Id.Value, EventId = eventId }; eventMetadata.Add(MetadataKeys.TimestampEpoch, now.ToUnixTime().ToString()); if (metadata != null) { eventMetadata.AddRange(metadata); } var domainEvent = new DomainEvent <TestAggregateId, TAggregateEvent>(Id, aggregateEvent, eventMetadata, now, Version); Publish(domainEvent); }
protected virtual Object FromObject(Object aggregateEvent, Int64 version, IEventMetadata metadata = null) { if (aggregateEvent is IAggregateEvent) { var eventDefinition = _eventDefinitionService.GetDefinition(aggregateEvent.GetType()); var aggregateSequenceNumber = version + 1; var eventId = EventId.NewDeterministic( GuidFactories.Deterministic.Namespaces.Events, $"{Id.Value}-v{aggregateSequenceNumber}"); var now = DateTimeOffset.UtcNow; var eventMetadata = new EventMetadata(PinnedEvent.Metadata) { Timestamp = now, AggregateSequenceNumber = aggregateSequenceNumber, AggregateName = Name.Value, AggregateId = Id.Value, EventId = eventId, EventName = eventDefinition.Name, EventVersion = eventDefinition.Version }; eventMetadata.AddOrUpdateValue(MetadataKeys.TimestampEpoch, now.ToUnixTime().ToString()); if (metadata != null) { eventMetadata.AddRange(metadata); } var genericType = typeof(CommittedEvent <,>) .MakeGenericType(typeof(TIdentity), aggregateEvent.GetType()); var committedEvent = Activator.CreateInstance( genericType, Id, aggregateEvent, eventMetadata, now, aggregateSequenceNumber); return(committedEvent); } throw new InvalidOperationException("could not perform the required mapping for committed event."); }