diff --git a/Samples.sln b/Samples.sln index ae50bb915..5dab74820 100644 --- a/Samples.sln +++ b/Samples.sln @@ -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} diff --git a/src/samples/Sample17/Activities/CreateDocument.cs b/src/samples/Sample17/Activities/CreateDocument.cs new file mode 100644 index 000000000..7a2ed8bf5 --- /dev/null +++ b/src/samples/Sample17/Activities/CreateDocument.cs @@ -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 TitleExpression + { + get => GetState>(); + set => SetState(value); + } + + protected override async Task OnExecuteAsync( + WorkflowExecutionContext context, + CancellationToken cancellationToken) + { + var title = await expressionEvaluator.EvaluateAsync(TitleExpression, context, cancellationToken); + var document = new Document { Title = title}; + + Output["Document"] = document; + return Done(); + } + } +} \ No newline at end of file diff --git a/src/samples/Sample17/CreateDocumentWorkflow.cs b/src/samples/Sample17/CreateDocumentWorkflow.cs new file mode 100644 index 000000000..7a9e5bb42 --- /dev/null +++ b/src/samples/Sample17/CreateDocumentWorkflow.cs @@ -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(x => x.TextExpression = new LiteralExpression("Enter a title")) + .Then(id: "DocumentTitleInput") + .Then(x => x.TitleExpression = new JavaScriptExpression("DocumentTitleInput.Input"), id: "CreateDocument") + .Then(x => x.TextExpression = new JavaScriptExpression("`A new document was created with title \"${CreateDocument.Document.Title}\"`")); + } + } +} \ No newline at end of file diff --git a/src/samples/Sample17/Models/Document.cs b/src/samples/Sample17/Models/Document.cs new file mode 100644 index 000000000..31b3dcff0 --- /dev/null +++ b/src/samples/Sample17/Models/Document.cs @@ -0,0 +1,7 @@ +namespace Sample17.Models +{ + public class Document + { + public string Title { get; set; } + } +} \ No newline at end of file diff --git a/src/samples/Sample17/Program.cs b/src/samples/Sample17/Program.cs new file mode 100644 index 000000000..eb7d72bad --- /dev/null +++ b/src/samples/Sample17/Program.cs @@ -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(); + + await workflowInvoker.StartAsync(); + } + + private static IServiceProvider BuildServices() + { + return new ServiceCollection() + .AddWorkflows() + .AddWorkflow() + .AddConsoleActivities() + .AddActivity() + .BuildServiceProvider(); + } + } +} \ No newline at end of file diff --git a/src/samples/Sample17/Sample17.csproj b/src/samples/Sample17/Sample17.csproj new file mode 100644 index 000000000..32f47e3b5 --- /dev/null +++ b/src/samples/Sample17/Sample17.csproj @@ -0,0 +1,15 @@ + + + + Exe + netcoreapp3.0 + latest + + + + + + + + +