Skip to content

Commit b89876f

Browse files
authored
Merge pull request #6 from navtech-io/develop
Develop
2 parents 6692e2e + 7c1e616 commit b89876f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+847
-375
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Install package via Nuget. Using the NuGet package manager console within Visual
1616
Install-Package Simpleflow
1717
```
1818

19-
**Try following Simpleflow script:**
19+
**Try the following Simpleflow script:**
2020

2121
```csharp
2222
using Simpleflow;

build/Build.cs

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Linq;
33
using Nuke.Common;
44
using Nuke.Common.CI.AppVeyor;
5+
using Nuke.Common.CI.GitHubActions;
56
using Nuke.Common.Execution;
67
using Nuke.Common.Git;
78
using Nuke.Common.IO;
@@ -10,6 +11,7 @@
1011
using Nuke.Common.Tools.DotNet;
1112
using Nuke.Common.Tools.GitVersion;
1213
using Nuke.Common.Utilities.Collections;
14+
using Serilog;
1315
using static Nuke.Common.EnvironmentInfo;
1416
using static Nuke.Common.IO.FileSystemTasks;
1517
using static Nuke.Common.IO.PathConstruction;
@@ -40,6 +42,15 @@ class Build : NukeBuild
4042
AbsolutePath TestsDirectory => RootDirectory / "test";
4143
AbsolutePath ArtifactsDirectory => RootDirectory / "artifacts";
4244
AbsolutePath NugetDirectory => ArtifactsDirectory / "nuget";
45+
GitHubActions GitHubActions => GitHubActions.Instance;
46+
47+
48+
Target Print => _ => _
49+
.Executes(() =>
50+
{
51+
Log.Information("Branch = {Branch}", GitHubActions.Ref);
52+
Log.Information("Commit = {Commit}", GitHubActions.Sha);
53+
});
4354

4455
Target Clean => _ => _
4556
.Before(Restore)
@@ -114,14 +125,14 @@ class Build : NukeBuild
114125
.AddProperty("PackageLicenseExpression", "Apache-2.0")
115126
.AddProperty("PackageIcon", @"PackageIcon.png")
116127
.SetIncludeSymbols(true)
117-
.SetVersion("0.1.0-beta05" /*NuGetVersionCustom*/)
118-
.SetDescription("Lightweight rule engine")
128+
.SetVersion("0.1.0-beta06")
129+
.SetDescription("Build dynamic rules and workflows using script")
119130
.SetPackageTags("Simpleflow.NET Workflow RuleEngine DynamicExpressionEvaluator")
120131
.SetNoDependencies(true)
121132
.SetOutputDirectory(ArtifactsDirectory / "nuget"));
122133
});
123134

124-
Target Push => _ => _
135+
Target Publish => _ => _
125136
.Requires(() => NugetApiUrl)
126137
.Requires(() => NugetApiKey)
127138
.Requires(() => Configuration.Equals(Configuration.Release))
@@ -141,12 +152,5 @@ class Build : NukeBuild
141152
});
142153
});
143154

144-
// Target PullRequest
145-
146-
//Target Print => _ => _
147-
// .Executes(() =>
148-
// {
149-
// Log.Information("Branch = {Branch}", GitHubActions.Ref);
150-
// Log.Information("Commit = {Commit}", GitHubActions.Sha);
151-
// });
155+
152156
}

src/Simpleflow/CacheOptions.cs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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+
/// Represents the cache options that applied to <see cref="Services.CacheService"/>
8+
/// </summary>
9+
public class CacheOptions
10+
{
11+
/// <summary>
12+
/// Gets or sets how long a cache entry can be inactive (e.g. not accessed) before it will be removed.
13+
/// This will not extend the entry lifetime beyond the absolute expiration (if set).
14+
/// </summary>
15+
public System.TimeSpan? SlidingExpiration { get; set; } = System.TimeSpan.FromMinutes(3);
16+
17+
/// <summary>
18+
/// Gets or sets an absolute expiration date for the cache entry.
19+
/// </summary>
20+
public System.DateTimeOffset? AbsoluteExpiration { get; set; }
21+
22+
/// <summary>
23+
/// Gets or sets hashing algorithm to identify script compiled object uniquely
24+
/// Check available hash algorithms and names here: https://docs.microsoft.com/en-us/dotnet/api/system.security.cryptography.hashalgorithm.create?view=net-6.0
25+
/// </summary>
26+
public string HashingAlgToIdentifyScriptUniquely { get; set; } = "MD5";
27+
}
28+
}

src/Simpleflow/CodeGenerator/SimpleflowCodeVisitor.VisitArithmeticExpression.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,17 @@ public override Expression VisitArithmeticExpression(SimpleflowParser.Arithmetic
6969
return Expression.Divide(left, right);
7070
}
7171

72-
// TODO InvalidArithmeticExpression
73-
throw new Exception("Invalid operator or expression");
72+
if (context.ModuloOp() != null)
73+
{
74+
var left = Visit(context.arithmeticExpression()[0]);
75+
var right = Visit(context.arithmeticExpression()[1]);
76+
77+
(left, right) = ConvertToBiggerNumberType(left, right);
78+
79+
return Expression.Modulo(left, right);
80+
}
81+
82+
throw new Exceptions.SimpleflowException("Invalid operator or expression");
7483
}
7584

7685
private (Expression left, Expression right) ConvertToBiggerNumberType(Expression left, Expression right)

src/Simpleflow/CodeGenerator/SimpleflowCodeVisitor.VisitFunction.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,14 +97,14 @@ private Expression CreateFunctionParameterExpression(ParameterInfo methodParamet
9797

9898
private void CheckRepeatedParameters(SimpleflowParser.FunctionParameterContext[] parameters)
9999
{
100-
var repeatedParameter = (from parameter in parameters
100+
var repeatedParameters = (from parameter in parameters
101101
group parameter by parameter.Identifier().GetText() into g
102102
where g.Count() > 1
103103
select g.Key).ToList();
104104

105-
if (repeatedParameter.Count > 0)
105+
if (repeatedParameters.Count > 0)
106106
{
107-
throw new DuplicateParametersException(string.Join(',', repeatedParameter));
107+
throw new DuplicateParametersException(repeatedParameters);
108108
}
109109
}
110110

src/Simpleflow/CodeGenerator/SimpleflowCodeVisitor.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,6 @@ private void CreateUserDefinedVariableExpressions(List<Expression> statementExpr
126126

127127
private void InjectSmartVariables(List<Expression> statementExpressions)
128128
{
129-
// TODO write comments
130129
int index = 0;
131130
while (index < SmartJsonVariables.Count)
132131
{

src/Simpleflow/Exceptions/AccessDeniedException.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,19 @@
33

44
namespace Simpleflow.Exceptions
55
{
6+
7+
/// <summary>
8+
/// This exception is thrown when a script uses a denied function.
9+
/// </summary>
610
public class AccessDeniedException : SimpleflowException
711
{
12+
/// <summary>
13+
/// Initializes a new instance of the <see cref="AccessDeniedException"/> class with
14+
/// a specified error message.
15+
/// </summary>
16+
/// <param name="message">The message that describes the error</param>
817
public AccessDeniedException(string message) : base(message)
918
{
10-
1119
}
1220
}
1321
}

src/Simpleflow/Exceptions/DuplicateActivityException.cs

Lines changed: 0 additions & 25 deletions
This file was deleted.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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+
/// <summary>
7+
/// The exception is thrown when a function with a name is already registered.
8+
/// </summary>
9+
public class DuplicateFunctionException : SimpleflowException
10+
{
11+
/// <summary>
12+
/// Initializes a new instance of the <see cref="DuplicateFunctionException"/> class with
13+
/// a specified function name.
14+
/// </summary>
15+
/// <param name="functionName">The name of the function that caused the exception</param>
16+
/// <param name="message">The message describes the exception</param>
17+
public DuplicateFunctionException(string functionName, string message=null) : base(message ?? $"Function '{functionName}' is already registered, cannot be duplicated.") {
18+
FunctionName = functionName;
19+
}
20+
21+
/// <summary>
22+
/// Gets name of the function that has been re-registered.
23+
/// </summary>
24+
public string FunctionName { get; }
25+
}
26+
}
Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
11
// Copyright (c) navtech.io. All rights reserved.
22
// See License in the project root for license information.
33

4-
using System;
4+
using System.Collections.Generic;
55

66
namespace Simpleflow.Exceptions
77
{
8+
/// <summary>
9+
/// The exception is thrown when same parameters are specified multiple times
10+
/// while invoking a function in script
11+
/// </summary>
812
public class DuplicateParametersException : SimpleflowException
913
{
10-
// TODO
11-
1214
/// <summary>
13-
///
15+
/// Initializes a new instance of the <see cref="DuplicateParametersException"/> class with
16+
/// a specified function name.
1417
/// </summary>
15-
/// <param name="name"></param>
16-
public DuplicateParametersException(string message) : base(message) { }
18+
/// <param name="repeatedParameters">The repeated parameters that caused the exception.</param>
19+
public DuplicateParametersException(IEnumerable<string> repeatedParameters) : base($"Duplicate parameters '{string.Join(',', repeatedParameters)}' cannot be allowed." ) { }
1720
}
1821
}

0 commit comments

Comments
 (0)