elsa-core/src/bundles/Elsa.ServerAndStudio.Web/Program.cs

136 lines
5.6 KiB
C#
Raw Normal View History

using Elsa.Common.DistributedLocks.Noop;
using Elsa.EntityFrameworkCore.Extensions;
2023-01-14 11:22:38 +00:00
using Elsa.EntityFrameworkCore.Modules.Management;
using Elsa.EntityFrameworkCore.Modules.Runtime;
using Elsa.MassTransit.Options;
using Elsa.Extensions;
using Elsa.ServerAndStudio.Web.Extensions;
Implemented distributed cache refresh for workflow definitions (#5095) * Moved handler to correct namespace * Added version deletion messages to activity registry handler * Add MassTransit support for workflow management * Moved logic from Workflow.Management.MassTransit project into Elsa.MassTransit project * Added notifier to MT project for creating distributed messages * Rename and update workflow consumer class Renamed `WorkflowDefinitionConsumer` to `WorkflowDefinitionEventsConsumer` to better reflect its purpose. Updated references accordingly in the `MassTransitWorkflowManagementFeature` class to align with the new name. * Shortened instance (queue) names * Remove unnecessary comment in handler definition An unnecessary comment mark ("/") was removed in the definition of the DistributedWorkflowDefinitionNotificationsHandler class. This change contributes to code cleanup and increases code readability. * Add additional destinations in LoadBalancer settings Three new destinations have been added to the LoadBalancer settings in Elsa Server. These are primarily intended to provide broader network coverage and improve overall server performance. * Add MassTransit support in Elsa.Server A new using directive for Elsa.MassTransit.Extensions has been included at the start of the script. In addition, under certain conditions, the system now uses the MassTransit Dispatcher in the workflow management system. These changes provide support for using MassTransit in the Elsa.Server component. * Add MassTransitBroker enum for MassTransit setup A new enum called MassTransitBroker has been added to represent different types of messaging brokers used in MassTransit. This has also been integrated into the Web project's Program.cs file to allow conditional usage of brokers in the MassTransit setup, enabling more flexible and dynamic configuration. * Refactor WorkflowManagementFeature class The WorkflowManagementFeature class has been cleaned up and its formatting has been corrected. A blank line was removed, a line break was added for readability in the AddVariableType method, and several stray spaces were also removed. * Refactor RefreshActivityRegistryHandler.cs This commit removes unnecessary whitespace and improves the code readability in RefreshActivityRegistryHandler.cs. The changes include deletion of extra lines and adjustment of indentation. --------- Co-authored-by: Sipke Schoorstra <sipkeschoorstra@outlook.com>
2024-03-24 20:09:51 +00:00
using Elsa.MassTransit.Extensions;
using Elsa.ServerAndStudio.Web.Enums;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Data.Sqlite;
using Proto.Persistence.Sqlite;
2022-04-29 12:40:25 +00:00
const bool useMassTransit = true;
const bool useProtoActor = false;
2022-04-29 12:40:25 +00:00
var builder = WebApplication.CreateBuilder(args);
builder.WebHost.UseStaticWebAssets();
2022-04-29 12:40:25 +00:00
var services = builder.Services;
2022-12-09 11:24:05 +00:00
var configuration = builder.Configuration;
var sqliteConnectionString = configuration.GetConnectionString("Sqlite")!;
var rabbitMqConnectionString = configuration.GetConnectionString("RabbitMq")!;
var azureServiceBusConnectionString = configuration.GetConnectionString("AzureServiceBus")!;
2022-12-09 11:24:05 +00:00
var identitySection = configuration.GetSection("Identity");
2023-01-01 21:54:07 +00:00
var identityTokenSection = identitySection.GetSection("Tokens");
var massTransitSection = configuration.GetSection("MassTransit");
var massTransitDispatcherSection = configuration.GetSection("MassTransit.Dispatcher");
var heartbeatSection = configuration.GetSection("Heartbeat");
const MassTransitBroker useMassTransitBroker = MassTransitBroker.AzureServiceBus;
services.Configure<MassTransitOptions>(massTransitSection);
services.Configure<MassTransitWorkflowDispatcherOptions>(massTransitDispatcherSection);
2022-04-29 12:40:25 +00:00
// Add Elsa services.
2022-04-29 12:40:25 +00:00
services
.AddElsa(elsa =>
{
elsa
.UseSasTokens()
.UseIdentity(identity =>
{
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()
.UseInstanceManagement(x => x.HeartbeatOptions = settings => heartbeatSection.Bind(settings))
Implemented distributed cache refresh for workflow definitions (#5095) * Moved handler to correct namespace * Added version deletion messages to activity registry handler * Add MassTransit support for workflow management * Moved logic from Workflow.Management.MassTransit project into Elsa.MassTransit project * Added notifier to MT project for creating distributed messages * Rename and update workflow consumer class Renamed `WorkflowDefinitionConsumer` to `WorkflowDefinitionEventsConsumer` to better reflect its purpose. Updated references accordingly in the `MassTransitWorkflowManagementFeature` class to align with the new name. * Shortened instance (queue) names * Remove unnecessary comment in handler definition An unnecessary comment mark ("/") was removed in the definition of the DistributedWorkflowDefinitionNotificationsHandler class. This change contributes to code cleanup and increases code readability. * Add additional destinations in LoadBalancer settings Three new destinations have been added to the LoadBalancer settings in Elsa Server. These are primarily intended to provide broader network coverage and improve overall server performance. * Add MassTransit support in Elsa.Server A new using directive for Elsa.MassTransit.Extensions has been included at the start of the script. In addition, under certain conditions, the system now uses the MassTransit Dispatcher in the workflow management system. These changes provide support for using MassTransit in the Elsa.Server component. * Add MassTransitBroker enum for MassTransit setup A new enum called MassTransitBroker has been added to represent different types of messaging brokers used in MassTransit. This has also been integrated into the Web project's Program.cs file to allow conditional usage of brokers in the MassTransit setup, enabling more flexible and dynamic configuration. * Refactor WorkflowManagementFeature class The WorkflowManagementFeature class has been cleaned up and its formatting has been corrected. A blank line was removed, a line break was added for readability in the AddVariableType method, and several stray spaces were also removed. * Refactor RefreshActivityRegistryHandler.cs This commit removes unnecessary whitespace and improves the code readability in RefreshActivityRegistryHandler.cs. The changes include deletion of extra lines and adjustment of indentation. --------- Co-authored-by: Sipke Schoorstra <sipkeschoorstra@outlook.com>
2024-03-24 20:09:51 +00:00
.UseWorkflowManagement(management =>
{
if (useMassTransit)
{
management.UseMassTransitDispatcher();
}
management.UseEntityFrameworkCore(ef => ef.UseSqlite(sqliteConnectionString));
})
.UseWorkflowRuntime(runtime =>
{
runtime.UseEntityFrameworkCore(ef => ef.UseSqlite(sqliteConnectionString));
runtime.UseMassTransitDispatcher();
if (useProtoActor)
{
runtime.UseProtoActor(proto => proto.PersistenceProvider = _ =>
{
return new SqliteProvider(new SqliteConnectionStringBuilder(sqliteConnectionString));
});
}
Implemented distributed cache refresh for workflow definitions (#5095) * Moved handler to correct namespace * Added version deletion messages to activity registry handler * Add MassTransit support for workflow management * Moved logic from Workflow.Management.MassTransit project into Elsa.MassTransit project * Added notifier to MT project for creating distributed messages * Rename and update workflow consumer class Renamed `WorkflowDefinitionConsumer` to `WorkflowDefinitionEventsConsumer` to better reflect its purpose. Updated references accordingly in the `MassTransitWorkflowManagementFeature` class to align with the new name. * Shortened instance (queue) names * Remove unnecessary comment in handler definition An unnecessary comment mark ("/") was removed in the definition of the DistributedWorkflowDefinitionNotificationsHandler class. This change contributes to code cleanup and increases code readability. * Add additional destinations in LoadBalancer settings Three new destinations have been added to the LoadBalancer settings in Elsa Server. These are primarily intended to provide broader network coverage and improve overall server performance. * Add MassTransit support in Elsa.Server A new using directive for Elsa.MassTransit.Extensions has been included at the start of the script. In addition, under certain conditions, the system now uses the MassTransit Dispatcher in the workflow management system. These changes provide support for using MassTransit in the Elsa.Server component. * Add MassTransitBroker enum for MassTransit setup A new enum called MassTransitBroker has been added to represent different types of messaging brokers used in MassTransit. This has also been integrated into the Web project's Program.cs file to allow conditional usage of brokers in the MassTransit setup, enabling more flexible and dynamic configuration. * Refactor WorkflowManagementFeature class The WorkflowManagementFeature class has been cleaned up and its formatting has been corrected. A blank line was removed, a line break was added for readability in the AddVariableType method, and several stray spaces were also removed. * Refactor RefreshActivityRegistryHandler.cs This commit removes unnecessary whitespace and improves the code readability in RefreshActivityRegistryHandler.cs. The changes include deletion of extra lines and adjustment of indentation. --------- Co-authored-by: Sipke Schoorstra <sipkeschoorstra@outlook.com>
2024-03-24 20:09:51 +00:00
runtime.DistributedLockProvider = _ => new NoopDistributedSynchronizationProvider();
Implemented distributed cache refresh for workflow definitions (#5095) * Moved handler to correct namespace * Added version deletion messages to activity registry handler * Add MassTransit support for workflow management * Moved logic from Workflow.Management.MassTransit project into Elsa.MassTransit project * Added notifier to MT project for creating distributed messages * Rename and update workflow consumer class Renamed `WorkflowDefinitionConsumer` to `WorkflowDefinitionEventsConsumer` to better reflect its purpose. Updated references accordingly in the `MassTransitWorkflowManagementFeature` class to align with the new name. * Shortened instance (queue) names * Remove unnecessary comment in handler definition An unnecessary comment mark ("/") was removed in the definition of the DistributedWorkflowDefinitionNotificationsHandler class. This change contributes to code cleanup and increases code readability. * Add additional destinations in LoadBalancer settings Three new destinations have been added to the LoadBalancer settings in Elsa Server. These are primarily intended to provide broader network coverage and improve overall server performance. * Add MassTransit support in Elsa.Server A new using directive for Elsa.MassTransit.Extensions has been included at the start of the script. In addition, under certain conditions, the system now uses the MassTransit Dispatcher in the workflow management system. These changes provide support for using MassTransit in the Elsa.Server component. * Add MassTransitBroker enum for MassTransit setup A new enum called MassTransitBroker has been added to represent different types of messaging brokers used in MassTransit. This has also been integrated into the Web project's Program.cs file to allow conditional usage of brokers in the MassTransit setup, enabling more flexible and dynamic configuration. * Refactor WorkflowManagementFeature class The WorkflowManagementFeature class has been cleaned up and its formatting has been corrected. A blank line was removed, a line break was added for readability in the AddVariableType method, and several stray spaces were also removed. * Refactor RefreshActivityRegistryHandler.cs This commit removes unnecessary whitespace and improves the code readability in RefreshActivityRegistryHandler.cs. The changes include deletion of extra lines and adjustment of indentation. --------- Co-authored-by: Sipke Schoorstra <sipkeschoorstra@outlook.com>
2024-03-24 20:09:51 +00:00
runtime.WorkflowInboxCleanupOptions = options => configuration.GetSection("Runtime:WorkflowInboxCleanup").Bind(options);
runtime.WorkflowDispatcherOptions = options => configuration.GetSection("Runtime:WorkflowDispatcher").Bind(options);
})
.UseScheduling()
.UseJavaScript(options => options.AllowClrAccess = true)
.UseLiquid()
.UseCSharp()
Implemented distributed cache refresh for workflow definitions (#5095) * Moved handler to correct namespace * Added version deletion messages to activity registry handler * Add MassTransit support for workflow management * Moved logic from Workflow.Management.MassTransit project into Elsa.MassTransit project * Added notifier to MT project for creating distributed messages * Rename and update workflow consumer class Renamed `WorkflowDefinitionConsumer` to `WorkflowDefinitionEventsConsumer` to better reflect its purpose. Updated references accordingly in the `MassTransitWorkflowManagementFeature` class to align with the new name. * Shortened instance (queue) names * Remove unnecessary comment in handler definition An unnecessary comment mark ("/") was removed in the definition of the DistributedWorkflowDefinitionNotificationsHandler class. This change contributes to code cleanup and increases code readability. * Add additional destinations in LoadBalancer settings Three new destinations have been added to the LoadBalancer settings in Elsa Server. These are primarily intended to provide broader network coverage and improve overall server performance. * Add MassTransit support in Elsa.Server A new using directive for Elsa.MassTransit.Extensions has been included at the start of the script. In addition, under certain conditions, the system now uses the MassTransit Dispatcher in the workflow management system. These changes provide support for using MassTransit in the Elsa.Server component. * Add MassTransitBroker enum for MassTransit setup A new enum called MassTransitBroker has been added to represent different types of messaging brokers used in MassTransit. This has also been integrated into the Web project's Program.cs file to allow conditional usage of brokers in the MassTransit setup, enabling more flexible and dynamic configuration. * Refactor WorkflowManagementFeature class The WorkflowManagementFeature class has been cleaned up and its formatting has been corrected. A blank line was removed, a line break was added for readability in the AddVariableType method, and several stray spaces were also removed. * Refactor RefreshActivityRegistryHandler.cs This commit removes unnecessary whitespace and improves the code readability in RefreshActivityRegistryHandler.cs. The changes include deletion of extra lines and adjustment of indentation. --------- Co-authored-by: Sipke Schoorstra <sipkeschoorstra@outlook.com>
2024-03-24 20:09:51 +00:00
// .UsePython()
.UseHttp(http => http.ConfigureHttpOptions = options => configuration.GetSection("Http").Bind(options))
.UseEmail(email => email.ConfigureOptions = options => configuration.GetSection("Smtp").Bind(options))
.UseWebhooks(webhooks => webhooks.WebhookOptions = options => builder.Configuration.GetSection("Webhooks").Bind(options))
.UseWorkflowsApi()
.UseRealTimeWorkflows()
.AddActivitiesFrom<Program>()
.AddWorkflowsFrom<Program>();
if (useMassTransit)
2022-12-09 11:24:05 +00:00
{
elsa.UseMassTransit(massTransit =>
{
switch (useMassTransitBroker)
Implemented distributed cache refresh for workflow definitions (#5095) * Moved handler to correct namespace * Added version deletion messages to activity registry handler * Add MassTransit support for workflow management * Moved logic from Workflow.Management.MassTransit project into Elsa.MassTransit project * Added notifier to MT project for creating distributed messages * Rename and update workflow consumer class Renamed `WorkflowDefinitionConsumer` to `WorkflowDefinitionEventsConsumer` to better reflect its purpose. Updated references accordingly in the `MassTransitWorkflowManagementFeature` class to align with the new name. * Shortened instance (queue) names * Remove unnecessary comment in handler definition An unnecessary comment mark ("/") was removed in the definition of the DistributedWorkflowDefinitionNotificationsHandler class. This change contributes to code cleanup and increases code readability. * Add additional destinations in LoadBalancer settings Three new destinations have been added to the LoadBalancer settings in Elsa Server. These are primarily intended to provide broader network coverage and improve overall server performance. * Add MassTransit support in Elsa.Server A new using directive for Elsa.MassTransit.Extensions has been included at the start of the script. In addition, under certain conditions, the system now uses the MassTransit Dispatcher in the workflow management system. These changes provide support for using MassTransit in the Elsa.Server component. * Add MassTransitBroker enum for MassTransit setup A new enum called MassTransitBroker has been added to represent different types of messaging brokers used in MassTransit. This has also been integrated into the Web project's Program.cs file to allow conditional usage of brokers in the MassTransit setup, enabling more flexible and dynamic configuration. * Refactor WorkflowManagementFeature class The WorkflowManagementFeature class has been cleaned up and its formatting has been corrected. A blank line was removed, a line break was added for readability in the AddVariableType method, and several stray spaces were also removed. * Refactor RefreshActivityRegistryHandler.cs This commit removes unnecessary whitespace and improves the code readability in RefreshActivityRegistryHandler.cs. The changes include deletion of extra lines and adjustment of indentation. --------- Co-authored-by: Sipke Schoorstra <sipkeschoorstra@outlook.com>
2024-03-24 20:09:51 +00:00
{
case MassTransitBroker.AzureServiceBus:
massTransit.UseAzureServiceBus(azureServiceBusConnectionString);
break;
case MassTransitBroker.RabbitMq:
massTransit.UseRabbitMq(rabbitMqConnectionString);
break;
Implemented distributed cache refresh for workflow definitions (#5095) * Moved handler to correct namespace * Added version deletion messages to activity registry handler * Add MassTransit support for workflow management * Moved logic from Workflow.Management.MassTransit project into Elsa.MassTransit project * Added notifier to MT project for creating distributed messages * Rename and update workflow consumer class Renamed `WorkflowDefinitionConsumer` to `WorkflowDefinitionEventsConsumer` to better reflect its purpose. Updated references accordingly in the `MassTransitWorkflowManagementFeature` class to align with the new name. * Shortened instance (queue) names * Remove unnecessary comment in handler definition An unnecessary comment mark ("/") was removed in the definition of the DistributedWorkflowDefinitionNotificationsHandler class. This change contributes to code cleanup and increases code readability. * Add additional destinations in LoadBalancer settings Three new destinations have been added to the LoadBalancer settings in Elsa Server. These are primarily intended to provide broader network coverage and improve overall server performance. * Add MassTransit support in Elsa.Server A new using directive for Elsa.MassTransit.Extensions has been included at the start of the script. In addition, under certain conditions, the system now uses the MassTransit Dispatcher in the workflow management system. These changes provide support for using MassTransit in the Elsa.Server component. * Add MassTransitBroker enum for MassTransit setup A new enum called MassTransitBroker has been added to represent different types of messaging brokers used in MassTransit. This has also been integrated into the Web project's Program.cs file to allow conditional usage of brokers in the MassTransit setup, enabling more flexible and dynamic configuration. * Refactor WorkflowManagementFeature class The WorkflowManagementFeature class has been cleaned up and its formatting has been corrected. A blank line was removed, a line break was added for readability in the AddVariableType method, and several stray spaces were also removed. * Refactor RefreshActivityRegistryHandler.cs This commit removes unnecessary whitespace and improves the code readability in RefreshActivityRegistryHandler.cs. The changes include deletion of extra lines and adjustment of indentation. --------- Co-authored-by: Sipke Schoorstra <sipkeschoorstra@outlook.com>
2024-03-24 20:09:51 +00:00
}
}
);
}
});
2022-12-09 11:24:05 +00:00
services.AddHealthChecks();
2023-05-28 18:31:42 +00:00
services.AddCors(cors => cors.Configure(configuration.GetSection("CorsPolicy")));
2022-04-29 12:40:25 +00:00
// Razor Pages.
2023-01-14 11:22:38 +00:00
services.AddRazorPages(options => options.Conventions.ConfigureFilter(new IgnoreAntiforgeryTokenAttribute()));
2022-04-29 12:40:25 +00:00
// Configure middleware pipeline.
var app = builder.Build();
// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Error");
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseBlazorFrameworkFiles();
app.MapHealthChecks("/health");
app.UseRouting();
2023-01-14 11:22:38 +00:00
app.UseCors();
2022-04-29 12:40:25 +00:00
app.UseStaticFiles();
2022-12-09 11:24:05 +00:00
app.UseAuthentication();
2022-04-29 12:40:25 +00:00
app.UseAuthorization();
app.UseWorkflowsApi();
app.UseWorkflows();
app.UseWorkflowsSignalRHubs();
app.MapFallbackToPage("/_Host");
app.Run();