Skip to content

Commit 0ab174f

Browse files
author
Jani Giannoudis
committed
updated nugets
updated to version 0.8.0-beta.2
1 parent c15556a commit 0ab174f

26 files changed

+496
-488
lines changed

Client.Scripting/Cache/Cache.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ protected List<DateTime> GetConsolidatedPeriodStarts(PayrunFunction function, Co
113113
}
114114

115115
// order periods from newest to oldest
116-
return new(periodStarts.OrderByDescending(x => x));
116+
return [..periodStarts.OrderByDescending(x => x)];
117117
}
118118

119119
// Duplicated in backend payroll repository command

Client.Scripting/CasePayrollValue.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ namespace PayrollEngine.Client.Scripting;
1414
/// <summary>Dictionary of case value grouped by date period</summary>
1515
public class PeriodCasePayrollValueDictionary : Dictionary<DatePeriod, CasePayrollValue>, IEnumerable<PeriodValue>
1616
{
17-
private readonly List<PeriodValue> periodValues = new();
17+
private readonly List<PeriodValue> periodValues = [];
1818

1919
/// <inheritdoc />
2020
public PeriodCasePayrollValueDictionary(IDictionary<DatePeriod, CasePayrollValue> values) :
@@ -33,7 +33,7 @@ IEnumerator<PeriodValue> IEnumerable<PeriodValue>.GetEnumerator() =>
3333
/// <summary>Dictionary of multiple case values grouped by case field name</summary>
3434
public class CasePayrollValueDictionary : Dictionary<string, CasePayrollValue>, IEnumerable<PeriodValue>
3535
{
36-
private readonly List<PeriodValue> periodValues = new();
36+
private readonly List<PeriodValue> periodValues = [];
3737

3838
/// <inheritdoc />
3939
public CasePayrollValueDictionary(IDictionary<string, CasePayrollValue> values) :
@@ -428,6 +428,7 @@ private static PayrollValue AddToResult(PayrollValue result, PayrollValue value)
428428
/// <summary>Returns an enumerator that iterates through the collection</summary>
429429
/// <returns>An enumerator that can be used to iterate through the collection</returns>
430430
public IEnumerator<PeriodValue> GetEnumerator() =>
431+
// ReSharper disable once NotDisposedResourceIsReturned
431432
PeriodValues.GetEnumerator();
432433

433434
IEnumerator IEnumerable.GetEnumerator() =>

Client.Scripting/ClientScript.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public enum LogLevel
9090
Fatal
9191
}
9292

93-
/// <summary>The type of a case</summary>
93+
/// <summary>The case type</summary>
9494
public enum CaseType
9595
{
9696
/// <summary>Global case</summary>

Client.Scripting/Date.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public static class Date
4545
public static DateTime YearStart(int year) =>
4646
new(year, 1, 1, 0, 0, 0, DateTimeKind.Utc);
4747

48-
/// <summary>Get the year end date in UTC</summary>
48+
/// <summary>Get the year-end date in UTC</summary>
4949
public static DateTime YearEnd(int year) =>
5050
YearStart(year).AddYears(1).AddTicks(-1);
5151

Client.Scripting/DatePeriod.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ public DatePeriod(DateTime? start, DateTime? end)
113113
[JsonIgnore]
114114
public bool IsWithinDay => Start.IsSameDay(End);
115115

116-
/// <summary>Test if the period is within a hour</summary>
116+
/// <summary>Test if the period is within an hour</summary>
117117
[JsonIgnore]
118118
public bool IsWithinHour => Start.IsSameHour(End);
119119

Client.Scripting/Extensions.cs

Lines changed: 32 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,7 @@ public static string GetLocalization(this string culture, Dictionary<string, str
9494
return defaultValue;
9595
}
9696
var baseCulture = culture.Substring(0, index);
97-
if (localizations.TryGetValue(baseCulture, out var baseLocalization))
98-
{
99-
return baseLocalization;
100-
}
101-
return defaultValue;
97+
return localizations.GetValueOrDefault(baseCulture, defaultValue);
10298
}
10399

104100
#endregion
@@ -393,11 +389,11 @@ public static T ObjectValueJson<T>(this string json, string objectKey, T default
393389
}
394390

395391
var dictionary = ConvertJson<Dictionary<string, object>>(json);
396-
if (!dictionary.ContainsKey(objectKey))
392+
if (!dictionary.TryGetValue(objectKey, out var value))
397393
{
398394
return defaultValue;
399395
}
400-
var value = dictionary[objectKey];
396+
401397
if (value == null)
402398
{
403399
return defaultValue;
@@ -688,9 +684,9 @@ public static string ToUtcString(this DateTime dateTime) =>
688684
public static string ToUtcString(this DateTime dateTime, IFormatProvider provider) =>
689685
dateTime.ToUtcTime().ToString("o", provider);
690686

691-
/// <summary>Round to hour, if it is the last tick from a hour</summary>
687+
/// <summary>Round to hour, if it is the last tick from an hour</summary>
692688
/// <param name="dateTime">The source date time</param>
693-
/// <returns>Date of the next hour if the input is on the last tick on a hour, else the original value</returns>
689+
/// <returns>Date of the next hour if the input is on the last tick on an hour, else the original value</returns>
694690
public static DateTime RoundTickToHour(this DateTime dateTime)
695691
{
696692
if (dateTime >= Date.MaxValue)
@@ -708,7 +704,7 @@ public static DateTime RoundTickToHour(this DateTime dateTime)
708704
public static DateTime YearStart(this DateTime yearMoment) =>
709705
Date.YearStart(yearMoment.Year);
710706

711-
/// <summary>Get the year end date in UTC</summary>
707+
/// <summary>Get the year-end date in UTC</summary>
712708
/// <param name="yearMoment">The year moment</param>
713709
/// <returns>Last moment of the year</returns>
714710
public static DateTime YearEnd(this DateTime yearMoment) =>
@@ -896,14 +892,14 @@ public static DateTime FirstDayOfWeek(int year, int weekOfYear, CultureInfo cult
896892
return firstWeekDay.AddDays(weekOfYear * 7);
897893
}
898894

899-
/// <summary>Get week end date by ISO 8601 week number of the year</summary>
895+
/// <summary>Get weekend date by ISO 8601 week number of the year</summary>
900896
/// <param name="year">The year</param>
901897
/// <param name="weekOfYear">The ISO 8601 week number of the year</param>
902898
/// <returns>Last day of the week</returns>
903899
public static DateTime LastDayOfWeek(int year, int weekOfYear) =>
904900
LastDayOfWeek(year, weekOfYear, CultureInfo.CurrentCulture);
905901

906-
/// <summary>Get week end date by ISO 8601 week number of the year</summary>
902+
/// <summary>Get weekend date by ISO 8601 week number of the year</summary>
907903
/// <param name="year">The year</param>
908904
/// <param name="weekOfYear">The ISO 8601 week number of the year</param>
909905
/// <param name="culture">The calendar culture</param>
@@ -982,13 +978,13 @@ public static bool IsSameHour(this DateTime date, DateTime compare) =>
982978
date.IsSameDay(compare) && date.Hour == compare.Hour;
983979

984980
/// <summary>Calculates the current age, counting the completed years</summary>
985-
/// <param name="birthDate">The birth date</param>
981+
/// <param name="birthDate">The birthdate</param>
986982
/// <returns>The current age</returns>
987983
public static int Age(this DateTime birthDate) =>
988984
Age(birthDate, DateTime.UtcNow);
989985

990986
/// <summary>Calculates the age at a specific moment, counting the completed years</summary>
991-
/// <param name="birthDate">The birth date</param>
987+
/// <param name="birthDate">The birthdate</param>
992988
/// <param name="testMoment">The test moment</param>
993989
/// <returns>The age at the test moment</returns>
994990
public static int Age(this DateTime birthDate, DateTime testMoment)
@@ -1199,11 +1195,11 @@ public static class DictionaryExtensions
11991195
/// <returns>The dictionary value</returns>
12001196
public static object GetValue(this Dictionary<string, object> dictionary, string key, object defaultValue = default)
12011197
{
1202-
if (!dictionary.ContainsKey(key))
1198+
if (!dictionary.TryGetValue(key, out var value))
12031199
{
12041200
return defaultValue;
12051201
}
1206-
var value = dictionary[key];
1202+
12071203
if (value is JsonElement jsonElement)
12081204
{
12091205
value = jsonElement.GetValue();
@@ -1714,7 +1710,7 @@ public static TimeSpan TotalDuration(this IEnumerable<CaseValue> periodValues) =
17141710
/// <param name="intersectPeriod">The period to intersect</param>
17151711
/// <returns>List of intersecting date periods</returns>
17161712
public static List<CaseValue> Intersections(this IEnumerable<CaseValue> periodValues, DatePeriod intersectPeriod) =>
1717-
new(periodValues.Where(periodValue => periodValue.Period().IsOverlapping(intersectPeriod)));
1713+
[..periodValues.Where(periodValue => periodValue.Period().IsOverlapping(intersectPeriod))];
17181714

17191715
/// <summary>Get case period values matching a period predicate</summary>
17201716
/// <param name="periodValues">The time periods to test</param>
@@ -1906,7 +1902,7 @@ public static IEnumerable<TimeSpan> GetDurations(this IEnumerable<PeriodValue> v
19061902

19071903
/// <summary>Summarize the total duration from all date period durations</summary>
19081904
/// <param name="values">The period payroll values</param>
1909-
/// <returns>Total duration from all periods,, an empty time span on empty collection</returns>
1905+
/// <returns>Total duration from all periods, an empty time span on empty collection</returns>
19101906
public static TimeSpan TotalDuration(this IEnumerable<PeriodValue> values) =>
19111907
// summarize from all durations the time span ticks
19121908
values != null ? new(GetDurations(values).Sum(ts => ts.Ticks)) : TimeSpan.Zero;
@@ -2061,7 +2057,7 @@ public static List<decimal> Values(this IEnumerable<WageTypeCustomResult> result
20612057

20622058
/// <summary>Get summary of wage type custom results</summary>
20632059
/// <param name="results">The wage type custom results</param>
2064-
/// <returns>Wage type results result values summary</returns>
2060+
/// <returns>Wage type result values summary</returns>
20652061
public static decimal Sum(this IEnumerable<WageTypeCustomResult> results) =>
20662062
Values(results).Sum();
20672063
}
@@ -2095,7 +2091,7 @@ valueType is ValueType.Date or
20952091
public static bool IsNumber(this ValueType valueType) =>
20962092
IsInteger(valueType) || IsDecimal(valueType);
20972093

2098-
/// <summary>Test if value type is a integer</summary>
2094+
/// <summary>Test if value type is an integer</summary>
20992095
/// <param name="valueType">The value type</param>
21002096
/// <returns>True for integer value types</returns>
21012097
public static bool IsInteger(this ValueType valueType) =>
@@ -2299,21 +2295,24 @@ public static CasePayrollValueDictionary TupleToCaseValuesDictionary(this Dictio
22992295
/// <param name="values">The tuple values</param>
23002296
/// <returns>The collector results</returns>
23012297
public static List<CollectorResult> TupleToCollectorResults(this List<Tuple<string, Tuple<DateTime, DateTime>, decimal, List<string>, Dictionary<string, object>>> values) =>
2302-
new(values.Select(x => new CollectorResult
2298+
[
2299+
..values.Select(x => new CollectorResult
23032300
{
23042301
CollectorName = x.Item1,
23052302
Start = x.Item2.Item1,
23062303
End = x.Item2.Item2,
23072304
Value = x.Item3,
23082305
Tags = x.Item4,
23092306
Attributes = x.Item5
2310-
}));
2307+
})
2308+
];
23112309

23122310
/// <summary>Convert tuple values to a collector custom result</summary>
23132311
/// <param name="values">The tuple values</param>
23142312
/// <returns>The collector custom results</returns>
23152313
public static List<CollectorCustomResult> TupleToCollectorCustomResults(this List<Tuple<string, string, Tuple<DateTime, DateTime>, decimal, List<string>, Dictionary<string, object>>> values) =>
2316-
new(values.Select(x => new CollectorCustomResult
2314+
[
2315+
..values.Select(x => new CollectorCustomResult
23172316
{
23182317
CollectorName = x.Item1,
23192318
Source = x.Item2,
@@ -2322,13 +2321,15 @@ public static List<CollectorCustomResult> TupleToCollectorCustomResults(this Lis
23222321
Value = x.Item4,
23232322
Tags = x.Item5,
23242323
Attributes = x.Item6
2325-
}));
2324+
})
2325+
];
23262326

23272327
/// <summary>Convert tuple values to a wage type result</summary>
23282328
/// <param name="values">The tuple values</param>
23292329
/// <returns>The wage type results</returns>
23302330
public static List<WageTypeResult> TupleToWageTypeResults(this List<Tuple<decimal, string, Tuple<DateTime, DateTime>, decimal, List<string>, Dictionary<string, object>>> values) =>
2331-
new(values.Select(x => new WageTypeResult
2331+
[
2332+
..values.Select(x => new WageTypeResult
23322333
{
23332334
WageTypeNumber = x.Item1,
23342335
WageTypeName = x.Item2,
@@ -2337,13 +2338,15 @@ public static List<WageTypeResult> TupleToWageTypeResults(this List<Tuple<decima
23372338
Value = x.Item4,
23382339
Tags = x.Item5,
23392340
Attributes = x.Item6
2340-
}));
2341+
})
2342+
];
23412343

23422344
/// <summary>Convert tuple values to a wage type custom result</summary>
23432345
/// <param name="values">The tuple values</param>
23442346
/// <returns>The wage type custom results</returns>
23452347
public static List<WageTypeCustomResult> TupleToWageTypeCustomResults(this List<Tuple<decimal, string, string, Tuple<DateTime, DateTime>, decimal, List<string>, Dictionary<string, object>>> values) =>
2346-
new(values.Select(x => new WageTypeCustomResult
2348+
[
2349+
..values.Select(x => new WageTypeCustomResult
23472350
{
23482351
WageTypeNumber = x.Item1,
23492352
Name = x.Item2,
@@ -2353,5 +2356,6 @@ public static List<WageTypeCustomResult> TupleToWageTypeCustomResults(this List<
23532356
Value = x.Item5,
23542357
Tags = x.Item6,
23552358
Attributes = x.Item7
2356-
}));
2359+
})
2360+
];
23572361
}

Client.Scripting/Function/CaseAction.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ public abstract class ActionMethodBase<TContext, TFunc, TValue> : IActionMethod<
381381
public DateTime CaseValueDate { get; }
382382

383383
/// <summary>The method parameters</summary>
384-
public List<string> Parameters { get; } = new();
384+
public List<string> Parameters { get; } = [];
385385

386386
/// <summary>Test for method parameters</summary>
387387
public bool HasParameters => Parameters.Count > 0;
@@ -426,11 +426,11 @@ protected void RegisterFunction(string name, ActionValueType valueType, Func<TVa
426426

427427
private Tuple<ActionValueType, Func<TValue, object>> GetValueFunction()
428428
{
429-
if (!valueFunctions.ContainsKey(Name))
429+
if (!valueFunctions.TryGetValue(Name, out var function))
430430
{
431431
throw new ScriptException($"Missing action function {Name}");
432432
}
433-
return valueFunctions[Name];
433+
return function;
434434
}
435435

436436
#endregion
@@ -1773,12 +1773,12 @@ protected object GetObjectValue(string lookupValue, string objectKey)
17731773
}
17741774

17751775
var dictionary = JsonSerializer.Deserialize<Dictionary<string, object>>(lookupValue);
1776-
if (dictionary == null || !dictionary.ContainsKey(objectKey))
1776+
if (dictionary == null || !dictionary.TryGetValue(objectKey, out var value))
17771777
{
17781778
Context.Function.LogError($"Invalid lookup object key: {objectKey}");
17791779
return null;
17801780
}
1781-
return dictionary[objectKey];
1781+
return value;
17821782
}
17831783
}
17841784

0 commit comments

Comments
 (0)