Skip to content

Commit 483004e

Browse files
authored
Merge pull request #1 from navtech-io/develop
Develop
2 parents 4a52370 + faf49b0 commit 483004e

24 files changed

+549
-66
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Copyright (c) navtech.io. All rights reserved.
2+
// See License in the project root for license information.
3+
4+
using System;
5+
6+
namespace Simpleflow.CodeGenerator
7+
{
8+
internal enum EventType
9+
{
10+
None,
11+
VisitFunctionOnAvail
12+
}
13+
internal class ParserEventPublisher
14+
{
15+
public Action<EventType, object> OnVisit;
16+
17+
public void Publish(EventType eventType, object data)
18+
{
19+
OnVisit(eventType, data);
20+
}
21+
}
22+
}

src/Simpleflow/CodeGenerator/SimpleflowCodeVisitor.VisitFunction.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,19 @@ partial class SimpleflowCodeVisitor<TArg>
2121

2222
public override Expression VisitFunction([NotNull] SimpleflowParser.FunctionContext context)
2323
{
24-
var functionName = context.FunctionName().GetText();
24+
var functionName = context.FunctionName().GetText().Substring(1); // Remove $ symbol
2525

2626
// Get registered function
27-
var function = FunctionRegister.GetFunction(functionName.Substring(1)); // Remove $ symbol
27+
var function = FunctionRegister.GetFunction(functionName);
2828

2929
if (function == null)
3030
{
3131
throw new InvalidFunctionException(functionName);
3232
}
3333

34+
// Publish event once function is available to compile
35+
EventPublisher.Publish(EventType.VisitFunctionOnAvail, functionName);
36+
3437
// Get actual method meta-data info and parameters
3538
var methodInfo = function.GetMethodInfo();
3639

src/Simpleflow/CodeGenerator/SimpleflowCodeVisitor.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,12 @@ internal partial class SimpleflowCodeVisitor<TArg> : SimpleflowBaseVisitor<Expre
2727
protected readonly ParameterExpression Output; // script main function parameter 2
2828
protected readonly ParameterExpression ScriptHelperContext; //script main function parameter 3
2929

30-
public SimpleflowCodeVisitor(IFunctionRegister functionRegister)
30+
protected readonly ParserEventPublisher EventPublisher;
31+
32+
public SimpleflowCodeVisitor(IFunctionRegister functionRegister, ParserEventPublisher eventPublisher)
3133
{
3234
FunctionRegister = functionRegister ?? throw new ArgumentNullException(nameof(functionRegister));
35+
EventPublisher = eventPublisher;
3336

3437
/* Initialize smart variables and smart json variables */
3538
Variables = new List<ParameterExpression>();

src/Simpleflow/CodeGenerator/SimpleflowCompiler.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ namespace Simpleflow.CodeGenerator
1515
internal class SimpleflowCompiler
1616
{
1717

18-
public static Action<FlowInput<TArg>, FlowOutput, ScriptHelperContext> Compile<TArg>(string code, IFunctionRegister activityRegister)
18+
public static Action<FlowInput<TArg>, FlowOutput, ScriptHelperContext> Compile<TArg>(string code,
19+
IFunctionRegister activityRegister,
20+
ParserEventPublisher eventPublisher)
1921
{
2022
var inputStream = new AntlrInputStream(code);
2123

@@ -43,8 +45,9 @@ public static Action<FlowInput<TArg>, FlowOutput, ScriptHelperContext> Compile<T
4345
throw new SyntaxException(errorListener.GetAggregateMessages(), errorListener.Errors);
4446
}
4547

48+
4649
// Generate code
47-
var visitor = new SimpleflowCodeVisitor<TArg>(activityRegister);
50+
var visitor = new SimpleflowCodeVisitor<TArg>(activityRegister, eventPublisher);
4851
var program = visitor.Visit(programContext);
4952

5053
// Compile
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Copyright (c) navtech.io. All rights reserved.
2+
// See License in the project root for license information.
3+
4+
namespace Simpleflow.Exceptions
5+
{
6+
public class AccessDeniedException : SimpleflowException
7+
{
8+
public AccessDeniedException(string message) : base(message)
9+
{
10+
11+
}
12+
}
13+
}

src/Simpleflow/FlowContext.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public sealed class FlowContext<TArg>
2929
public IFunctionRegister ActivityRegister { get; set; }
3030

3131
///
32-
public IOptions Options { get; set; }
32+
public IContextOptions Options { get; set; }
3333

3434
/// <summary>
3535
/// Gets or sets output.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright (c) navtech.io. All rights reserved.
2+
// See License in the project root for license information.
3+
4+
using Simpleflow.Services;
5+
6+
namespace Simpleflow
7+
{
8+
/// <summary>
9+
///
10+
/// </summary>
11+
public class FlowContextOptions : FlowOptions, IContextOptions
12+
{
13+
/// <summary>
14+
/// Gets or sets unique id of the script
15+
/// If Id is supplied, <see cref="CacheService"/> will use it to identify the compiled object
16+
/// in cache otherwise it creates a hash id for that script.
17+
/// </summary>
18+
public string Id { get; set; }
19+
20+
}
21+
}

src/Simpleflow/FlowOptions.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,25 @@
11
// Copyright (c) navtech.io. All rights reserved.
22
// See License in the project root for license information.
33

4+
45
namespace Simpleflow
56
{
67
/// <inheritdoc />
78
public class FlowOptions : IOptions
89
{
9-
/// <inheritdoc />
10+
/// <summary>
11+
/// Gets or sets AllowArgumentToMutate
12+
/// </summary>
1013
public bool AllowArgumentToMutate { get; set; }
1114

12-
/// <inheritdoc />
15+
/// <summary>
16+
/// Gets or sets AllowFunctions
17+
/// </summary>
1318
public string[] AllowFunctions { get; set; }
1419

15-
/// <inheritdoc />
20+
/// <summary>
21+
/// Gets or sets DenyFunctions
22+
/// </summary>
1623
public string[] DenyFunctions { get; set; }
1724
}
1825
}

src/Simpleflow/IContextOptions.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright (c) navtech.io. All rights reserved.
2+
// See License in the project root for license information.
3+
4+
namespace Simpleflow
5+
{
6+
/// <summary>
7+
///
8+
/// </summary>
9+
public interface IContextOptions : IOptions
10+
{
11+
/// <summary>
12+
/// Gets unique id of the script
13+
/// </summary>
14+
string Id { get; }
15+
}
16+
}

src/Simpleflow/IOptions.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ public interface IOptions
2020

2121

2222
/// <summary>
23-
/// Gets or sets DenyFunctions
24-
/// DenyFunctions overrides the <see cref="AllowFunctions"/>
23+
/// Gets or sets DenyFunctions.
2524
/// </summary>
2625
public string[] DenyFunctions { get; set; }
2726
}

0 commit comments

Comments
 (0)