예제 #1
0
        async Task INHibernateChildProjector.ProjectEvent(object anEvent, NHibernateProjectionContext context)
        {
            if (anEvent == null)
            {
                throw new ArgumentNullException(nameof(anEvent));
            }

            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            try
            {
                await mapConfigurator.ProjectEvent(anEvent, context).ConfigureAwait(false);
            }
            catch (ProjectionException projectionException)
            {
                if (string.IsNullOrEmpty(projectionException.ChildProjector))
                {
                    projectionException.ChildProjector = typeof(TProjection).ToString();
                }

                throw;
            }
            catch (Exception exception)
            {
                throw new ProjectionException("Projector failed to project an event.", exception)
                      {
                          ChildProjector = typeof(TProjection).ToString()
                      };
            }
        }
예제 #2
0
        private async Task ProjectTransaction(Transaction transaction, ISession session)
        {
            foreach (EventEnvelope eventEnvelope in transaction.Events)
            {
                var context = new NHibernateProjectionContext
                {
                    TransactionId      = transaction.Id,
                    Session            = session,
                    StreamId           = transaction.StreamId,
                    TimeStampUtc       = transaction.TimeStampUtc,
                    Checkpoint         = transaction.Checkpoint,
                    EventHeaders       = eventEnvelope.Headers,
                    TransactionHeaders = transaction.Headers
                };

                try
                {
                    await mapConfigurator.ProjectEvent(eventEnvelope.Body, context).ConfigureAwait(false);
                }
                catch (ProjectionException projectionException)
                {
                    projectionException.TransactionId = transaction.Id;
                    projectionException.CurrentEvent  = eventEnvelope;
                    throw;
                }
                catch (Exception exception)
                {
                    throw new ProjectionException("Projector failed to project an event.", exception)
                          {
                              TransactionId = transaction.Id,
                              CurrentEvent  = eventEnvelope
                          };
                }
            }
        }