internal async Task ApplyEventAsync(IEventEnvelope @event) { foreach (var projection in _projections) { await projection.ApplyAsync(@event).ConfigureAwait(false); } }
internal void ApplyEvent(IEventEnvelope @event) { foreach (var projection in _projections) { projection.Apply(@event); } }
/// <summary> /// Adds event envelope to this transition /// Event metadata should has correct StreamId, StreamVersion and TransitionSequence. /// </summary> public ITransitionBuilder AddEvent(IEventEnvelope envelope) { ValidateEventMetadata(envelope.Metadata); _eventEnvelopes.Add(envelope); _transitionSequence = envelope.Metadata.TransitionSequence + 1; return this; }
private void Project(IEventEnvelope eventEnvelope) { switch (eventEnvelope.Data) { case (WalkOfInterestRegistered @event): _interestById.TryAdd(@event.Interest.Id, @event.Interest); _interestIndex.Add(@event.Interest); break; case (NodeOfInterestRegistered @event): _interestById[@event.Interest.Id] = @event.Interest; _interestIndex.Add(@event.Interest); break; case (WalkOfInterestRouteNetworkElementsModified @event): if (_interestById.TryGetValue(@event.InterestId, out var existingInterestToModify)) { var updatedInterest = existingInterestToModify with { RouteNetworkElementRefs = @event.RouteNetworkElementIds }; _interestById.TryUpdate(@event.InterestId, updatedInterest, existingInterestToModify); _interestIndex.Update(updatedInterest, existingInterestToModify); } break; case (InterestUnregistered @event): if (_interestById.TryGetValue(@event.InterestId, out var existingInterestToUnregister)) { _interestById.TryRemove(@event.InterestId, out _); _interestIndex.Remove(existingInterestToUnregister); } break; } }
private void Project(IEventEnvelope eventEnvelope) { switch (eventEnvelope.Data) { case (NodeContainerSpecificationAdded @event): _nodeContainerSpecifications.Add(@event.Specification); break; } }
private void Project(IEventEnvelope eventEnvelope) { switch (eventEnvelope.Data) { case (ManufacturerAdded @event): _manufacturer.Add(@event.Manufacturer); break; } }
private void Project(IEventEnvelope eventEnvelope) { switch (eventEnvelope.Data) { case (DogBorn @event): _poopStatByDogId[eventEnvelope.StreamId] = new DogPoopStat(@event.Name); break; case (DogPooped @event): _poopStatByDogId[eventEnvelope.StreamId].AddPoop(@event.WeightInGrams); break; } }
void SetState(IEventProcessor eventProcessor, IEventEnvelope envelope, EventProcessingStatus processingStatus) { dynamic state = new ExpandoObject(); state.EventProcessor = eventProcessor.Identifier; state.LastProcessedSequenceNumber = envelope.SequenceNumber; state.LastProcessedSequenceNumberForEventType = envelope.SequenceNumberForEventType; state.LastProcessed = _systemClock.GetCurrentTime(); state.LastProcessingStatus = processingStatus; var json = _serializer.ToJson(state); _database.StringSet(GetKeyFor(eventProcessor), json); }
void WriteState(IEventProcessor eventProcessor, IEventEnvelope envelope, EventProcessingStatus processingStatus) { dynamic state = new ExpandoObject(); state.EventProcessor = eventProcessor.Identifier; state.LastProcessedSequenceNumber = envelope.SequenceNumber; state.LastProcessedSequenceNumberForEventType = envelope.SequenceNumberForEventType; state.LastProcessed = _systemClock.GetCurrentTime(); state.LastProcessingStatus = processingStatus; var json = _serializer.ToJson(state); var fileName = GetFileNameFor(eventProcessor); _files.WriteString(_configuration.Path, fileName, json); }
void WriteState(IEventProcessor eventProcessor, IEventEnvelope envelope, EventProcessingStatus processingStatus) { dynamic state = new ExpandoObject(); state.EventProcessor = eventProcessor.Identifier; state.LastProcessedSequenceNumber = envelope.SequenceNumber; state.LastProcessedSequenceNumberForEventType = envelope.SequenceNumberForEventType; state.LastProcessed = _systemClock.GetCurrentTime(); state.LastProcessingStatus = processingStatus; var json = _serializer.ToJson(state); var path = GetPathFor(eventProcessor); File.WriteAllText(path, json); }
/// <inheritdoc/> public IEventProcessingResults Process(IEventEnvelope envelope, IEvent @event) { var identifier = _applicationResources.Identify(@event); if (!_eventProcessorsByResourceIdentifier.ContainsKey(identifier)) { return(new EventProcessingResults(new IEventProcessingResult[0])); } List <IEventProcessingResult> results = new List <IEventProcessingResult>(); var eventProcessors = _eventProcessorsByResourceIdentifier[identifier]; eventProcessors.ForEach(e => results.Add(e.Process(envelope, @event))); return(new EventProcessingResults(results)); }
private void Project(IEventEnvelope eventEnvelope) { switch (eventEnvelope.Data) { case (SpanStructureSpecificationAdded @event): _spanStructureSpecifications.Add(@event.Specification); break; case (SpanStructureSpecificationDeprecated @event): _spanStructureSpecifications[@event.SpanStructureSpecificationId] = _spanStructureSpecifications[@event.SpanStructureSpecificationId] with { Deprecated = true }; break; } } }
public virtual async Task HandleRecivedEvent(IEventEnvelope data, StreamSequenceToken token) { using (log.BeginScope(ActorId)) { if (data.EventVersion == (version + 1)) { await Dispatcher.DispatchAsync(this, data); log.LogInformation("Projection recived event:{eventData}", data); version++; } else { version = +await eventTableStoreStream.ReadEvents(Apply, version); } fileStorageProvider.SaveToFile <T>(new ProjectionStoreEntity <T>(version, state), Id); } }
public async Task ApplyAsync(IEventEnvelope @event) { var eventType = @event.Data.GetType(); if (_handlers.TryGetValue(eventType, out MyEventHandler handler)) { await handler.Handler(@event).ConfigureAwait(false); } else { foreach (var handlerRegistered in _handlers) { if (eventType.IsSubclassOf(handlerRegistered.Key)) { await handlerRegistered.Value.Handler(@event).ConfigureAwait(false); } } } }
public void Apply(IEventEnvelope @event) { var eventType = @event.Data.GetType(); if (_handlers.TryGetValue(eventType, out MyEventHandler handler)) { handler.Handler(@event); } else { foreach (var handlerRegistered in _handlers) { if (eventType.IsSubclassOf(handlerRegistered.Key)) { handlerRegistered.Value.Handler(@event); } } } }
/// <inheritdoc/> public IEventProcessingResult Process(IEventEnvelope envelope, IEvent @event) { var status = EventProcessingStatus.Success; var start = _systemClock.GetCurrentTime(); var messages = new EventProcessingMessage[0]; try { var processor = _container.Get(_methodInfo.DeclaringType); _methodInfo.Invoke(processor, new[] { @event }); } catch (Exception ex) { status = EventProcessingStatus.Failed; messages = new[] { new EventProcessingMessage(EventProcessingMessageSeverity.Error, ex.Message, ex.StackTrace.Split(Environment.NewLine.ToCharArray())) }; } var end = _systemClock.GetCurrentTime(); return(new EventProcessingResult(envelope.CorrelationId, this, status, start, end, messages)); }
/// <inheritdoc/> public IEventProcessingResults Process(IEventEnvelope envelope, IEvent @event) { _logger.Trace("Process event"); var identifier = _applicationResources.Identify(@event); _logger.Trace($"Identifier for event - {identifier}"); if (!_eventProcessorsByResourceIdentifier.ContainsKey(identifier)) { _logger.Trace("No event processors able to process - return"); return(new EventProcessingResults(new IEventProcessingResult[0])); } List <IEventProcessingResult> results = new List <IEventProcessingResult>(); var eventProcessors = _eventProcessorsByResourceIdentifier[identifier]; eventProcessors.ForEach(e => { _logger.Trace($"Process event with processor : {e.Identifier}"); results.Add(e.Process(envelope, @event)); }); return(new EventProcessingResults(results)); }
/// <ineritdoc/> public void ReportFailureFor(IEventProcessor eventProcessor, IEvent @event, IEventEnvelope envelope) { }
/// <inheritdoc/> public void ReportSuccessFor(IEventProcessor eventProcessor, IEvent @event, IEventEnvelope envelope) { WriteState(eventProcessor, envelope, EventProcessingStatus.Success); }
/// <inheritdoc/> public void ReportFailureFor(IEventProcessor eventProcessor, IEvent @event, IEventEnvelope envelope) { WriteState(eventProcessor, envelope, EventProcessingStatus.Failed); }
/// <inheritdoc/> public void Info(IEventProcessor processor, IEvent @event, IEventEnvelope envelope, IEnumerable <EventProcessingMessage> messages) { }
/// <ineritdoc/> public void ReportSuccessFor(IEventProcessor eventProcessor, IEvent @event, IEventEnvelope envelope) { }
public EventContentAndEnvelope(Dictionary <string, object> content, IEventEnvelope envelope) { Content = content; Envelope = envelope; }
/// <inheritdoc/> public void Info(IEventProcessor processor, IEvent @event, IEventEnvelope envelope, IEnumerable <EventProcessingMessage> messages) { throw new NotImplementedException(); }
/// <summary> /// Initializes a new instance of <see cref="EventAndEnvelope"/> /// </summary> /// <param name="envelope"><see cref="IEventEnvelope">Envelope</see> with metadata for the <see cref="IEvent"/></param> /// <param name="theEvent"><see cref="IEvent">Event</see> that is represented</param> public EventAndEnvelope(IEventEnvelope envelope, IEvent theEvent) { Envelope = envelope; Event = theEvent; }
/// <inheritdoc/> public void ReportSuccessFor(IEventProcessor eventProcessor, IEvent @event, IEventEnvelope envelope) { MakeSurePathExists(); WriteState(eventProcessor, envelope, EventProcessingStatus.Success); }