Пример #1
0
 internal async Task ApplyEventAsync(IEventEnvelope @event)
 {
     foreach (var projection in _projections)
     {
         await projection.ApplyAsync(@event).ConfigureAwait(false);
     }
 }
Пример #2
0
 internal void ApplyEvent(IEventEnvelope @event)
 {
     foreach (var projection in _projections)
     {
         projection.Apply(@event);
     }
 }
Пример #3
0
 /// <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;
 }
Пример #4
0
        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;
     }
 }
Пример #6
0
 private void Project(IEventEnvelope eventEnvelope)
 {
     switch (eventEnvelope.Data)
     {
     case (ManufacturerAdded @event):
         _manufacturer.Add(@event.Manufacturer);
         break;
     }
 }
Пример #7
0
        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;
            }
        }
Пример #8
0
        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);
        }
Пример #9
0
        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);
        }
Пример #10
0
        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);
        }
Пример #11
0
        /// <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;
            }
        }
    }
Пример #13
0
        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);
            }
        }
Пример #14
0
        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);
                    }
                }
            }
        }
Пример #15
0
        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));
        }
Пример #17
0
        /// <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));
        }
Пример #18
0
 /// <ineritdoc/>
 public void ReportFailureFor(IEventProcessor eventProcessor, IEvent @event, IEventEnvelope envelope)
 {
 }
Пример #19
0
 /// <inheritdoc/>
 public void ReportSuccessFor(IEventProcessor eventProcessor, IEvent @event, IEventEnvelope envelope)
 {
     WriteState(eventProcessor, envelope, EventProcessingStatus.Success);
 }
Пример #20
0
 /// <inheritdoc/>
 public void ReportFailureFor(IEventProcessor eventProcessor, IEvent @event, IEventEnvelope envelope)
 {
     WriteState(eventProcessor, envelope, EventProcessingStatus.Failed);
 }
Пример #21
0
 /// <inheritdoc/>
 public void Info(IEventProcessor processor, IEvent @event, IEventEnvelope envelope, IEnumerable <EventProcessingMessage> messages)
 {
 }
Пример #22
0
 /// <ineritdoc/>
 public void ReportSuccessFor(IEventProcessor eventProcessor, IEvent @event, IEventEnvelope envelope)
 {
 }
Пример #23
0
 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();
 }
Пример #25
0
 /// <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;
 }
Пример #26
0
        /// <inheritdoc/>
        public void ReportSuccessFor(IEventProcessor eventProcessor, IEvent @event, IEventEnvelope envelope)
        {
            MakeSurePathExists();

            WriteState(eventProcessor, envelope, EventProcessingStatus.Success);
        }