2022-04-09 20:15:48 +00:00
|
|
|
using System;
|
|
|
|
|
using System.Text.Json;
|
2022-03-22 13:33:15 +00:00
|
|
|
using Elsa.Activities;
|
2022-01-04 08:42:12 +00:00
|
|
|
using Elsa.Api.Extensions;
|
2022-04-09 20:15:48 +00:00
|
|
|
using Elsa.Contracts;
|
2022-01-04 08:42:12 +00:00
|
|
|
using Elsa.Extensions;
|
2022-03-07 21:56:16 +00:00
|
|
|
using Elsa.Jobs.Extensions;
|
2022-01-04 08:42:12 +00:00
|
|
|
using Elsa.Management.Extensions;
|
2022-04-09 20:15:48 +00:00
|
|
|
using Elsa.Modules.Activities.Configurators;
|
2022-04-20 19:06:39 +00:00
|
|
|
using Elsa.Modules.Activities.Console;
|
|
|
|
|
using Elsa.Modules.Activities.Workflows;
|
2022-02-21 15:13:55 +00:00
|
|
|
using Elsa.Modules.AzureServiceBus.Activities;
|
|
|
|
|
using Elsa.Modules.AzureServiceBus.Extensions;
|
2022-03-08 11:59:35 +00:00
|
|
|
using Elsa.Modules.Hangfire.Services;
|
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;
|
2022-04-09 20:15:48 +00:00
|
|
|
using Elsa.Modules.Scheduling.Extensions;
|
2022-03-08 13:40:47 +00:00
|
|
|
using Elsa.Modules.WorkflowContexts.Extensions;
|
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;
|
2022-04-09 20:15:48 +00:00
|
|
|
using Elsa.Samples.Web1.Models;
|
|
|
|
|
using Elsa.Samples.Web1.Serialization;
|
2022-01-04 08:42:12 +00:00
|
|
|
using Elsa.Samples.Web1.Workflows;
|
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-04-09 20:15:48 +00:00
|
|
|
using Elsa.Serialization;
|
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
|
|
|
|
2022-03-21 10:41:27 +00:00
|
|
|
// Run the SqlServer container from docker-compose.yml to start a SQL Server container.
|
|
|
|
|
var sqlServerConnectionString = configuration.GetConnectionString("SqlServer");
|
|
|
|
|
|
2022-01-04 08:42:12 +00:00
|
|
|
// Add services.
|
|
|
|
|
services
|
|
|
|
|
.AddElsa()
|
|
|
|
|
.AddEntityFrameworkCorePersistence((_, ef) => ef.UseSqlite())
|
2022-01-18 19:28:48 +00:00
|
|
|
.AddProtoActorWorkflowHost()
|
2022-01-04 08:42:12 +00:00
|
|
|
.IndexWorkflowTriggers()
|
|
|
|
|
.AddElsaManagement()
|
2022-03-21 10:41:27 +00:00
|
|
|
.AddJobServices(new QuartzJobSchedulerProvider(), new HangfireJobQueueProvider(sqlServerConnectionString))
|
2022-04-09 20:15:48 +00:00
|
|
|
.AddSchedulingServices()
|
2022-01-04 08:42:12 +00:00
|
|
|
.AddHttpActivityServices()
|
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.
|
2022-04-04 14:00:31 +00:00
|
|
|
options.Workflows.Add<HelloWorldWorkflow>();
|
2022-04-09 20:15:48 +00:00
|
|
|
//options.Workflows.Add<HeartbeatWorkflow>();
|
2022-04-04 14:00:31 +00:00
|
|
|
options.Workflows.Add<HttpWorkflow>();
|
|
|
|
|
options.Workflows.Add<ForkedHttpWorkflow>();
|
|
|
|
|
options.Workflows.Add<CompositeActivitiesWorkflow>();
|
|
|
|
|
options.Workflows.Add<SendMessageWorkflow>();
|
|
|
|
|
options.Workflows.Add<ReceiveMessageWorkflow>();
|
|
|
|
|
options.Workflows.Add<RunJavaScriptWorkflow>();
|
|
|
|
|
options.Workflows.Add<WorkflowContextsWorkflow>();
|
|
|
|
|
options.Workflows.Add<SubmitJobWorkflow>();
|
2022-04-09 20:15:48 +00:00
|
|
|
options.Workflows.Add<DelayWorkflow>();
|
|
|
|
|
options.Workflows.Add<OrderProcessingWorkflow>();
|
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()));
|
|
|
|
|
|
2022-04-04 14:00:31 +00:00
|
|
|
// Register activities available from the designer.
|
2022-01-04 08:42:12 +00:00
|
|
|
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-04-09 20:15:48 +00:00
|
|
|
// Register serialization configurator for configuring what types to allow to be serialized.
|
|
|
|
|
services.AddSingleton<ISerializationOptionsConfigurator, CustomSerializationOptionConfigurator>();
|
|
|
|
|
services.AddSingleton<ISerializationOptionsConfigurator, SerializationOptionsConfigurator>();
|
|
|
|
|
|
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");
|
|
|
|
|
|
2022-04-09 20:15:48 +00:00
|
|
|
var order = new Order("order-1", 1, "customer-1", new[] { new OrderItem("product-i1", 2) });
|
|
|
|
|
var serializationOptions = serviceProvider.GetRequiredService<WorkflowSerializerOptionsProvider>().CreatePersistenceOptions();
|
|
|
|
|
var json = JsonSerializer.Serialize(order, serializationOptions);
|
|
|
|
|
Console.WriteLine(json);
|
|
|
|
|
|
2022-01-04 08:42:12 +00:00
|
|
|
// Configure workflow engine execution pipeline.
|
2022-03-04 20:42:27 +00:00
|
|
|
serviceProvider.ConfigureDefaultWorkflowExecutionPipeline(pipeline =>
|
|
|
|
|
pipeline
|
|
|
|
|
.UseWorkflowExecutionEvents()
|
|
|
|
|
.UseWorkflowExecutionLogPersistence()
|
|
|
|
|
.UsePersistence()
|
2022-03-08 13:40:47 +00:00
|
|
|
.UseWorkflowContexts()
|
2022-04-21 21:00:01 +00:00
|
|
|
.UseStackBasedActivityScheduler()
|
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();
|