Incremental work on While sample project
This commit is contained in:
parent
a2afe4498c
commit
a8699bdea1
24
Samples.sln
24
Samples.sln
|
|
@ -98,12 +98,12 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Elsa.Samples.FileBasedWorkf
|
|||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "dashboards", "dashboards", "{86773701-E2D0-41B4-A9BF-836E6902C7D3}"
|
||||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "alpinejs", "alpinejs", "{5091DF54-2733-48D6-9577-1BDBC8A698F6}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ElsaDashboard.Alpine.Web", "src\dashboards\aspnetcore+alpinejs\ElsaDashboard.Alpine.Web\ElsaDashboard.Alpine.Web.csproj", "{E70A85E9-C649-483F-AA8E-4531D86AD595}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Elsa.Samples.ReadModelHttp", "src\samples\Elsa.Samples.ReadModelHttp\Elsa.Samples.ReadModelHttp.csproj", "{E4485289-F1DF-4322-B07D-9A0C9B002D31}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Elsa.Samples.WhileLoopConsole", "src\samples\Elsa.Samples.WhileLoopConsole\Elsa.Samples.WhileLoopConsole.csproj", "{6B83CCE1-D523-4E3F-84EB-8D79AAF6F7C2}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Elsa.Samples.WhileLoopWorker", "src\samples\Elsa.Samples.WhileLoopWorker\Elsa.Samples.WhileLoopWorker.csproj", "{85A70E7C-A4AC-49BA-942B-635F974DE255}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
|
|
@ -231,14 +231,18 @@ Global
|
|||
{8DDF71CE-573D-4620-82F7-77507BB198D5}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{8DDF71CE-573D-4620-82F7-77507BB198D5}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{8DDF71CE-573D-4620-82F7-77507BB198D5}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{E70A85E9-C649-483F-AA8E-4531D86AD595}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{E70A85E9-C649-483F-AA8E-4531D86AD595}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{E70A85E9-C649-483F-AA8E-4531D86AD595}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{E70A85E9-C649-483F-AA8E-4531D86AD595}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{E4485289-F1DF-4322-B07D-9A0C9B002D31}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{E4485289-F1DF-4322-B07D-9A0C9B002D31}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{E4485289-F1DF-4322-B07D-9A0C9B002D31}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{E4485289-F1DF-4322-B07D-9A0C9B002D31}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{6B83CCE1-D523-4E3F-84EB-8D79AAF6F7C2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{6B83CCE1-D523-4E3F-84EB-8D79AAF6F7C2}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{6B83CCE1-D523-4E3F-84EB-8D79AAF6F7C2}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{6B83CCE1-D523-4E3F-84EB-8D79AAF6F7C2}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{85A70E7C-A4AC-49BA-942B-635F974DE255}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{85A70E7C-A4AC-49BA-942B-635F974DE255}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{85A70E7C-A4AC-49BA-942B-635F974DE255}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{85A70E7C-A4AC-49BA-942B-635F974DE255}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
|
@ -284,9 +288,9 @@ Global
|
|||
{44E0B699-A140-4551-A0E9-9FD9F171A9C2} = {468E498C-59DB-4541-8D8A-0D89DE9083AB}
|
||||
{8DDF71CE-573D-4620-82F7-77507BB198D5} = {5E5E1E84-DDBC-40D6-B891-0D563A15A44A}
|
||||
{86773701-E2D0-41B4-A9BF-836E6902C7D3} = {DA71CDAA-8DD3-4D5F-9FBD-8E4B37A2D925}
|
||||
{5091DF54-2733-48D6-9577-1BDBC8A698F6} = {86773701-E2D0-41B4-A9BF-836E6902C7D3}
|
||||
{E70A85E9-C649-483F-AA8E-4531D86AD595} = {5091DF54-2733-48D6-9577-1BDBC8A698F6}
|
||||
{E4485289-F1DF-4322-B07D-9A0C9B002D31} = {5E5E1E84-DDBC-40D6-B891-0D563A15A44A}
|
||||
{6B83CCE1-D523-4E3F-84EB-8D79AAF6F7C2} = {5E5E1E84-DDBC-40D6-B891-0D563A15A44A}
|
||||
{85A70E7C-A4AC-49BA-942B-635F974DE255} = {5E5E1E84-DDBC-40D6-B891-0D563A15A44A}
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {8B0975FD-7050-48B0-88C5-48C33378E158}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,16 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="3.1.9" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\core\Elsa\Elsa.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
32
src/samples/Elsa.Samples.WhileLoopConsole/Program.cs
Normal file
32
src/samples/Elsa.Samples.WhileLoopConsole/Program.cs
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
using System.Threading.Tasks;
|
||||
using Elsa.Services;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace Elsa.Samples.WhileLoopConsole
|
||||
{
|
||||
/// <summary>
|
||||
/// Demonstrates a workflow with a While looping construct.
|
||||
/// </summary>
|
||||
static class Program
|
||||
{
|
||||
private static async Task Main()
|
||||
{
|
||||
// Create a service container with Elsa services.
|
||||
var services = new ServiceCollection()
|
||||
.AddElsa()
|
||||
.AddConsoleActivities()
|
||||
.AddWorkflow<WhileMakingACallWorkflow>()
|
||||
.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.GetService<IWorkflowRunner>();
|
||||
|
||||
// Execute the workflow.
|
||||
await workflowRunner.RunWorkflowAsync<WhileMakingACallWorkflow>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
using System;
|
||||
using Elsa.Activities.Console;
|
||||
using Elsa.Activities.ControlFlow;
|
||||
using Elsa.Activities.Timers;
|
||||
using Elsa.Builders;
|
||||
using NodaTime;
|
||||
|
||||
namespace Elsa.Samples.WhileLoopConsole
|
||||
{
|
||||
/// <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 WhileMakingACallWorkflow : IWorkflow
|
||||
{
|
||||
public void Build(IWorkflowBuilder workflow)
|
||||
{
|
||||
workflow
|
||||
.WriteLine("Simulating a phone call... ringgg ringg.")
|
||||
.While(context => !context.GetVariable<bool>("CallFinished"),
|
||||
@while =>
|
||||
{
|
||||
@while
|
||||
.TimerEvent(Duration.FromSeconds(5));
|
||||
})
|
||||
.WriteLine("Workflow finished.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk.Worker">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net5.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="5.0.0-rc.2.20475.5"/>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
21
src/samples/Elsa.Samples.WhileLoopWorker/Program.cs
Normal file
21
src/samples/Elsa.Samples.WhileLoopWorker/Program.cs
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
|
||||
namespace Elsa.Samples.WhileLoopWorker
|
||||
{
|
||||
public class Program
|
||||
{
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
CreateHostBuilder(args).Build().Run();
|
||||
}
|
||||
|
||||
public static IHostBuilder CreateHostBuilder(string[] args) =>
|
||||
Host.CreateDefaultBuilder(args)
|
||||
.ConfigureServices((hostContext, services) => { services.AddHostedService<Worker>(); });
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
{
|
||||
"profiles": {
|
||||
"Elsa.Samples.WhileLoopWorker": {
|
||||
"commandName": "Project",
|
||||
"dotnetRunMessages": "true",
|
||||
"environmentVariables": {
|
||||
"DOTNET_ENVIRONMENT": "Development"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
29
src/samples/Elsa.Samples.WhileLoopWorker/Worker.cs
Normal file
29
src/samples/Elsa.Samples.WhileLoopWorker/Worker.cs
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace Elsa.Samples.WhileLoopWorker
|
||||
{
|
||||
public class Worker : BackgroundService
|
||||
{
|
||||
private readonly ILogger<Worker> _logger;
|
||||
|
||||
public Worker(ILogger<Worker> logger)
|
||||
{
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
|
||||
{
|
||||
while (!stoppingToken.IsCancellationRequested)
|
||||
{
|
||||
_logger.LogInformation("Worker running at: {time}", DateTimeOffset.Now);
|
||||
await Task.Delay(1000, stoppingToken);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft": "Warning",
|
||||
"Microsoft.Hosting.Lifetime": "Information"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft": "Warning",
|
||||
"Microsoft.Hosting.Lifetime": "Information"
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue