Fixed a number of activity expression property names and updated Sample09 with a functioning console app workflow

This commit is contained in:
Sipke Schoorstra 2019-07-22 21:58:29 +02:00
parent 7ba8b1e8d6
commit d117cdec01
8 changed files with 153 additions and 84 deletions

View file

@ -53,7 +53,7 @@ namespace Sample04
.Then<WriteLine>(x => x.TextExpression = new PlainTextExpression("Try again? (y/n)"))
.Then<ReadLine>(x => x.VariableName = "retry")
.Then<IfElse>(
x => x.ConditionExpression = new JavaScriptExpression<bool>("retry.toLowerCase() === 'y'"),
x => x.Expression = new JavaScriptExpression<bool>("retry.toLowerCase() === 'y'"),
ifElse =>
{
ifElse

View file

@ -29,7 +29,7 @@ namespace Sample07
activity =>
{
activity.VariableName = "document";
activity.ValueExpression = new JavaScriptExpression<object>("lastResult().ParsedContent");
activity.Expression = new JavaScriptExpression<object>("lastResult().ParsedContent");
}
)
.Then<SendEmail>(
@ -69,7 +69,7 @@ namespace Sample07
}
)
.Add<Join>(activity => activity.Mode = Join.JoinMode.WaitAny, "join-signals")
.Then<IfElse>(activity => activity.ConditionExpression = new JavaScriptExpression<bool>("input('signal') === 'approve'"),
.Then<IfElse>(activity => activity.Expression = new JavaScriptExpression<bool>("input('signal') === 'approve'"),
ifElse =>
{
ifElse

View file

@ -30,7 +30,7 @@ namespace Sample08.Workflows
activity =>
{
activity.VariableName = "order";
activity.ValueExpression = new JavaScriptExpression<object>("lastResult().ParsedContent");
activity.Expression = new JavaScriptExpression<object>("lastResult().ParsedContent");
}
)
.Then<SendMassTransitMessage>(activity =>

View file

@ -19,7 +19,7 @@ namespace Sample08.Workflows
activity =>
{
activity.VariableName = "order";
activity.ValueExpression = new JavaScriptExpression<object>("lastResult().Order");
activity.Expression = new JavaScriptExpression<object>("lastResult().Order");
}
)
.Then<TimerEvent>(activity => activity.TimeoutExpression = new PlainTextExpression<TimeSpan>("00:00:05"))

View file

@ -2,8 +2,8 @@
"activities": [
{
"id": "cb5bc5c3-c8a2-4e13-b469-3780af6f1502",
"top": 156,
"left": 322,
"top": 170,
"left": 326,
"type": "ReadLine",
"state": {
"variableName": "a"
@ -15,16 +15,22 @@
"left": 29,
"type": "WriteLine",
"state": {
"textExpression": "Welcome to Calculator!"
"textExpression": {
"expression": "Welcome to Calculator",
"syntax": "PlainText"
}
}
},
{
"id": "c06feed1-c9f7-407e-820f-68dd045788c0",
"top": 295,
"left": 46,
"top": 466,
"left": 77,
"type": "WriteLine",
"state": {
"textExpression": "Enter a number:"
"textExpression": {
"expression": "Enter a number",
"syntax": "PlainText"
}
}
},
{
@ -33,13 +39,16 @@
"left": 613,
"type": "WriteLine",
"state": {
"textExpression": "Enter another number:"
"textExpression": {
"expression": "Enter another number",
"syntax": "PlainText"
}
}
},
{
"id": "b05e7717-39f2-4bf1-a13f-ee30295287c3",
"top": 188,
"left": 789,
"top": 179,
"left": 798,
"type": "ReadLine",
"state": {
"variableName": "b"
@ -47,20 +56,26 @@
},
{
"id": "e5edc24d-59ca-4682-8af0-a464de2b2725",
"top": 338,
"left": 545,
"top": 374,
"left": 644,
"type": "WriteLine",
"state": {
"textExpression": "Enter an operation. Options: add, subtract, multiply, divide"
"textExpression": {
"expression": "Enter an operation. Options: Add, Subtract, Multiply, Divide",
"syntax": "PlainText"
}
}
},
{
"id": "cf9f8965-5765-482e-a280-000c7105e378",
"top": 535,
"left": 626,
"top": 47,
"left": 1462,
"type": "Switch",
"state": {
"expression": "parseFloat(operation)",
"expression": {
"expression": "operation",
"syntax": "JavaScript"
},
"cases": [
"Add",
"Subtract",
@ -71,66 +86,100 @@
},
{
"id": "2ef2fc1e-c439-482f-a9a7-9ec0fec7d868",
"top": 17,
"left": 1258,
"top": 307,
"left": 1274,
"type": "SetVariable",
"state": {
"variableName": "result",
"variableExpression": "a + b"
"variableExpression": {
"expression": "a + b",
"syntax": "JavaScript"
},
"expression": {
"expression": "a + b",
"syntax": "JavaScript"
}
}
},
{
"id": "47396ebe-8e62-432b-bd28-4260c07d1ffe",
"top": 172,
"left": 1259,
"top": 297,
"left": 1472,
"type": "SetVariable",
"state": {
"variableName": "result",
"variableExpression": "a - b"
"variableExpression": {
"expression": "a - b",
"syntax": "JavaScript"
},
"expression": {
"expression": "a - b",
"syntax": "JavaScript"
}
}
},
{
"id": "f700f606-6995-4e80-b30e-c6bbfba91c81",
"top": 365,
"left": 1258,
"top": 303,
"left": 1659,
"type": "SetVariable",
"state": {
"variableName": "result",
"variableExpression": "a * b"
"variableExpression": {
"expression": "a * b",
"syntax": "JavaScript"
},
"expression": {
"expression": "a * b",
"syntax": "JavaScript"
}
}
},
{
"id": "80c41881-edc6-4d3f-8f1b-9cc3fc9cbfc1",
"top": 526,
"left": 1263,
"top": 305,
"left": 1870,
"type": "SetVariable",
"state": {
"variableName": "result",
"variableExpression": "a / b"
"variableExpression": {
"expression": "a / b",
"syntax": "JavaScript"
},
"expression": {
"expression": "a / b",
"syntax": "JavaScript"
}
}
},
{
"id": "3343d0cc-eea0-4f28-a370-c182ae74b007",
"top": 266,
"left": 1607,
"top": 509,
"left": 1495,
"type": "WriteLine",
"state": {
"textExpression": "`Result: ${result}`"
"textExpression": {
"expression": "`Result: ${result}`",
"syntax": "JavaScript"
}
}
},
{
"id": "be435fd5-1740-40ee-98e1-7843da139e9a",
"top": 465,
"left": 1611,
"top": 697,
"left": 1490,
"type": "WriteLine",
"state": {
"textExpression": "Try again? (y/n)"
"textExpression": {
"expression": "Try again? (y/n)",
"syntax": "PlainText"
}
}
},
{
"id": "b3f5818e-9a24-4621-9d15-07af7de4da32",
"top": 821,
"left": 1591,
"top": 904,
"left": 1349,
"type": "ReadLine",
"state": {
"variableName": "retry"
@ -138,20 +187,35 @@
},
{
"id": "701a7580-2b6a-42ff-9f18-82ca1910b192",
"top": 735,
"left": 568,
"top": 848,
"left": 687,
"type": "IfElse",
"state": {
"expression": "retry === 'y'"
"expression": {
"expression": "retry === 'y'",
"syntax": "JavaScript"
}
}
},
{
"id": "9e0f75ca-d599-4bf7-8132-ffb305004c2d",
"top": 846,
"left": 83,
"top": 920,
"left": 104,
"type": "WriteLine",
"state": {
"textExpression": "Bye!"
"textExpression": {
"expression": "Bye!",
"syntax": "PlainText"
}
}
},
{
"id": "b3cab833-452b-4b8e-bf34-15447d2ac61d",
"top": 557,
"left": 769,
"type": "ReadLine",
"state": {
"variableName": "operation"
}
}
],
@ -181,11 +245,6 @@
"destinationActivityId": "e5edc24d-59ca-4682-8af0-a464de2b2725",
"outcome": "Done"
},
{
"sourceActivityId": "e5edc24d-59ca-4682-8af0-a464de2b2725",
"destinationActivityId": "cf9f8965-5765-482e-a280-000c7105e378",
"outcome": "Done"
},
{
"sourceActivityId": "cf9f8965-5765-482e-a280-000c7105e378",
"destinationActivityId": "2ef2fc1e-c439-482f-a9a7-9ec0fec7d868",
@ -250,6 +309,16 @@
"sourceActivityId": "701a7580-2b6a-42ff-9f18-82ca1910b192",
"destinationActivityId": "9e0f75ca-d599-4bf7-8132-ffb305004c2d",
"outcome": "False"
},
{
"sourceActivityId": "e5edc24d-59ca-4682-8af0-a464de2b2725",
"destinationActivityId": "b3cab833-452b-4b8e-bf34-15447d2ac61d",
"outcome": "Done"
},
{
"sourceActivityId": "b3cab833-452b-4b8e-bf34-15447d2ac61d",
"destinationActivityId": "cf9f8965-5765-482e-a280-000c7105e378",
"outcome": "Done"
}
]
}

View file

@ -1,30 +1,30 @@
using System;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using NodaTime;
using NodaTime.Serialization.JsonNet;
namespace Elsa.Extensions
{
public static class StateExtensions
{
private static readonly JsonSerializer Serializer = new JsonSerializer().ConfigureForNodaTime(DateTimeZoneProviders.Tzdb);
public static T GetState<T>(this JObject state, string key, Func<T> defaultValue = null)
{
var item = state[key];
return item != null ? item.ToObject<T>(Serializer) : defaultValue != null ? defaultValue() : default;
}
public static T GetState<T>(this JObject state, Type type, string key, Func<T> defaultValue = null)
{
var item = state[key];
return item != null ? (T) item.ToObject(type, Serializer) : defaultValue != null ? defaultValue() : default;
}
public static void SetState(this JObject state, string key, object value)
{
state[key] = JToken.FromObject(value, Serializer);
}
}
using System;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using NodaTime;
using NodaTime.Serialization.JsonNet;
namespace Elsa.Extensions
{
public static class StateExtensions
{
private static readonly JsonSerializer Serializer = new JsonSerializer().ConfigureForNodaTime(DateTimeZoneProviders.Tzdb);
public static T GetState<T>(this JObject state, string key, Func<T> defaultValue = null)
{
var item = state.GetValue(key, StringComparison.OrdinalIgnoreCase);
return item != null ? item.ToObject<T>(Serializer) : defaultValue != null ? defaultValue() : default;
}
public static T GetState<T>(this JObject state, Type type, string key, Func<T> defaultValue = null)
{
var item = state.GetValue(key, StringComparison.OrdinalIgnoreCase);
return item != null ? (T) item.ToObject(type, Serializer) : defaultValue != null ? defaultValue() : default;
}
public static void SetState(this JObject state, string key, object value)
{
state[key] = JToken.FromObject(value, Serializer);
}
}
}

View file

@ -17,7 +17,7 @@ namespace Elsa.Activities.ControlFlow
this.expressionEvaluator = expressionEvaluator;
}
public WorkflowExpression<bool> ConditionExpression
public WorkflowExpression<bool> Expression
{
get => GetState(() => new JavaScriptExpression<bool>("true"));
set => SetState(value);
@ -25,7 +25,7 @@ namespace Elsa.Activities.ControlFlow
protected override async Task<ActivityExecutionResult> OnExecuteAsync(WorkflowExecutionContext workflowContext, CancellationToken cancellationToken)
{
var result = await expressionEvaluator.EvaluateAsync(ConditionExpression, workflowContext, cancellationToken);
var result = await expressionEvaluator.EvaluateAsync(Expression, workflowContext, cancellationToken);
return Outcome(result ? OutcomeNames.True: OutcomeNames.False);
}
}

View file

@ -23,7 +23,7 @@ namespace Elsa.Activities.Primitives
set => SetState(value);
}
public WorkflowExpression<object> ValueExpression
public WorkflowExpression<object> Expression
{
get => GetState<WorkflowExpression<object>>();
set => SetState(value);
@ -31,7 +31,7 @@ namespace Elsa.Activities.Primitives
protected override async Task<ActivityExecutionResult> OnExecuteAsync(WorkflowExecutionContext workflowContext, CancellationToken cancellationToken)
{
var value = await expressionEvaluator.EvaluateAsync(ValueExpression, workflowContext, cancellationToken);
var value = await expressionEvaluator.EvaluateAsync(Expression, workflowContext, cancellationToken);
workflowContext.CurrentScope.SetVariable(VariableName, value);
return Done();
}