2022-12-31 15:16:43 +00:00
|
|
|
using Elsa.EntityFrameworkCore.Extensions;
|
2022-05-26 10:47:31 +00:00
|
|
|
using Elsa.Extensions;
|
|
|
|
|
using Elsa.Http;
|
2022-12-09 11:25:39 +00:00
|
|
|
using Elsa.Identity;
|
2022-08-31 13:47:10 +00:00
|
|
|
using Elsa.Identity.Options;
|
2022-05-26 10:47:31 +00:00
|
|
|
using Elsa.JavaScript.Activities;
|
2022-08-11 10:45:07 +00:00
|
|
|
using Elsa.Jobs.Activities.Implementations;
|
2022-10-27 10:05:30 +00:00
|
|
|
using Elsa.Jobs.Activities.Middleware.Activities;
|
2022-08-11 10:45:07 +00:00
|
|
|
using Elsa.Jobs.Activities.Services;
|
2022-12-30 12:11:29 +00:00
|
|
|
using Elsa.EntityFrameworkCore.Modules.ActivityDefinitions;
|
|
|
|
|
using Elsa.EntityFrameworkCore.Modules.Labels;
|
|
|
|
|
using Elsa.EntityFrameworkCore.Modules.Management;
|
|
|
|
|
using Elsa.EntityFrameworkCore.Modules.Runtime;
|
2023-01-01 17:02:38 +00:00
|
|
|
using Elsa.MassTransit.Options;
|
2022-09-04 15:04:14 +00:00
|
|
|
using Elsa.Requirements;
|
2022-12-30 12:11:29 +00:00
|
|
|
using Elsa.Scheduling.Activities;
|
2022-05-26 10:47:31 +00:00
|
|
|
using Elsa.Workflows.Core.Activities;
|
2022-12-26 17:38:30 +00:00
|
|
|
using Elsa.Workflows.Core.Middleware.Activities;
|
2022-10-27 10:05:30 +00:00
|
|
|
using Elsa.Workflows.Core.Middleware.Workflows;
|
2022-07-26 21:30:42 +00:00
|
|
|
using Elsa.Workflows.Management.Services;
|
2022-08-10 14:02:53 +00:00
|
|
|
using Elsa.WorkflowServer.Web.Jobs;
|
2022-08-31 13:47:10 +00:00
|
|
|
using Microsoft.AspNetCore.Authorization;
|
2022-05-26 10:47:31 +00:00
|
|
|
|
|
|
|
|
var builder = WebApplication.CreateBuilder(args);
|
|
|
|
|
var services = builder.Services;
|
2022-08-31 13:47:10 +00:00
|
|
|
var configuration = builder.Configuration;
|
2022-12-30 12:11:29 +00:00
|
|
|
var sqliteConnectionString = configuration.GetConnectionString("Sqlite")!;
|
2022-08-31 13:47:10 +00:00
|
|
|
var identityOptions = new IdentityOptions();
|
|
|
|
|
var identitySection = configuration.GetSection("Identity");
|
|
|
|
|
identitySection.Bind(identityOptions);
|
2023-01-01 17:02:38 +00:00
|
|
|
var rabbitMqOptions = new RabbitMqOptions();
|
|
|
|
|
configuration.GetSection(RabbitMqOptions.RabbitMq).Bind(rabbitMqOptions);
|
2022-08-27 19:58:22 +00:00
|
|
|
|
2022-05-26 10:47:31 +00:00
|
|
|
// Add Elsa services.
|
|
|
|
|
services
|
2022-05-26 14:07:01 +00:00
|
|
|
.AddElsa(elsa => elsa
|
2022-11-19 21:30:43 +00:00
|
|
|
.UseWorkflowManagement(management => management
|
2022-09-04 15:04:14 +00:00
|
|
|
.UseEntityFrameworkCore(ef => ef.UseSqlite(sqliteConnectionString))
|
2022-11-24 15:03:35 +00:00
|
|
|
.AddActivitiesFrom<WriteLine>()
|
|
|
|
|
.AddActivitiesFrom<HttpEndpoint>()
|
2022-12-30 12:11:29 +00:00
|
|
|
.AddActivitiesFrom<Delay>()
|
2022-11-24 15:03:35 +00:00
|
|
|
.AddActivitiesFrom<RunJavaScript>()
|
|
|
|
|
.AddActivitiesFrom<Program>()
|
2022-05-26 14:07:01 +00:00
|
|
|
)
|
2022-12-09 11:25:39 +00:00
|
|
|
.UseIdentity(identity =>
|
2022-08-31 13:47:10 +00:00
|
|
|
{
|
|
|
|
|
identity.CreateDefaultUser = true;
|
2022-12-30 12:11:29 +00:00
|
|
|
identity.IdentityOptions = identityOptions;
|
2022-08-31 13:47:10 +00:00
|
|
|
})
|
2022-12-30 12:11:29 +00:00
|
|
|
.UseDefaultAuthentication()
|
2022-11-23 21:36:43 +00:00
|
|
|
.UseWorkflowRuntime(runtime =>
|
2022-09-07 15:28:36 +00:00
|
|
|
{
|
2022-12-21 18:36:40 +00:00
|
|
|
//runtime.UseProtoActor(proto => proto.PersistenceProvider = _ => new SqliteProvider(new SqliteConnectionStringBuilder(sqliteConnectionString)));
|
2022-09-07 15:28:36 +00:00
|
|
|
runtime.UseEntityFrameworkCore(ef => ef.UseSqlite(sqliteConnectionString));
|
|
|
|
|
})
|
2022-09-04 15:04:14 +00:00
|
|
|
.UseLabels(labels => labels.UseEntityFrameworkCore(ef => ef.UseSqlite(sqliteConnectionString)))
|
|
|
|
|
.UseActivityDefinitions(feature => feature.UseEntityFrameworkCore(ef => ef.UseSqlite(sqliteConnectionString)))
|
2022-10-27 10:05:30 +00:00
|
|
|
.UseJobs(jobs => jobs.ConfigureOptions = options => options.WorkerCount = 10)
|
2022-08-11 10:45:07 +00:00
|
|
|
.UseJobActivities()
|
2022-08-11 18:04:47 +00:00
|
|
|
.UseScheduling()
|
2022-12-30 12:11:29 +00:00
|
|
|
.UseWorkflowsApi()
|
2022-05-26 15:05:36 +00:00
|
|
|
.UseJavaScript()
|
|
|
|
|
.UseLiquid()
|
2022-05-26 14:07:01 +00:00
|
|
|
.UseHttp()
|
2022-12-20 11:13:53 +00:00
|
|
|
);
|
2022-05-26 10:47:31 +00:00
|
|
|
|
|
|
|
|
services.AddHealthChecks();
|
|
|
|
|
services.AddCors(cors => cors.AddDefaultPolicy(policy => policy.AllowAnyHeader().AllowAnyMethod().AllowAnyOrigin()));
|
2022-08-31 13:47:10 +00:00
|
|
|
services.AddHttpContextAccessor();
|
|
|
|
|
services.AddSingleton<IAuthorizationHandler, LocalHostRequirementHandler>();
|
2022-12-09 11:25:39 +00:00
|
|
|
services.AddAuthorization(options => options.AddPolicy(IdentityPolicyNames.SecurityRoot, policy => policy.AddRequirements(new LocalHostRequirement())));
|
2022-05-26 10:47:31 +00:00
|
|
|
|
|
|
|
|
// Configure middleware pipeline.
|
|
|
|
|
var app = builder.Build();
|
|
|
|
|
var serviceProvider = app.Services;
|
|
|
|
|
|
2022-07-26 21:30:42 +00:00
|
|
|
// Register a dummy job for demo purposes.
|
|
|
|
|
var jobRegistry = serviceProvider.GetRequiredService<IJobRegistry>();
|
|
|
|
|
jobRegistry.Add(typeof(IndexBlockchainJob));
|
|
|
|
|
|
|
|
|
|
// Update activity providers.
|
|
|
|
|
var activityRegistryPopulator = serviceProvider.GetRequiredService<IActivityRegistryPopulator>();
|
|
|
|
|
activityRegistryPopulator.PopulateRegistryAsync(typeof(JobActivityProvider));
|
|
|
|
|
|
2022-05-26 10:47:31 +00:00
|
|
|
// Configure workflow engine execution pipeline.
|
|
|
|
|
serviceProvider.ConfigureDefaultWorkflowExecutionPipeline(pipeline =>
|
|
|
|
|
pipeline
|
2022-09-04 15:04:14 +00:00
|
|
|
.UsePersistentVariables()
|
2022-12-09 11:49:57 +00:00
|
|
|
.UseBookmarkPersistence()
|
2022-05-26 10:47:31 +00:00
|
|
|
.UseWorkflowContexts()
|
2022-10-27 10:05:30 +00:00
|
|
|
.UseDefaultActivityScheduler()
|
2022-05-26 10:47:31 +00:00
|
|
|
);
|
|
|
|
|
|
2022-10-27 10:05:30 +00:00
|
|
|
// Configure activity execution pipeline to use the job-based activity invoker.
|
2022-12-26 17:38:30 +00:00
|
|
|
serviceProvider.ConfigureDefaultActivityExecutionPipeline(pipeline => pipeline
|
|
|
|
|
.UseExceptionHandling()
|
|
|
|
|
.UseJobBasedActivityInvoker());
|
2022-10-27 10:05:30 +00:00
|
|
|
|
2022-05-26 10:47:31 +00:00
|
|
|
if (app.Environment.IsDevelopment())
|
|
|
|
|
app.UseDeveloperExceptionPage();
|
|
|
|
|
|
|
|
|
|
// CORS.
|
|
|
|
|
app.UseCors();
|
|
|
|
|
|
|
|
|
|
// Health checks.
|
|
|
|
|
app.MapHealthChecks("/");
|
|
|
|
|
|
2022-07-21 14:18:42 +00:00
|
|
|
app.UseAuthentication();
|
|
|
|
|
app.UseAuthorization();
|
|
|
|
|
|
2022-05-26 10:47:31 +00:00
|
|
|
// Register Elsa middleware.
|
2022-12-30 12:11:29 +00:00
|
|
|
app.UseWorkflowsApi();
|
2022-05-26 10:47:31 +00:00
|
|
|
app.UseJsonSerializationErrorHandler();
|
2022-12-30 12:11:29 +00:00
|
|
|
app.UseWorkflows();
|
2022-05-26 10:47:31 +00:00
|
|
|
|
|
|
|
|
// Run.
|
2022-08-31 13:47:10 +00:00
|
|
|
app.Run();
|