コード例 #1
0
        static void Main(string[] args)
        {
            // Set up
            var connectionString =
                "Application Name=EventStore;Integrated Security=SSPI;Data Source=.\\SQL2008R2;Initial Catalog=temp_db";
            var databaseName = "EventStoreSample_" + DateTime.Now.ToString("yyyyMMddHHmmss");
            var serializationMethod = new XmlDataContractSerialization();

            var persistenceMethod = new SqlServer2008PersistenceMethod(connectionString, databaseName, serializationMethod);
            var eventStore = new EventStore(persistenceMethod);

            // Pre-generate some id's for our streams.
            var stream1Id = Guid.NewGuid();
            var stream2Id = Guid.NewGuid();

            // Write-only sample.
            using (var session = eventStore.NewSession())
            {
                // Adding an event to an event stream that doesn't exist implicitly creates the stream.
                session.AddEvent(stream1Id, new TheHelloWorldEvent("Hello World"));
                session.AddEvent(stream1Id, new TheHelloWorldEvent("Hello World Again"));
                session.AddEvent(stream2Id, new TheHelloWorldEvent("Hello World Again"));

                // Mark the session as successfully completed.
                session.Complete();

                // When the session is disposed, if it is marked as completed it will persist the events.
            }

            // Read-only model
            foreach (var eventStream in eventStore.GetAll())
            {
                WriteStreamToConsole(eventStream);
            }

            // Read & Write Sample
            using (var session = eventStore.NewSession())
            {
                var eventStream = session.GetById(stream1Id);
                WriteStreamToConsole(eventStream);
            }

            Console.WriteLine("Press any key to continue.");
            Console.ReadLine();
        }
コード例 #2
0
        static void Main(string[] args)
        {
            // Set up
            var persistenceMethod = new InMemoryPersistenceMethod();
            var eventStore = new EventStore(persistenceMethod);

            // Pre-generate some id's for our streams.
            var stream1Id = Guid.NewGuid();
            var stream2Id = Guid.NewGuid();

            // Write-only sample.
            using (var session = eventStore.NewSession())
            {
                // Adding an event to an event stream that doesn't exist implicitly creates the stream.
                session.AddEvent(stream1Id, new TheHelloWorldEvent("Hello World"));
                session.AddEvent(stream1Id, new TheHelloWorldEvent("Hello World Again"));
                session.AddEvent(stream2Id, new TheHelloWorldEvent("Hello World Again"));

                // Mark the session as successfully completed.
                session.Complete();

                // When the session is disposed, if it is marked as completed it will persist the events.
            }

            // Read-only model
            foreach (var eventStream in eventStore.GetAll())
            {
                WriteStreamToConsole(eventStream);
            }

            // Read & Write Sample
            using (var session = eventStore.NewSession())
            {
                var eventStream = session.GetById(stream1Id);
                WriteStreamToConsole(eventStream);
            }

            Console.WriteLine("Press any key to continue.");
            Console.ReadLine();
        }
コード例 #3
0
 public EventStoreSession(EventStore eventStore, IPersistenceSession persistenceSession)
 {
     this.Context = new ExpandoObject();
     this.eventStore = eventStore;
     this.persistenceSession = persistenceSession;
 }