diff --git a/Elsa.sln b/Elsa.sln index a47d0c1b2..b49eccd67 100644 --- a/Elsa.sln +++ b/Elsa.sln @@ -232,6 +232,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Elsa.Workflows.Core.UnitTes EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Elsa.ProtoCluster.ComponentTests", "test\component\Elsa.ProtoCluster.ComponentTests\Elsa.ProtoCluster.ComponentTests.csproj", "{B99B23D4-6D36-4A31-BE92-DE2415514C79}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Elsa.Samples.AspNet.ChildWorkflows", "src\samples\aspnet\Elsa.Samples.AspNet.ChildWorkflows\Elsa.Samples.AspNet.ChildWorkflows.csproj", "{2EA47068-6079-4276-8776-F67DE99B568D}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -578,6 +580,10 @@ Global {B99B23D4-6D36-4A31-BE92-DE2415514C79}.Debug|Any CPU.Build.0 = Debug|Any CPU {B99B23D4-6D36-4A31-BE92-DE2415514C79}.Release|Any CPU.ActiveCfg = Release|Any CPU {B99B23D4-6D36-4A31-BE92-DE2415514C79}.Release|Any CPU.Build.0 = Release|Any CPU + {2EA47068-6079-4276-8776-F67DE99B568D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {2EA47068-6079-4276-8776-F67DE99B568D}.Debug|Any CPU.Build.0 = Debug|Any CPU + {2EA47068-6079-4276-8776-F67DE99B568D}.Release|Any CPU.ActiveCfg = Release|Any CPU + {2EA47068-6079-4276-8776-F67DE99B568D}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(NestedProjects) = preSolution {155227F0-A33B-40AA-A4B4-06F813EB921B} = {61017E64-6D00-49CB-9E81-5002DC8F7D5F} @@ -682,5 +688,6 @@ Global {28818676-F6AF-4203-8B65-BD33A50CB9A2} = {C6658DE0-2B2F-47F0-BB61-2CA66D435C09} {DC9CCAD0-7363-4691-B964-FF5B3AEA3F95} = {18453B51-25EB-4317-A4B3-B10518252E92} {B99B23D4-6D36-4A31-BE92-DE2415514C79} = {08B41FFA-CEE3-46A7-B5C0-3EB65D37A16C} + {2EA47068-6079-4276-8776-F67DE99B568D} = {56C2FFB8-EA54-45B5-A095-4A78142EB4B5} EndGlobalSection EndGlobal diff --git a/src/samples/aspnet/Elsa.Samples.AspNet.ChildWorkflows/Elsa.Samples.AspNet.ChildWorkflows.csproj b/src/samples/aspnet/Elsa.Samples.AspNet.ChildWorkflows/Elsa.Samples.AspNet.ChildWorkflows.csproj new file mode 100644 index 000000000..e6d6cba40 --- /dev/null +++ b/src/samples/aspnet/Elsa.Samples.AspNet.ChildWorkflows/Elsa.Samples.AspNet.ChildWorkflows.csproj @@ -0,0 +1,18 @@ + + + + net7.0 + enable + enable + + + + + + + + + + + + diff --git a/src/samples/aspnet/Elsa.Samples.AspNet.ChildWorkflows/Program.cs b/src/samples/aspnet/Elsa.Samples.AspNet.ChildWorkflows/Program.cs new file mode 100644 index 000000000..64ed4d8b5 --- /dev/null +++ b/src/samples/aspnet/Elsa.Samples.AspNet.ChildWorkflows/Program.cs @@ -0,0 +1,58 @@ +using Elsa.EntityFrameworkCore.Modules.Management; +using Elsa.EntityFrameworkCore.Modules.Runtime; +using Elsa.Extensions; + +var builder = WebApplication.CreateBuilder(args); + +// Add services to the container. +builder.Services.AddElsa(elsa => +{ + // Configure management feature to use EF Core. + elsa.UseWorkflowManagement(management => management.UseEntityFrameworkCore()); + + // Configure runtime feature to use EF Core. + elsa.UseWorkflowRuntime(runtime => + { + runtime.UseEntityFrameworkCore(); + }); + + // Expose API endpoints. + elsa.UseWorkflowsApi(); + + // Add services for HTTP activities and workflow middleware. + elsa.UseHttp(); + + // Configure identity so that we can create a default admin user. + elsa.UseIdentity(identity => + { + identity.UseAdminUserProvider(); + identity.TokenOptions = options => + { + options.SigningKey = "secret-token-signing-key"; + options.AccessTokenLifetime = TimeSpan.FromDays(1); + }; + }); + + // Use default authentication (JWT). + elsa.UseDefaultAuthentication(auth => auth.UseAdminApiKey()); + + // Register custom activities. + elsa.AddActivitiesFrom(); + + // Register programmatically defined workflows. + elsa.AddWorkflowsFrom(); +}); + +// Configure CORS to allow designer app hosted on a different origin to invoke the APIs. +builder.Services.AddCors(cors => cors.AddDefaultPolicy(policy => policy.AllowAnyOrigin().AllowAnyHeader().AllowAnyMethod())); + +var app = builder.Build(); + +// Configure the HTTP request pipeline. +app.UseHttpsRedirection(); +app.UseCors(); +app.UseAuthentication(); +app.UseAuthorization(); +app.UseWorkflowsApi(); +app.UseWorkflows(); +app.Run(); \ No newline at end of file diff --git a/src/samples/aspnet/Elsa.Samples.AspNet.ChildWorkflows/Properties/launchSettings.json b/src/samples/aspnet/Elsa.Samples.AspNet.ChildWorkflows/Properties/launchSettings.json new file mode 100644 index 000000000..d540d3790 --- /dev/null +++ b/src/samples/aspnet/Elsa.Samples.AspNet.ChildWorkflows/Properties/launchSettings.json @@ -0,0 +1,37 @@ +{ + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:8068", + "sslPort": 44312 + } + }, + "profiles": { + "http": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "applicationUrl": "http://localhost:5185", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "https": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "applicationUrl": "https://localhost:7083;http://localhost:5185", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} diff --git a/src/samples/aspnet/Elsa.Samples.AspNet.ChildWorkflows/Workflows/ChildWorkflow.cs b/src/samples/aspnet/Elsa.Samples.AspNet.ChildWorkflows/Workflows/ChildWorkflow.cs new file mode 100644 index 000000000..2b83375b1 --- /dev/null +++ b/src/samples/aspnet/Elsa.Samples.AspNet.ChildWorkflows/Workflows/ChildWorkflow.cs @@ -0,0 +1,27 @@ +using Elsa.Extensions; +using Elsa.Workflows.Core; +using Elsa.Workflows.Core.Activities; +using Elsa.Workflows.Core.Contracts; +using Elsa.Workflows.Management.Activities.SetOutput; + +namespace Elsa.Samples.AspNet.ChildWorkflows.Workflows; + +public class ChildWorkflow : WorkflowBase +{ + protected override void Build(IWorkflowBuilder builder) + { + builder.Root = new Sequence + { + Activities = + { + new WriteLine(context => $"I am the child workflow. My parent said: \"{context.GetInput("ParentMessage")}\"."), + new WriteLine("Let's say hi to the parent!"), + new SetOutput + { + OutputName = new("ChildMessage"), + OutputValue = new("Hello from child!") + } + } + }; + } +} \ No newline at end of file diff --git a/src/samples/aspnet/Elsa.Samples.AspNet.ChildWorkflows/Workflows/ParentWorkflow.cs b/src/samples/aspnet/Elsa.Samples.AspNet.ChildWorkflows/Workflows/ParentWorkflow.cs new file mode 100644 index 000000000..1772c707d --- /dev/null +++ b/src/samples/aspnet/Elsa.Samples.AspNet.ChildWorkflows/Workflows/ParentWorkflow.cs @@ -0,0 +1,33 @@ +using Elsa.Workflows.Core; +using Elsa.Workflows.Core.Activities; +using Elsa.Workflows.Core.Contracts; +using Elsa.Workflows.Runtime.Activities; + +namespace Elsa.Samples.AspNet.ChildWorkflows.Workflows; + +public class ParentWorkflow : WorkflowBase +{ + protected override void Build(IWorkflowBuilder builder) + { + var childOutput = builder.WithVariable>(); + + builder.Root = new Sequence + { + Activities = + { + new WriteLine("I am the parent workflow."), + new DispatchWorkflow + { + WorkflowDefinitionId = new(nameof(ChildWorkflow)), + Input = new(new Dictionary + { + ["ParentMessage"] = "Hello from parent!" + }), + WaitForCompletion = new(true), + Result = new(childOutput) + }, + new WriteLine(context => $"Child finished executing and said: {childOutput.Get(context)!["ChildMessage"]}") + } + }; + } +} \ No newline at end of file diff --git a/src/samples/aspnet/Elsa.Samples.AspNet.ChildWorkflows/appsettings.Development.json b/src/samples/aspnet/Elsa.Samples.AspNet.ChildWorkflows/appsettings.Development.json new file mode 100644 index 000000000..0c208ae91 --- /dev/null +++ b/src/samples/aspnet/Elsa.Samples.AspNet.ChildWorkflows/appsettings.Development.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + } +} diff --git a/src/samples/aspnet/Elsa.Samples.AspNet.ChildWorkflows/appsettings.json b/src/samples/aspnet/Elsa.Samples.AspNet.ChildWorkflows/appsettings.json new file mode 100644 index 000000000..46bdb4522 --- /dev/null +++ b/src/samples/aspnet/Elsa.Samples.AspNet.ChildWorkflows/appsettings.json @@ -0,0 +1,10 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning", + "Microsoft.EntityFrameworkCore": "Warning" + } + }, + "AllowedHosts": "*" +}