示例#1
0
        /// <summary>
        /// Creates a new instance of the options class.
        /// </summary>
        /// <param name="mainDbContextOptionsBuilderCfg">Options for DbContext configuration</param>
        /// <param name="snapshotBehaviorProvider">Provider of snapshot behaviors</param>
        /// <param name="bufferInfo">Buffer info to use. Disabled by default.</param>
        /// <param name="archiveBehavior">Behavior to adopt when creating a snapshot</param>
        /// <param name="archiveDbContextOptionsBuilderCfg">Configuration to apply to access archive events</param>
        /// A value is needed if <paramref name="snapshotBehaviorProvider"/> is provided and
        /// <paramref name="archiveBehavior"/> is set to StoreToNewDatabase.
        /// </param>
        public EFEventStoreOptions(
            Action <DbContextOptionsBuilder <EventStoreDbContext> > mainDbContextOptionsBuilderCfg,
            ISnapshotBehaviorProvider snapshotBehaviorProvider = null,
            BufferInfo bufferInfo = null,
            SnapshotEventsArchiveBehavior?archiveBehavior = null,
            Action <DbContextOptionsBuilder <ArchiveEventStoreDbContext> > archiveDbContextOptionsBuilderCfg = null)
        {
            if (mainDbContextOptionsBuilderCfg == null)
            {
                throw new ArgumentNullException(nameof(mainDbContextOptionsBuilderCfg));
            }
            if (archiveBehavior == SnapshotEventsArchiveBehavior.StoreToNewDatabase && archiveDbContextOptionsBuilderCfg == null)
            {
                throw new ArgumentException("A DbContextOptions should be provided to access archive database cause " +
                                            "SnapshotEventsArchiveBehavior is set to StoreToNewDatabase.");
            }
            var mainDbContextOptionsBuilder = new DbContextOptionsBuilder <EventStoreDbContext>();

            mainDbContextOptionsBuilderCfg(mainDbContextOptionsBuilder);
            DbContextOptions = mainDbContextOptionsBuilder.Options;

            SnapshotBehaviorProvider = snapshotBehaviorProvider;
            BufferInfo = bufferInfo ?? BufferInfo.Disabled;
            if (archiveBehavior.HasValue && snapshotBehaviorProvider != null && archiveDbContextOptionsBuilderCfg != null)
            {
                var archiveDbContextOptionsBuilder = new DbContextOptionsBuilder <ArchiveEventStoreDbContext>();
                archiveDbContextOptionsBuilderCfg(archiveDbContextOptionsBuilder);
                ArchiveBehavior         = archiveBehavior.Value;
                ArchiveDbContextOptions = archiveDbContextOptionsBuilder.Options;
            }
        }
        private void StoreNDomainEvents(ISnapshotBehaviorProvider provider = null)
        {
            var store = new EFEventStore(GetConfig(provider));

            for (int i = 0; i < 1000; i++)
            {
                store.StoreDomainEventAsync(new TestEvent(Guid.NewGuid(), AggregateId)
                {
                    AggregateStringValue = "test", AggregateIntValue = i
                }).GetAwaiter().GetResult();
            }
        }
        private void StoreNDomainEvents(ISnapshotBehaviorProvider provider = null)
        {
            EventStoreManager.Client = new MongoClient(GetMongoDbUrl());
            var store = new MongoDbEventStore(provider);

            for (int i = 0; i < N; i++)
            {
                store.StoreDomainEventAsync(new TestEvent(Guid.NewGuid(), AggregateId)
                {
                    AggregateStringValue = "test", AggregateIntValue = N
                }).GetAwaiter().GetResult();
            }
        }
 /// <summary>
 /// Creates a new options class with a defined snapshot behavior provider and servers urls.
 /// </summary>
 /// <param name="snapshotBehaviorProvider">Snapshot behavior provider.</param>
 /// <param name="snapshotEventsArchiveBehavior">Behavior for archive events after creating snapshot.</param>
 /// <param name="serversUrls">Collection of urls to use as server.</param>
 public MongoEventStoreOptions(ISnapshotBehaviorProvider snapshotBehaviorProvider,
                               SnapshotEventsArchiveBehavior snapshotEventsArchiveBehavior = SnapshotEventsArchiveBehavior.StoreToNewDatabase,
                               params string[] serversUrls)
 {
     if (serversUrls == null)
     {
         throw new ArgumentNullException(nameof(serversUrls));
     }
     if (serversUrls.Length == 0)
     {
         throw new ArgumentException("MongoDbEventStoreBootstrapperConfiguration.ctor() : At least one url should be provided, for main server.", nameof(serversUrls));
     }
     ServerUrls = serversUrls.AsEnumerable();
     SnapshotBehaviorProvider      = snapshotBehaviorProvider;
     SnapshotEventsArchiveBehavior = snapshotEventsArchiveBehavior;
 }
 /// <summary>
 /// Creates a new options class with a defined snapshot behavior provider and servers urls.
 /// </summary>
 /// <param name="snapshotBehaviorProvider">Snapshot behavior provider.</param>
 /// <param name="snapshotEventsArchiveBehavior">Behavior for archive events after creating snapshot.</param>
 /// <param name="serversUrls">Collection of urls to use as server.</param>
 public MongoEventStoreOptions(string userName, string password,
                               ISnapshotBehaviorProvider snapshotBehaviorProvider,
                               SnapshotEventsArchiveBehavior snapshotEventsArchiveBehavior = SnapshotEventsArchiveBehavior.StoreToNewDatabase,
                               params string[] serversUrls)
     : this(snapshotBehaviorProvider, snapshotEventsArchiveBehavior, serversUrls)
 {
     if (string.IsNullOrWhiteSpace(userName))
     {
         throw new ArgumentException("MongoDbEventStoreBootstrapperConfiguration.ctor() : Username should be provided", nameof(userName));
     }
     if (string.IsNullOrWhiteSpace(password))
     {
         throw new ArgumentException("MongoDbEventStoreBootstrapperConfiguration.ctor() : Password should be provided", nameof(password));
     }
     Username = userName;
     Password = password;
 }
        private EFEventStoreOptions GetConfig(
            ISnapshotBehaviorProvider snapshotBehaviorProvider = null,
            BufferInfo bufferInfo = null)
        {
            EFEventStoreOptions options = null;

            switch (DatabaseType)
            {
            case DatabaseType.SQLite:
                options = new EFEventStoreOptions(o => o.UseSqlite(GetConnectionString_SQLite()),
                                                  snapshotBehaviorProvider, bufferInfo);
                break;

            default:
                options = new EFEventStoreOptions(o => o.UseSqlite(GetConnectionString_SQLServer()),
                                                  snapshotBehaviorProvider, bufferInfo);
                break;
            }
            return(options);
        }
示例#7
0
        public EFEventStore(EFEventStoreOptions options, ILoggerFactory loggerFactory = null)
        {
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            _dbContextOptions         = options.DbContextOptions;
            _logger                   = (loggerFactory ?? new LoggerFactory()).CreateLogger <EFEventStore>();
            _snapshotBehaviorProvider = options.SnapshotBehaviorProvider;

            _bufferInfo      = options.BufferInfo;
            _archiveBehavior = options.ArchiveBehavior;
            _archiveBehaviorDbContextOptions = options.ArchiveDbContextOptions;

            if (_bufferInfo != null)
            {
                s_SlidingTimer  = new Timer(TreatBufferEvents, null, Timeout.Infinite, Timeout.Infinite);
                s_AbsoluteTimer = new Timer(TreatBufferEvents, null, Timeout.Infinite, Timeout.Infinite);
            }
        }
示例#8
0
 public MongoDbEventStore(ISnapshotBehaviorProvider snapshotBehaviorProvider = null,
                          SnapshotEventsArchiveBehavior archiveBehavior      = SnapshotEventsArchiveBehavior.StoreToNewTable)
 {
     _snapshotBehaviorProvider = snapshotBehaviorProvider;
     _archiveBehavior          = archiveBehavior;
 }
 private CosmosDbEventStore GetCosmosDbEventStore(ISnapshotBehaviorProvider snapshotBehavior = null)
 => new CosmosDbEventStore(snapshotBehavior);
示例#10
0
 public CosmosDbEventStore(ISnapshotBehaviorProvider snapshotBehaviorProvider = null)
 {
     _snapshotBehaviorProvider = snapshotBehaviorProvider;
 }