Skip to content

Commit

Permalink
RC3 (#108)
Browse files Browse the repository at this point in the history
* Add activity output example

* Update Sample17

* Extend SMTP options (#107)

* Remove unused imports

* Update Elsa.Scrutor package reference
  • Loading branch information
sfmskywalker committed Oct 24, 2019
1 parent 1b22bac commit d7fc571
Show file tree
Hide file tree
Showing 30 changed files with 201 additions and 21 deletions.
7 changes: 7 additions & 0 deletions Samples.sln
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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}
Expand Down
4 changes: 2 additions & 2 deletions src/activities/Elsa.Activities.Console/Activities/ReadLine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class ReadLine : Activity
{
private readonly TextReader input;

public ReadLine() : this(System.Console.In)
public ReadLine()
{
}

Expand Down Expand Up @@ -53,7 +53,7 @@ public string VariableName

protected override ActivityExecutionResult OnResume(WorkflowExecutionContext context)
{
var receivedInput = (string) context.Workflow.Input[VariableName];
var receivedInput = (string) context.Workflow.Input["ReadLineInput"];
return Execute(context, receivedInput);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Net;
using System.Net.Mail;
using Elsa.Activities.Email.Activities;
using Elsa.Activities.Email.Options;
Expand All @@ -23,8 +24,28 @@ public static IServiceCollection AddEmailActivities(this IServiceCollection serv
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;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace Elsa.Activities.Email.Options
{
public class SmtpCredentials
{
public string Username { get; set; }
public string Password { get; set; }
}
}
9 changes: 9 additions & 0 deletions src/activities/Elsa.Activities.Email/Options/SmtpOptions.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
using System;
using System.Net.Mail;

namespace Elsa.Activities.Email.Options
{
public class SmtpOptions
{
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; }
}
}
1 change: 1 addition & 0 deletions src/core/Elsa.Abstractions/Services/IActivityBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public interface IActivityBuilder
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();
Expand Down
2 changes: 1 addition & 1 deletion src/core/Elsa.Core/Elsa.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
6 changes: 6 additions & 0 deletions src/core/Elsa.Core/WorkflowBuilders/ActivityBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ public IOutcomeBuilder When(string outcome)
return activityBuilder;
}

public IActivityBuilder WithId(string id)
{
Id = id;
return this;
}

public IWorkflowBuilder Then(string activityId)
{
WorkflowBuilder.Connect(
Expand Down
1 change: 0 additions & 1 deletion src/dashboard/Elsa.Dashboard/Elsa.Dashboard.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

<ItemGroup>
<PackageReference Include="GravatarHelper.AspNetCore" Version="1.1.0" />
<PackageReference Include="Scrutor.Elsa" Version="3.0.2.21" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using Elsa.Dashboard.Options;
using Elsa.Dashboard.Services;
using Elsa.Mapping;
using Elsa.Persistence;
using Elsa.Runtime;
using Elsa.Serialization;
using Elsa.Serialization.Formatters;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Elsa.Extensions;
Expand Down
1 change: 0 additions & 1 deletion src/samples/Sample01/Program.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.Threading.Tasks;
using Elsa.Persistence.Memory;
using Elsa.Services;
using Microsoft.Extensions.DependencyInjection;
using Sample01.Activities;
Expand Down
1 change: 0 additions & 1 deletion src/samples/Sample02/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using Elsa.Activities.Console.Activities;
using Elsa.Activities.Console.Extensions;
using Elsa.Expressions;
using Elsa.Persistence.Memory;
using Elsa.Services;
using Microsoft.Extensions.DependencyInjection;

Expand Down
1 change: 0 additions & 1 deletion src/samples/Sample03/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using Elsa.Activities.Console.Extensions;
using Elsa.Expressions;
using Elsa.Models;
using Elsa.Persistence.Memory;
using Elsa.Services;
using Microsoft.Extensions.DependencyInjection;

Expand Down
1 change: 0 additions & 1 deletion src/samples/Sample04/Program.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
1 change: 0 additions & 1 deletion src/samples/Sample05/Program.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
1 change: 0 additions & 1 deletion src/samples/Sample06/Startup.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
1 change: 0 additions & 1 deletion src/samples/Sample07/Startup.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
1 change: 0 additions & 1 deletion src/samples/Sample08/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 0 additions & 1 deletion src/samples/Sample09/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
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;
Expand Down
1 change: 0 additions & 1 deletion src/samples/Sample10/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using Elsa.Extensions;
using Elsa.Models;
using Elsa.Persistence;
using Elsa.Persistence.Memory;
using Elsa.Persistence.YesSql.Extensions;
using Elsa.Runtime;
using Elsa.Services;
Expand Down
1 change: 0 additions & 1 deletion src/samples/Sample11/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using Elsa.Activities.Workflows;
using Elsa.Extensions;
using Elsa.Models;
using Elsa.Persistence.Memory;
using Elsa.Services;
using Microsoft.Extensions.DependencyInjection;

Expand Down
1 change: 0 additions & 1 deletion src/samples/Sample12/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
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;
Expand Down
1 change: 0 additions & 1 deletion src/samples/Sample13/Program.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
45 changes: 45 additions & 0 deletions src/samples/Sample17/Activities/CreatePerson.cs
Original file line number Diff line number Diff line change
@@ -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 changes: 41 additions & 0 deletions src/samples/Sample17/CreatePersonWorkflow.cs
Original file line number Diff line number Diff line change
@@ -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 changes: 10 additions & 0 deletions src/samples/Sample17/Models/Person.cs
Original file line number Diff line number Diff line change
@@ -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;
}
}
Loading

0 comments on commit d7fc571

Please sign in to comment.