Exemple #1
0
        public async Task ExecuteAsync(string streamName, IObserver <IEvent> observer,
                                       CancellationToken cancellationToken)
        {
            var goOn      = true;
            var iteration = 0;

            while (goOn && !cancellationToken.IsCancellationRequested)
            {
                int pos = iteration * batchSize;
                iteration++;
                StreamEventsSlice result = await connection.ReadStreamEventsForwardAsync(streamName, pos, batchSize, false);

                goOn = !result.IsEndOfStream;

                foreach (ResolvedEvent item in result.Events)
                {
                    IEvent @event = eventTransformer.FromResolvedEvent(item);

                    if (@event != null)
                    {
                        observer.OnNext(@event);
                    }
                    else
                    {
                        //If a event could not be created from the data, a placeholder event should be created to maintain the number and order of the total events
                        observer.OnNext(new SubstitutionEvent(item.OriginalStreamId, item.OriginalEventNumber, item.Event.Metadata, item.Event.Data));
                        HandleEventCreationFailure(item);
                    }
                }
            }

            observer.OnCompleted();
        }
Exemple #2
0
        public void Handle(EventStoreCatchUpSubscription sub, ResolvedEvent @event)
        {
            IEvent result = null;

            try
            {
                result = transformer.FromResolvedEvent(@event);
            }
            catch (Exception err)
            {
                Console.WriteLine(
                    $"Error parsing event {@event.OriginalStreamId}/{@event.OriginalEventNumber}; Msg: {err.Message}");
            }

            if (result != null)
            {
                long pos = @event.OriginalEventNumber;
                eventSub.OnNext(new OccuredEvent(pos, result));
            }
        }