/// <summary> /// filter only 'not null' IDomainEvent(s) and range of required date is applied. /// </summary> /// <param name="globalPosition"></param> /// <param name="pageSize"></param> /// <param name="cancellationToken"></param> /// <returns></returns> public async Task <AllEventsPage> LoadAllEventsAsync( GlobalPosition globalPosition, int pageSize, CancellationToken cancellationToken) { try { if (pageSize <= 0) { throw new ArgumentOutOfRangeException(nameof(pageSize)); } var task = _eventPersistence.LoadAllCommittedEvents( globalPosition, pageSize, cancellationToken); var allCommittedEventsPage = task.Result; var exception = task.Exception; IEnumerable <ICommittedDomainEvent> committedDomainEvents = allCommittedEventsPage.CommittedDomainEvents.ToList(); var domainEvents = committedDomainEvents .Select(e => _eventJsonSerializer.Deserialize(e)).Where(e => e != null && (_dataRetrievalConfiguration.FromDate.HasValue && _dataRetrievalConfiguration.ToDate.HasValue && e.Timestamp.DateTime >= _dataRetrievalConfiguration.FromDate && e.Timestamp.DateTime <= _dataRetrievalConfiguration.ToDate || _dataRetrievalConfiguration.FromDate.HasValue && !_dataRetrievalConfiguration.ToDate.HasValue && e.Timestamp.DateTime >= _dataRetrievalConfiguration.FromDate || !_dataRetrievalConfiguration.FromDate.HasValue && _dataRetrievalConfiguration.ToDate.HasValue && e.Timestamp.DateTime <= _dataRetrievalConfiguration.ToDate || !_dataRetrievalConfiguration.FromDate.HasValue && !_dataRetrievalConfiguration.ToDate.HasValue)).ToList(); var domainEventsList = (IReadOnlyCollection <IDomainEvent>)domainEvents; domainEventsList = _eventUpgradeManager.Upgrade(domainEventsList); return(new AllEventsPage(allCommittedEventsPage.NextGlobalPosition, domainEventsList)); } catch (Exception exp) { _log.Error($"Exception : {exp.Message}"); return(null); } }
public async Task <AllEventsPage> LoadAllEventsAsync( GlobalPosition globalPosition, int pageSize, CancellationToken cancellationToken) { if (pageSize <= 0) { throw new ArgumentOutOfRangeException(nameof(pageSize)); } var allCommittedEventsPage = await _eventPersistence.LoadAllCommittedEvents( globalPosition, pageSize, cancellationToken) .ConfigureAwait(false); var domainEvents = (IReadOnlyCollection <IDomainEvent>)allCommittedEventsPage.CommittedDomainEvents .Select(e => _eventJsonSerializer.Deserialize(e)) .ToList(); domainEvents = _eventUpgradeManager.Upgrade(domainEvents); return(new AllEventsPage(allCommittedEventsPage.NextGlobalPosition, domainEvents)); }