diff --git a/Elsa.sln b/Elsa.sln index d55a3f49e..46a1a4a64 100644 --- a/Elsa.sln +++ b/Elsa.sln @@ -114,6 +114,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Elsa.Samples.SequentialWork EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Elsa.Samples.ConditionalWorkflows", "src\samples\console\Elsa.Samples.ConditionalWorkflows\Elsa.Samples.ConditionalWorkflows.csproj", "{70D3ACE9-EB41-4B36-949C-08B8C22B99F7}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Elsa.Samples.LoopingWorkflows", "src\samples\console\Elsa.Samples.LoopingWorkflows\Elsa.Samples.LoopingWorkflows.csproj", "{997F5709-61E0-4874-BFC3-07974685E02E}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -288,6 +290,10 @@ Global {70D3ACE9-EB41-4B36-949C-08B8C22B99F7}.Debug|Any CPU.Build.0 = Debug|Any CPU {70D3ACE9-EB41-4B36-949C-08B8C22B99F7}.Release|Any CPU.ActiveCfg = Release|Any CPU {70D3ACE9-EB41-4B36-949C-08B8C22B99F7}.Release|Any CPU.Build.0 = Release|Any CPU + {997F5709-61E0-4874-BFC3-07974685E02E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {997F5709-61E0-4874-BFC3-07974685E02E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {997F5709-61E0-4874-BFC3-07974685E02E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {997F5709-61E0-4874-BFC3-07974685E02E}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(NestedProjects) = preSolution {155227F0-A33B-40AA-A4B4-06F813EB921B} = {61017E64-6D00-49CB-9E81-5002DC8F7D5F} @@ -339,5 +345,6 @@ Global {D253AFC2-9496-4538-B424-47CC579B7A96} = {873BFC3E-63C2-4495-A503-5EC05DCD84E4} {74B9AFE0-EB4B-4AD2-BF25-90753203EFF8} = {873BFC3E-63C2-4495-A503-5EC05DCD84E4} {70D3ACE9-EB41-4B36-949C-08B8C22B99F7} = {873BFC3E-63C2-4495-A503-5EC05DCD84E4} + {997F5709-61E0-4874-BFC3-07974685E02E} = {873BFC3E-63C2-4495-A503-5EC05DCD84E4} EndGlobalSection EndGlobal diff --git a/src/modules/Elsa.Scheduling/Elsa.Scheduling.csproj b/src/modules/Elsa.Scheduling/Elsa.Scheduling.csproj index afda17241..e251af603 100644 --- a/src/modules/Elsa.Scheduling/Elsa.Scheduling.csproj +++ b/src/modules/Elsa.Scheduling/Elsa.Scheduling.csproj @@ -1,7 +1,7 @@ - - + + net6.0 diff --git a/src/samples/console/Elsa.Samples.ConditionalWorkflows/Program.cs b/src/samples/console/Elsa.Samples.ConditionalWorkflows/Program.cs index 656811fb6..e6e45c90e 100644 --- a/src/samples/console/Elsa.Samples.ConditionalWorkflows/Program.cs +++ b/src/samples/console/Elsa.Samples.ConditionalWorkflows/Program.cs @@ -3,7 +3,6 @@ using Elsa.Workflows.Core.Activities; using Elsa.Workflows.Core.Models; using Elsa.Workflows.Core.Services; using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Logging; // Setup service container. var services = new ServiceCollection(); @@ -11,9 +10,6 @@ var services = new ServiceCollection(); // Add Elsa services. services.AddElsa(); -// Configure logging. -services.AddLogging(logging => logging.AddConsole().SetMinimumLevel(LogLevel.Debug)); - // Build service container. var serviceProvider = services.BuildServiceProvider(); diff --git a/src/samples/console/Elsa.Samples.HelloWorld/Program.cs b/src/samples/console/Elsa.Samples.HelloWorld/Program.cs index 70299da10..62e2c954d 100644 --- a/src/samples/console/Elsa.Samples.HelloWorld/Program.cs +++ b/src/samples/console/Elsa.Samples.HelloWorld/Program.cs @@ -2,7 +2,6 @@ using Elsa.Workflows.Core.Activities; using Elsa.Workflows.Core.Services; using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Logging; // Setup service container. var services = new ServiceCollection(); @@ -10,9 +9,6 @@ var services = new ServiceCollection(); // Add Elsa services. services.AddElsa(); -// Configure logging. -services.AddLogging(logging => logging.AddConsole().SetMinimumLevel(LogLevel.Debug)); - // Build service container. var serviceProvider = services.BuildServiceProvider(); diff --git a/src/samples/console/Elsa.Samples.LoopingWorkflows/Elsa.Samples.LoopingWorkflows.csproj b/src/samples/console/Elsa.Samples.LoopingWorkflows/Elsa.Samples.LoopingWorkflows.csproj new file mode 100644 index 000000000..d5e6b3aeb --- /dev/null +++ b/src/samples/console/Elsa.Samples.LoopingWorkflows/Elsa.Samples.LoopingWorkflows.csproj @@ -0,0 +1,15 @@ + + + + Exe + net6.0 + enable + enable + + + + + + + + diff --git a/src/samples/console/Elsa.Samples.LoopingWorkflows/Program.cs b/src/samples/console/Elsa.Samples.LoopingWorkflows/Program.cs new file mode 100644 index 000000000..c1a547498 --- /dev/null +++ b/src/samples/console/Elsa.Samples.LoopingWorkflows/Program.cs @@ -0,0 +1,19 @@ +using Elsa.Extensions; +using Elsa.Samples.LoopingWorkflows.Workflows; +using Elsa.Workflows.Core.Services; +using Microsoft.Extensions.DependencyInjection; + +// Setup service container. +var services = new ServiceCollection(); + +// Add Elsa services. +services.AddElsa(); + +// Build service container. +var serviceProvider = services.BuildServiceProvider(); + +// Resolve a workflow runner to run the workflow. +var workflowRunner = serviceProvider.GetRequiredService(); + +// Run the ForWorkflow. +await workflowRunner.RunAsync(ForWorkflow.Create()); \ No newline at end of file diff --git a/src/samples/console/Elsa.Samples.LoopingWorkflows/Readme.md b/src/samples/console/Elsa.Samples.LoopingWorkflows/Readme.md new file mode 100644 index 000000000..cb3997785 --- /dev/null +++ b/src/samples/console/Elsa.Samples.LoopingWorkflows/Readme.md @@ -0,0 +1,36 @@ +# Looping Workflows + +This sample demonstrates three activities that can be used to model looping constructs. + +## For + +The `For` activity executes a child activity for each step between a start and end value, similar to the following C# code: + +```csharp +for(var i = 0; i < 10; i++) +{ + // Logic to execute for each iteration. +} +``` + +## ForEach + +The `ForEach` activity executes a child activity for each item in a list, similar to the following C# code: + +```csharp +foreach(var item in items) +{ + // Logic to execute for each iteration. +} +``` + +## While + +The `While` activity executes a child activity for each iteration for as long as a certain condition evaluates to `true`, similar to the following C# code: + +```csharp +while(SomeConditionIstrue) +{ + // Logic to execute for each iteration. +} +``` \ No newline at end of file diff --git a/src/samples/console/Elsa.Samples.LoopingWorkflows/Workflows/ForWorkflow.cs b/src/samples/console/Elsa.Samples.LoopingWorkflows/Workflows/ForWorkflow.cs new file mode 100644 index 000000000..c1ee6f513 --- /dev/null +++ b/src/samples/console/Elsa.Samples.LoopingWorkflows/Workflows/ForWorkflow.cs @@ -0,0 +1,44 @@ +using Elsa.Expressions.Models; +using Elsa.Scheduling.Activities; +using Elsa.Scheduling.Models; +using Elsa.Workflows.Core.Activities; +using Elsa.Workflows.Core.Models; +using Elsa.Workflows.Core.Services; + +namespace Elsa.Samples.LoopingWorkflows.Workflows; + +public static class ForWorkflow +{ + public static IActivity Create() + { + var currentValueVariable = new Variable(); + + return new Sequence + { + Variables = { currentValueVariable }, + Activities = + { + new WriteLine("Counting down from 10 to 1:"), + new For(10, 1) + { + CurrentValue = new Output(currentValueVariable), + Body = new Sequence + { + Activities = + { + new WriteLine(context => $"Current value: {currentValueVariable.Get(context)}"), + new Delay + { + // The strategy determines whether the workflow should suspend or wait synchronously. + // For console applications without a host, long-running workflows aren't supported, so we use the Blocking strategy. + Strategy = new Input(DelayBlockingStrategy.Blocking), + TimeSpan = new Input(TimeSpan.FromSeconds(1)) + } + } + } + }, + new WriteLine("Happy coding!") + } + }; + } +} \ No newline at end of file diff --git a/src/samples/console/Elsa.Samples.SequentialWorkflows/Program.cs b/src/samples/console/Elsa.Samples.SequentialWorkflows/Program.cs index 60bfa3b53..bc5075c53 100644 --- a/src/samples/console/Elsa.Samples.SequentialWorkflows/Program.cs +++ b/src/samples/console/Elsa.Samples.SequentialWorkflows/Program.cs @@ -10,9 +10,6 @@ var services = new ServiceCollection(); // Add Elsa services. services.AddElsa(); -// Configure logging. -services.AddLogging(logging => logging.AddConsole().SetMinimumLevel(LogLevel.Debug)); - // Build service container. var serviceProvider = services.BuildServiceProvider();