public OptimizedEventStore(string streamType, ITextSerializer serializer, string connectionString, IUtcTimeProvider time, IGuidProvider guid, ILogger log) { Ensure.NotNullNeitherEmtpyNorWhiteSpace(streamType, nameof(streamType)); Ensure.NotNull(serializer, nameof(serializer)); Ensure.NotNullNeitherEmtpyNorWhiteSpace(connectionString, nameof(connectionString)); Ensure.NotNull(time, nameof(time)); Ensure.NotNull(guid, nameof(guid)); Ensure.NotNull(log, nameof(log)); this.streamType = streamType; this.serializer = serializer; this.connectionString = connectionString; this.time = time; this.guid = guid; this.log = log; this.cache = new MemoryCache(streamType); this.sql = new SqlClientLite(this.connectionString, timeoutInSeconds: 120); /// TODO: could be replaced with a compiled lambda to make it more performant. var fromMementoConstructor = typeof(T).GetConstructor(new[] { typeof(Guid), typeof(ISnapshot) }); Ensure.CastIsValid(fromMementoConstructor, "Type T must have a constructor with the following signature: .ctor(Guid, IMemento)"); this.originatorAggregateFactory = (id, memento) => (T)fromMementoConstructor.Invoke(new object[] { id, memento }); var fromStreamConstructor = typeof(T).GetConstructor(new[] { typeof(Guid), typeof(IEnumerable <IEvent>) }); Ensure.CastIsValid(fromStreamConstructor, "Type T must have a constructor with the following signature: .ctor(Guid, IEnumerable<IEvent>)"); this.aggregateFactory = (id, streamOfEvents) => (T)fromStreamConstructor.Invoke(new object[] { id, streamOfEvents }); this.eventCollectionVersion = this.GetLatestEventCollectionVersionFromDb(); }
public AdoDotNetEventStore(string streamType, ITextSerializer serializer, string connectionString, IUtcTimeProvider time, IGuidProvider guid, ILogger log, bool persistIncomingPayloads, bool persistSnapshots, Func <string, ITextSerializer, string, bool> consumerFilter) : base(streamType) { Ensure.NotNull(serializer, nameof(serializer)); Ensure.NotNullNeitherEmtpyNorWhiteSpace(connectionString, nameof(connectionString)); Ensure.NotNull(time, nameof(time)); Ensure.NotNull(guid, nameof(guid)); Ensure.NotNull(log, nameof(log)); this.serializer = serializer; this.connectionString = connectionString; this.time = time; this.guid = guid; this.log = log; this.consumerFilter = consumerFilter != null ? consumerFilter : EventStoreFuncs.DefaultFilter; this.cache = new MemoryCache(streamType); this.sql = new SqlClientLite(this.connectionString, timeoutInSeconds: 120); /// TODO: could be replaced with a compiled lambda to make it more performant. var fromMementoConstructor = typeof(T).GetConstructor(new[] { typeof(Guid), typeof(ISnapshot) }); Ensure.CastIsValid(fromMementoConstructor, "Type T must have a constructor with the following signature: .ctor(Guid, IMemento)"); this.originatorAggregateFactory = (id, memento) => (T)fromMementoConstructor.Invoke(new object[] { id, memento }); var fromStreamConstructor = typeof(T).GetConstructor(new[] { typeof(Guid), typeof(IEnumerable <IEvent>) }); Ensure.CastIsValid(fromStreamConstructor, "Type T must have a constructor with the following signature: .ctor(Guid, IEnumerable<IEvent>)"); this.aggregateFactory = (id, streamOfEvents) => (T)fromStreamConstructor.Invoke(new object[] { id, streamOfEvents }); this.eventCollectionVersion = this.GetLatestEventCollectionVersionFromDb(); this.CurrentEventCollectionVersion = this.eventCollectionVersion; if (persistIncomingPayloads) { this.addToInboxFactory = this.AddToInboxWithPayload; } else { this.addToInboxFactory = this.AddToInboxWithoutPayload; } // adding app subscription if missing var appSubCount = this.sql.ExecuteReaderFirstOrDefault(this.tryFindAppSubscription, r => r.GetInt32(0), new SqlParameter("@SubscriberStreamType", this.streamType), new SqlParameter("@StreamType", this.streamType + Constants.AppEventStreamNameSufix)); if (appSubCount == 0) { var now = DateTime.Now; this.sql.ExecuteNonQuery(this.createAppSubscription, new SqlParameter("@SubscriberStreamType", this.streamType), new SqlParameter("@StreamType", this.streamType + Constants.AppEventStreamNameSufix), new SqlParameter("@CreationLocalTime", now), new SqlParameter("@UpdateLocalTime", now)); } this.persistSnapshots = persistSnapshots; }
public OptimizedEventDao(Func <bool, IEventQueueDbContext> contextFactory, string connectionString, string streamType) { Ensure.NotNull(contextFactory, nameof(contextFactory)); Ensure.NotNullNeitherEmtpyNorWhiteSpace(connectionString, nameof(connectionString)); Ensure.NotNullNeitherEmtpyNorWhiteSpace(streamType, nameof(streamType)); this.sql = new SqlClientLite(connectionString, timeoutInSeconds: 120); this.contextFactory = contextFactory; this.streamType = streamType; }
public static void DropDb(PersistencePlugin plugin) { if (plugin != PersistencePlugin.SqlServer) { return; } Console.WriteLine("Drop db started..."); SqlClientLite.DropDatabase(FixedConnectionstring); Console.WriteLine("Db was droped!"); }