Add ForEach sample project

This commit is contained in:
Sipke Schoorstra 2021-02-11 11:02:08 +01:00
parent e3bb394a03
commit b18dff82cd
6 changed files with 84 additions and 3 deletions

View file

@ -222,6 +222,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Elsa.Activities.Rebus", "sr
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Elsa.Samples.UserTaskConsole", "src\samples\console\Elsa.Samples.UserTaskConsole\Elsa.Samples.UserTaskConsole.csproj", "{9BF25FEF-B667-4BB0-882D-6911B9F5B3C7}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Elsa.Samples.ForEachLoopConsole", "src\samples\console\Elsa.Samples.ForEachLoopConsole\Elsa.Samples.ForEachLoopConsole.csproj", "{43EC7BEE-35C5-4B70-AC39-C89696710310}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -532,6 +534,10 @@ Global
{9BF25FEF-B667-4BB0-882D-6911B9F5B3C7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9BF25FEF-B667-4BB0-882D-6911B9F5B3C7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9BF25FEF-B667-4BB0-882D-6911B9F5B3C7}.Release|Any CPU.Build.0 = Release|Any CPU
{43EC7BEE-35C5-4B70-AC39-C89696710310}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{43EC7BEE-35C5-4B70-AC39-C89696710310}.Debug|Any CPU.Build.0 = Debug|Any CPU
{43EC7BEE-35C5-4B70-AC39-C89696710310}.Release|Any CPU.ActiveCfg = Release|Any CPU
{43EC7BEE-35C5-4B70-AC39-C89696710310}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@ -636,6 +642,7 @@ Global
{76BF833E-3CAE-4402-99F1-B3BFD90622E4} = {E42743A0-FBDD-4150-9D53-6000496D9B87}
{9CBD9317-FD12-4BB9-A17D-CE7FA6B12DD8} = {B43B546E-23F3-46E8-ACB7-D04F05CDA180}
{9BF25FEF-B667-4BB0-882D-6911B9F5B3C7} = {FC9F520F-BA51-4AD2-BFEE-EF787798E734}
{43EC7BEE-35C5-4B70-AC39-C89696710310} = {FC9F520F-BA51-4AD2-BFEE-EF787798E734}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {8B0975FD-7050-48B0-88C5-48C33378E158}

View file

@ -0,0 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="5.0.1" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\core\Elsa\Elsa.csproj" />
</ItemGroup>
</Project>

View file

@ -0,0 +1,25 @@
using System;
using System.Globalization;
using System.Linq;
using Elsa.Activities.Console;
using Elsa.Activities.ControlFlow;
using Elsa.Activities.Primitives;
using Elsa.Builders;
namespace Elsa.Samples.ForEachLoopConsole
{
/// <summary>
/// This workflow prompts the user to enter an integer start value, then iterates back from that value to 0.
/// The workflow also demonstrates retrieving runtime values such as user input.
/// </summary>
public class ForEachLoopWorkflow : IWorkflow
{
public void Build(IWorkflowBuilder builder)
{
builder
.WriteLine("Enumerating all months of the year:")
.ForEach(DateTimeFormatInfo.CurrentInfo!.MonthNames.Cast<object>().ToList, iterate => iterate.WriteLine(context => context.GetInput<string>()))
.WriteLine("Done.");
}
}
}

View file

@ -0,0 +1,32 @@
using System.Threading.Tasks;
using Elsa.Services;
using Microsoft.Extensions.DependencyInjection;
namespace Elsa.Samples.ForEachLoopConsole
{
/// <summary>
/// Demonstrates a workflow with a For looping construct.
/// </summary>
static class Program
{
private static async Task Main()
{
// Create a service container with Elsa services.
var services = new ServiceCollection()
.AddElsa(options => options
.AddConsoleActivities()
.AddWorkflow<ForEachLoopWorkflow>())
.BuildServiceProvider();
// Run startup actions (not needed when registering Elsa with a Host).
var startupRunner = services.GetRequiredService<IStartupRunner>();
await startupRunner.StartupAsync();
// Get a workflow runner.
var workflowRunner = services.GetRequiredService<IWorkflowRunner>();
// Execute the workflow.
await workflowRunner.RunWorkflowAsync<ForEachLoopWorkflow>();
}
}
}

View file

@ -10,7 +10,7 @@ namespace Elsa.Samples.ForLoopConsole
/// This workflow prompts the user to enter an integer start value, then iterates back from that value to 0.
/// The workflow also demonstrates retrieving runtime values such as user input.
/// </summary>
public class LoopingWorkflow : IWorkflow
public class ForLoopWorkflow : IWorkflow
{
public void Build(IWorkflowBuilder builder)
{

View file

@ -15,7 +15,7 @@ namespace Elsa.Samples.ForLoopConsole
var services = new ServiceCollection()
.AddElsa(options => options
.AddConsoleActivities()
.AddWorkflow<LoopingWorkflow>())
.AddWorkflow<ForLoopWorkflow>())
.BuildServiceProvider();
// Run startup actions (not needed when registering Elsa with a Host).
@ -26,7 +26,7 @@ namespace Elsa.Samples.ForLoopConsole
var workflowRunner = services.GetRequiredService<IWorkflowRunner>();
// Execute the workflow.
await workflowRunner.RunWorkflowAsync<LoopingWorkflow>();
await workflowRunner.RunWorkflowAsync<ForLoopWorkflow>();
}
}
}