RC3 (#108)
* Add activity output example * Update Sample17 * Extend SMTP options (#107) * Remove unused imports * Update Elsa.Scrutor package reference
This commit is contained in:
parent
1b22bac07a
commit
d7fc571cdd
|
|
@ -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}
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ namespace Elsa.Activities.Console.Activities
|
|||
{
|
||||
private readonly TextReader input;
|
||||
|
||||
public ReadLine() : this(System.Console.In)
|
||||
public ReadLine()
|
||||
{
|
||||
}
|
||||
|
||||
|
|
@ -53,7 +53,7 @@ namespace Elsa.Activities.Console.Activities
|
|||
|
||||
protected override ActivityExecutionResult OnResume(WorkflowExecutionContext context)
|
||||
{
|
||||
var receivedInput = (string) context.Workflow.Input[VariableName];
|
||||
var receivedInput = (string) context.Workflow.Input["ReadLineInput"];
|
||||
return Execute(context, receivedInput);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
using System;
|
||||
using System.Net;
|
||||
using System.Net.Mail;
|
||||
using Elsa.Activities.Email.Activities;
|
||||
using Elsa.Activities.Email.Options;
|
||||
|
|
@ -23,8 +24,28 @@ namespace Elsa.Activities.Email.Extensions
|
|||
private static SmtpClient CreateSmtpClient(IServiceProvider serviceProvider)
|
||||
{
|
||||
var options = serviceProvider.GetRequiredService<IOptions<SmtpOptions>>().Value;
|
||||
var smtpClient = new SmtpClient(options.Host, options.Port);
|
||||
var credentials = options.Credentials;
|
||||
|
||||
return new SmtpClient(options.Host, options.Port);
|
||||
if (credentials != null && !string.IsNullOrWhiteSpace(credentials.Username))
|
||||
smtpClient.Credentials = new NetworkCredential(credentials.Username, credentials.Password);
|
||||
|
||||
if (options.Timeout != null)
|
||||
smtpClient.Timeout = (int)options.Timeout.Value.TotalSeconds;
|
||||
|
||||
if (options.DeliveryFormat != null)
|
||||
smtpClient.DeliveryFormat = options.DeliveryFormat.Value;
|
||||
|
||||
if (options.DeliveryMethod != null)
|
||||
smtpClient.DeliveryMethod = options.DeliveryMethod.Value;
|
||||
|
||||
if (options.EnableSsl != null)
|
||||
smtpClient.EnableSsl = options.EnableSsl.Value;
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(options.PickupDirectoryLocation))
|
||||
smtpClient.PickupDirectoryLocation = options.PickupDirectoryLocation;
|
||||
|
||||
return smtpClient;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
namespace Elsa.Activities.Email.Options
|
||||
{
|
||||
public class SmtpCredentials
|
||||
{
|
||||
public string Username { get; set; }
|
||||
public string Password { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
@ -1,3 +1,6 @@
|
|||
using System;
|
||||
using System.Net.Mail;
|
||||
|
||||
namespace Elsa.Activities.Email.Options
|
||||
{
|
||||
public class SmtpOptions
|
||||
|
|
@ -5,5 +8,11 @@ namespace Elsa.Activities.Email.Options
|
|||
public string Host { get; set; }
|
||||
public int Port { get; set; }
|
||||
public string DefaultSender { get; set; }
|
||||
public SmtpCredentials Credentials { get; set; }
|
||||
public TimeSpan? Timeout { get; set; }
|
||||
public SmtpDeliveryFormat? DeliveryFormat { get; set; }
|
||||
public SmtpDeliveryMethod? DeliveryMethod { get; set; }
|
||||
public bool? EnableSsl { get; set; }
|
||||
public string PickupDirectoryLocation { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
@ -12,6 +12,7 @@ namespace Elsa.Services
|
|||
IActivityBuilder Add<T>(Action<T> setup = default, string id = null) where T : class, IActivity;
|
||||
IOutcomeBuilder When(string outcome);
|
||||
IActivityBuilder Then<T>(Action<T> setup = null, Action<IActivityBuilder> branch = null, string id = null) where T : class, IActivity;
|
||||
IActivityBuilder WithId(string id);
|
||||
IWorkflowBuilder Then(string activityId);
|
||||
WorkflowDefinitionVersion Build();
|
||||
ActivityDefinition BuildActivity();
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@
|
|||
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="3.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="3.0.0" />
|
||||
<PackageReference Include="NodaTime.Serialization.JsonNet" Version="2.2.0" />
|
||||
<PackageReference Include="Scrutor.Elsa" Version="3.0.2.20" />
|
||||
<PackageReference Include="Elsa.Scrutor" Version="3.0.2.25" />
|
||||
|
||||
<PackageReference Include="YamlDotNet.NetStandard" Version="4.0.0" />
|
||||
</ItemGroup>
|
||||
|
|
|
|||
|
|
@ -40,6 +40,12 @@ namespace Elsa.WorkflowBuilders
|
|||
return activityBuilder;
|
||||
}
|
||||
|
||||
public IActivityBuilder WithId(string id)
|
||||
{
|
||||
Id = id;
|
||||
return this;
|
||||
}
|
||||
|
||||
public IWorkflowBuilder Then(string activityId)
|
||||
{
|
||||
WorkflowBuilder.Connect(
|
||||
|
|
|
|||
|
|
@ -21,7 +21,6 @@
|
|||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="GravatarHelper.AspNetCore" Version="1.1.0" />
|
||||
<PackageReference Include="Scrutor.Elsa" Version="3.0.2.21" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@ using Elsa.Dashboard.ActionFilters;
|
|||
using Elsa.Dashboard.Options;
|
||||
using Elsa.Dashboard.Services;
|
||||
using Elsa.Mapping;
|
||||
using Elsa.Persistence;
|
||||
using Elsa.Runtime;
|
||||
using Elsa.Serialization;
|
||||
using Elsa.Serialization.Formatters;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
using System;
|
||||
using Elsa.Models;
|
||||
using Elsa.Persistence.Memory;
|
||||
using Elsa.Persistence.MongoDb.Serialization;
|
||||
using Elsa.Persistence.MongoDb.Services;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Elsa.Extensions;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Elsa.Persistence.Memory;
|
||||
using Elsa.Services;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Sample01.Activities;
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@ using System.Threading.Tasks;
|
|||
using Elsa.Activities.Console.Activities;
|
||||
using Elsa.Activities.Console.Extensions;
|
||||
using Elsa.Expressions;
|
||||
using Elsa.Persistence.Memory;
|
||||
using Elsa.Services;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@ using Elsa.Activities.Console.Activities;
|
|||
using Elsa.Activities.Console.Extensions;
|
||||
using Elsa.Expressions;
|
||||
using Elsa.Models;
|
||||
using Elsa.Persistence.Memory;
|
||||
using Elsa.Services;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Elsa.Activities.Console.Extensions;
|
||||
using Elsa.Persistence.Memory;
|
||||
using Elsa.Services;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Sample04.Activities;
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
using System.Threading.Tasks;
|
||||
using Elsa.Activities.Console.Extensions;
|
||||
using Elsa.Activities.Timers.Extensions;
|
||||
using Elsa.Persistence.Memory;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
using Elsa.Activities.Http.Extensions;
|
||||
using Elsa.Persistence.Memory;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
using Elsa.Activities.Email.Extensions;
|
||||
using Elsa.Activities.Http.Extensions;
|
||||
using Elsa.Activities.Timers.Extensions;
|
||||
using Elsa.Persistence.Memory;
|
||||
using Elsa.Runtime;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@
|
|||
using Elsa.Activities.Http.Extensions;
|
||||
using Elsa.Activities.MassTransit.Extensions;
|
||||
using Elsa.Activities.Timers.Extensions;
|
||||
using Elsa.Persistence.Memory;
|
||||
using Elsa.Runtime;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@ using System.Reflection;
|
|||
using System.Threading.Tasks;
|
||||
using Elsa.Activities.Console.Extensions;
|
||||
using Elsa.Models;
|
||||
using Elsa.Persistence.Memory;
|
||||
using Elsa.Serialization;
|
||||
using Elsa.Serialization.Formatters;
|
||||
using Elsa.Services;
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@ using Elsa.Activities.Console.Extensions;
|
|||
using Elsa.Extensions;
|
||||
using Elsa.Models;
|
||||
using Elsa.Persistence;
|
||||
using Elsa.Persistence.Memory;
|
||||
using Elsa.Persistence.YesSql.Extensions;
|
||||
using Elsa.Runtime;
|
||||
using Elsa.Services;
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@ using Elsa.Activities.Console.Extensions;
|
|||
using Elsa.Activities.Workflows;
|
||||
using Elsa.Extensions;
|
||||
using Elsa.Models;
|
||||
using Elsa.Persistence.Memory;
|
||||
using Elsa.Services;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,6 @@ using Elsa.Activities.UserTask.Activities;
|
|||
using Elsa.Activities.UserTask.Extensions;
|
||||
using Elsa.Extensions;
|
||||
using Elsa.Models;
|
||||
using Elsa.Persistence.Memory;
|
||||
using Elsa.Services;
|
||||
using Elsa.Services.Extensions;
|
||||
using Elsa.Services.Models;
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Elsa.Activities.Console.Extensions;
|
||||
using Elsa.Persistence.Memory;
|
||||
using Elsa.Scripting;
|
||||
using Elsa.Services;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
|
|
|||
45
src/samples/Sample17/Activities/CreatePerson.cs
Normal file
45
src/samples/Sample17/Activities/CreatePerson.cs
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
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 CreatePerson : Activity
|
||||
{
|
||||
private readonly IWorkflowExpressionEvaluator expressionEvaluator;
|
||||
|
||||
public CreatePerson(IWorkflowExpressionEvaluator expressionEvaluator)
|
||||
{
|
||||
this.expressionEvaluator = expressionEvaluator;
|
||||
}
|
||||
|
||||
public WorkflowExpression<string> TitleExpression
|
||||
{
|
||||
get => GetState<WorkflowExpression<string>>();
|
||||
set => SetState(value);
|
||||
}
|
||||
|
||||
public WorkflowExpression<int> AgeExpression
|
||||
{
|
||||
get => GetState<WorkflowExpression<int>>();
|
||||
set => SetState(value);
|
||||
}
|
||||
|
||||
protected override async Task<ActivityExecutionResult> OnExecuteAsync(
|
||||
WorkflowExecutionContext context,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
var name = await expressionEvaluator.EvaluateAsync(TitleExpression, context, cancellationToken);
|
||||
var age = await expressionEvaluator.EvaluateAsync(AgeExpression, context, cancellationToken);
|
||||
var person = new Person { FullName = name, Age = age };
|
||||
|
||||
Output["Person"] = person;
|
||||
return Done();
|
||||
}
|
||||
}
|
||||
}
|
||||
41
src/samples/Sample17/CreatePersonWorkflow.cs
Normal file
41
src/samples/Sample17/CreatePersonWorkflow.cs
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
using Elsa.Activities.Console.Activities;
|
||||
using Elsa.Activities.Primitives;
|
||||
using Elsa.Expressions;
|
||||
using Elsa.Services;
|
||||
using Elsa.Services.Models;
|
||||
using Sample17.Activities;
|
||||
using Sample17.Models;
|
||||
|
||||
namespace Sample17
|
||||
{
|
||||
public class CreatePersonWorkflow : IWorkflow
|
||||
{
|
||||
public void Build(IWorkflowBuilder builder)
|
||||
{
|
||||
builder
|
||||
.StartWith<WriteLine>(x => x.TextExpression = new LiteralExpression("Enter name:"))
|
||||
.Then<ReadLine>().WithId("NameInput")
|
||||
.Then<WriteLine>(x => x.TextExpression = new LiteralExpression("Enter age:"))
|
||||
.Then<ReadLine>().WithId("AgeInput")
|
||||
.Then<CreatePerson>(
|
||||
x =>
|
||||
{
|
||||
x.TitleExpression = new JavaScriptExpression<string>("NameInput.Input");
|
||||
x.AgeExpression = new JavaScriptExpression<int>("AgeInput.Input");
|
||||
}).WithId("CreatePerson")
|
||||
.Then<SetVariable>(
|
||||
x =>
|
||||
{
|
||||
x.VariableName = "Person";
|
||||
x.ValueExpression = new JavaScriptExpression<Person>("CreatePerson.Person");
|
||||
})
|
||||
.Then<SetVariable>(
|
||||
x =>
|
||||
{
|
||||
x.VariableName = "Age";
|
||||
x.ValueExpression = new JavaScriptExpression<int>("CreatePerson.Person.Age");
|
||||
})
|
||||
.Then<WriteLine>(x => x.TextExpression = new JavaScriptExpression<string>("`A new person was created with name \"${Person.FullName}\" and age \"${Age}\"`"));
|
||||
}
|
||||
}
|
||||
}
|
||||
10
src/samples/Sample17/Models/Person.cs
Normal file
10
src/samples/Sample17/Models/Person.cs
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
namespace Sample17.Models
|
||||
{
|
||||
public class Person
|
||||
{
|
||||
public string FullName { get; set; }
|
||||
public int Age { get; set; }
|
||||
|
||||
public override string ToString() => FullName;
|
||||
}
|
||||
}
|
||||
34
src/samples/Sample17/Program.cs
Normal file
34
src/samples/Sample17/Program.cs
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Elsa.Activities.Console.Extensions;
|
||||
using Elsa.Services;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Sample17.Activities;
|
||||
using Sample17.Models;
|
||||
|
||||
namespace Sample17
|
||||
{
|
||||
internal static class Program
|
||||
{
|
||||
private static async Task Main(string[] args)
|
||||
{
|
||||
var services = BuildServices();
|
||||
var workflowInvoker = services.GetRequiredService<IWorkflowInvoker>();
|
||||
var workflowExecutionContext = await workflowInvoker.StartAsync<CreatePersonWorkflow>();
|
||||
var document = workflowExecutionContext.CurrentScope.GetVariable<Person>("Document");
|
||||
|
||||
Console.WriteLine("Created document: {0}", document);
|
||||
}
|
||||
|
||||
private static IServiceProvider BuildServices()
|
||||
{
|
||||
return new ServiceCollection()
|
||||
.AddWorkflows()
|
||||
.AddWorkflow<CreatePersonWorkflow>()
|
||||
.AddConsoleActivities()
|
||||
.AddActivity<CreatePerson>()
|
||||
.AddSingleton(Console.In)
|
||||
.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