Add For activity builder extensions and add sample
This commit is contained in:
parent
a4f339b243
commit
7c8b4a1018
14
Samples.sln
14
Samples.sln
|
|
@ -90,6 +90,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "locking", "locking", "{7CD5
|
|||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "YesSql.Provider.Sqlite.InMemory", "src\core\YesSql.Provider.Sqlite.InMemory\YesSql.Provider.Sqlite.InMemory.csproj", "{E2D63391-1986-45C8-A18F-4D58F3D71057}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Elsa.Samples.ForEachConsole", "src\samples\Elsa.Samples.ForEachConsole\Elsa.Samples.ForEachConsole.csproj", "{F755FB1F-72FB-4F7B-8270-F5F40F4D6952}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Elsa.Samples.ReadLineEchoConsole", "src\samples\Elsa.Samples.ReadLineEchoConsole\Elsa.Samples.ReadLineEchoConsole.csproj", "{867CB845-B803-4D40-9360-3D11ADBD9CE9}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
|
|
@ -209,6 +213,14 @@ Global
|
|||
{E2D63391-1986-45C8-A18F-4D58F3D71057}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{E2D63391-1986-45C8-A18F-4D58F3D71057}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{E2D63391-1986-45C8-A18F-4D58F3D71057}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{F755FB1F-72FB-4F7B-8270-F5F40F4D6952}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{F755FB1F-72FB-4F7B-8270-F5F40F4D6952}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{F755FB1F-72FB-4F7B-8270-F5F40F4D6952}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{F755FB1F-72FB-4F7B-8270-F5F40F4D6952}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{867CB845-B803-4D40-9360-3D11ADBD9CE9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{867CB845-B803-4D40-9360-3D11ADBD9CE9}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{867CB845-B803-4D40-9360-3D11ADBD9CE9}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{867CB845-B803-4D40-9360-3D11ADBD9CE9}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
|
@ -250,6 +262,8 @@ Global
|
|||
{EBD49CCA-5400-4C36-B5DF-7B28190AA323} = {7CD5C8D5-EC78-4A99-A514-F01CA7197AC8}
|
||||
{150EF356-E8BC-4922-91C2-362017479409} = {7CD5C8D5-EC78-4A99-A514-F01CA7197AC8}
|
||||
{E2D63391-1986-45C8-A18F-4D58F3D71057} = {35F44BE9-13D0-417C-A01A-F0787BEE6DC3}
|
||||
{F755FB1F-72FB-4F7B-8270-F5F40F4D6952} = {5E5E1E84-DDBC-40D6-B891-0D563A15A44A}
|
||||
{867CB845-B803-4D40-9360-3D11ADBD9CE9} = {5E5E1E84-DDBC-40D6-B891-0D563A15A44A}
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {8B0975FD-7050-48B0-88C5-48C33378E158}
|
||||
|
|
|
|||
|
|
@ -50,6 +50,6 @@ namespace Elsa.Activities.Console
|
|||
return Execute(receivedInput);
|
||||
}
|
||||
|
||||
private IActivityExecutionResult Execute(string receivedInput) => Done((object)receivedInput);
|
||||
private IActivityExecutionResult Execute(string receivedInput) => Done(receivedInput);
|
||||
}
|
||||
}
|
||||
|
|
@ -8,25 +8,12 @@ namespace Elsa.Activities.Console
|
|||
{
|
||||
public static class WriteLineBuilderExtensions
|
||||
{
|
||||
public static IOutcomeBuilder WriteLine(this IBuilder builder,
|
||||
Action<ISetupActivity<WriteLine>> setup) => WriteLine(builder.Then(setup));
|
||||
|
||||
public static IOutcomeBuilder WriteLine(this IBuilder builder, Func<ActivityExecutionContext, string> text) =>
|
||||
builder.WriteLine(activity => activity.Set(x => x.Text, text));
|
||||
|
||||
public static IOutcomeBuilder WriteLine(this IBuilder builder,
|
||||
Func<ActivityExecutionContext, ValueTask<string>> text) =>
|
||||
builder.WriteLine(activity => activity.Set(x => x.Text, text));
|
||||
|
||||
public static IOutcomeBuilder WriteLine(this IBuilder builder, Func<string> text) =>
|
||||
builder.WriteLine(activity => activity.Set(x => x.Text, text));
|
||||
|
||||
public static IOutcomeBuilder WriteLine(this IBuilder builder, Func<ValueTask<string>> text) =>
|
||||
builder.WriteLine(activity => activity.Set(x => x.Text, text));
|
||||
|
||||
public static IOutcomeBuilder WriteLine(this IBuilder builder, string text) =>
|
||||
builder.WriteLine(activity => activity.Set(x => x.Text, text));
|
||||
|
||||
public static IOutcomeBuilder WriteLine(this IBuilder builder, Action<ISetupActivity<WriteLine>> setup) => WriteLine(builder.Then(setup));
|
||||
public static IOutcomeBuilder WriteLine(this IBuilder builder, Func<ActivityExecutionContext, string> text) => builder.WriteLine(activity => activity.Set(x => x.Text, text));
|
||||
public static IOutcomeBuilder WriteLine(this IBuilder builder, Func<ActivityExecutionContext, ValueTask<string>> text) => builder.WriteLine(activity => activity.Set(x => x.Text, text));
|
||||
public static IOutcomeBuilder WriteLine(this IBuilder builder, Func<string> text) => builder.WriteLine(activity => activity.Set(x => x.Text, text));
|
||||
public static IOutcomeBuilder WriteLine(this IBuilder builder, Func<ValueTask<string>> text) => builder.WriteLine(activity => activity.Set(x => x.Text, text));
|
||||
public static IOutcomeBuilder WriteLine(this IBuilder builder, string text) => builder.WriteLine(activity => activity.Set(x => x.Text, text));
|
||||
private static IOutcomeBuilder WriteLine(IActivityBuilder writeLine) => writeLine.When(OutcomeNames.Done);
|
||||
}
|
||||
}
|
||||
|
|
@ -7,6 +7,7 @@ namespace Elsa.Models
|
|||
{
|
||||
public Variables()
|
||||
{
|
||||
Data = new JObject();
|
||||
}
|
||||
|
||||
public Variables(Variables other) : this(other.Data)
|
||||
|
|
@ -21,6 +22,7 @@ namespace Elsa.Models
|
|||
public JObject Data { get; set; }
|
||||
|
||||
public JToken? Get(string name) => Has(name) ? Data[name] : default;
|
||||
public T Get<T>(string name) => Has(name) ? Data.Value<T>(name) : default!;
|
||||
|
||||
public Variables Set(string name, JToken value)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Elsa.Builders;
|
||||
using Elsa.Models;
|
||||
using Elsa.Services.Models;
|
||||
|
||||
|
|
@ -26,5 +27,17 @@ namespace Elsa.Services
|
|||
object? input = default,
|
||||
string? correlationId = default,
|
||||
CancellationToken cancellationToken = default);
|
||||
|
||||
ValueTask<WorkflowInstance> RunWorkflowAsync<T>(
|
||||
string? activityId = default,
|
||||
object? input = default,
|
||||
string? correlationId = default,
|
||||
CancellationToken cancellationToken = default) where T:IWorkflow;
|
||||
|
||||
ValueTask<WorkflowInstance> RunWorkflowAsync<T>(
|
||||
WorkflowInstance workflowInstance,
|
||||
string? activityId = default,
|
||||
object? input = default,
|
||||
CancellationToken cancellationToken = default) where T:IWorkflow;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,7 +1,6 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Elsa.Comparers;
|
||||
using Elsa.Models;
|
||||
using Microsoft.Extensions.Localization;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
|
@ -52,7 +51,7 @@ namespace Elsa.Services.Models
|
|||
public WorkflowStatus Status => WorkflowInstance.Status;
|
||||
|
||||
public void SetVariable(string name, object? value) => WorkflowInstance.Variables.Set(name, JToken.FromObject(value!));
|
||||
public T GetVariable<T>(string name) => (T)GetVariable(name)!;
|
||||
public T GetVariable<T>(string name) => WorkflowInstance.Variables.Get<T>(name);
|
||||
public object? GetVariable(string name) => WorkflowInstance.Variables.Get(name);
|
||||
public void CompletePass() => IsFirstPass = false;
|
||||
public void Begin() => WorkflowInstance.Status = WorkflowStatus.Running;
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
using System;
|
||||
using Elsa.ActivityResults;
|
||||
using Elsa.Attributes;
|
||||
using Elsa.Services;
|
||||
|
|
@ -21,19 +22,34 @@ namespace Elsa.Activities.ControlFlow
|
|||
public int End { get; set; }
|
||||
|
||||
[ActivityProperty(Hint = "An expression that evaluates to the incrementing number on each step.")]
|
||||
public int Step { get; set; }
|
||||
public int Step { get; set; } = 1;
|
||||
|
||||
private int? CurrentValue { get; set; }
|
||||
[ActivityProperty(Hint = "The operator to use when comparing the current value against the end value.")]
|
||||
public Operator Operator { get; set; } = Operator.LessThan;
|
||||
|
||||
private int? CurrentValue
|
||||
{
|
||||
get => GetState<int?>();
|
||||
set => SetState(value);
|
||||
}
|
||||
|
||||
protected override IActivityExecutionResult OnExecute(ActivityExecutionContext context)
|
||||
{
|
||||
var currentValue = CurrentValue ?? Start;
|
||||
|
||||
if (currentValue < End)
|
||||
|
||||
var loop = Operator switch
|
||||
{
|
||||
currentValue += Step;
|
||||
CurrentValue = currentValue;
|
||||
return Combine(Schedule(Id), Output(currentValue), Done(OutcomeNames.Iterate));
|
||||
Operator.LessThan => currentValue < End,
|
||||
Operator.LessThanOrEqual => currentValue <= End,
|
||||
Operator.GreaterThan => currentValue > End,
|
||||
Operator.GreaterThanOrEqual => currentValue >= End,
|
||||
_ => throw new NotSupportedException()
|
||||
};
|
||||
|
||||
if (loop)
|
||||
{
|
||||
CurrentValue = currentValue + Step;
|
||||
return Combine(Schedule(Id), Output(currentValue), Outcome(OutcomeNames.Iterate));
|
||||
}
|
||||
|
||||
CurrentValue = null;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,71 @@
|
|||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Elsa.Builders;
|
||||
using Elsa.Services;
|
||||
using Elsa.Services.Models;
|
||||
|
||||
// ReSharper disable once CheckNamespace
|
||||
namespace Elsa.Activities.ControlFlow
|
||||
{
|
||||
public static class ForBuilderExtensions
|
||||
{
|
||||
public static IActivityBuilder For(this IBuilder builder, Action<ISetupActivity<For>> setup, Action<IOutcomeBuilder> iterate) => builder.Then(setup, branch => iterate(branch.When(OutcomeNames.Iterate)));
|
||||
|
||||
public static IActivityBuilder For(
|
||||
this IBuilder builder,
|
||||
Func<ActivityExecutionContext, int> start,
|
||||
Func<ActivityExecutionContext, int> end,
|
||||
Func<ActivityExecutionContext, int> step,
|
||||
Action<IOutcomeBuilder> iterate,
|
||||
Operator op = Operator.LessThan) =>
|
||||
builder.For(
|
||||
activity => activity
|
||||
.Set(x => x.Start, start)
|
||||
.Set(x => x.End, end)
|
||||
.Set(x => x.Step, step)
|
||||
.Set(x => x.Operator, op),
|
||||
iterate);
|
||||
|
||||
public static IActivityBuilder For(this IBuilder builder, Func<int> start, Func<int> end, Func<int> step, Action<IOutcomeBuilder> iterate, Operator op = Operator.LessThan) =>
|
||||
builder.For(
|
||||
activity => activity
|
||||
.Set(x => x.Start, start)
|
||||
.Set(x => x.End, end)
|
||||
.Set(x => x.Step, step)
|
||||
.Set(x => x.Operator, op),
|
||||
iterate);
|
||||
|
||||
public static IActivityBuilder For(this IBuilder builder, int start, int end, int step, Action<IOutcomeBuilder> iterate, Operator op = Operator.LessThan) =>
|
||||
builder.For(
|
||||
activity => activity
|
||||
.Set(x => x.Start, start)
|
||||
.Set(x => x.End, end)
|
||||
.Set(x => x.Step, step)
|
||||
.Set(x => x.Operator, op),
|
||||
iterate);
|
||||
|
||||
public static IActivityBuilder For(this IBuilder builder, Func<ActivityExecutionContext, int> start, Func<ActivityExecutionContext, int> end, Action<IOutcomeBuilder> iterate, Operator op = Operator.LessThan) =>
|
||||
builder.For(
|
||||
activity => activity
|
||||
.Set(x => x.Start, start)
|
||||
.Set(x => x.End, end)
|
||||
.Set(x => x.Operator, op),
|
||||
iterate);
|
||||
|
||||
public static IActivityBuilder For(this IBuilder builder, Func<int> start, Func<int> end, Action<IOutcomeBuilder> iterate, Operator op = Operator.LessThan) =>
|
||||
builder.For(
|
||||
activity => activity
|
||||
.Set(x => x.Start, start)
|
||||
.Set(x => x.End, end)
|
||||
.Set(x => x.Operator, op),
|
||||
iterate);
|
||||
|
||||
public static IActivityBuilder For(this IBuilder builder, int start, int end, Action<IOutcomeBuilder> iterate, Operator op = Operator.LessThan) =>
|
||||
builder.For(
|
||||
activity => activity
|
||||
.Set(x => x.Start, start)
|
||||
.Set(x => x.End, end)
|
||||
.Set(x => x.Operator, op),
|
||||
iterate);
|
||||
}
|
||||
}
|
||||
10
src/core/Elsa.Core/Activities/ControlFlow/For/Operator.cs
Normal file
10
src/core/Elsa.Core/Activities/ControlFlow/For/Operator.cs
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
namespace Elsa.Activities.ControlFlow
|
||||
{
|
||||
public enum Operator
|
||||
{
|
||||
LessThan,
|
||||
LessThanOrEqual,
|
||||
GreaterThan,
|
||||
GreaterThanOrEqual
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Elsa.Activities.Primitives;
|
||||
using Elsa.Builders;
|
||||
using Elsa.Services.Models;
|
||||
|
||||
// ReSharper disable once CheckNamespace
|
||||
namespace Elsa.Activities.ControlFlow
|
||||
{
|
||||
public static class SetVariableBuilderExtensions
|
||||
{
|
||||
public static IOutcomeBuilder SetVariable(this IBuilder builder, Action<ISetupActivity<SetVariable>> setup) => builder.Then(setup).When(OutcomeNames.Done);
|
||||
|
||||
public static IOutcomeBuilder SetVariable(this IBuilder builder, string name, Func<ActivityExecutionContext, object?> value) =>
|
||||
builder.SetVariable(
|
||||
activity => activity
|
||||
.Set(x => x.VariableName, name)
|
||||
.Set(x => x.Value, value));
|
||||
|
||||
public static IOutcomeBuilder SetVariable(this IBuilder builder, string name, Func<object?> value) =>
|
||||
builder.SetVariable(
|
||||
activity => activity
|
||||
.Set(x => x.VariableName, name)
|
||||
.Set(x => x.Value, value));
|
||||
|
||||
public static IOutcomeBuilder SetVariable(this IBuilder builder, string name, object? value) =>
|
||||
builder.SetVariable(
|
||||
activity => activity
|
||||
.Set(x => x.VariableName, name)
|
||||
.Set(x => x.Value, value));
|
||||
}
|
||||
}
|
||||
2
src/core/Elsa.Core/Elsa.Core.csproj.DotSettings
Normal file
2
src/core/Elsa.Core/Elsa.Core.csproj.DotSettings
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
|
||||
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=activities_005Ccontrolflow_005Cfor/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
|
||||
|
|
@ -17,14 +17,12 @@ using Elsa.Metadata;
|
|||
using Elsa.Metadata.Handlers;
|
||||
using Elsa.Runtime;
|
||||
using Elsa.Serialization;
|
||||
using Elsa.Serialization.Formatters;
|
||||
using Elsa.Services;
|
||||
using Elsa.StartupTasks;
|
||||
using Elsa.Triggers;
|
||||
using Elsa.WorkflowProviders;
|
||||
using MediatR;
|
||||
using Microsoft.Extensions.DependencyInjection.Extensions;
|
||||
using Newtonsoft.Json;
|
||||
using NodaTime;
|
||||
using Rebus.Handlers;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,8 +1,6 @@
|
|||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using Elsa.Attributes;
|
||||
using Elsa.Serialization;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using JsonSerializer = Newtonsoft.Json.JsonSerializer;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
using System;
|
||||
using Elsa.Converters;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
|
|
|||
|
|
@ -4,13 +4,13 @@ using System.Linq;
|
|||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Elsa.ActivityResults;
|
||||
using Elsa.Builders;
|
||||
using Elsa.Events;
|
||||
using Elsa.Exceptions;
|
||||
using Elsa.Models;
|
||||
using Elsa.Services.Models;
|
||||
using Elsa.Triggers;
|
||||
using MediatR;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace Elsa.Services
|
||||
|
|
@ -24,6 +24,7 @@ namespace Elsa.Services
|
|||
|
||||
private readonly IWorkflowRegistry _workflowRegistry;
|
||||
private readonly IWorkflowFactory _workflowFactory;
|
||||
private readonly IWorkflowBuilder _workflowBuilder;
|
||||
private readonly IMediator _mediator;
|
||||
private readonly IServiceProvider _serviceProvider;
|
||||
private readonly IEnumerable<ITriggerProvider> _triggerProviders;
|
||||
|
|
@ -32,6 +33,7 @@ namespace Elsa.Services
|
|||
public WorkflowHost(
|
||||
IWorkflowRegistry workflowRegistry,
|
||||
IWorkflowFactory workflowFactory,
|
||||
IWorkflowBuilder workflowBuilder,
|
||||
IMediator mediator,
|
||||
IServiceProvider serviceProvider,
|
||||
IEnumerable<ITriggerProvider> triggerProviders,
|
||||
|
|
@ -39,6 +41,7 @@ namespace Elsa.Services
|
|||
{
|
||||
_workflowRegistry = workflowRegistry;
|
||||
_workflowFactory = workflowFactory;
|
||||
_workflowBuilder = workflowBuilder;
|
||||
_mediator = mediator;
|
||||
_serviceProvider = serviceProvider;
|
||||
_triggerProviders = triggerProviders;
|
||||
|
|
@ -60,6 +63,22 @@ namespace Elsa.Services
|
|||
return await RunWorkflowAsync(workflowBlueprint, workflowInstance, activityId, input, cancellationToken);
|
||||
}
|
||||
|
||||
public async ValueTask<WorkflowInstance> RunWorkflowAsync<T>(
|
||||
string? activityId = default,
|
||||
object? input = default,
|
||||
string? correlationId = default,
|
||||
CancellationToken cancellationToken = default)
|
||||
where T : IWorkflow =>
|
||||
await RunWorkflowAsync(_workflowBuilder.Build<T>(), activityId, input, correlationId, cancellationToken);
|
||||
|
||||
public async ValueTask<WorkflowInstance> RunWorkflowAsync<T>(
|
||||
WorkflowInstance workflowInstance,
|
||||
string? activityId = default,
|
||||
object? input = default,
|
||||
CancellationToken cancellationToken = default)
|
||||
where T : IWorkflow =>
|
||||
await RunWorkflowAsync(_workflowBuilder.Build<T>(), workflowInstance, activityId, input, cancellationToken);
|
||||
|
||||
public async ValueTask<WorkflowInstance> RunWorkflowAsync(
|
||||
WorkflowInstance workflowInstance,
|
||||
string? activityId = default,
|
||||
|
|
@ -202,7 +221,7 @@ namespace Elsa.Services
|
|||
await _mediator.Publish(new ActivityExecuting(activityExecutionContext), cancellationToken);
|
||||
await result.ExecuteAsync(activityExecutionContext, cancellationToken);
|
||||
await _mediator.Publish(new ActivityExecuted(activityExecutionContext), cancellationToken);
|
||||
|
||||
|
||||
activityOperation = Execute;
|
||||
workflowExecutionContext.CompletePass();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,11 +1,9 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Elsa.Models;
|
||||
using Elsa.Services.Models;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Open.Linq.AsyncExtensions;
|
||||
|
||||
namespace Elsa.Services
|
||||
|
|
|
|||
|
|
@ -2,8 +2,6 @@ using Microsoft.Extensions.DependencyInjection;
|
|||
using Microsoft.Extensions.Hosting;
|
||||
using NodaTime;
|
||||
using System.Threading.Tasks;
|
||||
using Elsa.DistributedLocking.AzureBlob;
|
||||
using System;
|
||||
using Elsa.DistributedLocking.Redis;
|
||||
using YesSql.Provider.Sqlite;
|
||||
|
||||
|
|
|
|||
|
|
@ -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>
|
||||
30
src/samples/Elsa.Samples.ForEachConsole/LoopingWorkflow.cs
Normal file
30
src/samples/Elsa.Samples.ForEachConsole/LoopingWorkflow.cs
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
using System;
|
||||
using Elsa.Activities.Console;
|
||||
using Elsa.Activities.ControlFlow;
|
||||
using Elsa.Builders;
|
||||
|
||||
namespace Elsa.Samples.ForEachConsole
|
||||
{
|
||||
/// <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 LoopingWorkflow : IWorkflow
|
||||
{
|
||||
public void Build(IWorkflowBuilder builder)
|
||||
{
|
||||
builder
|
||||
.WriteLine("Enter a number:")
|
||||
.ReadLine()
|
||||
.SetVariable("From", context => int.Parse(((string)context.Input)!))
|
||||
.WriteLine(context => $"Counting down from {Math.Abs(context.GetVariable<int>("From")!)} to 0...")
|
||||
.For(
|
||||
context => context.GetVariable<int>("From"),
|
||||
_ => 0,
|
||||
_ => -1,
|
||||
iterate => iterate.WriteLine(context => $"Iteration {context.Input}"),
|
||||
Operator.GreaterThanOrEqual)
|
||||
.WriteLine("Done.");
|
||||
}
|
||||
}
|
||||
}
|
||||
32
src/samples/Elsa.Samples.ForEachConsole/Program.cs
Normal file
32
src/samples/Elsa.Samples.ForEachConsole/Program.cs
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
using System.Threading.Tasks;
|
||||
using Elsa.Services;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace Elsa.Samples.ForEachConsole
|
||||
{
|
||||
/// <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()
|
||||
.AddConsoleActivities()
|
||||
.AddWorkflow<LoopingWorkflow>()
|
||||
.BuildServiceProvider();
|
||||
|
||||
// Run startup actions (not needed when registering Elsa with a Host).
|
||||
var startupRunner = services.GetRequiredService<IStartupRunner>();
|
||||
await startupRunner.StartupAsync();
|
||||
|
||||
// Get the workflow host.
|
||||
var workflowHost = services.GetService<IWorkflowHost>();
|
||||
|
||||
// Execute the workflow.
|
||||
await workflowHost.RunWorkflowAsync<LoopingWorkflow>();
|
||||
}
|
||||
}
|
||||
}
|
||||
13
src/samples/Elsa.Samples.HelloWorldConsole/HelloWorld.cs
Normal file
13
src/samples/Elsa.Samples.HelloWorldConsole/HelloWorld.cs
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
using Elsa.Activities.Console;
|
||||
using Elsa.Builders;
|
||||
|
||||
namespace Elsa.Samples.HelloWorldConsole
|
||||
{
|
||||
/// <summary>
|
||||
/// A basic workflow with just one WriteLine activity.
|
||||
/// </summary>
|
||||
public class HelloWorld : IWorkflow
|
||||
{
|
||||
public void Build(IWorkflowBuilder builder) => builder.WriteLine("Hello World!");
|
||||
}
|
||||
}
|
||||
|
|
@ -1,7 +1,4 @@
|
|||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Elsa.Activities.Console;
|
||||
using Elsa.Builders;
|
||||
using System.Threading.Tasks;
|
||||
using Elsa.Services;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
|
|
@ -15,26 +12,18 @@ namespace Elsa.Samples.HelloWorldConsole
|
|||
var services = new ServiceCollection()
|
||||
.AddElsa()
|
||||
.AddConsoleActivities()
|
||||
.AddSingleton(Console.In)
|
||||
.AddWorkflow<HelloWorld>()
|
||||
.BuildServiceProvider();
|
||||
|
||||
// Run startup actions (not needed when registering Elsa with a Host).
|
||||
var startupRunner = services.GetRequiredService<IStartupRunner>();
|
||||
await startupRunner.StartupAsync();
|
||||
|
||||
// Build a new workflow.
|
||||
var workflow = services.GetService<IWorkflowBuilder>()
|
||||
.WriteLine("Hello World!")
|
||||
.WriteLine("What's your name?")
|
||||
.ReadLine()
|
||||
.WriteLine(context => $"Greetings, {context.Input}!")
|
||||
.Build();
|
||||
|
||||
// Get the workflow host.
|
||||
// Get a workflow host.
|
||||
var workflowHost = services.GetService<IWorkflowHost>();
|
||||
|
||||
// Execute the workflow.
|
||||
await workflowHost.RunWorkflowAsync(workflow);
|
||||
await workflowHost.RunWorkflowAsync<HelloWorld>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -4,6 +4,9 @@ using Elsa.Builders;
|
|||
|
||||
namespace Elsa.Samples.HelloWorldHttp
|
||||
{
|
||||
/// <summary>
|
||||
/// A workflow that is triggered when HTTP requests are made to /hello and writes a response.
|
||||
/// </summary>
|
||||
public class HelloHttpWorkflow : IWorkflow
|
||||
{
|
||||
public void Build(IWorkflowBuilder builder)
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ namespace Elsa.Samples.HelloWorldHttp
|
|||
|
||||
public void Configure(IApplicationBuilder app)
|
||||
{
|
||||
// Add HTTP activities middleware.
|
||||
app.UseHttpActivities();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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>
|
||||
37
src/samples/Elsa.Samples.ReadLineEchoConsole/Program.cs
Normal file
37
src/samples/Elsa.Samples.ReadLineEchoConsole/Program.cs
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
using System.Threading.Tasks;
|
||||
using Elsa.Activities.Console;
|
||||
using Elsa.Builders;
|
||||
using Elsa.Services;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace Elsa.Samples.ReadLineEchoConsole
|
||||
{
|
||||
class Program
|
||||
{
|
||||
static async Task Main(string[] args)
|
||||
{
|
||||
// Create a service container with Elsa services.
|
||||
var services = new ServiceCollection()
|
||||
.AddElsa()
|
||||
.AddConsoleActivities()
|
||||
.BuildServiceProvider();
|
||||
|
||||
// Run startup actions (not needed when registering Elsa with a Host).
|
||||
var startupRunner = services.GetRequiredService<IStartupRunner>();
|
||||
await startupRunner.StartupAsync();
|
||||
|
||||
// Build a new workflow.
|
||||
var workflow = services.GetService<IWorkflowBuilder>()
|
||||
.WriteLine("What's your name?")
|
||||
.ReadLine()
|
||||
.WriteLine(context => $"Greetings, {context.Input}!")
|
||||
.Build();
|
||||
|
||||
// Get the workflow host.
|
||||
var workflowHost = services.GetService<IWorkflowHost>();
|
||||
|
||||
// Execute the workflow.
|
||||
await workflowHost.RunWorkflowAsync(workflow);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,7 +1,6 @@
|
|||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Elsa.Activities.Console;
|
||||
using Elsa.Expressions;
|
||||
using Elsa.Models;
|
||||
using Elsa.Scripting.Liquid.Services;
|
||||
using Elsa.Serialization;
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
using System.Threading.Tasks;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using NodaTime;
|
||||
using YesSql.Provider.Sqlite;
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue