示例#1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ReadModelCatchup{TDbContext}" /> class.
        /// </summary>
        /// <param name="readModelDbContext">A delegate to create read model database contexts on demand.</param>
        /// <param name="eventStoreDbContext">A delegate to create event store database contexts on demand.</param>
        /// <param name="startAtEventId">The event id that the catchup should start from.</param>
        /// <param name="batchSize">The number of events queried from the event store at each iteration.</param>
        /// <param name="filter">An optional filter expression to constrain the query that the catchup uses over the event store.</param>
        /// <param name="projectors">The projectors to be updated as new events are added to the event store.</param>
        /// <exception cref="System.ArgumentNullException">
        /// </exception>
        /// <exception cref="System.ArgumentException">You must specify at least one projector.</exception>
        public ReadModelCatchup(
            Func <DbContext> readModelDbContext,
            Func <EventStoreDbContext> eventStoreDbContext,
            long startAtEventId = 0,
            int batchSize       = 10000,
            Expression <Func <StorableEvent, bool> > filter = null,
            params object[] projectors)
        {
            if (readModelDbContext == null)
            {
                throw new ArgumentNullException(nameof(readModelDbContext));
            }

            if (eventStoreDbContext == null)
            {
                throw new ArgumentNullException(nameof(eventStoreDbContext));
            }

            if (!projectors.OrEmpty().Any())
            {
                throw new ArgumentException("You must specify at least one projector.");
            }

            if (batchSize < 1)
            {
                throw new ArgumentException($"Argument {nameof(batchSize)} must be at least 1.");
            }

            createReadModelDbContext  = readModelDbContext;
            createEventStoreDbContext = eventStoreDbContext;
            this.startAtEventId       = startAtEventId;
            this.filter     = filter;
            this.projectors = new List <object>(projectors);
            this.batchSize  = batchSize;

            EnsureProjectorNamesAreDistinct();

            cancellationDisposable = new CancellationDisposable();
            disposables            = new CompositeDisposable
            {
                cancellationDisposable,
                Disposable.Create(() => progress.OnCompleted())
            };
            bus = new InProcessEventBus(new Subject <IEvent>());
            disposables.Add(bus.ReportErrorsToDatabase(() => createReadModelDbContext()));
            disposables.Add(bus);
            Sensors.ReadModelDbContexts.GetOrAdd(typeof(TDbContext).Name, createReadModelDbContext);
        }
示例#2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ReadModelCatchup{TDbContext}"/> class.
        /// </summary>
        /// <param name="projectors">The projectors to be updated as new events are added to the event store.</param>
        /// <exception cref="System.ArgumentException">You must specify at least one projector.</exception>
        public ReadModelCatchup(params object[] projectors)
        {
            if (!projectors.OrEmpty().Any())
            {
                throw new ArgumentException("You must specify at least one projector.");
            }

            this.projectors = new List <object>(projectors);

            EnsureProjectorNamesAreDistinct();

            cancellationDisposable = new CancellationDisposable();
            disposables            = new CompositeDisposable
            {
                cancellationDisposable,
                Disposable.Create(() => progress.OnCompleted())
            };
            bus = new InProcessEventBus(new Subject <IEvent>());
            disposables.Add(bus.ReportErrorsToDatabase(() => CreateReadModelDbContext()));
            disposables.Add(bus);
            Sensors.ReadModelDbContexts.GetOrAdd(typeof(TDbContext).Name, CreateReadModelDbContext);
        }