Ejemplo n.º 1
0
        public void event_capture_and_show_inline_aggregation()
        {
            theStore = DocumentStore.For(_ =>
            {
                _.Connection(ConnectionSource.ConnectionString);
                _.Events.InlineProjections.AggregateStreamsWith <QuestParty>();
            });


            var started = new QuestStarted
            {
                Id   = Guid.NewGuid(),
                Name = "Escape Emond's Field"
            };

            var joined = new MembersJoined {
                Members = new[] { "Rand", "Matt", "Perrin", "Thom" }
            };
            var departed = new MembersDeparted {
                Members = new[] { "Thom" }
            };

            using (var session = theStore.LightweightSession())
            {
                session.Events.StartStream(started.Id, started, joined, departed);
                session.SaveChanges();
            }


            using (var session = theStore.LightweightSession())
            {
                session.Events.Append(started.Id, new MembersJoined {
                    Members = new string[] { "Moiraine", "Lan" }
                });
                session.SaveChanges();
            }


            // Aggregate Live
            using (var session = theStore.LightweightSession())
            {
                var party = session.Load <QuestParty>(started.Id);

                _output.WriteLine(JsonConvert.SerializeObject(party));
            }
        }
Ejemplo n.º 2
0
        public void event_capture_and_show_live_aggregation()
        {
            var started = new QuestStarted
            {
                Id   = Guid.NewGuid(),
                Name = "Escape Emond's Field"
            };

            var questId = started.Id;

            var joined = new MembersJoined {
                Members = new[] { "Rand", "Matt", "Perrin", "Thom" }, Day = 1
            };
            var departed = new MembersDeparted {
                Members = new[] { "Thom" }, Day = 5
            };

            using (var session = theStore.LightweightSession())
            {
                session.Events.StartStream(started.Id, started, joined, departed);
                session.SaveChanges();
            }


            using (var session = theStore.LightweightSession())
            {
                session.Events.Append(started.Id, new MembersJoined {
                    Members = new string[] { "Moiraine", "Lan" }, Day = 7
                });
                session.SaveChanges();
            }


            // Aggregate Live
            using (var session = theStore.LightweightSession())
            {
                var party = session.Events
                            .AggregateStream <QuestParty>(questId);

                _output.WriteLine(JsonConvert.SerializeObject(party));
            }
        }