Exemplo n.º 1
0
        private void OnEventAppeared(EventStorePersistentSubscriptionBase subscription, ResolvedEvent resolvedEvent)
        {
            var eventJson = Encoding.UTF8.GetString(resolvedEvent.Event.Data);

            var eventType = _messageTypes.FirstOrDefault(@type => string.Equals(@type.Name, resolvedEvent.Event.EventType));

            if (eventType == null)
            {
                throw new MessageTypeMissing(resolvedEvent.Event.EventType);
            }

            var @event = JsonConvert.DeserializeObject(eventJson, eventType);

            var metadataJson = Encoding.UTF8.GetString(resolvedEvent.Event.Metadata);
            var metadata     = (Dictionary <string, string>)JsonConvert.DeserializeObject(metadataJson, typeof(Dictionary <string, string>));

            metadata.ChangeKey("$causationId", Constants.CausationIdKey);

            metadata.Add(Constants.StreamCheckpointTokenKey, resolvedEvent.Event.EventNumber.ToString());

            var envelope = this.FastInvoke(new[] { eventType }, x => x.CreateEnvelope(default(object), default(Dictionary <string, string>)), @event, metadata);

            _dispatcher.Dispatch(_handler, envelope);
        }
 public void Consume(IConsumeContext <InitiateApproval> context)
 {
     _dispatcher.Dispatch(_handler, context.ToEnvelope());
 }