* Refactor `IndexTriggersAsync` to use `WorkflowDefinition` and update null assignment for serialization logic. * Change default parameter value from `default` to `null` in `UseFluentStorageProvider` method signature. * Add in-memory workflows provider and materializer for integration tests Introduced `InMemoryWorkflowsProvider` and `InMemoryWorkflowMaterializer` to support integration testing scenarios for workflow definition population. Enhanced workflow handling with fluent method `WithId` for `WorkflowBuilder`. Updated event publishing and dependency injection logic. * Remove extraneous whitespace in DefaultWorkflowDefinitionStorePopulator. * Refine test class documentation for `WorkflowDefinitionStorePopulation` scenario.
45 lines
1.5 KiB
C#
45 lines
1.5 KiB
C#
using Elsa.Workflows.Helpers;
|
|
using Elsa.Workflows.Runtime.Activities;
|
|
using Elsa.Workflows.Runtime.Stimuli;
|
|
|
|
namespace Elsa.Workflows.Runtime;
|
|
|
|
/// <inheritdoc />
|
|
public class EventPublisher(IStimulusSender stimulusSender, IStimulusDispatcher stimulusDispatcher) : IEventPublisher
|
|
{
|
|
/// <inheritdoc />
|
|
public async Task PublishAsync(
|
|
string eventName,
|
|
string? correlationId = null,
|
|
string? workflowInstanceId = null,
|
|
string? activityInstanceId = null,
|
|
object? payload = null,
|
|
bool asynchronous = false,
|
|
CancellationToken cancellationToken = default)
|
|
{
|
|
var stimulus = new EventStimulus(eventName);
|
|
var workflowInput = new Dictionary<string, object>
|
|
{
|
|
[Event.EventInputWorkflowInputKey] = payload ?? new Dictionary<string, object>()
|
|
};
|
|
var metadata = new StimulusMetadata
|
|
{
|
|
CorrelationId = correlationId,
|
|
ActivityInstanceId = activityInstanceId,
|
|
WorkflowInstanceId = workflowInstanceId,
|
|
Input = workflowInput
|
|
};
|
|
var triggerName = ActivityTypeNameHelper.GenerateTypeName<Event>();
|
|
if (asynchronous)
|
|
{
|
|
await stimulusDispatcher.SendAsync(new()
|
|
{
|
|
ActivityTypeName = triggerName,
|
|
Stimulus = stimulus,
|
|
Metadata = metadata
|
|
}, cancellationToken);
|
|
}
|
|
else
|
|
await stimulusSender.SendAsync(triggerName, stimulus, metadata, cancellationToken);
|
|
}
|
|
} |