public async Task Publish <TEvent>(TEvent @event, CancellationToken cancellationToken) where TEvent : IEvent { var handlers = _lifetimeScope.Resolve <IHandleEvent <TEvent>[]>(); foreach (var handler in handlers) { await handler.Handle(@event, cancellationToken); } EventPublished?.Invoke(this, new EventPublishedEventArgs(@event)); }
private async Task ProcessEventPublishedAsync(EventPublished eventPublished) { using var scope = _serviceProvider.CreateScope(); var repository = scope.ServiceProvider.GetRequiredService <IEventPublishedRepository>(); eventPublished.Publish(); await repository.UpdateAndCommit(eventPublished); await _eventBus.PublishAsync(eventPublished.Event); eventPublished.Complete(); await repository.UpdateAndCommit(eventPublished); }
protected async Task PublishEvent(string payload, IotDeviceEventPropertyCollection properties) { try { Message message = new Message(Encoding.ASCII.GetBytes(payload)); if (properties != null) { foreach (string key in properties.Keys) { message.Properties.Add(key, properties[key]); } } await _deviceClient.SendEventAsync(message); EventPublished?.Invoke(DeviceId, payload, properties); } catch (Exception exc) { int x = 0; } }
public void Should_not_publish_browser_communication_timeout_when_a_message_arrives_within_the_specified_timeout_period() { EventPublished.ShouldBeFalse(); }
public void Should_not_fire_the_comm_err_event_if_the_TestRunCompletedEvent_has_arrived() { EventPublished.ShouldBeFalse(); }
public void Should_publish_browser_communication_timeout() { EventPublished.ShouldBeTrue(); }
protected virtual void OnEventPublished() { // If event has subscribers EventPublished?.Invoke(this, EventArgs.Empty); }
/// <summary> /// Raises the event. /// </summary> /// <param name="payload">The object sent along with the event.</param> public void Publish(T payload) { EventPublished?.Invoke(payload); }
public async Task UpdateAndCommit(EventPublished eventPublished) { context.Set <EventPublished>().Update(eventPublished); await context.SaveChangesAsync(); }