diff --git a/samples/Sample04/CalculatorWorkflow.cs b/samples/Sample04/CalculatorWorkflow.cs index 0bf96c711..a04ff643c 100644 --- a/samples/Sample04/CalculatorWorkflow.cs +++ b/samples/Sample04/CalculatorWorkflow.cs @@ -53,7 +53,7 @@ namespace Sample04 .Then(x => x.TextExpression = new PlainTextExpression("Try again? (y/n)")) .Then(x => x.VariableName = "retry") .Then( - x => x.ConditionExpression = new JavaScriptExpression("retry.toLowerCase() === 'y'"), + x => x.Expression = new JavaScriptExpression("retry.toLowerCase() === 'y'"), ifElse => { ifElse diff --git a/samples/Sample07/DocumentApprovalWorkflow.cs b/samples/Sample07/DocumentApprovalWorkflow.cs index 9087fb019..bb2e326a1 100644 --- a/samples/Sample07/DocumentApprovalWorkflow.cs +++ b/samples/Sample07/DocumentApprovalWorkflow.cs @@ -29,7 +29,7 @@ namespace Sample07 activity => { activity.VariableName = "document"; - activity.ValueExpression = new JavaScriptExpression("lastResult().ParsedContent"); + activity.Expression = new JavaScriptExpression("lastResult().ParsedContent"); } ) .Then( @@ -69,7 +69,7 @@ namespace Sample07 } ) .Add(activity => activity.Mode = Join.JoinMode.WaitAny, "join-signals") - .Then(activity => activity.ConditionExpression = new JavaScriptExpression("input('signal') === 'approve'"), + .Then(activity => activity.Expression = new JavaScriptExpression("input('signal') === 'approve'"), ifElse => { ifElse diff --git a/samples/Sample08/Workflows/CreateOrderWorkflow.cs b/samples/Sample08/Workflows/CreateOrderWorkflow.cs index 5ea2dca92..0def0c745 100644 --- a/samples/Sample08/Workflows/CreateOrderWorkflow.cs +++ b/samples/Sample08/Workflows/CreateOrderWorkflow.cs @@ -30,7 +30,7 @@ namespace Sample08.Workflows activity => { activity.VariableName = "order"; - activity.ValueExpression = new JavaScriptExpression("lastResult().ParsedContent"); + activity.Expression = new JavaScriptExpression("lastResult().ParsedContent"); } ) .Then(activity => diff --git a/samples/Sample08/Workflows/HandleOrderWorkflow.cs b/samples/Sample08/Workflows/HandleOrderWorkflow.cs index 620d7c733..7a4f68fe5 100644 --- a/samples/Sample08/Workflows/HandleOrderWorkflow.cs +++ b/samples/Sample08/Workflows/HandleOrderWorkflow.cs @@ -19,7 +19,7 @@ namespace Sample08.Workflows activity => { activity.VariableName = "order"; - activity.ValueExpression = new JavaScriptExpression("lastResult().Order"); + activity.Expression = new JavaScriptExpression("lastResult().Order"); } ) .Then(activity => activity.TimeoutExpression = new PlainTextExpression("00:00:05")) diff --git a/samples/Sample09/calculator.json b/samples/Sample09/calculator.json index b873ba212..04740bf22 100644 --- a/samples/Sample09/calculator.json +++ b/samples/Sample09/calculator.json @@ -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" } ] } \ No newline at end of file diff --git a/src/core/Elsa.Abstractions/Extensions/StateExtensions.cs b/src/core/Elsa.Abstractions/Extensions/StateExtensions.cs index b5b315e3e..a305a8ab0 100644 --- a/src/core/Elsa.Abstractions/Extensions/StateExtensions.cs +++ b/src/core/Elsa.Abstractions/Extensions/StateExtensions.cs @@ -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(this JObject state, string key, Func defaultValue = null) - { - var item = state[key]; - return item != null ? item.ToObject(Serializer) : defaultValue != null ? defaultValue() : default; - } - - public static T GetState(this JObject state, Type type, string key, Func 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(this JObject state, string key, Func defaultValue = null) + { + var item = state.GetValue(key, StringComparison.OrdinalIgnoreCase); + return item != null ? item.ToObject(Serializer) : defaultValue != null ? defaultValue() : default; + } + + public static T GetState(this JObject state, Type type, string key, Func 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); + } + } } \ No newline at end of file diff --git a/src/core/Elsa.Core/Activities/ControlFlow/IfElse.cs b/src/core/Elsa.Core/Activities/ControlFlow/IfElse.cs index 49936da9b..6b91e9c82 100644 --- a/src/core/Elsa.Core/Activities/ControlFlow/IfElse.cs +++ b/src/core/Elsa.Core/Activities/ControlFlow/IfElse.cs @@ -17,7 +17,7 @@ namespace Elsa.Activities.ControlFlow this.expressionEvaluator = expressionEvaluator; } - public WorkflowExpression ConditionExpression + public WorkflowExpression Expression { get => GetState(() => new JavaScriptExpression("true")); set => SetState(value); @@ -25,7 +25,7 @@ namespace Elsa.Activities.ControlFlow protected override async Task 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); } } diff --git a/src/core/Elsa.Core/Activities/Primitives/SetVariable.cs b/src/core/Elsa.Core/Activities/Primitives/SetVariable.cs index 75af5e1dd..62f2fc351 100644 --- a/src/core/Elsa.Core/Activities/Primitives/SetVariable.cs +++ b/src/core/Elsa.Core/Activities/Primitives/SetVariable.cs @@ -23,7 +23,7 @@ namespace Elsa.Activities.Primitives set => SetState(value); } - public WorkflowExpression ValueExpression + public WorkflowExpression Expression { get => GetState>(); set => SetState(value); @@ -31,7 +31,7 @@ namespace Elsa.Activities.Primitives protected override async Task 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(); }