From 545df0ea5317367c045b47385f2c7e2b099aca80 Mon Sep 17 00:00:00 2001 From: MariusVuscanNx <96233009+MariusVuscanNx@users.noreply.github.com> Date: Thu, 22 Jun 2023 12:50:02 +0300 Subject: [PATCH] Publish event improvements (#4150) --- .../Activities/PublishEvent.cs | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/modules/Elsa.Workflows.Runtime/Activities/PublishEvent.cs b/src/modules/Elsa.Workflows.Runtime/Activities/PublishEvent.cs index f63488035..f77868e04 100644 --- a/src/modules/Elsa.Workflows.Runtime/Activities/PublishEvent.cs +++ b/src/modules/Elsa.Workflows.Runtime/Activities/PublishEvent.cs @@ -1,10 +1,10 @@ -using System.Runtime.CompilerServices; -using System.Text.Json.Serialization; using Elsa.Extensions; using Elsa.Workflows.Core.Attributes; using Elsa.Workflows.Core.Models; using Elsa.Workflows.Runtime.Contracts; using JetBrains.Annotations; +using System.Runtime.CompilerServices; +using System.Text.Json.Serialization; namespace Elsa.Workflows.Runtime.Activities; @@ -20,7 +20,7 @@ public class PublishEvent : Activity public PublishEvent() { } - + /// public PublishEvent([CallerFilePath] string? source = default, [CallerLineNumber] int? line = default) : base(source, line) { @@ -31,20 +31,28 @@ public class PublishEvent : Activity /// [Input(Description = "The name of the event to publish.")] public Input EventName { get; set; } = default!; - + /// /// The correlation ID to scope the event to. /// [Input(Description = "The correlation ID to scope the event to.")] public Input CorrelationId { get; set; } = default!; + /// + /// The input to send as the event body. + /// + [Input(Description = "The input to send as the event body.")] + public Input?> Input { get; set; } = default!; + /// protected override async ValueTask ExecuteAsync(ActivityExecutionContext context) { var eventName = EventName.Get(context); var correlationId = CorrelationId.GetOrDefault(context); + var input = Input.GetOrDefault(context); var publisher = context.GetRequiredService(); - await publisher.DispatchAsync(eventName, correlationId, cancellationToken: context.CancellationToken); + await publisher.DispatchAsync(eventName, correlationId, input: input, cancellationToken: context.CancellationToken); + await context.CompleteActivityAsync(); } } \ No newline at end of file