2022-01-04 08:42:12 +00:00
|
|
|
using Elsa.Activities.Console;
|
|
|
|
|
using Elsa.Activities.ControlFlow;
|
|
|
|
|
using Elsa.Activities.Workflows;
|
|
|
|
|
using Elsa.Api.Extensions;
|
|
|
|
|
using Elsa.Extensions;
|
|
|
|
|
using Elsa.Management.Contracts;
|
|
|
|
|
using Elsa.Management.Extensions;
|
|
|
|
|
using Elsa.Mediator.Extensions;
|
2022-02-21 15:13:55 +00:00
|
|
|
using Elsa.Modules.AzureServiceBus.Activities;
|
|
|
|
|
using Elsa.Modules.AzureServiceBus.Extensions;
|
2022-02-01 19:45:11 +00:00
|
|
|
using Elsa.Modules.Http;
|
|
|
|
|
using Elsa.Modules.Http.Extensions;
|
2022-03-07 14:42:23 +00:00
|
|
|
using Elsa.Modules.JavaScript.Activities;
|
2022-01-14 12:54:17 +00:00
|
|
|
using Elsa.Modules.Quartz.Services;
|
2022-02-01 19:45:11 +00:00
|
|
|
using Elsa.Modules.Scheduling.Activities;
|
|
|
|
|
using Elsa.Modules.Scheduling.Extensions;
|
|
|
|
|
using Elsa.Modules.Scheduling.Triggers;
|
2022-01-04 08:42:12 +00:00
|
|
|
using Elsa.Persistence.EntityFrameworkCore.Extensions;
|
|
|
|
|
using Elsa.Persistence.EntityFrameworkCore.Sqlite;
|
|
|
|
|
using Elsa.Pipelines.WorkflowExecution.Components;
|
2022-03-04 20:42:27 +00:00
|
|
|
using Elsa.Runtime.Extensions;
|
2022-01-04 08:42:12 +00:00
|
|
|
using Elsa.Runtime.ProtoActor.Extensions;
|
|
|
|
|
using Elsa.Samples.Web1.Activities;
|
|
|
|
|
using Elsa.Samples.Web1.Workflows;
|
2022-01-18 11:39:05 +00:00
|
|
|
using Elsa.Scheduling.Extensions;
|
2022-01-12 10:15:07 +00:00
|
|
|
using Elsa.Scripting.JavaScript.Extensions;
|
2022-01-12 11:37:40 +00:00
|
|
|
using Elsa.Scripting.Liquid.Extensions;
|
2022-01-04 08:42:12 +00:00
|
|
|
using Microsoft.AspNetCore.Builder;
|
2022-02-21 15:13:55 +00:00
|
|
|
using Microsoft.Extensions.Configuration;
|
2022-01-04 08:42:12 +00:00
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
using Microsoft.Extensions.Hosting;
|
|
|
|
|
|
|
|
|
|
var builder = WebApplication.CreateBuilder(args);
|
|
|
|
|
|
|
|
|
|
var services = builder.Services;
|
2022-02-21 15:13:55 +00:00
|
|
|
var configuration = builder.Configuration;
|
2022-01-04 08:42:12 +00:00
|
|
|
|
|
|
|
|
// Add services.
|
|
|
|
|
services
|
|
|
|
|
.AddElsa()
|
|
|
|
|
.AddMediator()
|
|
|
|
|
.AddEntityFrameworkCorePersistence((_, ef) => ef.UseSqlite())
|
2022-01-18 19:28:48 +00:00
|
|
|
.AddProtoActorWorkflowHost()
|
2022-01-04 08:42:12 +00:00
|
|
|
.IndexWorkflowTriggers()
|
|
|
|
|
.AddElsaManagement()
|
2022-01-18 11:39:05 +00:00
|
|
|
.AddScheduling(new QuartzSchedulingServiceProvider())
|
2022-01-04 08:42:12 +00:00
|
|
|
.AddHttpActivityServices()
|
2022-01-18 11:39:05 +00:00
|
|
|
.AddSchedulingActivities()
|
2022-02-21 15:13:55 +00:00
|
|
|
.AddAzureServiceBusServices(options => configuration.GetSection("AzureServiceBus").Bind(options))
|
2022-01-04 08:42:12 +00:00
|
|
|
.ConfigureWorkflowRuntime(options =>
|
|
|
|
|
{
|
2022-02-22 11:51:59 +00:00
|
|
|
// Register workflows.
|
|
|
|
|
options.Workflows.Add(nameof(HelloWorldWorkflow), new HelloWorldWorkflow());
|
|
|
|
|
options.Workflows.Add(nameof(HttpWorkflow), new HttpWorkflow());
|
|
|
|
|
options.Workflows.Add(nameof(ForkedHttpWorkflow), new ForkedHttpWorkflow());
|
2022-01-04 08:42:12 +00:00
|
|
|
options.Workflows.Add(nameof(CompositeActivitiesWorkflow), new CompositeActivitiesWorkflow());
|
2022-02-22 11:51:59 +00:00
|
|
|
options.Workflows.Add(nameof(SendMessageWorkflow), new SendMessageWorkflow());
|
|
|
|
|
options.Workflows.Add(nameof(ReceiveMessageWorkflow), new ReceiveMessageWorkflow());
|
2022-03-07 14:42:23 +00:00
|
|
|
options.Workflows.Add(nameof(RunJavaScriptWorkflow), new RunJavaScriptWorkflow());
|
2022-01-04 08:42:12 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Testing only: allow client app to connect from anywhere.
|
|
|
|
|
services.AddCors(cors => cors.AddDefaultPolicy(policy => policy.AllowAnyHeader().AllowAnyMethod().AllowAnyOrigin()));
|
|
|
|
|
|
|
|
|
|
// Register available activities.
|
|
|
|
|
services
|
|
|
|
|
.AddActivity<WriteLine>()
|
|
|
|
|
.AddActivity<WriteLines>()
|
|
|
|
|
.AddActivity<ReadLine>()
|
|
|
|
|
.AddActivity<If>()
|
2022-03-07 11:01:27 +00:00
|
|
|
.AddActivity<HttpEndpoint>()
|
2022-01-13 21:38:01 +00:00
|
|
|
.AddActivity<Flowchart>()
|
2022-01-18 17:24:52 +00:00
|
|
|
.AddActivity<Delay>()
|
2022-03-04 20:42:27 +00:00
|
|
|
.AddActivity<Timer>()
|
2022-01-18 21:37:14 +00:00
|
|
|
.AddActivity<ForEach>()
|
|
|
|
|
.AddActivity<Switch>()
|
2022-02-22 11:51:59 +00:00
|
|
|
.AddActivity<SendMessage>()
|
2022-03-07 14:42:23 +00:00
|
|
|
.AddActivity<RunJavaScript>()
|
2022-01-13 21:38:01 +00:00
|
|
|
;
|
2022-01-04 08:42:12 +00:00
|
|
|
|
2022-01-11 12:28:21 +00:00
|
|
|
// Register scripting languages.
|
2022-01-12 11:37:40 +00:00
|
|
|
services
|
|
|
|
|
.AddJavaScriptExpressions()
|
|
|
|
|
.AddLiquidExpressions();
|
2022-01-11 12:28:21 +00:00
|
|
|
|
2022-01-04 08:42:12 +00:00
|
|
|
// Configure middleware pipeline.
|
|
|
|
|
var app = builder.Build();
|
|
|
|
|
var serviceProvider = app.Services;
|
|
|
|
|
|
|
|
|
|
// Add type aliases for prettier JSON serialization.
|
|
|
|
|
var wellKnownTypeRegistry = serviceProvider.GetRequiredService<IWellKnownTypeRegistry>();
|
|
|
|
|
wellKnownTypeRegistry.RegisterType<int>("int");
|
|
|
|
|
wellKnownTypeRegistry.RegisterType<float>("float");
|
|
|
|
|
wellKnownTypeRegistry.RegisterType<bool>("boolean");
|
|
|
|
|
wellKnownTypeRegistry.RegisterType<string>("string");
|
|
|
|
|
|
|
|
|
|
// Configure workflow engine execution pipeline.
|
2022-03-04 20:42:27 +00:00
|
|
|
serviceProvider.ConfigureDefaultWorkflowExecutionPipeline(pipeline =>
|
|
|
|
|
pipeline
|
|
|
|
|
.UseWorkflowExecutionEvents()
|
|
|
|
|
.UseWorkflowExecutionLogPersistence()
|
|
|
|
|
.UsePersistence()
|
|
|
|
|
.UseActivityScheduler()
|
2022-01-04 08:42:12 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if (app.Environment.IsDevelopment())
|
|
|
|
|
app.UseDeveloperExceptionPage();
|
|
|
|
|
|
|
|
|
|
// CORS.
|
|
|
|
|
app.UseCors();
|
|
|
|
|
|
|
|
|
|
// Root.
|
|
|
|
|
app.MapGet("/", () => "Hello World!");
|
|
|
|
|
|
|
|
|
|
// Map Elsa API endpoints.
|
|
|
|
|
app.MapElsaApiEndpoints();
|
|
|
|
|
|
|
|
|
|
// Register Elsa middleware.
|
|
|
|
|
app.UseJsonSerializationErrorHandler();
|
|
|
|
|
app.UseHttpActivities();
|
|
|
|
|
|
|
|
|
|
// Run.
|
|
|
|
|
app.Run();
|