/// <summary>
        /// Re-publishes events from unpublished queue.
        /// Uses <paramref name="formatter"/> to deserialize events from store.
        /// </summary>
        /// <param name="formatter">The event deserializer.</param>
        /// <returns>The continuation task.</returns>
        public async Task RecoverAsync(IDeserializer formatter)
        {
            IEnumerable <EventPublishingModel> models = await store.GetAsync();

            foreach (EventPublishingModel model in models)
            {
                IEvent eventModel = formatter.DeserializeEvent(Type.GetType(model.Event.EventKey.Type), model.Event.Payload);
                await RecoverEventAsync(eventModel, model.PublishedHandlerIdentifiers);
            }

            await store.ClearAsync();
        }
Пример #2
0
        /// <summary>
        /// Pushlishes all events on the registered handlers using <see cref="Add"/>.
        /// </summary>
        /// <returns>The continuation task.</returns>
        public async Task RunAsync()
        {
            // Use list of required event types to load events from store.
            IEnumerable <string> eventTypes = eventDispatcher
                                              .EnumerateEventTypes()
                                              .Select(t => t.AssemblyQualifiedName);

            IEnumerable <EventModel> eventData = await store.GetAsync(eventTypes);

            IEnumerable <IEvent> events = eventData
                                          .Where(IsFilterPassed)
                                          .Select(e => deserializer.DeserializeEvent(Type.GetType(e.EventKey.Type), e.Payload));

            // Replay events on handler(s).
            foreach (IEvent payload in events)
            {
                await eventDispatcher.PublishAsync(payload);
            }
        }
Пример #3
0
        /// <summary>
        /// Re-publishes events from unpublished queue.
        /// Uses <paramref name="formatter"/> to deserialize events from store.
        /// </summary>
        /// <param name="formatter">The event deserializer.</param>
        /// <returns>The continuation task.</returns>
        public async Task RecoverAsync(IDeserializer formatter)
        {
            Ensure.NotNull(formatter, "formatter");

            log.Debug("Starting recovery.");

            IEnumerable <EventPublishingModel> models = await store.GetAsync();

            foreach (EventPublishingModel model in models)
            {
                IEvent eventModel = formatter.DeserializeEvent(Type.GetType(model.Event.EventKey.Type), model.Event.Payload);

                log.Debug(eventModel, "Recovering an event.");
                await RecoverEventAsync(eventModel, model.PublishedHandlerIdentifiers);
            }

            await store.ClearAsync();

            log.Debug("Recovery finished.");
        }