Example #1
0
            public async Task PublishEvents()
            {
                var streams = TripStream.RandomStreams(5);

                while (streams.Any())
                {
                    var count = 0;
                    using (var session = _store.LightweightSession())
                    {
                        foreach (var stream in streams.ToArray())
                        {
                            if (stream.TryCheckOutEvents(out var events))
                            {
                                count += events.Length;
                                session.Events.Append(stream.StreamId, events);
                            }

                            if (stream.IsFinishedPublishing())
                            {
                                streams.Remove(stream);
                            }
                        }

                        await session.SaveChangesAsync();

                        Console.WriteLine($"Wrote {count} events at {DateTime.Now.ToShortTimeString()}");
                    }
                }
            }
Example #2
0
        public async Task PublishEvents()
        {
            var streams = TripStream.RandomStreams(5);

            while (streams.Any())
            {
                var count   = 0;
                var options = SessionOptions.ForDatabase(_database);

                await using var session = _store.OpenSession(options);
                foreach (var stream in streams.ToArray())
                {
                    if (stream.TryCheckOutEvents(out var events))
                    {
                        count += events.Length;
                        session.Events.Append(stream.StreamId, events);
                    }

                    if (stream.IsFinishedPublishing())
                    {
                        streams.Remove(stream);
                    }
                }

                await session.SaveChangesAsync();

                _board.Update(_name, count);
            }
        }