/// <summary> /// Append an event onto the event stream /// </summary> /// <param name="eventToAppend"> /// The event we want to write to the event stream /// </param> /// <param name="expectedTopSequence"> /// The sequence number we expect to be the last in the event stream - if events have been added since this then a /// concurrency error is thrown /// </param> public async Task AppendEvent(object eventToAppend, int?expectedTopSequence = null, EventStreamExistenceConstraint streamConstraint = EventStreamExistenceConstraint.Loose) { if (null != _writer) { // make an event instance of this event and append it to the event stream IAppendResult result = await _writer.AppendEvent(EventInstance.Wrap(eventToAppend), expectedTopSequence.GetValueOrDefault(0), streamConstraint : streamConstraint); if (null != result) { if (null != this._notificationDispatcher) { if (result.NewEventStreamCreated) { await _notificationDispatcher.NewEntityCreated(this, commentary : _context?.Commentary, context : _context); } await _notificationDispatcher.NewEventAppended(this, EventNameAttribute.GetEventName(eventToAppend.GetType()), result.SequenceNumber, commentary : _context?.Commentary, eventPayload : eventToAppend, context : _context); } } } }
public ProjectionBase() { // Wire up any explicit event handlers by dictionary foreach (var interfaceImplementation in GetType().GetInterfaces()) { if (interfaceImplementation.Name.StartsWith("IHandleEventType")) { Type eventArgumentType = interfaceImplementation.GetGenericArguments()[0]; string eventName = EventNameAttribute.GetEventName(eventArgumentType); System.Reflection.MethodInfo miEvent = interfaceImplementation.GetMethods()[0]; // add these to our internal dicttionary if (!typedEventHandlers.ContainsKey(eventName)) { typedEventHandlers.Add(eventName, new Tuple <Type, System.Reflection.MethodInfo> (eventArgumentType, miEvent)); } } } }