< Summary

Information
Class: Program
Assembly: Elsa.Server.Web
File(s): /home/runner/work/elsa-core/elsa-core/src/apps/Elsa.Server.Web/Program.cs
Line coverage
100%
Covered lines: 116
Uncovered lines: 0
Coverable lines: 116
Total lines: 205
Line coverage: 100%
Branch coverage
95%
Covered branches: 23
Total branches: 24
Branch coverage: 95.8%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
<Main>$()95.83%2424100%
get_ConfigureForTest()100%11100%

File(s)

/home/runner/work/elsa-core/elsa-core/src/apps/Elsa.Server.Web/Program.cs

#LineLine coverage
 1using System.Text.Encodings.Web;
 2using Elsa.Caching.Options;
 3using Elsa.Common.RecurringTasks;
 4using Elsa.Expressions.Helpers;
 5using Elsa.Extensions;
 6using Elsa.Features.Services;
 7using Elsa.Persistence.EFCore.Extensions;
 8using Elsa.Persistence.EFCore.Modules.Management;
 9using Elsa.Persistence.EFCore.Modules.Runtime;
 10using Elsa.Server.Web.Activities;
 11using Elsa.Server.Web.ActivityHosts;
 12using Elsa.Server.Web.Filters;
 13using Elsa.Tenants.AspNetCore;
 14using Elsa.Tenants.Extensions;
 15using Elsa.WorkflowProviders.BlobStorage.ElsaScript.Extensions;
 16using Elsa.Workflows;
 17using Elsa.Workflows.Activities.Flowchart.Extensions;
 18using Elsa.Workflows.Api;
 19using Elsa.Workflows.CommitStates.Strategies;
 20using Elsa.Workflows.IncidentStrategies;
 21using Elsa.Workflows.LogPersistence;
 22using Elsa.Workflows.Options;
 23using Elsa.Workflows.Runtime.Distributed.Extensions;
 24using Elsa.Workflows.Runtime.Options;
 25using Elsa.Workflows.Runtime.Tasks;
 26using JetBrains.Annotations;
 27using Microsoft.Extensions.Options;
 28
 29// ReSharper disable RedundantAssignment
 30const bool useReadOnlyMode = false;
 31const bool useSignalR = false; // Disabled until Elsa Studio sends authenticated requests.
 32const bool useMultitenancy = false;
 33const bool disableVariableWrappers = false;
 34
 735ObjectConverter.StrictMode = true;
 36
 737var builder = WebApplication.CreateBuilder(args);
 738var services = builder.Services;
 739var configuration = builder.Configuration;
 740var identitySection = configuration.GetSection("Identity");
 741var identityTokenSection = identitySection.GetSection("Tokens");
 42
 43// Add Elsa services.
 744services
 745    .AddElsa(elsa =>
 746    {
 747        elsa
 748            .AddActivitiesFrom<Program>()
 749            .AddActivityHost<Penguin>()
 750            .AddWorkflowsFrom<Program>()
 751            .UseIdentity(identity =>
 752            {
 753                identity.TokenOptions += options => identityTokenSection.Bind(options);
 754                identity.UseConfigurationBasedUserProvider(options => identitySection.Bind(options));
 755                identity.UseConfigurationBasedApplicationProvider(options => identitySection.Bind(options));
 756                identity.UseConfigurationBasedRoleProvider(options => identitySection.Bind(options));
 757            })
 758            .UseDefaultAuthentication()
 759            .UseWorkflows(workflows =>
 760            {
 761                workflows.UseCommitStrategies(strategies =>
 762                {
 763                    strategies.AddStandardStrategies();
 764                    strategies.Add("Every 10 seconds", new PeriodicWorkflowStrategy(TimeSpan.FromSeconds(10)));
 1465                });
 766            })
 767            .UseFlowchart(flowchart => flowchart.UseTokenBasedExecution())
 768            .UseWorkflowManagement(management =>
 769            {
 1470                management.UseEntityFrameworkCore(ef => ef.UseSqlite());
 771                management.SetDefaultLogPersistenceMode(LogPersistenceMode.Inherit);
 772                management.UseCache();
 773                management.UseReadOnlyMode(useReadOnlyMode);
 774            })
 775            .UseWorkflowRuntime(runtime =>
 776            {
 1477                runtime.UseEntityFrameworkCore(ef => ef.UseSqlite());
 778                runtime.UseCache();
 779                runtime.UseDistributedRuntime();
 780            })
 781            .UseWorkflowsApi()
 782            .UseFluentStorageProvider()
 783            .UseElsaScriptBlobStorage()
 784            .UseScheduling()
 785            .UseCSharp(options =>
 786            {
 787                options.DisableWrappers = disableVariableWrappers;
 788                options.AppendScript("string Greet(string name) => $\"Hello {name}!\";");
 789                options.AppendScript("string SayHelloWorld() => Greet(\"World\");");
 790            })
 791            .UseJavaScript(options =>
 792            {
 793                options.AllowClrAccess = true;
 794                options.ConfigureEngine(engine =>
 795                {
 2396                    engine.Execute("function greet(name) { return `Hello ${name}!`; }");
 2397                    engine.Execute("function sayHelloWorld() { return greet('World'); }");
 3098                });
 799            })
 7100            .UsePython(python =>
 7101            {
 7102                python.PythonOptions += options =>
 7103                {
 7104                    // Make sure to configure the path to the python DLL. E.g. /opt/homebrew/Cellar/python@3.11/3.11.6_1
 7105                    // alternatively, you can set the PYTHONNET_PYDLL environment variable.
 7106                    configuration.GetSection("Scripting:Python").Bind(options);
 7107
 7108                    options.AddScript(sb =>
 7109                    {
 7110                        sb.AppendLine("def greet():");
 7111                        sb.AppendLine("    return \"Hello, welcome to Python!\"");
 14112                    });
 14113                };
 7114            })
 14115            .UseLiquid(liquid => liquid.FluidOptions = options => options.Encoder = HtmlEncoder.Default)
 7116            .UseHttp(http =>
 7117            {
 14118                http.ConfigureHttpOptions = options => configuration.GetSection("Http").Bind(options);
 7119                http.UseCache();
 14120            });
 7121        ConfigureForTest?.Invoke(elsa);
 14122    });
 123
 124// Obfuscate HTTP request headers.
 7125services.AddActivityStateFilter<HttpRequestAuthenticationHeaderFilter>();
 126
 127// Optionally configure recurring tasks using alternative schedules.
 7128services.Configure<RecurringTaskOptions>(options =>
 7129{
 7130    options.Schedule.ConfigureTask<TriggerBookmarkQueueRecurringTask>(TimeSpan.FromSeconds(300));
 7131    options.Schedule.ConfigureTask<PurgeBookmarkQueueRecurringTask>(TimeSpan.FromSeconds(300));
 7132    options.Schedule.ConfigureTask<RestartInterruptedWorkflowsTask>(TimeSpan.FromSeconds(15));
 14133});
 134
 21135services.Configure<RuntimeOptions>(options => { options.InactivityThreshold = TimeSpan.FromSeconds(15); });
 7136services.Configure<BookmarkQueuePurgeOptions>(options => options.Ttl = TimeSpan.FromSeconds(3600));
 14137services.Configure<CachingOptions>(options => options.CacheDuration = TimeSpan.FromDays(1));
 8138services.Configure<IncidentOptions>(options => options.DefaultIncidentStrategy = typeof(ContinueWithIncidentsStrategy));
 7139services.AddHealthChecks();
 7140services.AddControllers();
 21141services.AddCors(cors => cors.AddDefaultPolicy(policy => policy.AllowAnyHeader().AllowAnyMethod().AllowAnyOrigin().WithE
 142
 143// Build the web application.
 7144var app = builder.Build();
 145
 146
 147// Configure the pipeline.
 7148if (app.Environment.IsDevelopment())
 7149    app.UseDeveloperExceptionPage();
 150
 151// CORS.
 7152app.UseCors();
 153
 154// Health checks.
 7155app.MapHealthChecks("/");
 156
 157// Routing used for SignalR.
 7158app.UseRouting();
 159
 160// Security.
 7161app.UseAuthentication();
 7162app.UseAuthorization();
 163
 164// Multitenancy.
 165if (useMultitenancy)
 166    app.UseTenants();
 167
 168// Elsa API endpoints for designer.
 7169var routePrefix = app.Services.GetRequiredService<IOptions<ApiEndpointOptions>>().Value.RoutePrefix;
 7170app.UseWorkflowsApi(routePrefix);
 171
 172// Captures unhandled exceptions and returns a JSON response.
 7173app.UseJsonSerializationErrorHandler();
 174
 175// Elsa HTTP Endpoint activities.
 7176app.UseWorkflows();
 177
 7178app.MapControllers();
 179
 180// Swagger API documentation.
 7181if (app.Environment.IsDevelopment())
 182{
 7183    app.UseSwaggerUI();
 184}
 185
 186// SignalR.
 187if (useSignalR)
 188{
 189    app.UseWorkflowsSignalRHubs();
 190}
 191
 192// Run.
 7193await app.RunAsync();
 194
 195/// <summary>
 196/// The main entry point for the application made public for end to end testing.
 197/// </summary>
 198[UsedImplicitly]
 199public partial class Program
 200{
 201    /// <summary>
 202    /// Set by the test runner to configure the module for testing.
 203    /// </summary>
 15204    public static Action<IModule>? ConfigureForTest { get; set; }
 205}

Methods/Properties

<Main>$()
get_ConfigureForTest()