This change integrates the MyEvent activity into the Elsa Workflow engine configuration. It ensures that the MyEvent activity is available for workflows in the console application. This setup is essential for utilizing custom events within the application's workflow definitions.
41 lines
1.2 KiB
C#
41 lines
1.2 KiB
C#
using Elsa.Extensions;
|
|
using Elsa.Samples.ConsoleApp.Bookmarks.Activities;
|
|
using Elsa.Workflows.Activities;
|
|
using Elsa.Workflows.Contracts;
|
|
using Elsa.Workflows.Options;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
// Setup service container.
|
|
var services = new ServiceCollection();
|
|
|
|
// Add Elsa services.
|
|
services.AddElsa().AddActivity<MyEvent>();
|
|
|
|
// Build service container.
|
|
var serviceProvider = services.BuildServiceProvider();
|
|
|
|
// Resolve a workflow runner to run the workflow.
|
|
var workflowRunner = serviceProvider.GetRequiredService<IWorkflowRunner>();
|
|
|
|
// Create a workflow.
|
|
|
|
var workflow = new Workflow
|
|
{
|
|
Root = new Sequence
|
|
{
|
|
Activities =
|
|
{
|
|
new WriteLine("Hello World!"),
|
|
new MyEvent(), // Blocks until the event bookmark is resumed.
|
|
new WriteLine("Event received!")
|
|
}
|
|
}
|
|
};
|
|
|
|
// Run the workflow.
|
|
var result = await workflowRunner.RunAsync(workflow);
|
|
|
|
// Resume the workflow using te created bookmark.
|
|
var bookmark = result.WorkflowState.Bookmarks.Single();
|
|
var workflowState = result.WorkflowState;
|
|
await workflowRunner.RunAsync(workflow, workflowState, new RunWorkflowOptions { BookmarkId = bookmark.Id }); |