PPPDDDChap23.EventSourcing.Application.Infrastructure.PayAsYouGoAccountRepository.FindBy C# (CSharp) Method

FindBy() public method

public FindBy ( System.Guid id ) : PayAsYouGoAccount
id System.Guid
return PPPDDDChap23.EventSourcing.Application.Model.PayAsYouGo.PayAsYouGoAccount
        public PayAsYouGoAccount FindBy(Guid id)
        {
            var streamName = string.Format("{0}-{1}", typeof(PayAsYouGoAccount).Name, id.ToString());

            // Check for snapshots

            var fromEventNumber = 0;
            var toEventNumber = int.MaxValue ;

            // pull back all events from snapshot
            var stream = _eventStore.GetStream(streamName, fromEventNumber, toEventNumber);

            var payAsYouGoAccount = new PayAsYouGoAccount();

            foreach(var @event in stream)
            {
                payAsYouGoAccount.Apply(@event);
            }

            return payAsYouGoAccount;            
        }

Usage Example

コード例 #1
0
        public void Run()
        {
            while(true)
            {
                foreach (var id in GetIds())
                {
                    using (var session = documentStore.OpenSession())
                    {
                        var repository = new PayAsYouGoAccountRepository(new EventStore(session));
                        var account = repository.FindBy(Guid.Parse(id));
                        var snapshot = account.GetPayAsYouGoAccountSnapshot();
                        repository.SaveSnapshot(snapshot, account);
                    }
                }

                // Create a new snapshot for each Aggregate every 12 hours
                Thread.Sleep(TimeSpan.FromHours(12));
            }
        }
All Usage Examples Of PPPDDDChap23.EventSourcing.Application.Infrastructure.PayAsYouGoAccountRepository::FindBy