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)); }
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; } }
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); }