예제 #1
0
 public EventStore(MessageStore store)
 {
     _store = store;
 }
예제 #2
0
        // public static method we call on startup to setup our simple console environment and to wire things up
        public static ConsoleEnvironment Build()
        {
            var log = LogManager.GetloggerFor<ConsoleEnvironment>();

            var integrationPath = AzureSettingsProvider.GetStringOrThrow(Conventions.StorageConfigName);

            if (integrationPath.StartsWith("file:"))
            {
                var path = integrationPath.Remove(0, 5);

                //log.Info("*Using store : {0}", path);

                var config = FileStorage.CreateConfig(path);
                Streaming = config.CreateStreaming();
                //setup.DocumentStoreFactory = config.CreateDocumentStore;
                //setup.QueueReaderFactory = s => config.CreateInbox(s, DecayEvil.BuildExponentialDecay(500));
                //setup.QueueWriterFactory = config.CreateQueueWriter;
                AppendOnlyStoreFactory = config.CreateAppendOnlyStore;

            //                setup.ConfigureQueues(1, 1);

            //                return env.Build();
            }

            // The SynchronousEventHandler class keeps event handling simple without queues for now.
            var eventHandler = new SynchronousEventHandler();

            var inbox = new ConsoleProjection();
            eventHandler.RegisterHandler(inbox);

            log.Debug("[good]: Creating AppendOnlyStore {0} ", DateTime.Now);

            var appendOnlyStore = AppendOnlyStoreFactory(SeismicEventContainer);
            //var appendOnlyStore = new GregYoungAppendOnlyStore(IPAddress.Parse("192.168.1.18"), 1113);
            //var appendOnlyStore = new SqlServerAppendOnlyStore("shale-domain");

            var messageStore = new MessageStore(appendOnlyStore, Streamer.MessageSerializer);
            var eventStore = new EventStore(messageStore);

            log.Debug("[good]: Done creating AppendOnlyStore {0} ", DateTime.Now);

            //messageStore.LoadDataContractsFromAssemblyOf(typeof(DrillShotPoints));
            var currentVersion = appendOnlyStore.GetCurrentVersion();

            if (currentVersion < 1)
            {
                log.Debug("Event Stream ver {0}. Drilling Department has no Event history yet", currentVersion);
            }

            if (currentVersion > 0)
            {
                log.Debug("Running in-memory replay of all Events that have ever happened to the Drilling Department");
                log.Debug("Event Stream ver {0} is what your Drilling Department is becoming aware of...", currentVersion);

                foreach (var record in messageStore.EnumerateAllItems(0, int.MaxValue))
                {
                    foreach (var item in record.Items.OfType<Event>())
                    {
                        eventHandler.Handle(item);
                    }
                }
                log.Debug("Event Replay complete");
            }

            // In non-demo environments we usually want Application Services decoupled from Projections
            // but we will not worry about that now for this simple example.
            // Application Service (Command message handler) - get app service ready to respond to Command messages
            var drillingDepartmentAppSvc = new DrillingDepartmentApplicationService(eventStore, new RealTimeProvider());

            var build = new ConsoleEnvironment
                {
                    Store = eventStore,
                    DrillingDepartmentAppService = drillingDepartmentAppSvc,
                    Commands = ConsoleCommands.Actions,
                    Session = new ConsoleSession(inbox.ViewInstance),
                    ConsoleView = inbox.ViewInstance
                };
            return build;
        }