Add activity output example
This commit is contained in:
parent
c7c41d10a5
commit
dc0a68c37d
|
|
@ -87,6 +87,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Elsa.Persistence.DocumentDb
|
|||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sample16", "src\samples\Sample16\Sample16.csproj", "{DFE72CF4-C77C-4932-A00F-A8D325E603CE}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sample17", "src\samples\Sample17\Sample17.csproj", "{8854DF17-D566-49C9-8210-68AB8F5659FA}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
|
|
@ -221,6 +223,10 @@ Global
|
|||
{DFE72CF4-C77C-4932-A00F-A8D325E603CE}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{DFE72CF4-C77C-4932-A00F-A8D325E603CE}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{DFE72CF4-C77C-4932-A00F-A8D325E603CE}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{8854DF17-D566-49C9-8210-68AB8F5659FA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{8854DF17-D566-49C9-8210-68AB8F5659FA}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{8854DF17-D566-49C9-8210-68AB8F5659FA}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{8854DF17-D566-49C9-8210-68AB8F5659FA}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
|
@ -263,6 +269,7 @@ Global
|
|||
{79E85459-EF54-44D6-9508-1E68B8238D00} = {B43B546E-23F3-46E8-ACB7-D04F05CDA180}
|
||||
{8C51A528-F9B5-464E-AAD1-1ADC44697085} = {600C4AE0-0585-4181-9CEC-2BB43430C713}
|
||||
{DFE72CF4-C77C-4932-A00F-A8D325E603CE} = {5E5E1E84-DDBC-40D6-B891-0D563A15A44A}
|
||||
{8854DF17-D566-49C9-8210-68AB8F5659FA} = {5E5E1E84-DDBC-40D6-B891-0D563A15A44A}
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {8B0975FD-7050-48B0-88C5-48C33378E158}
|
||||
|
|
|
|||
38
src/samples/Sample17/Activities/CreateDocument.cs
Normal file
38
src/samples/Sample17/Activities/CreateDocument.cs
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Elsa.Expressions;
|
||||
using Elsa.Extensions;
|
||||
using Elsa.Results;
|
||||
using Elsa.Services;
|
||||
using Elsa.Services.Models;
|
||||
using Sample17.Models;
|
||||
|
||||
namespace Sample17.Activities
|
||||
{
|
||||
public class CreateDocument : Activity
|
||||
{
|
||||
private readonly IWorkflowExpressionEvaluator expressionEvaluator;
|
||||
|
||||
public CreateDocument(IWorkflowExpressionEvaluator expressionEvaluator)
|
||||
{
|
||||
this.expressionEvaluator = expressionEvaluator;
|
||||
}
|
||||
|
||||
public WorkflowExpression<string> TitleExpression
|
||||
{
|
||||
get => GetState<WorkflowExpression<string>>();
|
||||
set => SetState(value);
|
||||
}
|
||||
|
||||
protected override async Task<ActivityExecutionResult> OnExecuteAsync(
|
||||
WorkflowExecutionContext context,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
var title = await expressionEvaluator.EvaluateAsync(TitleExpression, context, cancellationToken);
|
||||
var document = new Document { Title = title};
|
||||
|
||||
Output["Document"] = document;
|
||||
return Done();
|
||||
}
|
||||
}
|
||||
}
|
||||
20
src/samples/Sample17/CreateDocumentWorkflow.cs
Normal file
20
src/samples/Sample17/CreateDocumentWorkflow.cs
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
using Elsa.Activities.Console.Activities;
|
||||
using Elsa.Expressions;
|
||||
using Elsa.Services;
|
||||
using Elsa.Services.Models;
|
||||
using Sample17.Activities;
|
||||
|
||||
namespace Sample17
|
||||
{
|
||||
public class CreateDocumentWorkflow : IWorkflow
|
||||
{
|
||||
public void Build(IWorkflowBuilder builder)
|
||||
{
|
||||
builder
|
||||
.StartWith<WriteLine>(x => x.TextExpression = new LiteralExpression("Enter a title"))
|
||||
.Then<ReadLine>(id: "DocumentTitleInput")
|
||||
.Then<CreateDocument>(x => x.TitleExpression = new JavaScriptExpression<string>("DocumentTitleInput.Input"), id: "CreateDocument")
|
||||
.Then<WriteLine>(x => x.TextExpression = new JavaScriptExpression<string>("`A new document was created with title \"${CreateDocument.Document.Title}\"`"));
|
||||
}
|
||||
}
|
||||
}
|
||||
7
src/samples/Sample17/Models/Document.cs
Normal file
7
src/samples/Sample17/Models/Document.cs
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
namespace Sample17.Models
|
||||
{
|
||||
public class Document
|
||||
{
|
||||
public string Title { get; set; }
|
||||
}
|
||||
}
|
||||
30
src/samples/Sample17/Program.cs
Normal file
30
src/samples/Sample17/Program.cs
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Elsa.Activities.Console.Extensions;
|
||||
using Elsa.Services;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Sample17.Activities;
|
||||
|
||||
namespace Sample17
|
||||
{
|
||||
internal static class Program
|
||||
{
|
||||
private static async Task Main(string[] args)
|
||||
{
|
||||
var services = BuildServices();
|
||||
var workflowInvoker = services.GetRequiredService<IWorkflowInvoker>();
|
||||
|
||||
await workflowInvoker.StartAsync<CreateDocumentWorkflow>();
|
||||
}
|
||||
|
||||
private static IServiceProvider BuildServices()
|
||||
{
|
||||
return new ServiceCollection()
|
||||
.AddWorkflows()
|
||||
.AddWorkflow<CreateDocumentWorkflow>()
|
||||
.AddConsoleActivities()
|
||||
.AddActivity<CreateDocument>()
|
||||
.BuildServiceProvider();
|
||||
}
|
||||
}
|
||||
}
|
||||
15
src/samples/Sample17/Sample17.csproj
Normal file
15
src/samples/Sample17/Sample17.csproj
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>netcoreapp3.0</TargetFramework>
|
||||
<LangVersion>latest</LangVersion>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\activities\Elsa.Activities.Console\Elsa.Activities.Console.csproj" />
|
||||
<ProjectReference Include="..\..\core\Elsa.Core\Elsa.Core.csproj" />
|
||||
<ProjectReference Include="..\..\persistence\Elsa.Persistence.MongoDb\Elsa.Persistence.MongoDb.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
Loading…
Reference in a new issue