Skip to content

Commit 35e1df9

Browse files
committed
custom exceptions
1 parent 7f94711 commit 35e1df9

File tree

3 files changed

+25
-6
lines changed

3 files changed

+25
-6
lines changed

ReleaseNotes/1.4.0.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ Full details of the capabilities of expression language can be found [here](htt
9898
"StepType": "MyApp.HelloWorld, MyApp",
9999
"NextStepId": "Print"
100100
},
101-
{
101+
{
102102
"Id": "Print",
103103
"StepType": "MyApp.PrintMessage, MyApp",
104104
"Inputs": { "Message": "\"Hi there!\"" }
@@ -287,7 +287,7 @@ The `.Recur` can be implemented as follows
287287
"Id": "MyScheduleStep",
288288
"StepType": "WorkflowCore.Primitives.Recur, WorkflowCore",
289289
"Inputs": {
290-
"Interval": "<<expression to evaluate>>",
290+
"Interval": "<<expression to evaluate>>",
291291
"StopCondition": "<<expression to evaluate>>"
292292
},
293293
"Do": [[
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
5+
namespace WorkflowCore.Exceptions
6+
{
7+
public class WorkflowDefinitionLoadException : Exception
8+
{
9+
public WorkflowDefinitionLoadException(string message)
10+
: base (message)
11+
{
12+
}
13+
}
14+
}

src/WorkflowCore/Services/DefinitionStorage/DefinitionLoader.cs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
using WorkflowCore.Primitives;
1212
using WorkflowCore.Models.DefinitionStorage;
1313
using WorkflowCore.Models.DefinitionStorage.v1;
14+
using WorkflowCore.Exceptions;
1415

1516
namespace WorkflowCore.Services.DefinitionStorage
1617
{
@@ -22,7 +23,7 @@ public DefinitionLoader(IWorkflowRegistry registry)
2223
{
2324
_registry = registry;
2425
}
25-
26+
2627
public WorkflowDefinition LoadDefinition(string json)
2728
{
2829
var source = JsonConvert.DeserializeObject<DefinitionSourceV1>(json);
@@ -107,8 +108,14 @@ private List<WorkflowStep> ConvertSteps(ICollection<StepSourceV1> source, Type d
107108

108109
foreach (var step in result)
109110
{
111+
if (result.Any(x => x.Tag == step.Tag && x.Id != step.Id))
112+
throw new WorkflowDefinitionLoadException($"Duplicate step Id {step.Tag}");
113+
110114
foreach (var outcome in step.Outcomes)
111115
{
116+
if (result.All(x => x.Tag != outcome.Tag))
117+
throw new WorkflowDefinitionLoadException($"Cannot find step id {outcome.Tag}");
118+
112119
outcome.NextStep = result.Single(x => x.Tag == outcome.Tag).Id;
113120
}
114121
}
@@ -137,8 +144,6 @@ private void AttachInputs(StepSourceV1 source, Type dataType, Type stepType, Wor
137144
{
138145
var dataParameter = Expression.Parameter(dataType, "data");
139146
var contextParameter = Expression.Parameter(typeof(IStepExecutionContext), "context");
140-
141-
// https://github.com/StefH/System.Linq.Dynamic.Core/wiki/Dynamic-Expressions
142147
var sourceExpr = DynamicExpressionParser.ParseLambda(new [] { dataParameter, contextParameter }, typeof(object), input.Value);
143148
var targetExpr = Expression.Property(Expression.Parameter(stepType), input.Key);
144149

@@ -168,7 +173,7 @@ private void AttachOutputs(StepSourceV1 source, Type dataType, Type stepType, Wo
168173

169174
private Type FindType(string name)
170175
{
171-
return Type.GetType(name);
176+
return Type.GetType(name, true, true);
172177
}
173178

174179
}

0 commit comments

Comments
 (0)