Skip to content

Commit 090c475

Browse files
author
Jani Giannoudis
committed
new design for actions: refactored case actions, added action support for collector and wage type
function: new method to get calendar day count payroll function: added support for the regulation namespace payrun function: added get/set payrun result payrun function: added get wage type name/number by number/name date period extensions: fixed condition in GetWorkingDaysCount() updated to c# 14 updated database version to 0.9.5 updated version to 0.9.0-beta.13
1 parent bc46cc9 commit 090c475

77 files changed

Lines changed: 8004 additions & 14427 deletions

File tree

Some content is hidden

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

Client.Scripting.Tests/PayrollEngine.Client.Scripting.Tests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
</PropertyGroup>
99

1010
<ItemGroup>
11-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.0.0" />
11+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.0.1" />
1212
<PackageReference Include="xunit" Version="2.9.3" />
1313
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.5">
1414
<PrivateAssets>all</PrivateAssets>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using System;
2+
3+
namespace PayrollEngine.Client.Scripting;
4+
5+
/// <summary>
6+
/// Action property info
7+
/// </summary>
8+
public class ActionPropertyInfo
9+
{
10+
/// <summary>The property name</summary>
11+
public FunctionType FunctionType { get; init; }
12+
13+
/// <summary>The property name</summary>
14+
public string Name { get; init; }
15+
16+
/// <summary>The property description</summary>
17+
public string Description { get; init; }
18+
19+
/// <summary>The property type</summary>
20+
public Type Type { get; init; }
21+
22+
/// <summary>Readonly property</summary>
23+
public bool ReadOnly { get; init; }
24+
}

Client.Scripting/ActionReflector.cs

Lines changed: 21 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -47,29 +47,25 @@ public static List<ActionInfo> LoadFrom(Assembly assembly)
4747

4848
// setup action cache
4949
var actions = new List<ActionInfo>();
50-
foreach (var type in assembly.GetTypes().Where(x => !x.IsGenericType && !x.IsNested))
51-
{
52-
53-
// action provider attribute
54-
var providerAttribute = GetProviderAttribute(type);
55-
if (providerAttribute == null)
56-
{
57-
continue;
58-
}
5950

60-
foreach (var typeMethod in type.GetMethods(BindingFlags.Public | BindingFlags.Instance))
51+
// each type
52+
var types = assembly.GetTypes().Where(x => IsFunctionType(x) && !x.IsGenericType && !x.IsNested);
53+
foreach (var type in types)
54+
{
55+
// each method
56+
var methods = type.GetMethods(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly);
57+
foreach (var method in methods)
6158
{
6259
// action attribute
63-
var actionAttribute = GetActionAttribute(typeMethod);
60+
var actionAttribute = GetActionAttribute(method);
6461
if (actionAttribute == null)
6562
{
6663
continue;
6764
}
6865

6966
// action attribute
70-
var actionInfo = new ActionInfo(providerAttribute.Type)
67+
var actionInfo = new ActionInfo(type)
7168
{
72-
Namespace = providerAttribute.Namespace,
7369
Name = GetPropertyValue<string>(actionAttribute,
7470
nameof(ActionAttribute.Name)),
7571
Description = GetPropertyValue<string>(actionAttribute,
@@ -82,7 +78,7 @@ public static List<ActionInfo> LoadFrom(Assembly assembly)
8278
actions.Add(actionInfo);
8379

8480
// action parameter attributes (optional)
85-
var parameterAttributes = GetActionParameterAttributes(typeMethod,
81+
var parameterAttributes = GetActionParameterAttributes(method,
8682
typeof(ActionParameterAttribute));
8783
if (parameterAttributes != null)
8884
{
@@ -92,7 +88,7 @@ public static List<ActionInfo> LoadFrom(Assembly assembly)
9288
nameof(ActionParameterAttribute.Name));
9389

9490
// test parameter
95-
if (!typeMethod.GetParameters().Any(x => string.Equals(x.Name, name)))
91+
if (!method.GetParameters().Any(x => string.Equals(x.Name, name)))
9692
{
9793
throw new PayrollException($"Invalid action parameter {actionInfo.Name}.{name}");
9894
}
@@ -131,7 +127,7 @@ public static List<ActionInfo> LoadFrom(Assembly assembly)
131127
}
132128

133129
// action issue attributes (optional)
134-
var issuesAttributes = GetActionParameterAttributes(typeMethod, typeof(ActionIssueAttribute));
130+
var issuesAttributes = GetActionParameterAttributes(method, typeof(ActionIssueAttribute));
135131
if (issuesAttributes != null)
136132
{
137133
foreach (var issueAttribute in issuesAttributes)
@@ -151,26 +147,25 @@ public static List<ActionInfo> LoadFrom(Assembly assembly)
151147
}
152148

153149
// order by action name
154-
actions.Sort((x, y) => string.CompareOrdinal(x.FullName, y.FullName));
150+
actions.Sort((x, y) => string.CompareOrdinal(x.Name, y.Name));
155151
return actions;
156152
}
157153

158154
/// <summary>
159-
/// Get action provider attribute
155+
/// Test for function type
160156
/// </summary>
161-
/// <param name="type">Action member type</param>
162-
private static ActionProviderAttribute GetProviderAttribute(MemberInfo type)
157+
/// <param name="type">Type to test</param>
158+
private static bool IsFunctionType(Type type)
163159
{
164-
var providerAttributeName = typeof(ActionProviderAttribute).FullName;
165-
foreach (var typeAttribute in type.GetCustomAttributes())
160+
while (type != null)
166161
{
167-
// provider attribute type
168-
if (string.Equals(providerAttributeName, typeAttribute.GetType().FullName))
162+
if (type == typeof(Function.Function))
169163
{
170-
return typeAttribute as ActionProviderAttribute;
164+
return true;
171165
}
166+
type = type.BaseType;
172167
}
173-
return null;
168+
return false;
174169
}
175170

176171
/// <summary>
Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
//#define CACHE_LOG
33

44
using System;
5-
using System.Collections.Generic;
65
using System.Linq;
76
using System.Text.Json;
7+
using System.Collections.Generic;
88
using PayrollEngine.Client.Scripting.Function;
99

10-
namespace PayrollEngine.Client.Scripting.Cache;
10+
namespace PayrollEngine.Client.Scripting;
1111

1212

1313
/// <summary>Result cache cycle</summary>
@@ -24,13 +24,13 @@ public enum ResultCacheCycle
2424
public abstract class ConsolidatedResultCacheBase
2525
{
2626
/// <summary>The caching start date</summary>
27-
public DateTime CycleStartDate { get; }
27+
private DateTime CycleStartDate { get; }
2828

2929
/// <summary>The result cache cycle</summary>
30-
public ResultCacheCycle CacheCycle { get; }
30+
private ResultCacheCycle CacheCycle { get; }
3131

3232
/// <summary>The payrun job status</summary>
33-
public PayrunJobStatus? JobStatus { get; }
33+
protected PayrunJobStatus? JobStatus { get; }
3434

3535
/// <summary>Cache constructor</summary>
3636
/// <param name="cycleStartDate">The cycle start date</param>
@@ -81,19 +81,11 @@ protected List<DateTime> GetConsolidatedPeriodStarts(PayrunFunction function, Co
8181
return null;
8282
}
8383

84-
// job status
84+
// mismatching job status
8585
if (query.JobStatus != JobStatus)
8686
{
87-
if (!query.JobStatus.HasValue || !JobStatus.HasValue)
88-
{
89-
// mismatching job status
90-
return null;
91-
}
92-
// test matching job status by bit mask, duplicated in backend database stored procedure GetConsolidatedXxxResults
93-
if ((query.JobStatus.Value & JobStatus.Value) != query.JobStatus.Value)
94-
{
95-
return null;
96-
}
87+
function.LogWarning($"Mismatching cache query job status: {query.JobStatus} vs {JobStatus}");
88+
return null;
9789
}
9890

9991
// periods: duplicated in backend domain scripting type PayrunRuntime
@@ -113,7 +105,7 @@ protected List<DateTime> GetConsolidatedPeriodStarts(PayrunFunction function, Co
113105
}
114106

115107
// order periods from newest to oldest
116-
return [..periodStarts.OrderByDescending(x => x)];
108+
return [.. periodStarts.OrderByDescending(x => x)];
117109
}
118110

119111
// Duplicated in backend payroll repository command
@@ -352,7 +344,7 @@ private bool PrepareResultCache(PayrunFunction function, string runtimeKey = nul
352344
var cacheStartDate = GetCacheStartDate(function);
353345
// initialize cache
354346
var query = new WageTypeConsolidatedResultQuery(new List<decimal>(),
355-
cacheStartDate, PayrunJobStatus.Legal);
347+
cacheStartDate, JobStatus);
356348
ConsolidatedResults = function.GetConsolidatedWageTypeResults(query);
357349

358350
#if CACHE_LOG

Client.Scripting/CaseObject.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ public static string GetNamespace(this MemberInfo member) =>
2929

3030
/// <summary>Get case field name</summary>
3131
/// <param name="property">Property</param>
32-
public static string GetCaseFieldName(this PropertyInfo property) =>
33-
GetNamespace(property) + property.Name;
32+
public static string GetCaseFieldName(this PropertyInfo property) =>
33+
property.GetNamespace() + property.Name;
3434
}
3535

3636
/// <summary>Case object</summary>

0 commit comments

Comments
 (0)