private Task <Transaction[]> LoadNextPageAsync()
        {
            return(Task.Run(() =>
            {
                var transactions = new List <Transaction>();

                Transaction transaction = null;

                string json;

                do
                {
                    json = CurrentReader.ReadLine();
                    if (json != null)
                    {
                        object @event = JsonConvert.DeserializeObject(json, new JsonSerializerSettings
                        {
                            TypeNameHandling = TypeNameHandling.All,
                            TypeNameAssemblyFormat = FormatterAssemblyStyle.Full
                        });

                        string streamId = ExtractStreamIdFrom(@event);
                        if (transaction != null && transaction.StreamId != streamId)
                        {
                            transaction = null;
                        }

                        if (transaction == null)
                        {
                            transaction = new Transaction
                            {
                                Id = Guid.NewGuid().ToString(),
                                TimeStampUtc = DateTime.UtcNow,
                                StreamId = streamId,
                                Checkpoint = lastCheckpoint++
                            };

                            transactions.Add(transaction);
                        }

                        transaction.Events.Add(new EventEnvelope
                        {
                            Body = @event
                        });
                    }
                }while ((json != null) && (transactions.Count < pageSize));

                Console.WriteLine(
                    $"Loaded page of {transactions.Count} transactions " +
                    $"(checkpoint {transactions.First().Checkpoint}-{transactions.Last().Checkpoint}) " +
                    $"with {transactions.Sum(t => t.Events.Count)} events");

                return transactions.ToArray();
            }));
        }
        private Task <Transaction[]> LoadNextPageAsync()
        {
            return(Task.Run(() =>
            {
                var transactions = new List <Transaction>();

                var transaction = new Transaction
                {
                    Checkpoint = ++lastCheckpoint
                };

                string json;

                do
                {
                    json = CurrentReader.ReadLine();

                    if (json != null)
                    {
                        try
                        {
                            transaction.Events.Add(new EventEnvelope
                            {
                                Body = JsonConvert.DeserializeObject(json, new JsonSerializerSettings
                                {
                                    TypeNameHandling = TypeNameHandling.All,
                                    TypeNameAssemblyFormatHandling = TypeNameAssemblyFormatHandling.Full
                                })
                            });
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine(e);
                            throw;
                        }
                    }

                    if ((transaction.Events.Count == AverageEventsPerTransaction) || (json == null))
                    {
                        if (transaction.Events.Count > 0)
                        {
                            transactions.Add(transaction);
                        }

                        transaction = new Transaction
                        {
                            Checkpoint = ++lastCheckpoint
                        };
                    }
                }while ((json != null) && (transactions.Count < pageSize));

                return transactions.ToArray();
            }));
        }