Update samples
This commit is contained in:
parent
3be2e128d8
commit
5e35dad9e7
7
Elsa.sln
7
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
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<Import Project="..\..\..\common.props"/>
|
||||
<Import Project="..\..\..\configureawait.props"/>
|
||||
<Import Project="..\..\..\common.props" />
|
||||
<Import Project="..\..\..\configureawait.props" />
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,15 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\..\bundles\Elsa\Elsa.csproj" />
|
||||
<ProjectReference Include="..\..\..\modules\Elsa.Scheduling\Elsa.Scheduling.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
19
src/samples/console/Elsa.Samples.LoopingWorkflows/Program.cs
Normal file
19
src/samples/console/Elsa.Samples.LoopingWorkflows/Program.cs
Normal file
|
|
@ -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<IWorkflowRunner>();
|
||||
|
||||
// Run the ForWorkflow.
|
||||
await workflowRunner.RunAsync(ForWorkflow.Create());
|
||||
36
src/samples/console/Elsa.Samples.LoopingWorkflows/Readme.md
Normal file
36
src/samples/console/Elsa.Samples.LoopingWorkflows/Readme.md
Normal file
|
|
@ -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.
|
||||
}
|
||||
```
|
||||
|
|
@ -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<int>();
|
||||
|
||||
return new Sequence
|
||||
{
|
||||
Variables = { currentValueVariable },
|
||||
Activities =
|
||||
{
|
||||
new WriteLine("Counting down from 10 to 1:"),
|
||||
new For(10, 1)
|
||||
{
|
||||
CurrentValue = new Output<MemoryBlockReference?>(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>(DelayBlockingStrategy.Blocking),
|
||||
TimeSpan = new Input<TimeSpan>(TimeSpan.FromSeconds(1))
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
new WriteLine("Happy coding!")
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
@ -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();
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue