private void HandleNewEvent(object sender, OrderedEvent ev) { if (eventSubscriptions.TryGetValue(ev.Event.GetType(), out var subscriptionsList)) { var subscription = subscriptionsList.FirstOrDefault(x => x.Predicate == null || (bool)x.Predicate.DynamicInvoke(ev.Event)); if (subscription == null) { return; } lock (eventReceivedLock) { incommingEventQueue?.Enqueue(new Tuple <Delegate, IEvent>(subscription.WhenAction, ev.Event)); if (whenActionToExecute == null) { whenActionToExecute = subscription.WhenAction; receivedEvent = ev; } eventReceivedEvent.Set(); } } }
public void Publish(IEvent ev) { OrderedEvent orderedEvent; lock (sourceLock) { var id = GenerateId(); orderedEvent = new OrderedEvent(id, ev); events.AddLast(orderedEvent); LastEventId = id; counter++; if (counter >= MaxEventCount) { events.RemoveFirst(); counter--; } } NewEventReceived?.Invoke(this, orderedEvent); }