Esempio n. 1
0
 public void Dispose()
 {
     using (AppendOnlyStore)
     {
         AppendOnlyStore = null;
     }
 }
Esempio n. 2
0
        /// <summary>
        /// Copy the content of one appender to another. The bytestreams will be identical.
        /// Use AddEvents(appender, events) to compress the bytestreams.
        /// </summary>
        /// <param name="source"></param>
        /// <param name="to"></param>
        /// <param name="version"></param>
        public static void CopyAppender(this IAppendOnlyStore source, IAppendOnlyStore to, int version)
        {
            var serializer = new BinaryFormatterSerializer();

            if (source == null)
            {
                throw new ArgumentNullException("source");
            }

            if (to == null)
            {
                throw new ArgumentNullException("to");
            }

            var versions = new Dictionary <string, int>();

            foreach (var record in source.ReadRecords(0, version))
            {
                if (!versions.ContainsKey(record.Name))
                {
                    versions[record.Name] = 0;
                }

                var events = serializer.DeserializeEvent(record.Data);
                to.Append(record.Name, record.Data, versions[record.Name]);
                versions[record.Name]++;
            }
        }
		/// <summary>
		/// Copy the content of one appender to another. The bytestreams will be identical.
		/// Use AddEvents(appender, events) to compress the bytestreams.
		/// </summary>
		/// <param name="source"></param>
		/// <param name="to"></param>
		/// <param name="version"></param>
        public static void CopyAppender(this IAppendOnlyStore source, IAppendOnlyStore to, int version)
        {
            var serializer = new BinaryFormatterSerializer();

            if (source == null)
            {
                throw new ArgumentNullException("source");
            }

            if (to == null)
            {
                throw new ArgumentNullException("to");
            }

            var versions = new Dictionary<string, int>();

            foreach (var record in source.ReadRecords(0, version))
            {
                if (!versions.ContainsKey(record.Name))
                {
                    versions[record.Name] = 0;
                }

                var events = serializer.DeserializeEvent(record.Data);
                to.Append(record.Name, record.Data, versions[record.Name]);
                versions[record.Name]++;
            }
        }
Esempio n. 4
0
        public EventStoreDB(IAppendOnlyStore store, ISerializer serializer)
        {
            Condition.Requires(store, "store").IsNotNull();
            Condition.Requires(serializer, "serializer").IsNotNull();

            AppendOnlyStore = store;
            Serializer      = serializer;
        }
Esempio n. 5
0
 public HandlerTests()
 {
     _eventBus     = new MemoryEventBus();
     _appendOnly   = new MemoryAppendOnlyStore(_eventBus);
     _eventStore   = new EventStore(_appendOnly);
     _snapShotRepo = new SnapshotRepository();
     _factory      = new AggregateFactory(_eventStore, _snapShotRepo);
 }
Esempio n. 6
0
 public HandlerTests()
 {
     _queueService = new MemoryQueueService();
     _appendOnly   = new MemoryAppendOnlyStore(_queueService);
     _eventStore   = new EventStore(_appendOnly);
     _snapShotRepo = new SnapshotRepository();
     _factory      = new AggregateFactory(_eventStore, _snapShotRepo);
 }
Esempio n. 7
0
        public EventStoreDB(IAppendOnlyStore store, ISerializer serializer)
        {
            Condition.Requires(store, "store").IsNotNull();
              Condition.Requires(serializer, "serializer").IsNotNull();

              AppendOnlyStore = store;
              Serializer = serializer;
        }
Esempio n. 8
0
 public void Dispose()
 {
     _appendOnly   = null;
     _queueService = null;;
     _eventStore   = null;;
     _snapShotRepo = null;;
     _factory      = null;;
 }
Esempio n. 9
0
 protected override void SetUp()
 {
     base.SetUp();
     AppendOnlyStore = new SQLiteAppendOnlyStore(SetupFixture.SqlConnectionString, false);
     Serializer      = new TSerializer();
     EventStore      = new EventStoreDB(AppendOnlyStore, Serializer);
     Repository      = new GenericRepository <UserAccount, UserAccountState, UserAccountId>(EventStore);
     UserAccountApplicationService = new UserAccountApplicationService(EventStore, UserNameValidator);
 }
Esempio n. 10
0
 public ProjectionTests()
 {
     _resolver     = new MemoryResolver();
     _eventBus     = new MemoryEventBus(_resolver);
     _appendOnly   = new MemoryAppendOnlyStore(_eventBus);
     _eventStore   = new EventStore(_appendOnly, _eventBus);
     _snapShotRepo = new SnapshotRepository();
     _factory      = new AggregateFactory(_eventStore, _snapShotRepo);
 }
 protected override void SetUp()
 {
   base.SetUp();
   AppendOnlyStore = new SQLiteAppendOnlyStore(SetupFixture.SqlConnectionString, false);
   ISerializer serializer = new ProtoBufSerializer();
   Store = new EventStoreDB(AppendOnlyStore, serializer);
   Repository = new GenericRepository<Forum, ForumId>(Store);
   Service = new ForumApplicationService(Store);
 }
Esempio n. 12
0
        public EventStore(IAppendOnlyStore appendOnlyStore)
        {
            if (appendOnlyStore == null)
            {
                throw new ArgumentNullException("appendOnlyStore");
            }

            this.Formatter       = new BinaryFormatterSerializer();
            this.AppendOnlyStore = appendOnlyStore;
        }
Esempio n. 13
0
        public EventStore(IAppendOnlyStore appendOnlyStore, IEventSerializer serializer)
        {
            if (appendOnlyStore == null)
            {
                throw new ArgumentNullException("appendOnlyStore");
            }

            this.Formatter       = serializer;
            this.AppendOnlyStore = appendOnlyStore;
        }
        public static void SetAppendOnlyStore(EventStoreConfiguration cfg, IAppendOnlyStore store)
        {
            if (cfg.ContainsKey(AppendOnlyStore_SettingsKey))
            throw new InvalidOperationException("You should not configure append-only back-end store for event store twice.");

              Condition.Requires(cfg, "cfg").IsNotNull();
              Condition.Requires(store, "store").IsNotNull();
              cfg.Set(AppendOnlyStore_SettingsKey, store);
              Logger.DebugFormat("Using {0} as storage engine for EventStore", store);
        }
Esempio n. 15
0
        public static void Main(string[] args)
        {
            AbstractSerializer.RegisterKnownType(typeof(UserCreatedEvent));

            // Create serializers after registering known types
            ISerializer[] Serializers =
            {
                new DataContractSerializer(),
                new ProtoBufSerializer(),
                new BsonNetSerializer(),
                new JsonNetSerializer()
            };

            foreach (Func <IAppendOnlyStore> aStoreBuilder in AppendOnlyStores)
            {
                foreach (ISerializer serializer in Serializers)
                {
                    UserId        id     = new UserId(1);
                    List <IEvent> events = new List <IEvent>()
                    {
                        new UserCreatedEvent(id, "John")
                    };

                    IAppendOnlyStore aStore = aStoreBuilder();
                    try
                    {
                        EventStoreDB eStore = new EventStoreDB(aStore, serializer);
                        eStore.Append(id, 0, events);

                        // Warm up various caches
                        for (int i = 0; i < 10; ++i)
                        {
                            EventStream s = eStore.Load(id);
                            eStore.Append(id, s.Version, events);
                        }

                        int      count = 0;
                        DateTime t1    = DateTime.Now;
                        do
                        {
                            id = new UserId(100 + count);
                            //EventStream s = eStore.Load(id);
                            eStore.Append(id, 0, new IEvent[] { new UserCreatedEvent(id, "John") });
                            ++count;
                        }while ((DateTime.Now - t1) < TimeSpan.FromMilliseconds(1000));

                        Console.WriteLine("{0} + {1}: {2}", aStore, serializer, count);
                    }
                    finally
                    {
                        aStore.Dispose();
                    }
                }
            }
        }
Esempio n. 16
0
        public EventStorePublisher(
			IAppendOnlyStore store,
			EventStoreConfig config,
			ICheckpointWriter checkpoint,
			string streamName
			)
        {
            _store = store;
            _config = config;
            _checkpoint = checkpoint;
            _streamName = streamName;
        }
Esempio n. 17
0
 public EventStorePublisher(
     IAppendOnlyStore store,
     EventStoreConfig config,
     ICheckpointWriter checkpoint,
     string streamName
     )
 {
     _store      = store;
     _config     = config;
     _checkpoint = checkpoint;
     _streamName = streamName;
 }
        public static void SetAppendOnlyStore(EventStoreConfiguration cfg, IAppendOnlyStore store)
        {
            if (cfg.ContainsKey(AppendOnlyStore_SettingsKey))
            {
                throw new InvalidOperationException("You should not configure append-only back-end store for event store twice.");
            }

            Condition.Requires(cfg, "cfg").IsNotNull();
            Condition.Requires(store, "store").IsNotNull();
            cfg.Set(AppendOnlyStore_SettingsKey, store);
            Logger.DebugFormat("Using {0} as storage engine for EventStore", store);
        }
Esempio n. 19
0
        /// <summary>
        /// Add events to an existing appender, events in order will be serialized as a single bytestream.
        /// </summary>
        /// <param name="dest">appender</param>
        /// <param name="source">events to add</param>
        /// <paramref name="serializer">serializer, default binary</paramref>
        public static void AddEvents(this IAppendOnlyStore dest, IEnumerable <IEvent> source, IEventSerializer serializer = null)
        {
            if (dest == null)
            {
                throw new ArgumentNullException("dest");
            }
            if (source == null)
            {
                throw new ArgumentNullException("source");
            }

            var es = new EventStore.EventStore(dest, serializer ?? new BinaryFormatterSerializer());

            var events = source as IEvent[] ?? source.ToArray();

            var versions = new Dictionary <IIdentity, int>();

            List <IEvent> stack = new List <IEvent>();


            Action savestack = () =>
            {
                if (!versions.ContainsKey(stack[0].AggregateId))
                {
                    versions[stack[0].AggregateId] = 0;
                }

                es.AppendToStream(stack[0].AggregateId, versions[stack[0].AggregateId], stack);
                versions[stack[0].AggregateId]++;
                stack.Clear();
            };

            if (events.Any())
            {
                IIdentity lastid = null;

                foreach (var e in events)
                {
                    if (stack.Any() && !lastid.Equals(e.AggregateId))
                    {
                        savestack();
                    }
                    //else
                    {
                        stack.Add(e);
                        lastid = e.AggregateId;
                    }
                }
            }

            savestack();
        }
Esempio n. 20
0
 public void Handle(SystemMessage.Init message)
 {
     Log.Info("Storage starting");
     try
     {
         _store = _func();
         _publisher.Publish(new SystemMessage.StorageWriterInitializationDone());
     }
     catch (Exception ex)
     {
         Application.Exit(ExitCode.Error, "Failed to initialize store: " + ex.Message);
     }
 }
Esempio n. 21
0
        public EventStore(IAppendOnlyStore appendOnlyStore)
        {
            this.appendOnlyStore = appendOnlyStore;

            //this.hubConnectionBuilder = hubConnectionBuilder;

            var hubConnectionBuilder = new HubConnectionBuilder();

            connection = hubConnectionBuilder.WithUrl("https://localhost:5001/events").Build();

            connection.On <string, DateTime, byte[], long>("Append", Append);

            connection.StartAsync();
        }
        public static async Task CopyAppender(this IAppendOnlyAsync to, IAppendOnlyStore @from)
        {
            var records = @from.ReadRecords(0, int.MaxValue);

            var versions = new Dictionary <string, int>();

            foreach (var record in records)
            {
                if (!versions.ContainsKey(record.Name))
                {
                    versions[record.Name] = 0;
                }

                await to.Append(record.Name, record.Data, versions[record.Name]);

                versions[record.Name]++;
            }
        }
Esempio n. 23
0
        static void TestLoad(object o)
        {
            TestLoadData data = (TestLoadData)o;

            IAppendOnlyStore appendOnlyStore = data.Store;
            {
                ISerializer  serializer = new JsonNetSerializer();
                EventStoreDB store      = new EventStoreDB(appendOnlyStore, serializer);

                UserId      id = new UserId(data.N);
                EventStream s  = store.Load(id);
                System.Threading.Thread.Sleep(Rand.GetInts(100, 500, 1)[0]);
                Assert.AreEqual(s.Version, 0);
                List <IEvent> events = new List <IEvent>()
                {
                    new UserCreatedEvent(id, "John")
                };
                store.Append(id, 0, events);
            }
        }
        /// <summary>
        /// No more configuration needed for event store - now configure something else or start event store.
        /// </summary>
        /// <param name="cfg"></param>
        /// <returns></returns>
        public static BaseConfiguration Done(this EventStoreConfiguration cfg)
        {
            IAppendOnlyStore aStore            = cfg.Get <IAppendOnlyStore>(AppendOnlyStore_SettingsKey);
            ISerializer      messageSerializer = cfg.Get <ISerializer>(MessageSerializer_SettingsKey);

            if (aStore == null)
            {
                throw new InvalidOperationException("Mising storage mechanism (IAppendOnlyStore) for event store.");
            }
            if (messageSerializer == null)
            {
                throw new InvalidOperationException("Missing event serializer for event store.");
            }

            EventStoreDB eStore = new EventStoreDB(aStore, messageSerializer);

            cfg.Set(EventStoreDB_SettingsKey, eStore);

            IObjectContainer container = Xyperico.Agres.Configuration.ObjectContainerConfigurationExtensions.GetObjectContainer(cfg);

            container.RegisterInstance <IEventStore>(eStore);

            return(new BaseConfiguration(cfg));
        }
Esempio n. 25
0
 public static void CopyAppender(this IAppendOnlyStore source, IAppendOnlyStore to)
 {
     CopyAppender(source, to, int.MaxValue);
 }
Esempio n. 26
0
 public EventStore(IAppendOnlyStore <Guid> appendOnlyStore)
 {
     _appendOnlyStore = appendOnlyStore;
 }
Esempio n. 27
0
 public void WithAppendOnlyStore(IAppendOnlyStore appendOnlyStore)
 {
     Settings.AppendOnlyStore = appendOnlyStore;
 }
 public SagaEventStore(IAppendOnlyStore appendOnlyStore)
     : base(appendOnlyStore)
 {
 }
Esempio n. 29
0
 public EventStore(IAppendOnlyStore <Guid> appendOnlyStore, IEventBus eventBus)
 {
     _appendOnlyStore = appendOnlyStore;
     _eventBus        = eventBus;
 }
 public SerializingAppendOnlyStore(IAppendOnlyStore appendOnlyStore, IStoreSerializer serializer)
 {
     _appendOnlyStore = appendOnlyStore;
     _serializer      = serializer;
 }
Esempio n. 31
0
 public EventStoreForwarder(IAppendOnlyStore appendOnlyStore, Action <IEvent> forward = null)
     : base(appendOnlyStore)
 {
     this.Forward = forward;
 }
Esempio n. 32
0
 public EventStore(IAppendOnlyStore appendOnlyStore)
 {
     _appendOnlyStore = appendOnlyStore;
 }
Esempio n. 33
0
 public MessageStore(IAppendOnlyStore appendOnlyStore)
 {
     _appendOnlyStore = appendOnlyStore;
 }
 public SerializingAppendOnlyStore(IAppendOnlyStore appendOnlyStore, IStoreSerializer serializer)
 {
     _appendOnlyStore = appendOnlyStore;
     _serializer = serializer;
 }
Esempio n. 35
0
 public MessageStore(IAppendOnlyStore appendOnlyStore, IMessageSerializer serializer)
 {
     _appendOnlyStore = appendOnlyStore;
     _serializer      = serializer;
 }
 public static void CopyAppender(this IAppendOnlyStore source, IAppendOnlyStore to)
 {
     CopyAppender(source, to, int.MaxValue);
 }
Esempio n. 37
0
 public MessageStore(IAppendOnlyStore appendOnlyStore, IMessageSerializer serializer)
 {
     _appendOnlyStore = appendOnlyStore;
     _serializer = serializer;
 }
Esempio n. 38
0
 public EventHub(IAppendOnlyStore appendOnlyStore)
 {
     this.appendOnlyStore = appendOnlyStore;
 }
Esempio n. 39
0
 public EventStore(IAppendOnlyStore appendOnlyStore, IMessaging messaging)
 {
     _appendOnlyStore = appendOnlyStore;
     _messaging       = messaging;
 }
Esempio n. 40
0
 public EventStore(IAppendOnlyStore appendOnlyStore)
 {
     _appendOnlyStore = appendOnlyStore;
 }
Esempio n. 41
0
 public EventStore CopyAndVersion(IAppendOnlyStore to, int version)
 {
     this.AppendOnlyStore.CopyAppender(to, version);
     return(new EventStore(to));
 }