public static EventStoreDB GetEventStoreDB(AbstractConfiguration cfg)
        {
            EventStoreDB eStore = cfg.Get <EventStoreDB>(EventStoreDB_SettingsKey);

            if (eStore == null)
            {
                throw new InvalidOperationException("Missing event store. Are you missing a call to Done() in the event store configuration code?");
            }
            return(eStore);
        }
Esempio n. 2
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();
              }
            }
              }
        }
        /// <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);
        }
        /// <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));
        }
        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);
              }
        }
        protected override void SetUp()
        {
            base.SetUp();

              // Get concrete implementation from inheriting test class
              AppendOnlyStore = BuildAppendOnlyStore();

              // Use a simple serializer that works for just about everything
              ISerializer serializer = new JsonNetSerializer();

              EventStore = new EventStoreDB(AppendOnlyStore, serializer);
        }