Add sample project demonstrating signals and JSON based workflows
This commit is contained in:
parent
9650962755
commit
b28dfa92ee
7
Elsa.sln
7
Elsa.sln
|
|
@ -287,6 +287,8 @@ ProjectSection(SolutionItems) = preProject
|
|||
.github\workflows\publish-latest-dashboard-and-server-docker.yml = .github\workflows\publish-latest-dashboard-and-server-docker.yml
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Elsa.Samples.SignalApi", "src\samples\aspnet\Elsa.Samples.SignalApi\Elsa.Samples.SignalApi.csproj", "{3E2423CF-50E6-4D2B-8749-17B1EF540FE4}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
|
|
@ -673,6 +675,10 @@ Global
|
|||
{5F81C84A-4C04-48FF-981C-23E48A7ACA6C}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{5F81C84A-4C04-48FF-981C-23E48A7ACA6C}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{5F81C84A-4C04-48FF-981C-23E48A7ACA6C}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{3E2423CF-50E6-4D2B-8749-17B1EF540FE4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{3E2423CF-50E6-4D2B-8749-17B1EF540FE4}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{3E2423CF-50E6-4D2B-8749-17B1EF540FE4}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{3E2423CF-50E6-4D2B-8749-17B1EF540FE4}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
|
@ -803,6 +809,7 @@ Global
|
|||
{30A9B140-14F5-4D00-84ED-1447F96D13C8} = {FC9F520F-BA51-4AD2-BFEE-EF787798E734}
|
||||
{28C5C63F-2DCF-46BE-9576-1F50A7CFE8C4} = {164EB38A-D6D2-4092-8835-C944ECEE357C}
|
||||
{5F81C84A-4C04-48FF-981C-23E48A7ACA6C} = {28C5C63F-2DCF-46BE-9576-1F50A7CFE8C4}
|
||||
{3E2423CF-50E6-4D2B-8749-17B1EF540FE4} = {22E75696-6FE9-436A-9097-EE21C603F818}
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {8B0975FD-7050-48B0-88C5-48C33378E158}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,33 @@
|
|||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Elsa.Activities.Signaling.Services;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace Elsa.Samples.SignalApi.Controllers
|
||||
{
|
||||
[ApiController]
|
||||
[Route("fire")]
|
||||
public class FireController : Controller
|
||||
{
|
||||
private readonly ISignaler _signaler;
|
||||
|
||||
public FireController(ISignaler signaler)
|
||||
{
|
||||
_signaler = signaler;
|
||||
}
|
||||
|
||||
[HttpGet("start")]
|
||||
public async Task<IActionResult> StartFire(CancellationToken cancellationToken)
|
||||
{
|
||||
var startedWorkflows = await _signaler.TriggerSignalAsync("Fire", cancellationToken: cancellationToken);
|
||||
return Ok(startedWorkflows);
|
||||
}
|
||||
|
||||
[HttpGet("{workflowInstanceId}/extinguish")]
|
||||
public async Task<IActionResult> Extinguish(string workflowInstanceId, CancellationToken cancellationToken)
|
||||
{
|
||||
var startedWorkflows = await _signaler.TriggerSignalAsync("Water", workflowInstanceId: workflowInstanceId, cancellationToken: cancellationToken);
|
||||
return Ok(startedWorkflows);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net5.0</TargetFramework>
|
||||
<IsPackable>false</IsPackable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\..\activities\Elsa.Activities.Http\Elsa.Activities.Http.csproj" />
|
||||
<ProjectReference Include="..\..\..\activities\Elsa.Activities.Temporal.Quartz\Elsa.Activities.Temporal.Quartz.csproj" />
|
||||
<ProjectReference Include="..\..\..\core\Elsa\Elsa.csproj" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
14
src/samples/aspnet/Elsa.Samples.SignalApi/Program.cs
Normal file
14
src/samples/aspnet/Elsa.Samples.SignalApi/Program.cs
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
|
||||
namespace Elsa.Samples.SignalApi
|
||||
{
|
||||
public class Program
|
||||
{
|
||||
public static void Main(string[] args) => CreateHostBuilder(args).Build().Run();
|
||||
|
||||
public static IHostBuilder CreateHostBuilder(string[] args) =>
|
||||
Host.CreateDefaultBuilder(args)
|
||||
.ConfigureWebHostDefaults(webBuilder => { webBuilder.UseStartup<Startup>(); });
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
{
|
||||
"profiles": {
|
||||
"Elsa.Samples.SignalApi": {
|
||||
"commandName": "Project",
|
||||
"launchBrowser": false,
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
},
|
||||
"applicationUrl": "https://localhost:7309"
|
||||
}
|
||||
}
|
||||
}
|
||||
43
src/samples/aspnet/Elsa.Samples.SignalApi/Startup.cs
Normal file
43
src/samples/aspnet/Elsa.Samples.SignalApi/Startup.cs
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
using System.IO;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Storage.Net;
|
||||
|
||||
namespace Elsa.Samples.SignalApi
|
||||
{
|
||||
public class Startup
|
||||
{
|
||||
private readonly IHostEnvironment _environment;
|
||||
|
||||
public Startup(IConfiguration configuration, IHostEnvironment environment)
|
||||
{
|
||||
_environment = environment;
|
||||
Configuration = configuration;
|
||||
}
|
||||
|
||||
public IConfiguration Configuration { get; }
|
||||
|
||||
public void ConfigureServices(IServiceCollection services)
|
||||
{
|
||||
services
|
||||
.AddControllers();
|
||||
|
||||
services
|
||||
.AddElsa(options => options
|
||||
.UseStorage(() => StorageFactory.Blobs.DirectoryFiles(Path.Combine(_environment.ContentRootPath, "Workflows")))
|
||||
.AddConsoleActivities()
|
||||
.AddHttpActivities(httpOptions => Configuration.GetSection("Elsa:Http").Bind(httpOptions))
|
||||
.AddQuartzTemporalActivities()
|
||||
);
|
||||
}
|
||||
|
||||
public void Configure(IApplicationBuilder app)
|
||||
{
|
||||
app.UseRouting();
|
||||
app.UseEndpoints(endpoints => endpoints.MapControllers());
|
||||
app.UseWelcomePage();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,262 @@
|
|||
{
|
||||
"$id": "1",
|
||||
"definitionId": "cd6b168f415e4a85a3497d7b8ae377ed",
|
||||
"versionId": "594123a8e04145b4a273d9338c2d7476",
|
||||
"name": "Fire Protocol",
|
||||
"version": 3,
|
||||
"variables": {
|
||||
"$id": "2",
|
||||
"data": {}
|
||||
},
|
||||
"customAttributes": {
|
||||
"$id": "3",
|
||||
"data": {}
|
||||
},
|
||||
"isSingleton": false,
|
||||
"persistenceBehavior": "WorkflowBurst",
|
||||
"deleteCompletedInstances": false,
|
||||
"isPublished": true,
|
||||
"isLatest": true,
|
||||
"activities": [
|
||||
{
|
||||
"$id": "4",
|
||||
"activityId": "8611ce28-21ac-446a-a3eb-59f47a04fa8b",
|
||||
"type": "SignalReceived",
|
||||
"displayName": "Signal Received",
|
||||
"persistWorkflow": false,
|
||||
"loadWorkflowContext": false,
|
||||
"saveWorkflowContext": false,
|
||||
"persistOutput": false,
|
||||
"properties": [
|
||||
{
|
||||
"$id": "5",
|
||||
"name": "Signal",
|
||||
"expressions": {
|
||||
"$id": "6",
|
||||
"Literal": "Fire"
|
||||
}
|
||||
},
|
||||
{
|
||||
"$id": "7",
|
||||
"name": "Scope",
|
||||
"expressions": {
|
||||
"$id": "8"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"$id": "9",
|
||||
"activityId": "c242e5dc-a4c8-4085-82aa-69d5aafc2e80",
|
||||
"type": "WriteLine",
|
||||
"displayName": "Write Line",
|
||||
"persistWorkflow": false,
|
||||
"loadWorkflowContext": false,
|
||||
"saveWorkflowContext": false,
|
||||
"persistOutput": false,
|
||||
"properties": [
|
||||
{
|
||||
"$id": "10",
|
||||
"name": "Text",
|
||||
"syntax": "Liquid",
|
||||
"expressions": {
|
||||
"$id": "11",
|
||||
"Literal": "",
|
||||
"Liquid": "There's a fire! Need water for workflow instance {{ WorkflowInstanceId }} fast!"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"$id": "12",
|
||||
"activityId": "8f27a5df-4c9f-49d2-a257-238213971530",
|
||||
"type": "Fork",
|
||||
"displayName": "Fork",
|
||||
"persistWorkflow": false,
|
||||
"loadWorkflowContext": false,
|
||||
"saveWorkflowContext": false,
|
||||
"persistOutput": false,
|
||||
"properties": [
|
||||
{
|
||||
"$id": "13",
|
||||
"name": "Branches",
|
||||
"expressions": {
|
||||
"$id": "14",
|
||||
"Json": "[\"Timeout\",\"Extinguish\"]"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"$id": "15",
|
||||
"activityId": "3ef2c69e-3e86-443e-8aa9-570eb98969bb",
|
||||
"type": "Timer",
|
||||
"displayName": "Timer",
|
||||
"persistWorkflow": false,
|
||||
"loadWorkflowContext": false,
|
||||
"saveWorkflowContext": false,
|
||||
"persistOutput": false,
|
||||
"properties": [
|
||||
{
|
||||
"$id": "16",
|
||||
"name": "Timeout",
|
||||
"syntax": "JavaScript",
|
||||
"expressions": {
|
||||
"$id": "17",
|
||||
"JavaScript": "Duration.FromSeconds(10)"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"$id": "18",
|
||||
"activityId": "c13ef790-ad08-46a1-8744-7f13062e9824",
|
||||
"type": "WriteLine",
|
||||
"displayName": "Write Line",
|
||||
"persistWorkflow": false,
|
||||
"loadWorkflowContext": false,
|
||||
"saveWorkflowContext": false,
|
||||
"persistOutput": false,
|
||||
"properties": [
|
||||
{
|
||||
"$id": "19",
|
||||
"name": "Text",
|
||||
"expressions": {
|
||||
"$id": "20",
|
||||
"Literal": "There goes the omelet :("
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"$id": "21",
|
||||
"activityId": "fd27b8eb-3465-42d9-ba7e-f84e03b8a2e0",
|
||||
"type": "Finish",
|
||||
"displayName": "Finish",
|
||||
"persistWorkflow": false,
|
||||
"loadWorkflowContext": false,
|
||||
"saveWorkflowContext": false,
|
||||
"persistOutput": false,
|
||||
"properties": [
|
||||
{
|
||||
"$id": "22",
|
||||
"name": "OutputValue",
|
||||
"expressions": {
|
||||
"$id": "23"
|
||||
}
|
||||
},
|
||||
{
|
||||
"$id": "24",
|
||||
"name": "OutcomeNames",
|
||||
"expressions": {
|
||||
"$id": "25"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"$id": "26",
|
||||
"activityId": "d79e1bbe-16db-46f3-aeb8-acbedf4b6e99",
|
||||
"type": "WriteLine",
|
||||
"displayName": "Write Line",
|
||||
"persistWorkflow": false,
|
||||
"loadWorkflowContext": false,
|
||||
"saveWorkflowContext": false,
|
||||
"persistOutput": false,
|
||||
"properties": [
|
||||
{
|
||||
"$id": "27",
|
||||
"name": "Text",
|
||||
"expressions": {
|
||||
"$id": "28",
|
||||
"Literal": "Whew! Breakfast saved just in time :)"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"$id": "29",
|
||||
"activityId": "21e9a4d0-e49f-46b4-9d0b-d96cf3d4fea1",
|
||||
"type": "SignalReceived",
|
||||
"displayName": "Signal Received",
|
||||
"persistWorkflow": false,
|
||||
"loadWorkflowContext": false,
|
||||
"saveWorkflowContext": false,
|
||||
"persistOutput": false,
|
||||
"properties": [
|
||||
{
|
||||
"$id": "30",
|
||||
"name": "Signal",
|
||||
"expressions": {
|
||||
"$id": "31",
|
||||
"Literal": "Water"
|
||||
}
|
||||
},
|
||||
{
|
||||
"$id": "32",
|
||||
"name": "Scope",
|
||||
"expressions": {
|
||||
"$id": "33"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"connections": [
|
||||
{
|
||||
"$id": "34",
|
||||
"sourceActivityId": "8611ce28-21ac-446a-a3eb-59f47a04fa8b",
|
||||
"targetActivityId": "c242e5dc-a4c8-4085-82aa-69d5aafc2e80",
|
||||
"outcome": "Done"
|
||||
},
|
||||
{
|
||||
"$id": "35",
|
||||
"sourceActivityId": "c242e5dc-a4c8-4085-82aa-69d5aafc2e80",
|
||||
"targetActivityId": "8f27a5df-4c9f-49d2-a257-238213971530",
|
||||
"outcome": "Done"
|
||||
},
|
||||
{
|
||||
"$id": "36",
|
||||
"sourceActivityId": "8f27a5df-4c9f-49d2-a257-238213971530",
|
||||
"targetActivityId": "3ef2c69e-3e86-443e-8aa9-570eb98969bb",
|
||||
"outcome": "Timeout"
|
||||
},
|
||||
{
|
||||
"$id": "37",
|
||||
"sourceActivityId": "3ef2c69e-3e86-443e-8aa9-570eb98969bb",
|
||||
"targetActivityId": "c13ef790-ad08-46a1-8744-7f13062e9824",
|
||||
"outcome": "Done"
|
||||
},
|
||||
{
|
||||
"$id": "38",
|
||||
"sourceActivityId": "c13ef790-ad08-46a1-8744-7f13062e9824",
|
||||
"targetActivityId": "fd27b8eb-3465-42d9-ba7e-f84e03b8a2e0",
|
||||
"outcome": "Done"
|
||||
},
|
||||
{
|
||||
"$id": "39",
|
||||
"sourceActivityId": "d79e1bbe-16db-46f3-aeb8-acbedf4b6e99",
|
||||
"targetActivityId": "fd27b8eb-3465-42d9-ba7e-f84e03b8a2e0",
|
||||
"outcome": "Done"
|
||||
},
|
||||
{
|
||||
"$id": "40",
|
||||
"sourceActivityId": "8f27a5df-4c9f-49d2-a257-238213971530",
|
||||
"targetActivityId": "21e9a4d0-e49f-46b4-9d0b-d96cf3d4fea1",
|
||||
"outcome": "Extinguish"
|
||||
},
|
||||
{
|
||||
"$id": "41",
|
||||
"sourceActivityId": "21e9a4d0-e49f-46b4-9d0b-d96cf3d4fea1",
|
||||
"targetActivityId": "d79e1bbe-16db-46f3-aeb8-acbedf4b6e99",
|
||||
"outcome": "Extinguish"
|
||||
},
|
||||
{
|
||||
"$id": "42",
|
||||
"sourceActivityId": "21e9a4d0-e49f-46b4-9d0b-d96cf3d4fea1",
|
||||
"targetActivityId": "d79e1bbe-16db-46f3-aeb8-acbedf4b6e99",
|
||||
"outcome": "Done"
|
||||
}
|
||||
],
|
||||
"id": "594123a8e04145b4a273d9338c2d7476"
|
||||
}
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft": "Warning",
|
||||
"Microsoft.Hosting.Lifetime": "Information"
|
||||
}
|
||||
}
|
||||
}
|
||||
14
src/samples/aspnet/Elsa.Samples.SignalApi/appsettings.json
Normal file
14
src/samples/aspnet/Elsa.Samples.SignalApi/appsettings.json
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft": "Warning",
|
||||
"Microsoft.Hosting.Lifetime": "Information"
|
||||
}
|
||||
},
|
||||
"Elsa": {
|
||||
"Http": {
|
||||
"BaseUrl": "https://localhost:7309"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,9 +1,9 @@
|
|||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Warning",
|
||||
"Default": "Debug",
|
||||
"Orleans": "Warning",
|
||||
"System": "Warning",
|
||||
"System": "Information",
|
||||
"Microsoft": "Warning"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue