2023-06-28 20:46:58 +00:00
|
|
|
using Elsa.EntityFrameworkCore.Modules.Identity;
|
|
|
|
|
using Elsa.EntityFrameworkCore.Modules.Management;
|
|
|
|
|
using Elsa.EntityFrameworkCore.Modules.Runtime;
|
2022-05-26 10:47:31 +00:00
|
|
|
using Elsa.Extensions;
|
2023-05-01 10:06:51 +00:00
|
|
|
using Elsa.Http.Handlers;
|
2023-02-15 11:09:45 +00:00
|
|
|
using Elsa.JavaScript.Options;
|
2023-06-28 20:44:51 +00:00
|
|
|
using Elsa.MongoDb.Extensions;
|
2023-08-05 08:34:10 +00:00
|
|
|
using Elsa.MongoDb.Modules.Identity;
|
|
|
|
|
using Elsa.MongoDb.Modules.Management;
|
|
|
|
|
using Elsa.MongoDb.Modules.Runtime;
|
2023-04-16 22:11:58 +00:00
|
|
|
using Elsa.WorkflowServer.Web;
|
2023-07-23 19:05:31 +00:00
|
|
|
using Microsoft.Data.Sqlite;
|
|
|
|
|
using Proto.Persistence.Sqlite;
|
2022-05-26 10:47:31 +00:00
|
|
|
|
2023-08-05 08:34:10 +00:00
|
|
|
const bool useMongoDb = false;
|
2023-08-06 15:03:36 +00:00
|
|
|
const bool useProtoActor = false;
|
2023-08-12 20:22:40 +00:00
|
|
|
const bool useHangfire = true;
|
2023-05-16 18:03:12 +00:00
|
|
|
|
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;
|
|
|
|
|
var identitySection = configuration.GetSection("Identity");
|
2023-01-02 21:24:05 +00:00
|
|
|
var identityTokenSection = identitySection.GetSection("Tokens");
|
2023-07-23 19:05:31 +00:00
|
|
|
var sqliteConnectionString = configuration.GetConnectionString("Sqlite");
|
2023-08-05 08:34:10 +00:00
|
|
|
var mongoDbConnectionString = configuration.GetConnectionString("MongoDb")!;
|
2022-08-27 19:58:22 +00:00
|
|
|
|
2022-05-26 10:47:31 +00:00
|
|
|
// Add Elsa services.
|
|
|
|
|
services
|
2023-08-05 08:34:10 +00:00
|
|
|
.AddElsa(elsa =>
|
|
|
|
|
{
|
|
|
|
|
if(useMongoDb)
|
|
|
|
|
elsa.UseMongoDb(mongoDbConnectionString);
|
|
|
|
|
|
2023-08-12 20:22:40 +00:00
|
|
|
if (useHangfire)
|
|
|
|
|
elsa.UseHangfire();
|
|
|
|
|
|
2023-08-05 08:34:10 +00:00
|
|
|
elsa
|
|
|
|
|
.AddActivitiesFrom<Program>()
|
2023-08-06 18:55:24 +00:00
|
|
|
.AddWorkflowsFrom<Program>()
|
2023-08-05 08:34:10 +00:00
|
|
|
.UseFluentStorageProvider()
|
|
|
|
|
.AddTypeAlias<ApiResponse<User>>("ApiResponse[User]")
|
|
|
|
|
.UseIdentity(identity =>
|
|
|
|
|
{
|
|
|
|
|
if(useMongoDb)
|
|
|
|
|
identity.UseMongoDb();
|
|
|
|
|
else
|
|
|
|
|
identity.UseEntityFrameworkCore();
|
|
|
|
|
|
|
|
|
|
identity.IdentityOptions = options => identitySection.Bind(options);
|
|
|
|
|
identity.TokenOptions = options => identityTokenSection.Bind(options);
|
|
|
|
|
identity.UseConfigurationBasedUserProvider(options => identitySection.Bind(options));
|
|
|
|
|
identity.UseConfigurationBasedApplicationProvider(options => identitySection.Bind(options));
|
|
|
|
|
identity.UseConfigurationBasedRoleProvider(options => identitySection.Bind(options));
|
|
|
|
|
})
|
|
|
|
|
.UseDefaultAuthentication()
|
|
|
|
|
.UseWorkflowManagement(management =>
|
|
|
|
|
{
|
|
|
|
|
if(useMongoDb)
|
|
|
|
|
management.UseMongoDb();
|
|
|
|
|
else
|
|
|
|
|
management.UseEntityFrameworkCore();
|
|
|
|
|
|
|
|
|
|
management.AddVariableType<ApiResponse<User>>("Api");
|
|
|
|
|
management.AddVariableType<User>("Api");
|
|
|
|
|
management.AddVariableType<Support>("Api");
|
|
|
|
|
})
|
|
|
|
|
.UseWorkflowRuntime(runtime =>
|
|
|
|
|
{
|
|
|
|
|
if(useMongoDb)
|
|
|
|
|
runtime.UseMongoDb();
|
|
|
|
|
else
|
|
|
|
|
runtime.UseEntityFrameworkCore();
|
|
|
|
|
|
|
|
|
|
if(useProtoActor)
|
|
|
|
|
runtime.UseProtoActor(proto => proto.PersistenceProvider = _ => new SqliteProvider(new SqliteConnectionStringBuilder(sqliteConnectionString)));
|
|
|
|
|
else
|
|
|
|
|
runtime.UseDefaultRuntime(dr =>
|
|
|
|
|
{
|
|
|
|
|
if(useMongoDb)
|
|
|
|
|
dr.UseMongoDb();
|
|
|
|
|
else
|
|
|
|
|
dr.UseEntityFrameworkCore();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
runtime.UseExecutionLogRecords(e =>
|
|
|
|
|
{
|
|
|
|
|
if(useMongoDb)
|
|
|
|
|
e.UseMongoDb();
|
|
|
|
|
else
|
|
|
|
|
e.UseEntityFrameworkCore();
|
|
|
|
|
});
|
|
|
|
|
runtime.UseMassTransitDispatcher();
|
|
|
|
|
})
|
|
|
|
|
.UseEnvironments(environments => environments.EnvironmentsOptions = options => configuration.GetSection("Environments").Bind(options))
|
2023-08-12 20:22:40 +00:00
|
|
|
.UseScheduling(scheduling =>
|
|
|
|
|
{
|
|
|
|
|
if (useHangfire)
|
|
|
|
|
scheduling.UseHangfireScheduler();
|
|
|
|
|
})
|
2023-08-05 08:34:10 +00:00
|
|
|
.UseWorkflowsApi(api => api.AddFastEndpointsAssembly<Program>())
|
|
|
|
|
.UseRealTimeWorkflows()
|
|
|
|
|
.UseJavaScript()
|
|
|
|
|
.UseLiquid()
|
|
|
|
|
.UseHttp(http => http.HttpEndpointAuthorizationHandler = sp => sp.GetRequiredService<AllowAnonymousHttpEndpointAuthorizationHandler>())
|
|
|
|
|
.UseEmail(email => email.ConfigureOptions = options => configuration.GetSection("Smtp").Bind(options));
|
|
|
|
|
});
|
2022-05-26 10:47:31 +00:00
|
|
|
|
2023-02-15 11:09:45 +00:00
|
|
|
services.Configure<JintOptions>(options => options.AllowClrAccess = true);
|
2022-05-26 10:47:31 +00:00
|
|
|
services.AddHealthChecks();
|
2023-07-25 19:02:07 +00:00
|
|
|
services.AddCors(cors => cors.AddDefaultPolicy(policy => policy.AllowAnyHeader().AllowAnyMethod().AllowAnyOrigin().WithExposedHeaders("*")));
|
2022-05-26 10:47:31 +00:00
|
|
|
|
|
|
|
|
// Configure middleware pipeline.
|
|
|
|
|
var app = builder.Build();
|
2022-07-26 21:30:42 +00:00
|
|
|
|
2022-05-26 10:47:31 +00:00
|
|
|
if (app.Environment.IsDevelopment())
|
|
|
|
|
app.UseDeveloperExceptionPage();
|
|
|
|
|
|
|
|
|
|
// CORS.
|
|
|
|
|
app.UseCors();
|
|
|
|
|
|
|
|
|
|
// Health checks.
|
|
|
|
|
app.MapHealthChecks("/");
|
|
|
|
|
|
2023-08-05 08:34:10 +00:00
|
|
|
// Routing used for SignalR.
|
|
|
|
|
app.UseRouting();
|
|
|
|
|
|
|
|
|
|
// Security.
|
2022-07-21 14:18:42 +00:00
|
|
|
app.UseAuthentication();
|
|
|
|
|
app.UseAuthorization();
|
|
|
|
|
|
2023-04-17 13:23:05 +00:00
|
|
|
// Elsa API endpoints for designer.
|
2022-12-30 12:11:29 +00:00
|
|
|
app.UseWorkflowsApi();
|
2023-04-17 13:23:05 +00:00
|
|
|
|
|
|
|
|
// Captures unhandled exceptions and returns a JSON response.
|
2022-05-26 10:47:31 +00:00
|
|
|
app.UseJsonSerializationErrorHandler();
|
2023-04-17 13:23:05 +00:00
|
|
|
|
|
|
|
|
// Elsa HTTP Endpoint activities
|
2022-12-30 12:11:29 +00:00
|
|
|
app.UseWorkflows();
|
2022-05-26 10:47:31 +00:00
|
|
|
|
2023-07-25 13:12:27 +00:00
|
|
|
// SignalR.
|
|
|
|
|
app.UseWorkflowsSignalRHubs();
|
|
|
|
|
|
2022-05-26 10:47:31 +00:00
|
|
|
// Run.
|
2022-08-31 13:47:10 +00:00
|
|
|
app.Run();
|