/// <summary> Apply the specified event to the state. </summary>
        /// <remarks> The sequence number must be greater than <see cref="Sequence"/>. </remarks>
        public void Apply(uint seq, TEvent e)
        {
            if (seq <= Sequence)
            {
                throw new ArgumentException($"Event seq {seq} applied after seq {Sequence}", nameof(seq));
            }

            // Always update sequence, even if update fails.
            Sequence = seq;

            try
            {
                var newState = _projection.Apply(seq, e, Current);
                if (newState == null)
                {
                    throw new InvalidOperationException("Event generated a null state.");
                }

                Current = newState;
            }
            catch (Exception ex)
            {
                _log?.Warning($"[{Name}] error at seq {seq}", ex);

                _possiblyInconsistent = true;
                throw;
            }
        }
Beispiel #2
0
 public void Apply(IDocumentSession session, IReadOnlyList <StreamAction> streams)
 {
     _inner.Apply(session, new EventPage(streams.Select(x => x.ShimForOldProjections()).ToArray()));
 }