diff --git a/.gitignore b/.gitignore index 809f06a76..ed8c08844 100644 --- a/.gitignore +++ b/.gitignore @@ -58,3 +58,5 @@ $tf/pendingchanges.tfb $tf/properties.tf1 project.lock.json **/.vs/ + +.claude/ \ No newline at end of file diff --git a/Sources/.editorconfig b/Sources/.editorconfig index 1bae2e959..d1110ea7e 100644 --- a/Sources/.editorconfig +++ b/Sources/.editorconfig @@ -50,4 +50,4 @@ csharp_new_line_before_catch = true csharp_new_line_before_finally = true csharp_indent_case_contents = true csharp_indent_switch_labels = true -csharp_preserve_single_line_statements = false \ No newline at end of file +csharp_preserve_single_line_statements = false diff --git a/Sources/Core/Directory.Build.props b/Sources/Core/Directory.Build.props index 15f391280..fa8e33c0e 100644 --- a/Sources/Core/Directory.Build.props +++ b/Sources/Core/Directory.Build.props @@ -3,15 +3,5 @@ - - - all - runtime; build; native; contentfiles; analyzers - - - - - $(EnlistmentRoot)\Sources\Microsoft.StreamProcessing.ruleset - diff --git a/Sources/Core/Microsoft.StreamProcessing.Provider/Microsoft.StreamProcessing.Provider.csproj b/Sources/Core/Microsoft.StreamProcessing.Provider/Microsoft.StreamProcessing.Provider.csproj index 1d9de4e69..00948d43b 100644 --- a/Sources/Core/Microsoft.StreamProcessing.Provider/Microsoft.StreamProcessing.Provider.csproj +++ b/Sources/Core/Microsoft.StreamProcessing.Provider/Microsoft.StreamProcessing.Provider.csproj @@ -1,7 +1,7 @@  - netstandard2.0 + net10.0 x64;AnyCPU @@ -11,19 +11,7 @@ - - - - - - - - - - - - - + diff --git a/Sources/Core/Microsoft.StreamProcessing/Aggregates/AggregateFunctions.cs b/Sources/Core/Microsoft.StreamProcessing/Aggregates/AggregateFunctions.cs index dcc3e31f0..9073f7692 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Aggregates/AggregateFunctions.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Aggregates/AggregateFunctions.cs @@ -48,8 +48,8 @@ public static IAggregate Wrap aggregate, Expression> transform) { - Contract.Requires(aggregate != null); - Contract.Requires(transform != null); + ArgumentNullException.ThrowIfNull(aggregate); + ArgumentNullException.ThrowIfNull(transform); return aggregate.TransformInput(transform); } @@ -62,8 +62,8 @@ public static IAggregate Wrap aggregate, Expression> transform) where TAggregateInput : struct { - Contract.Requires(aggregate != null); - Contract.Requires(transform != null); + ArgumentNullException.ThrowIfNull(aggregate); + ArgumentNullException.ThrowIfNull(transform); return aggregate.MakeInputNullableAndSkipNulls().TransformInput(transform); } @@ -71,8 +71,8 @@ internal static IAggregate TransformInput aggregate, Expression> transform) { - Contract.Requires(aggregate != null); - Contract.Requires(transform != null); + ArgumentNullException.ThrowIfNull(aggregate); + ArgumentNullException.ThrowIfNull(transform); return GeneratedAggregate.Create( initialState: aggregate.InitialState(), @@ -86,19 +86,19 @@ private static Expression> TransformInput3> func, Expression> transform) { - Contract.Requires(func != null); - Contract.Requires(transform != null); + ArgumentNullException.ThrowIfNull(func); + ArgumentNullException.ThrowIfNull(transform); var result = func.ReplaceParametersInBody(func.Parameters[0], func.Parameters[1], transform.Body); var transformParam = transform.Parameters[0]; - return Expression.Lambda>(result, new[] { func.Parameters[0], func.Parameters[1], transformParam }); + return Expression.Lambda>(result, [func.Parameters[0], func.Parameters[1], transformParam]); } internal static IAggregate TransformOutput( this IAggregate aggregate, Expression> transform) { - Contract.Requires(aggregate != null); - Contract.Requires(transform != null); + ArgumentNullException.ThrowIfNull(aggregate); + ArgumentNullException.ThrowIfNull(transform); return GeneratedAggregate.Create( initialState: aggregate.InitialState(), @@ -112,8 +112,8 @@ private static Expression> TransformOutput> func, Expression> transform) { - Contract.Requires(func != null); - Contract.Requires(transform != null); + ArgumentNullException.ThrowIfNull(func); + ArgumentNullException.ThrowIfNull(transform); var result = transform.ReplaceParametersInBody(func.Body); return Expression.Lambda>(result, func.Parameters); } @@ -127,7 +127,7 @@ public static IAggregate ApplyFilter aggregate, Expression> filter) { - Contract.Requires(aggregate != null); + ArgumentNullException.ThrowIfNull(aggregate); if (filter == null || filter.Body.ExpressionEquals(Expression.Constant(true))) return aggregate; Expression> newAccumulate = (oldState, timestamp, input) => @@ -151,7 +151,7 @@ public static IAggregate ApplyFilter MakeInputNullableAndSkipNulls( this IAggregate aggregate) where TInput : struct { - Contract.Requires(aggregate != null); + ArgumentNullException.ThrowIfNull(aggregate); Expression> newAccumulate = (oldState, timestamp, input) => input.HasValue ? CallInliner.Call(aggregate.Accumulate(), oldState, timestamp, input.Value) : oldState; @@ -175,9 +175,9 @@ public static IAggregate ApplyFilter SkipNulls( this IAggregate aggregate) { - Contract.Requires(aggregate != null); + ArgumentNullException.ThrowIfNull(aggregate); - var inputType = typeof(TInput).GetTypeInfo(); + var inputType = typeof(TInput); return inputType.IsClass ? GeneratedAggregate.Create( initialState: aggregate.InitialState(), @@ -229,7 +229,7 @@ private static Expression> AddSkipNullValueLo public static IAggregate, TResult?> MakeOutputNullableAndOutputNullWhenEmpty( this IAggregate aggregate) where TResult : struct { - Contract.Requires(aggregate != null); + ArgumentNullException.ThrowIfNull(aggregate); Expression>> newInitialState = () => new NullOutputWrapper @@ -279,7 +279,7 @@ private static Expression> AddSkipNullValueLo public static IAggregate, TResult> OutputDefaultWhenEmpty( this IAggregate aggregate) { - Contract.Requires(aggregate != null); + ArgumentNullException.ThrowIfNull(aggregate); Expression>> newInitialState = () => new NullOutputWrapper diff --git a/Sources/Core/Microsoft.StreamProcessing/Aggregates/AggregateFunctionsTemplate.cs b/Sources/Core/Microsoft.StreamProcessing/Aggregates/AggregateFunctionsTemplate.cs index e6435694f..74a7ee508 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Aggregates/AggregateFunctionsTemplate.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Aggregates/AggregateFunctionsTemplate.cs @@ -30,8 +30,8 @@ public static IAggregate, TResult> Combine aggregate1, Expression> merger) { - Contract.Requires(aggregate1 != null); - Contract.Requires(merger != null); + ArgumentNullException.ThrowIfNull(aggregate1); + ArgumentNullException.ThrowIfNull(merger); var duplicate = new bool[1]; Expression, TState1>> target1 = state => state.Item1; @@ -93,9 +93,9 @@ public static IAggregate, TResult> Combine IAggregate aggregate2, Expression> merger) { - Contract.Requires(aggregate1 != null); - Contract.Requires(aggregate2 != null); - Contract.Requires(merger != null); + ArgumentNullException.ThrowIfNull(aggregate1); + ArgumentNullException.ThrowIfNull(aggregate2); + ArgumentNullException.ThrowIfNull(merger); var duplicate = new bool[2]; Expression, TState1>> target1 = state => state.Item1; @@ -171,10 +171,10 @@ public static IAggregate, TResult IAggregate aggregate3, Expression> merger) { - Contract.Requires(aggregate1 != null); - Contract.Requires(aggregate2 != null); - Contract.Requires(aggregate3 != null); - Contract.Requires(merger != null); + ArgumentNullException.ThrowIfNull(aggregate1); + ArgumentNullException.ThrowIfNull(aggregate2); + ArgumentNullException.ThrowIfNull(aggregate3); + ArgumentNullException.ThrowIfNull(merger); var duplicate = new bool[3]; Expression, TState1>> target1 = state => state.Item1; @@ -268,11 +268,11 @@ public static IAggregate IAggregate aggregate4, Expression> merger) { - Contract.Requires(aggregate1 != null); - Contract.Requires(aggregate2 != null); - Contract.Requires(aggregate3 != null); - Contract.Requires(aggregate4 != null); - Contract.Requires(merger != null); + ArgumentNullException.ThrowIfNull(aggregate1); + ArgumentNullException.ThrowIfNull(aggregate2); + ArgumentNullException.ThrowIfNull(aggregate3); + ArgumentNullException.ThrowIfNull(aggregate4); + ArgumentNullException.ThrowIfNull(merger); var duplicate = new bool[4]; Expression, TState1>> target1 = state => state.Item1; @@ -388,12 +388,12 @@ public static IAggregate aggregate5, Expression> merger) { - Contract.Requires(aggregate1 != null); - Contract.Requires(aggregate2 != null); - Contract.Requires(aggregate3 != null); - Contract.Requires(aggregate4 != null); - Contract.Requires(aggregate5 != null); - Contract.Requires(merger != null); + ArgumentNullException.ThrowIfNull(aggregate1); + ArgumentNullException.ThrowIfNull(aggregate2); + ArgumentNullException.ThrowIfNull(aggregate3); + ArgumentNullException.ThrowIfNull(aggregate4); + ArgumentNullException.ThrowIfNull(aggregate5); + ArgumentNullException.ThrowIfNull(merger); var duplicate = new bool[5]; Expression, TState1>> target1 = state => state.Item1; @@ -535,13 +535,13 @@ public static IAggregate aggregate6, Expression> merger) { - Contract.Requires(aggregate1 != null); - Contract.Requires(aggregate2 != null); - Contract.Requires(aggregate3 != null); - Contract.Requires(aggregate4 != null); - Contract.Requires(aggregate5 != null); - Contract.Requires(aggregate6 != null); - Contract.Requires(merger != null); + ArgumentNullException.ThrowIfNull(aggregate1); + ArgumentNullException.ThrowIfNull(aggregate2); + ArgumentNullException.ThrowIfNull(aggregate3); + ArgumentNullException.ThrowIfNull(aggregate4); + ArgumentNullException.ThrowIfNull(aggregate5); + ArgumentNullException.ThrowIfNull(aggregate6); + ArgumentNullException.ThrowIfNull(merger); var duplicate = new bool[6]; Expression, TState1>> target1 = state => state.Item1; @@ -713,14 +713,14 @@ public static IAggregate aggregate7, Expression> merger) { - Contract.Requires(aggregate1 != null); - Contract.Requires(aggregate2 != null); - Contract.Requires(aggregate3 != null); - Contract.Requires(aggregate4 != null); - Contract.Requires(aggregate5 != null); - Contract.Requires(aggregate6 != null); - Contract.Requires(aggregate7 != null); - Contract.Requires(merger != null); + ArgumentNullException.ThrowIfNull(aggregate1); + ArgumentNullException.ThrowIfNull(aggregate2); + ArgumentNullException.ThrowIfNull(aggregate3); + ArgumentNullException.ThrowIfNull(aggregate4); + ArgumentNullException.ThrowIfNull(aggregate5); + ArgumentNullException.ThrowIfNull(aggregate6); + ArgumentNullException.ThrowIfNull(aggregate7); + ArgumentNullException.ThrowIfNull(merger); var duplicate = new bool[7]; Expression, TState1>> target1 = state => state.Item1; @@ -926,15 +926,15 @@ public static IAggregate aggregate8, Expression> merger) { - Contract.Requires(aggregate1 != null); - Contract.Requires(aggregate2 != null); - Contract.Requires(aggregate3 != null); - Contract.Requires(aggregate4 != null); - Contract.Requires(aggregate5 != null); - Contract.Requires(aggregate6 != null); - Contract.Requires(aggregate7 != null); - Contract.Requires(aggregate8 != null); - Contract.Requires(merger != null); + ArgumentNullException.ThrowIfNull(aggregate1); + ArgumentNullException.ThrowIfNull(aggregate2); + ArgumentNullException.ThrowIfNull(aggregate3); + ArgumentNullException.ThrowIfNull(aggregate4); + ArgumentNullException.ThrowIfNull(aggregate5); + ArgumentNullException.ThrowIfNull(aggregate6); + ArgumentNullException.ThrowIfNull(aggregate7); + ArgumentNullException.ThrowIfNull(aggregate8); + ArgumentNullException.ThrowIfNull(merger); var duplicate = new bool[8]; Expression, TState1>> target1 = state => state.Item1; @@ -1178,16 +1178,16 @@ public static IAggregate aggregate9, Expression> merger) { - Contract.Requires(aggregate1 != null); - Contract.Requires(aggregate2 != null); - Contract.Requires(aggregate3 != null); - Contract.Requires(aggregate4 != null); - Contract.Requires(aggregate5 != null); - Contract.Requires(aggregate6 != null); - Contract.Requires(aggregate7 != null); - Contract.Requires(aggregate8 != null); - Contract.Requires(aggregate9 != null); - Contract.Requires(merger != null); + ArgumentNullException.ThrowIfNull(aggregate1); + ArgumentNullException.ThrowIfNull(aggregate2); + ArgumentNullException.ThrowIfNull(aggregate3); + ArgumentNullException.ThrowIfNull(aggregate4); + ArgumentNullException.ThrowIfNull(aggregate5); + ArgumentNullException.ThrowIfNull(aggregate6); + ArgumentNullException.ThrowIfNull(aggregate7); + ArgumentNullException.ThrowIfNull(aggregate8); + ArgumentNullException.ThrowIfNull(aggregate9); + ArgumentNullException.ThrowIfNull(merger); var duplicate = new bool[9]; Expression, TState1>> target1 = state => state.Item1; @@ -1473,17 +1473,17 @@ public static IAggregate aggregate10, Expression> merger) { - Contract.Requires(aggregate1 != null); - Contract.Requires(aggregate2 != null); - Contract.Requires(aggregate3 != null); - Contract.Requires(aggregate4 != null); - Contract.Requires(aggregate5 != null); - Contract.Requires(aggregate6 != null); - Contract.Requires(aggregate7 != null); - Contract.Requires(aggregate8 != null); - Contract.Requires(aggregate9 != null); - Contract.Requires(aggregate10 != null); - Contract.Requires(merger != null); + ArgumentNullException.ThrowIfNull(aggregate1); + ArgumentNullException.ThrowIfNull(aggregate2); + ArgumentNullException.ThrowIfNull(aggregate3); + ArgumentNullException.ThrowIfNull(aggregate4); + ArgumentNullException.ThrowIfNull(aggregate5); + ArgumentNullException.ThrowIfNull(aggregate6); + ArgumentNullException.ThrowIfNull(aggregate7); + ArgumentNullException.ThrowIfNull(aggregate8); + ArgumentNullException.ThrowIfNull(aggregate9); + ArgumentNullException.ThrowIfNull(aggregate10); + ArgumentNullException.ThrowIfNull(merger); var duplicate = new bool[10]; Expression, TState1>> target1 = state => state.Item1; @@ -1815,18 +1815,18 @@ public static IAggregate aggregate11, Expression> merger) { - Contract.Requires(aggregate1 != null); - Contract.Requires(aggregate2 != null); - Contract.Requires(aggregate3 != null); - Contract.Requires(aggregate4 != null); - Contract.Requires(aggregate5 != null); - Contract.Requires(aggregate6 != null); - Contract.Requires(aggregate7 != null); - Contract.Requires(aggregate8 != null); - Contract.Requires(aggregate9 != null); - Contract.Requires(aggregate10 != null); - Contract.Requires(aggregate11 != null); - Contract.Requires(merger != null); + ArgumentNullException.ThrowIfNull(aggregate1); + ArgumentNullException.ThrowIfNull(aggregate2); + ArgumentNullException.ThrowIfNull(aggregate3); + ArgumentNullException.ThrowIfNull(aggregate4); + ArgumentNullException.ThrowIfNull(aggregate5); + ArgumentNullException.ThrowIfNull(aggregate6); + ArgumentNullException.ThrowIfNull(aggregate7); + ArgumentNullException.ThrowIfNull(aggregate8); + ArgumentNullException.ThrowIfNull(aggregate9); + ArgumentNullException.ThrowIfNull(aggregate10); + ArgumentNullException.ThrowIfNull(aggregate11); + ArgumentNullException.ThrowIfNull(merger); var duplicate = new bool[11]; Expression, TState1>> target1 = state => state.Item1; @@ -2208,19 +2208,19 @@ public static IAggregate aggregate12, Expression> merger) { - Contract.Requires(aggregate1 != null); - Contract.Requires(aggregate2 != null); - Contract.Requires(aggregate3 != null); - Contract.Requires(aggregate4 != null); - Contract.Requires(aggregate5 != null); - Contract.Requires(aggregate6 != null); - Contract.Requires(aggregate7 != null); - Contract.Requires(aggregate8 != null); - Contract.Requires(aggregate9 != null); - Contract.Requires(aggregate10 != null); - Contract.Requires(aggregate11 != null); - Contract.Requires(aggregate12 != null); - Contract.Requires(merger != null); + ArgumentNullException.ThrowIfNull(aggregate1); + ArgumentNullException.ThrowIfNull(aggregate2); + ArgumentNullException.ThrowIfNull(aggregate3); + ArgumentNullException.ThrowIfNull(aggregate4); + ArgumentNullException.ThrowIfNull(aggregate5); + ArgumentNullException.ThrowIfNull(aggregate6); + ArgumentNullException.ThrowIfNull(aggregate7); + ArgumentNullException.ThrowIfNull(aggregate8); + ArgumentNullException.ThrowIfNull(aggregate9); + ArgumentNullException.ThrowIfNull(aggregate10); + ArgumentNullException.ThrowIfNull(aggregate11); + ArgumentNullException.ThrowIfNull(aggregate12); + ArgumentNullException.ThrowIfNull(merger); var duplicate = new bool[12]; Expression, TState1>> target1 = state => state.Item1; @@ -2656,20 +2656,20 @@ public static IAggregate aggregate13, Expression> merger) { - Contract.Requires(aggregate1 != null); - Contract.Requires(aggregate2 != null); - Contract.Requires(aggregate3 != null); - Contract.Requires(aggregate4 != null); - Contract.Requires(aggregate5 != null); - Contract.Requires(aggregate6 != null); - Contract.Requires(aggregate7 != null); - Contract.Requires(aggregate8 != null); - Contract.Requires(aggregate9 != null); - Contract.Requires(aggregate10 != null); - Contract.Requires(aggregate11 != null); - Contract.Requires(aggregate12 != null); - Contract.Requires(aggregate13 != null); - Contract.Requires(merger != null); + ArgumentNullException.ThrowIfNull(aggregate1); + ArgumentNullException.ThrowIfNull(aggregate2); + ArgumentNullException.ThrowIfNull(aggregate3); + ArgumentNullException.ThrowIfNull(aggregate4); + ArgumentNullException.ThrowIfNull(aggregate5); + ArgumentNullException.ThrowIfNull(aggregate6); + ArgumentNullException.ThrowIfNull(aggregate7); + ArgumentNullException.ThrowIfNull(aggregate8); + ArgumentNullException.ThrowIfNull(aggregate9); + ArgumentNullException.ThrowIfNull(aggregate10); + ArgumentNullException.ThrowIfNull(aggregate11); + ArgumentNullException.ThrowIfNull(aggregate12); + ArgumentNullException.ThrowIfNull(aggregate13); + ArgumentNullException.ThrowIfNull(merger); var duplicate = new bool[13]; Expression, TState1>> target1 = state => state.Item1; @@ -3163,21 +3163,21 @@ public static IAggregate aggregate14, Expression> merger) { - Contract.Requires(aggregate1 != null); - Contract.Requires(aggregate2 != null); - Contract.Requires(aggregate3 != null); - Contract.Requires(aggregate4 != null); - Contract.Requires(aggregate5 != null); - Contract.Requires(aggregate6 != null); - Contract.Requires(aggregate7 != null); - Contract.Requires(aggregate8 != null); - Contract.Requires(aggregate9 != null); - Contract.Requires(aggregate10 != null); - Contract.Requires(aggregate11 != null); - Contract.Requires(aggregate12 != null); - Contract.Requires(aggregate13 != null); - Contract.Requires(aggregate14 != null); - Contract.Requires(merger != null); + ArgumentNullException.ThrowIfNull(aggregate1); + ArgumentNullException.ThrowIfNull(aggregate2); + ArgumentNullException.ThrowIfNull(aggregate3); + ArgumentNullException.ThrowIfNull(aggregate4); + ArgumentNullException.ThrowIfNull(aggregate5); + ArgumentNullException.ThrowIfNull(aggregate6); + ArgumentNullException.ThrowIfNull(aggregate7); + ArgumentNullException.ThrowIfNull(aggregate8); + ArgumentNullException.ThrowIfNull(aggregate9); + ArgumentNullException.ThrowIfNull(aggregate10); + ArgumentNullException.ThrowIfNull(aggregate11); + ArgumentNullException.ThrowIfNull(aggregate12); + ArgumentNullException.ThrowIfNull(aggregate13); + ArgumentNullException.ThrowIfNull(aggregate14); + ArgumentNullException.ThrowIfNull(merger); var duplicate = new bool[14]; Expression, TState1>> target1 = state => state.Item1; @@ -3733,22 +3733,22 @@ public static IAggregate aggregate15, Expression> merger) { - Contract.Requires(aggregate1 != null); - Contract.Requires(aggregate2 != null); - Contract.Requires(aggregate3 != null); - Contract.Requires(aggregate4 != null); - Contract.Requires(aggregate5 != null); - Contract.Requires(aggregate6 != null); - Contract.Requires(aggregate7 != null); - Contract.Requires(aggregate8 != null); - Contract.Requires(aggregate9 != null); - Contract.Requires(aggregate10 != null); - Contract.Requires(aggregate11 != null); - Contract.Requires(aggregate12 != null); - Contract.Requires(aggregate13 != null); - Contract.Requires(aggregate14 != null); - Contract.Requires(aggregate15 != null); - Contract.Requires(merger != null); + ArgumentNullException.ThrowIfNull(aggregate1); + ArgumentNullException.ThrowIfNull(aggregate2); + ArgumentNullException.ThrowIfNull(aggregate3); + ArgumentNullException.ThrowIfNull(aggregate4); + ArgumentNullException.ThrowIfNull(aggregate5); + ArgumentNullException.ThrowIfNull(aggregate6); + ArgumentNullException.ThrowIfNull(aggregate7); + ArgumentNullException.ThrowIfNull(aggregate8); + ArgumentNullException.ThrowIfNull(aggregate9); + ArgumentNullException.ThrowIfNull(aggregate10); + ArgumentNullException.ThrowIfNull(aggregate11); + ArgumentNullException.ThrowIfNull(aggregate12); + ArgumentNullException.ThrowIfNull(aggregate13); + ArgumentNullException.ThrowIfNull(aggregate14); + ArgumentNullException.ThrowIfNull(aggregate15); + ArgumentNullException.ThrowIfNull(merger); var duplicate = new bool[15]; Expression, TState1>> target1 = state => state.Item1; diff --git a/Sources/Core/Microsoft.StreamProcessing/Aggregates/AggregateFunctionsTemplate.tt b/Sources/Core/Microsoft.StreamProcessing/Aggregates/AggregateFunctionsTemplate.tt index 4e9d03d82..1770cb83e 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Aggregates/AggregateFunctionsTemplate.tt +++ b/Sources/Core/Microsoft.StreamProcessing/Aggregates/AggregateFunctionsTemplate.tt @@ -35,8 +35,8 @@ namespace Microsoft.StreamProcessing.Aggregates <#= IterateCommaLine(" IAggregate aggregate$", count) #>, Expression, TResult>> merger) { -<#= IterateLine(" Contract.Requires(aggregate$ != null);", count) #> - Contract.Requires(merger != null); +<#= IterateLine(" ArgumentNullException.ThrowIfNull(aggregate$);", count) #> + ArgumentNullException.ThrowIfNull(merger); var duplicate = new bool[<#= count #>]; <# for (int i = 1; i <= count; i++) { #> diff --git a/Sources/Core/Microsoft.StreamProcessing/Aggregates/CountAggregate.cs b/Sources/Core/Microsoft.StreamProcessing/Aggregates/CountAggregate.cs index db3e0ab86..d4ab16d42 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Aggregates/CountAggregate.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Aggregates/CountAggregate.cs @@ -21,7 +21,7 @@ internal sealed class CountAggregate : ISummableAggregate> diff = (leftCount, rightCount) => leftCount - rightCount; public Expression> Difference() => diff; - private static readonly Expression> sum = (leftCount, rightCount) => leftCount - rightCount; + private static readonly Expression> sum = (leftCount, rightCount) => leftCount + rightCount; public Expression> Sum() => sum; private static readonly Expression> res = count => count; diff --git a/Sources/Core/Microsoft.StreamProcessing/Aggregates/GeneratedAggregate.cs b/Sources/Core/Microsoft.StreamProcessing/Aggregates/GeneratedAggregate.cs index 2c85abddc..ad890db45 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Aggregates/GeneratedAggregate.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Aggregates/GeneratedAggregate.cs @@ -17,7 +17,7 @@ public static GeneratedAggregate Create> deaccumulate, Expression> difference, Expression> computeResult) - => new GeneratedAggregate(initialState, accumulate, deaccumulate, difference, computeResult); + => new(initialState, accumulate, deaccumulate, difference, computeResult); } internal class GeneratedAggregate : IAggregate @@ -39,11 +39,11 @@ public GeneratedAggregate( Expression> difference, Expression> computeResult) { - Contract.Requires(initialState != null); - Contract.Requires(accumulate != null); - Contract.Requires(deaccumulate != null); - Contract.Requires(difference != null); - Contract.Requires(computeResult != null); + ArgumentNullException.ThrowIfNull(initialState); + ArgumentNullException.ThrowIfNull(accumulate); + ArgumentNullException.ThrowIfNull(deaccumulate); + ArgumentNullException.ThrowIfNull(difference); + ArgumentNullException.ThrowIfNull(computeResult); this.initialState = initialState; this.accumulate = accumulate; this.deaccumulate = deaccumulate; diff --git a/Sources/Core/Microsoft.StreamProcessing/Aggregates/MinMaxAggregate.cs b/Sources/Core/Microsoft.StreamProcessing/Aggregates/MinMaxAggregate.cs index 0b8a7c037..0177d4a3b 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Aggregates/MinMaxAggregate.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Aggregates/MinMaxAggregate.cs @@ -16,7 +16,7 @@ protected MinMaxAggregateBase(QueryContainer container) : this(ComparerExpressio protected MinMaxAggregateBase(IComparerExpression comparer, QueryContainer container) { - Contract.Requires(comparer != null); + ArgumentNullException.ThrowIfNull(comparer); var generator = comparer.CreateSortedDictionaryGenerator(container); Expression>, MinMaxState>> template @@ -26,7 +26,7 @@ Expression>, MinMaxState>> template } private readonly Expression>> initialState; - public Expression>> InitialState() => initialState; + public Expression>> InitialState() => this.initialState; private static readonly Expression, long, T, MinMaxState>> acc = (set, timestamp, input) => new MinMaxState { savedValues = set.savedValues.Add(input) }; diff --git a/Sources/Core/Microsoft.StreamProcessing/Aggregates/PercentileContinuous.cs b/Sources/Core/Microsoft.StreamProcessing/Aggregates/PercentileContinuous.cs index c92063a7f..f4703205d 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Aggregates/PercentileContinuous.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Aggregates/PercentileContinuous.cs @@ -18,12 +18,12 @@ public PercentileContinuousDoubleAggregate(double percentile, QueryContainer con public PercentileContinuousDoubleAggregate(double percentile, IComparerExpression rankComparer, QueryContainer container) : base(rankComparer, container) { - Contract.Requires(rankComparer != null); + ArgumentNullException.ThrowIfNull(rankComparer); Contract.Requires(percentile >= 0.0 && percentile <= 1.0); this.percentile = percentile; } - public override Expression, double>> ComputeResult() => set => CalculatePercentile(set); + public override Expression, double>> ComputeResult() => set => this.CalculatePercentile(set); public double CalculatePercentile(SortedMultiSet set) { diff --git a/Sources/Core/Microsoft.StreamProcessing/Aggregates/PercentileDiscrete.cs b/Sources/Core/Microsoft.StreamProcessing/Aggregates/PercentileDiscrete.cs index 2cd3d8771..0e99e6a86 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Aggregates/PercentileDiscrete.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Aggregates/PercentileDiscrete.cs @@ -18,12 +18,12 @@ public PercentileDiscreteDoubleAggregate(double percentile, QueryContainer conta public PercentileDiscreteDoubleAggregate(double percentile, IComparerExpression rankComparer, QueryContainer container) : base(rankComparer, container) { - Contract.Requires(rankComparer != null); + ArgumentNullException.ThrowIfNull(rankComparer); Contract.Requires(percentile >= 0.0 && percentile <= 1.0); this.percentile = percentile; } - public override Expression, double>> ComputeResult() => set => CalculatePercentile(set); + public override Expression, double>> ComputeResult() => set => this.CalculatePercentile(set); public double CalculatePercentile(SortedMultiSet set) { diff --git a/Sources/Core/Microsoft.StreamProcessing/Aggregates/SlidingMaxAggregate.cs b/Sources/Core/Microsoft.StreamProcessing/Aggregates/SlidingMaxAggregate.cs index fe31f2630..519484698 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Aggregates/SlidingMaxAggregate.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Aggregates/SlidingMaxAggregate.cs @@ -19,7 +19,7 @@ public SlidingMaxAggregate(QueryContainer container) : this(ComparerExpression comparer, QueryContainer container) { - Contract.Requires(comparer != null); + ArgumentNullException.ThrowIfNull(comparer); this.comparer = comparer.GetCompareExpr().Compile(); var generator = comparer.CreateSortedDictionaryGenerator(container); @@ -30,10 +30,10 @@ Expression>, MinMaxState>> template } private readonly Expression>> initialState; - public Expression>> InitialState() => initialState; + public Expression>> InitialState() => this.initialState; public Expression, long, T, MinMaxState>> Accumulate() - => (state, timestamp, input) => Accumulate(state, timestamp, input); + => (state, timestamp, input) => this.Accumulate(state, timestamp, input); private MinMaxState Accumulate(MinMaxState state, long timestamp, T input) { @@ -75,7 +75,7 @@ private static MinMaxState Difference(MinMaxState leftSet, MinMaxState return leftSet; } - public Expression, T>> ComputeResult() => state => ComputeResult(state); + public Expression, T>> ComputeResult() => state => this.ComputeResult(state); private T ComputeResult(MinMaxState state) { diff --git a/Sources/Core/Microsoft.StreamProcessing/Aggregates/SlidingMinAggregate.cs b/Sources/Core/Microsoft.StreamProcessing/Aggregates/SlidingMinAggregate.cs index 9ad193bec..5e6e203bd 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Aggregates/SlidingMinAggregate.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Aggregates/SlidingMinAggregate.cs @@ -19,7 +19,7 @@ public SlidingMinAggregate(QueryContainer container) : this(ComparerExpression comparer, QueryContainer container) { - Contract.Requires(comparer != null); + ArgumentNullException.ThrowIfNull(comparer); this.comparer = comparer.GetCompareExpr().Compile(); var generator = comparer.CreateSortedDictionaryGenerator(container); @@ -30,10 +30,10 @@ Expression>, MinMaxState>> template } private readonly Expression>> initialState; - public Expression>> InitialState() => initialState; + public Expression>> InitialState() => this.initialState; public Expression, long, T, MinMaxState>> Accumulate() - => (state, timestamp, input) => Accumulate(state, timestamp, input); + => (state, timestamp, input) => this.Accumulate(state, timestamp, input); private MinMaxState Accumulate(MinMaxState state, long timestamp, T input) { @@ -75,7 +75,7 @@ private static MinMaxState Difference(MinMaxState leftSet, MinMaxState return leftSet; } - public Expression, T>> ComputeResult() => state => ComputeResult(state); + public Expression, T>> ComputeResult() => state => this.ComputeResult(state); private T ComputeResult(MinMaxState state) { diff --git a/Sources/Core/Microsoft.StreamProcessing/Aggregates/SortedMultisetAggregateBase.cs b/Sources/Core/Microsoft.StreamProcessing/Aggregates/SortedMultisetAggregateBase.cs index 645f9f226..17dc5c772 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Aggregates/SortedMultisetAggregateBase.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Aggregates/SortedMultisetAggregateBase.cs @@ -17,11 +17,11 @@ protected SortedMultisetAggregateBase(IComparerExpression comparer, QueryCont Expression>, SortedMultiSet>> template = (g) => new SortedMultiSet(g); var replaced = template.ReplaceParametersInBody(generator); - initialState = Expression.Lambda>>(replaced); + this.initialState = Expression.Lambda>>(replaced); } private readonly Expression>> initialState; - public Expression>> InitialState() => initialState; + public Expression>> InitialState() => this.initialState; private static readonly Expression, long, T, SortedMultiSet>> acc = (set, timestamp, input) => set.Add(input); diff --git a/Sources/Core/Microsoft.StreamProcessing/Aggregates/TopKAggregate.cs b/Sources/Core/Microsoft.StreamProcessing/Aggregates/TopKAggregate.cs index 15ebdacff..c9ff82461 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Aggregates/TopKAggregate.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Aggregates/TopKAggregate.cs @@ -22,8 +22,8 @@ public TopKAggregate(int k, IComparerExpression rankComparer, QueryContainer public TopKAggregate(int k, IComparerExpression rankComparer, IComparerExpression overallComparer, QueryContainer container) : base(ThenOrderBy(Reverse(rankComparer), overallComparer), container) { - Contract.Requires(rankComparer != null); - Contract.Requires(overallComparer != null); + ArgumentNullException.ThrowIfNull(rankComparer); + ArgumentNullException.ThrowIfNull(overallComparer); Contract.Requires(k > 0); this.compiledRankComparer = Reverse(rankComparer).GetCompareExpr().Compile(); this.k = k; @@ -31,7 +31,7 @@ public TopKAggregate(int k, IComparerExpression rankComparer, IComparerExpres private static IComparerExpression Reverse(IComparerExpression comparer) { - Contract.Requires(comparer != null); + ArgumentNullException.ThrowIfNull(comparer); var expression = comparer.GetCompareExpr(); Expression> template = (left, right) => CallInliner.Call(expression, right, left); var reversedExpression = template.InlineCalls(); @@ -40,8 +40,8 @@ private static IComparerExpression Reverse(IComparerExpression comparer) private static IComparerExpression ThenOrderBy(IComparerExpression comparer1, IComparerExpression comparer2) { - Contract.Requires(comparer1 != null); - Contract.Requires(comparer2 != null); + ArgumentNullException.ThrowIfNull(comparer1); + ArgumentNullException.ThrowIfNull(comparer2); var primary = comparer1.GetCompareExpr(); var secondary = comparer2.GetCompareExpr(); Expression> template = @@ -53,7 +53,7 @@ private static IComparerExpression ThenOrderBy(IComparerExpression compare return new ComparerExpression(newExpression); } - public override Expression, List>>> ComputeResult() => set => GetTopK(set); + public override Expression, List>>> ComputeResult() => set => this.GetTopK(set); private List> GetTopK(SortedMultiSet set) { diff --git a/Sources/Core/Microsoft.StreamProcessing/Aggregates/TumblingMaxAggregate.cs b/Sources/Core/Microsoft.StreamProcessing/Aggregates/TumblingMaxAggregate.cs index f53686fa5..a76600c71 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Aggregates/TumblingMaxAggregate.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Aggregates/TumblingMaxAggregate.cs @@ -19,7 +19,7 @@ public TumblingMaxAggregate() : this(ComparerExpression.Default) { } public TumblingMaxAggregate(IComparerExpression comparer) { - Contract.Requires(comparer != null); + ArgumentNullException.ThrowIfNull(comparer); var stateExpression = Expression.Parameter(typeof(MinMaxState), "state"); var timestampExpression = Expression.Parameter(typeof(long), "timestamp"); @@ -32,7 +32,7 @@ public TumblingMaxAggregate(IComparerExpression comparer) var comparerExpression = comparer.GetCompareExpr().ReplaceParametersInBody( inputExpression, currentValue.ReplaceParametersInBody(stateExpression)); - var typeInfo = typeof(MinMaxState).GetTypeInfo(); + var minMaxStateType = typeof(MinMaxState); this.accumulate = Expression.Lambda, long, T, MinMaxState>>( Expression.Condition( Expression.OrElse( @@ -40,8 +40,8 @@ public TumblingMaxAggregate(IComparerExpression comparer) Expression.GreaterThan(comparerExpression, Expression.Constant(0))), Expression.MemberInit( (NewExpression)constructor.Body, - Expression.Bind(typeInfo.GetField("currentTimestamp"), timestampExpression), - Expression.Bind(typeInfo.GetField("currentValue"), inputExpression)), + Expression.Bind(minMaxStateType.GetField("currentTimestamp"), timestampExpression), + Expression.Bind(minMaxStateType.GetField("currentValue"), inputExpression)), stateExpression), stateExpression, timestampExpression, diff --git a/Sources/Core/Microsoft.StreamProcessing/Aggregates/TumblingMinAggregate.cs b/Sources/Core/Microsoft.StreamProcessing/Aggregates/TumblingMinAggregate.cs index 2427e3e86..7e83e473d 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Aggregates/TumblingMinAggregate.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Aggregates/TumblingMinAggregate.cs @@ -19,7 +19,7 @@ public TumblingMinAggregate() : this(ComparerExpression.Default) { } public TumblingMinAggregate(IComparerExpression comparer) { - Contract.Requires(comparer != null); + ArgumentNullException.ThrowIfNull(comparer); var stateExpression = Expression.Parameter(typeof(MinMaxState), "state"); var timestampExpression = Expression.Parameter(typeof(long), "timestamp"); @@ -32,7 +32,7 @@ public TumblingMinAggregate(IComparerExpression comparer) var comparerExpression = comparer.GetCompareExpr().ReplaceParametersInBody( inputExpression, currentValue.ReplaceParametersInBody(stateExpression)); - var typeInfo = typeof(MinMaxState).GetTypeInfo(); + var minMaxStateType = typeof(MinMaxState); this.accumulate = Expression.Lambda, long, T, MinMaxState>>( Expression.Condition( Expression.OrElse( @@ -40,8 +40,8 @@ public TumblingMinAggregate(IComparerExpression comparer) Expression.LessThan(comparerExpression, Expression.Constant(0))), Expression.MemberInit( (NewExpression)constructor.Body, - Expression.Bind(typeInfo.GetField("currentTimestamp"), timestampExpression), - Expression.Bind(typeInfo.GetField("currentValue"), inputExpression)), + Expression.Bind(minMaxStateType.GetField("currentTimestamp"), timestampExpression), + Expression.Bind(minMaxStateType.GetField("currentValue"), inputExpression)), stateExpression), stateExpression, timestampExpression, diff --git a/Sources/Core/Microsoft.StreamProcessing/CacheUtilities/StreamableIO.cs b/Sources/Core/Microsoft.StreamProcessing/CacheUtilities/StreamableIO.cs index c30e42081..b3ed00143 100644 --- a/Sources/Core/Microsoft.StreamProcessing/CacheUtilities/StreamableIO.cs +++ b/Sources/Core/Microsoft.StreamProcessing/CacheUtilities/StreamableIO.cs @@ -149,27 +149,19 @@ private static void InferProperties( } } - internal sealed class QueuedMessageObservable : IObservable>> + internal sealed class QueuedMessageObservable( + IStreamable stream + ) : IObservable>> { - private readonly IStreamable streamable; - - public QueuedMessageObservable(IStreamable stream) => this.streamable = stream; - public IDisposable Subscribe(IObserver>> observer) - => this.streamable.Subscribe(new QueuedMessageObserver(observer)); + => stream.Subscribe(new QueuedMessageObserver(observer)); } - internal sealed class QueuedMessageObserver : IStreamObserver, IDisposable + internal sealed class QueuedMessageObserver( + IObserver>> observer + ) : IStreamObserver, IDisposable { - private readonly IObserver>> observer; - - public QueuedMessageObserver(IObserver>> observer) - { - this.observer = observer; - this.ClassId = Guid.NewGuid(); - } - - public Guid ClassId { get; } + public Guid ClassId { get; } = Guid.NewGuid(); public int CurrentlyBufferedOutputCount => 0; @@ -177,10 +169,10 @@ public QueuedMessageObserver(IObserver throw new NotImplementedException(); - public void OnCompleted() => this.observer.OnCompleted(); + public void OnCompleted() => observer.OnCompleted(); public void OnError(Exception error) => throw error; - public void OnFlush() => this.observer.OnNext(new QueuedMessage> { Kind = MessageKind.Flush }); - public void OnNext(StreamMessage value) => this.observer.OnNext(new QueuedMessage> { Kind = MessageKind.DataBatch, Message = value }); + public void OnFlush() => observer.OnNext(new() { Kind = MessageKind.Flush }); + public void OnNext(StreamMessage value) => observer.OnNext(new() { Kind = MessageKind.DataBatch, Message = value }); public void ProduceQueryPlan(PlanNode previous) { } public void Reset() { } public void Restore(Stream stream) { } diff --git a/Sources/Core/Microsoft.StreamProcessing/Collections/CircularBuffer.cs b/Sources/Core/Microsoft.StreamProcessing/Collections/CircularBuffer.cs index 3df34156c..77e8d5a49 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Collections/CircularBuffer.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Collections/CircularBuffer.cs @@ -134,7 +134,7 @@ public IEnumerable Iterate() [EditorBrowsable(EditorBrowsableState.Never)] public sealed class ElasticCircularBuffer : IEnumerable { - private readonly LinkedList> buffers = new LinkedList>(); + private readonly LinkedList> buffers = new(); private LinkedListNode> head; private LinkedListNode> tail; @@ -144,7 +144,7 @@ public sealed class ElasticCircularBuffer : IEnumerable [EditorBrowsable(EditorBrowsableState.Never)] public ElasticCircularBuffer() { - var node = new LinkedListNode>(new CircularBuffer()); + var node = new LinkedListNode>(new()); this.buffers.AddFirst(node); this.tail = this.head = node; this.Count = 0; @@ -164,7 +164,7 @@ public void Enqueue(ref T value) if (next == null) next = this.buffers.First; if (!next.Value.IsEmpty()) { - next = new LinkedListNode>(new CircularBuffer()); + next = new LinkedListNode>(new()); this.buffers.AddAfter(this.tail, next); } @@ -180,7 +180,7 @@ public void Enqueue(ref T value) /// /// [EditorBrowsable(EditorBrowsableState.Never)] - public void Add(T value) => Enqueue(ref value); + public void Add(T value) => this.Enqueue(ref value); /// /// Currently for internal use only - do not use directly. @@ -260,6 +260,6 @@ public IEnumerator GetEnumerator() } } - System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() => GetEnumerator(); + System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() => this.GetEnumerator(); } } diff --git a/Sources/Core/Microsoft.StreamProcessing/Collections/ColumnBatch.cs b/Sources/Core/Microsoft.StreamProcessing/Collections/ColumnBatch.cs index 77c3fdfd5..4f2bf77f4 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Collections/ColumnBatch.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Collections/ColumnBatch.cs @@ -2,6 +2,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License // ********************************************************************* +using System; using System.ComponentModel; using System.Runtime.CompilerServices; using System.Runtime.Serialization; @@ -22,7 +23,7 @@ public sealed class ColumnBatch /// Used to make sure this class is thread-safe when it makes decisions /// about the reference count. (See . /// - private readonly object columnBatchLock = new object(); + private readonly Lock columnBatchLock = new(); /// /// Currently for internal use only - do not use directly. @@ -61,7 +62,7 @@ internal ColumnBatch(ColumnPool pool, int size) [MethodImpl(MethodImplOptions.AggressiveInlining)] internal void IncrementRefCount(int cnt) { - lock (this.columnBatchLock) + using (this.columnBatchLock.EnterScope()) { Interlocked.Add(ref this.RefCount, cnt); } @@ -76,7 +77,7 @@ internal void IncrementRefCount(int cnt) [EditorBrowsable(EditorBrowsableState.Never)] public ColumnBatch MakeWritable(ColumnPool pool) { - lock (this.columnBatchLock) + using (this.columnBatchLock.EnterScope()) { if (this.RefCount == 1) { @@ -85,7 +86,7 @@ public ColumnBatch MakeWritable(ColumnPool pool) else { pool.Get(out var result); - System.Array.Copy(this.col, result.col, this.col.Length); + this.col.AsSpan().CopyTo(result.col); result.UsedLength = this.UsedLength; Interlocked.Decrement(ref this.RefCount); return result; @@ -96,14 +97,16 @@ public ColumnBatch MakeWritable(ColumnPool pool) [MethodImpl(MethodImplOptions.AggressiveInlining)] internal void Return() { - lock (this.columnBatchLock) + using (this.columnBatchLock.EnterScope()) { int localRefCount = Interlocked.Decrement(ref this.RefCount); if (localRefCount == 0) { if (Config.ClearColumnsOnReturn) - System.Array.Clear(this.col, 0, this.col.Length); + { + this.col.AsSpan().Clear(); + } if ((this.pool != null) && (!Config.DisableMemoryPooling)) { this.UsedLength = 0; @@ -116,14 +119,14 @@ internal void Return() [MethodImpl(MethodImplOptions.AggressiveInlining)] internal void ReturnClear() { - lock (this.columnBatchLock) + using (this.columnBatchLock.EnterScope()) { int localRefCount = Interlocked.Decrement(ref this.RefCount); if (localRefCount == 0) { - System.Array.Clear(this.col, 0, this.col.Length); - if ((this.pool != null) && (!Config.DisableMemoryPooling)) + this.col.AsSpan().Clear(); + if (this.pool != null && !Config.DisableMemoryPooling) { this.UsedLength = 0; this.pool.Return(this); diff --git a/Sources/Core/Microsoft.StreamProcessing/Collections/ColumnPool.cs b/Sources/Core/Microsoft.StreamProcessing/Collections/ColumnPool.cs index 9d46f8b13..fbc30183f 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Collections/ColumnPool.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Collections/ColumnPool.cs @@ -53,7 +53,7 @@ public abstract class ColumnPoolBase [EditorBrowsable(EditorBrowsableState.Never)] public class ColumnPool : ColumnPoolBase { - private readonly ConcurrentQueue> queue = new ConcurrentQueue>(); + private readonly ConcurrentQueue> queue = new(); private long createdObjects; private readonly int size; @@ -96,14 +96,14 @@ public bool Get(out ColumnBatch result) [EditorBrowsable(EditorBrowsableState.Never)] public override string GetStatusReport() => string.Format(CultureInfo.InvariantCulture, "[{0}] Objects Created - {1,5} - Queue Size - {2,5}\t{3}", - !SomethingIsWrong() ? " " : "X", this.createdObjects, this.queue.Count, typeof(T).GetCSharpSourceSyntax()); + !this.SomethingIsWrong() ? " " : "X", this.createdObjects, this.queue.Count, typeof(T).GetCSharpSourceSyntax()); /// /// Currently for internal use only - do not use directly. /// [EditorBrowsable(EditorBrowsableState.Never)] public override ColumnPoolBase Leaked - => ((!Config.DisableMemoryPooling) && SomethingIsWrong()) ? this : null; + => ((!Config.DisableMemoryPooling) && this.SomethingIsWrong()) ? this : null; private bool SomethingIsWrong() => (this.createdObjects != this.queue.Count) || this.queue.Any(cb => cb.RefCount != 0); diff --git a/Sources/Core/Microsoft.StreamProcessing/Collections/DataStructurePool.cs b/Sources/Core/Microsoft.StreamProcessing/Collections/DataStructurePool.cs index 59d53890b..9129a26f1 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Collections/DataStructurePool.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Collections/DataStructurePool.cs @@ -5,6 +5,7 @@ using System; using System.Collections.Concurrent; using System.ComponentModel; +using System.Linq; using System.Runtime.CompilerServices; namespace Microsoft.StreamProcessing.Internal.Collections @@ -14,30 +15,17 @@ namespace Microsoft.StreamProcessing.Internal.Collections /// /// [EditorBrowsable(EditorBrowsableState.Never)] - public sealed class DataStructurePool : IDisposable where T : new() + public sealed class DataStructurePool(Func creator) : IDisposable where T : new() { - private readonly ConcurrentQueue queue; - private readonly Func creator; + private readonly ConcurrentQueue queue = []; /// /// Currently for internal use only - do not use directly. /// [EditorBrowsable(EditorBrowsableState.Never)] public DataStructurePool() - { - this.queue = new ConcurrentQueue(); - this.creator = () => new T(); - } - - /// - /// Currently for internal use only - do not use directly. - /// - /// - [EditorBrowsable(EditorBrowsableState.Never)] - public DataStructurePool(Func creator) - { - this.queue = new ConcurrentQueue(); - this.creator = creator; + : this(static () => new()) + { } /// @@ -59,7 +47,7 @@ public void Return(T item) [EditorBrowsable(EditorBrowsableState.Never)] public void Get(out T result) { - if (!this.queue.TryDequeue(out result)) result = this.creator(); + if (!this.queue.TryDequeue(out result)) result = creator(); } /// @@ -68,9 +56,9 @@ public void Get(out T result) [EditorBrowsable(EditorBrowsableState.Never)] public void Dispose() { - foreach (var q in this.queue) + foreach (var q in this.queue.OfType()) { - if (q is IDisposable d) d.Dispose(); + q.Dispose(); } } } diff --git a/Sources/Core/Microsoft.StreamProcessing/Collections/DoublingArrayPool.cs b/Sources/Core/Microsoft.StreamProcessing/Collections/DoublingArrayPool.cs index 12075781b..fe0003d21 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Collections/DoublingArrayPool.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Collections/DoublingArrayPool.cs @@ -33,11 +33,11 @@ public void Return(T[] item) this.pool[pos].Enqueue(item); } - private static readonly int[] MultiplyDeBruijnBitPosition2 = new int[32] - { + private static readonly int[] MultiplyDeBruijnBitPosition2 = + [ 0, 1, 28, 2, 29, 14, 24, 3, 30, 22, 20, 15, 25, 17, 4, 8, 31, 27, 13, 23, 21, 19, 16, 7, 26, 12, 18, 6, 11, 5, 10, 9 - }; + ]; [MethodImpl(MethodImplOptions.AggressiveInlining)] private static bool IsPowerOfTwo(long x) => (x > 0) && ((x & (x - 1)) == 0); @@ -93,9 +93,8 @@ public override void Free(bool reset = false) { if (queue != null) { - while (queue.TryDequeue(out T[] result)) + while (queue.TryDequeue(out _)) { - result = null; Interlocked.Decrement(ref this.createdObjects); } } diff --git a/Sources/Core/Microsoft.StreamProcessing/Collections/EndPointHeap.cs b/Sources/Core/Microsoft.StreamProcessing/Collections/EndPointHeap.cs index 76aed4d20..91749d8a6 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Collections/EndPointHeap.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Collections/EndPointHeap.cs @@ -64,7 +64,7 @@ public int Capacity public unsafe void Insert(long time, int value) { // If out of space in the stack, then grow. - if (this.count == this.capacity) Grow(); + if (this.count == this.capacity) this.Grow(); fixed (long* timeArray = this.times) fixed (int* valueArray = this.values) @@ -129,7 +129,7 @@ public bool TryGetNext(out long time, out int value) // Return top element and remove top. time = this.times[0]; value = this.values[0]; - RemoveTop(); + this.RemoveTop(); return true; } @@ -147,7 +147,7 @@ public bool TryGetNextInclusive(long maxTime, out long time, out int value) // Return top element and remove top. time = this.times[0]; value = this.values[0]; - RemoveTop(); + this.RemoveTop(); return true; } @@ -165,7 +165,7 @@ public bool TryGetNextExclusive(long maxTime, out long time, out int value) // Return top element and remove top. time = this.times[0]; value = this.values[0]; - RemoveTop(); + this.RemoveTop(); return true; } diff --git a/Sources/Core/Microsoft.StreamProcessing/Collections/EndPointQueue.cs b/Sources/Core/Microsoft.StreamProcessing/Collections/EndPointQueue.cs index a07a254af..290bc99e7 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Collections/EndPointQueue.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Collections/EndPointQueue.cs @@ -79,7 +79,7 @@ public void Insert(long time, int value) // Grow the array if needed. if (newWriteIndex == this.readIndex) { - Grow(); + this.Grow(); // After growing, it is guaranteed that writeIndex + 1 does not need to wrap. insertIndex = this.writeIndex; diff --git a/Sources/Core/Microsoft.StreamProcessing/Collections/FastDictionary.cs b/Sources/Core/Microsoft.StreamProcessing/Collections/FastDictionary.cs index 23886d20c..b5d963457 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Collections/FastDictionary.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Collections/FastDictionary.cs @@ -3,6 +3,7 @@ // Licensed under the MIT License // ********************************************************************* using System; +using System.Buffers; using System.ComponentModel; using System.Runtime.CompilerServices; using System.Runtime.Serialization; @@ -17,7 +18,7 @@ namespace Microsoft.StreamProcessing.Internal.Collections /// [DataContract] [EditorBrowsable(EditorBrowsableState.Never)] - public class FastDictionary + public class FastDictionary : IDisposable { /// /// Currently for internal use only - do not use directly. @@ -50,6 +51,16 @@ public class FastDictionary [DataMember] private byte[] bitvector; + /// + /// True when was obtained from (resize path); + /// not serialized — after deserialization the array is always a normal array. + /// + [IgnoreDataMember] + private bool bitvectorFromPool; + + [IgnoreDataMember] + private bool disposed; + /// /// Currently for internal use only - do not use directly. /// @@ -69,7 +80,7 @@ public FastDictionary(int capacity, Func equals, Func[this.Size]; - this.bitvector = new byte[1 + (this.Size >> 3)]; + this.bitvector = new byte[HashHelpers.BitvectorByteLength(this.Size)]; this.comparerEquals = equals; this.comparerGetHashCode = getHashCode; this.resizeThreshold = this.Size >> 1; @@ -141,9 +152,9 @@ public void Insert(ref int index, TKey key, TValue value) this.Count++; if (this.Count > this.resizeThreshold) { - Resize(); + this.Resize(); /* resizing may make index obsolete, hence we compute the index */ - Lookup(key, out index); + this.Lookup(key, out index); } } @@ -177,16 +188,18 @@ public bool Iterate(ref int index) public void Clear() { this.Count = 0; - Array.Clear(this.bitvector, 0, 1 + (this.Size >> 3)); + this.bitvector.AsSpan(0, HashHelpers.BitvectorByteLength(this.Size)).Clear(); if (Config.ClearColumnsOnReturn) - Array.Clear(this.entries, 0, this.entries.Length); + this.entries.AsSpan().Clear(); } private void Resize() { int newSize = HashHelpers.ExpandPrime(this.Size * 2); var newEntries = new Entry[newSize]; - byte[] newBitvector = new byte[1 + (newSize >> 3)]; + int newBvLen = HashHelpers.BitvectorByteLength(newSize); + byte[] newBitvector = ArrayPool.Shared.Rent(newBvLen); + newBitvector.AsSpan(0, newBvLen).Clear(); int index = 0; int num, newindex; @@ -208,10 +221,40 @@ private void Resize() index++; } + byte[] oldBitvector = this.bitvector; + if (this.bitvectorFromPool) + { + ArrayPool.Shared.Return(oldBitvector); + } + this.Size = newSize; this.entries = newEntries; this.bitvector = newBitvector; + this.bitvectorFromPool = true; this.resizeThreshold = this.Size >> 1; } + + /// + /// Returns pooled bitvector storage to when applicable. + /// After disposal, do not use this instance. + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public void Dispose() + { + if (this.disposed) + { + return; + } + + this.disposed = true; + + if (this.bitvectorFromPool) + { + ArrayPool.Shared.Return(this.bitvector); + this.bitvectorFromPool = false; + } + + this.bitvector = []; + } } } \ No newline at end of file diff --git a/Sources/Core/Microsoft.StreamProcessing/Collections/FastDictionary2.cs b/Sources/Core/Microsoft.StreamProcessing/Collections/FastDictionary2.cs index 7078a465b..1f700410c 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Collections/FastDictionary2.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Collections/FastDictionary2.cs @@ -80,7 +80,7 @@ public FastDictionary2(int capacity, Func equals, Func @@ -139,7 +139,7 @@ public int Insert(TKey key, TValue value) { if (this.count == this.Size) { - Resize(); + this.Resize(); index = num % this.Size; } freeList = this.count; @@ -151,7 +151,7 @@ public int Insert(TKey key, TValue value) this.entries[freeList].key = key; this.entries[freeList].value = value; this.buckets[index] = freeList; - if (this.Count > (this.Size >> 1)) Resize(); + if (this.Count > (this.Size >> 1)) this.Resize(); return freeList; } @@ -178,7 +178,7 @@ public int Insert(TKey key, TValue value, int hashCode) { if (this.count == this.Size) { - Resize(); + this.Resize(); index = num % this.Size; } freeList = this.count; @@ -190,7 +190,7 @@ public int Insert(TKey key, TValue value, int hashCode) this.entries[freeList].key = key; this.entries[freeList].value = value; this.buckets[index] = freeList; - if (this.Count > (this.Size >> 1)) Resize(); + if (this.Count > (this.Size >> 1)) this.Resize(); return freeList; } diff --git a/Sources/Core/Microsoft.StreamProcessing/Collections/FastDictionary3.cs b/Sources/Core/Microsoft.StreamProcessing/Collections/FastDictionary3.cs index 957a77b61..e4e9e0eaf 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Collections/FastDictionary3.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Collections/FastDictionary3.cs @@ -3,6 +3,7 @@ // Licensed under the MIT License // ********************************************************************* using System; +using System.Buffers; using System.ComponentModel; using System.Runtime.CompilerServices; using System.Runtime.Serialization; @@ -17,7 +18,7 @@ namespace Microsoft.StreamProcessing.Internal.Collections /// [DataContract] [EditorBrowsable(EditorBrowsableState.Never)] - public class FastDictionary3 + public class FastDictionary3 : IDisposable { /// /// Currently for internal use only - do not use directly. @@ -66,6 +67,15 @@ public class FastDictionary3 [DataMember] private byte[] dirtyBitvector; + [IgnoreDataMember] + private bool bitvectorFromPool; + + [IgnoreDataMember] + private bool dirtyBitvectorFromPool; + + [IgnoreDataMember] + private bool disposed; + /// /// Currently for internal use only - do not use directly. /// @@ -85,8 +95,9 @@ public FastDictionary3(int capacity, Func equals, Func[this.Size]; - this.bitvector = new byte[1 + (this.Size >> 3)]; - this.dirtyBitvector = new byte[1 + (this.Size >> 3)]; + int bvLen = HashHelpers.BitvectorByteLength(this.Size); + this.bitvector = new byte[bvLen]; + this.dirtyBitvector = new byte[bvLen]; this.comparerEquals = equals; this.resizeThreshold = this.Size >> 1; this.Count = 0; @@ -145,9 +156,9 @@ public void Insert(ref int index, TKey key, TValue value, int hashCode) this.Count++; if (this.Count > this.resizeThreshold) { - Resize(); + this.Resize(); /* resizing may make index obsolete, hence we compute the index */ - Lookup(key, hashCode, out index); + this.Lookup(key, hashCode, out index); } } @@ -198,7 +209,7 @@ public bool IterateDirty(ref int index) /// [MethodImpl(MethodImplOptions.AggressiveInlining)] [EditorBrowsable(EditorBrowsableState.Never)] - public void Clean() => Array.Clear(this.dirtyBitvector, 0, 1 + (this.Size >> 3)); + public void Clean() => this.dirtyBitvector.AsSpan(0, HashHelpers.BitvectorByteLength(this.Size)).Clear(); /// /// Currently for internal use only - do not use directly. @@ -225,17 +236,22 @@ public bool IterateDirty(ref int index) public void Clear() { this.Count = 0; - if (Config.ClearColumnsOnReturn) Array.Clear(this.entries, 0, this.entries.Length); - Array.Clear(this.bitvector, 0, 1 + (this.Size >> 3)); - Array.Clear(this.dirtyBitvector, 0, 1 + (this.Size >> 3)); + if (Config.ClearColumnsOnReturn) + this.entries.AsSpan().Clear(); + int bvLen = HashHelpers.BitvectorByteLength(this.Size); + this.bitvector.AsSpan(0, bvLen).Clear(); + this.dirtyBitvector.AsSpan(0, bvLen).Clear(); } private void Resize() { int newSize = HashHelpers.ExpandPrime(this.Size); var newEntries = new Entry3[newSize]; - byte[] newBitvector = new byte[1 + (newSize >> 3)]; - byte[] newDirtyBitvector = new byte[1 + (newSize >> 3)]; + int newBvLen = HashHelpers.BitvectorByteLength(newSize); + byte[] newBitvector = ArrayPool.Shared.Rent(newBvLen); + byte[] newDirtyBitvector = ArrayPool.Shared.Rent(newBvLen); + newBitvector.AsSpan(0, newBvLen).Clear(); + newDirtyBitvector.AsSpan(0, newBvLen).Clear(); int index = 0; int num, newindex; @@ -262,12 +278,54 @@ private void Resize() index++; } + if (this.bitvectorFromPool) + { + ArrayPool.Shared.Return(this.bitvector); + } + + if (this.dirtyBitvectorFromPool) + { + ArrayPool.Shared.Return(this.dirtyBitvector); + } + this.Size = newSize; this.entries = newEntries; this.bitvector = newBitvector; this.dirtyBitvector = newDirtyBitvector; + this.bitvectorFromPool = true; + this.dirtyBitvectorFromPool = true; this.resizeThreshold = this.Size >> 1; } + /// + /// Returns pooled bitvector storage to when applicable. + /// After disposal, do not use this instance. + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public void Dispose() + { + if (this.disposed) + { + return; + } + + this.disposed = true; + + if (this.bitvectorFromPool) + { + ArrayPool.Shared.Return(this.bitvector); + this.bitvectorFromPool = false; + } + + if (this.dirtyBitvectorFromPool) + { + ArrayPool.Shared.Return(this.dirtyBitvector); + this.dirtyBitvectorFromPool = false; + } + + this.bitvector = []; + this.dirtyBitvector = []; + } + } } \ No newline at end of file diff --git a/Sources/Core/Microsoft.StreamProcessing/Collections/FastLinkedList.cs b/Sources/Core/Microsoft.StreamProcessing/Collections/FastLinkedList.cs index 48be3849c..b6ae80769 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Collections/FastLinkedList.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Collections/FastLinkedList.cs @@ -114,7 +114,7 @@ public T[] Values public int Insert() { // Allocate free value to store new value. - int index = AllocateValue(); + int index = this.AllocateValue(); // Insert 'index' into bucket linked-list. this.next[index] = this.listHead; @@ -131,7 +131,7 @@ public int Insert() [EditorBrowsable(EditorBrowsableState.Never)] public int Insert(T value) { - int index = Insert(); + int index = this.Insert(); this.values[index] = value; return index; } @@ -147,7 +147,7 @@ public void Remove(int index) Contract.Assume(index > 0 && index <= this.initialized); // Remove from current list. - RemoveFromList(index); + this.RemoveFromList(index); // Insert into free list (with inverted index to denote invisible list). this.next[index] = this.freeHead; @@ -187,7 +187,7 @@ private int AllocateValue() if (this.initialized >= this.capacity) { // No free entries available, so resize. - Grow(); + this.Grow(); } this.count++; diff --git a/Sources/Core/Microsoft.StreamProcessing/Collections/FastMap.cs b/Sources/Core/Microsoft.StreamProcessing/Collections/FastMap.cs index 15f46eafc..0bcd2966d 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Collections/FastMap.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Collections/FastMap.cs @@ -148,7 +148,7 @@ public T[] Values public int Insert(int hash) { // Allocate free value to store new value. - int index = AllocateValue(); + int index = this.AllocateValue(); // Insert 'index' into bucket linked-list. int bucketPos = (hash & NotHighestBit) % this.capacity; @@ -168,7 +168,7 @@ public int Insert(int hash) [EditorBrowsable(EditorBrowsableState.Never)] public int Insert(int hash, T value) { - int index = Insert(hash); + int index = this.Insert(hash); this.values[index] = value; return index; } @@ -183,7 +183,7 @@ public int Insert(int hash, T value) public int InsertInvisible(int hash) { // Allocate free value to store new value. - int index = AllocateValue(); + int index = this.AllocateValue(); // Insert 'index' into invisible linked-list. this.hashAndNext[index] = ((long)hash << 32) | (uint)this.invisibleHead; @@ -202,7 +202,7 @@ public void MakeInvisible(int index) Contract.Assume(index > 0 && index <= this.initialized); // Remove from current list. - long hashNext = RemoveFromList(index); + long hashNext = this.RemoveFromList(index); // Insert into invisible list (with inverted index to denote invisible list). this.hashAndNext[index] = (hashNext & OnlyHashBits) | (uint)this.invisibleHead; @@ -225,7 +225,7 @@ public void Remove(int index) } // Remove from current list. - RemoveFromList(index); + this.RemoveFromList(index); // Insert into free list (with inverted index to denote invisible list). this.hashAndNext[index] = (uint)this.freeHead; @@ -276,7 +276,7 @@ public void Clear() /// [MethodImpl(MethodImplOptions.AggressiveInlining)] [EditorBrowsable(EditorBrowsableState.Never)] - public FindTraverser Find(int hash) => new FindTraverser(this, hash); + public FindTraverser Find(int hash) => new(this, hash); /// /// Currently for internal use only - do not use directly. @@ -310,7 +310,7 @@ public bool Find(int hash, ref FindTraverser ft) /// [MethodImpl(MethodImplOptions.AggressiveInlining)] [EditorBrowsable(EditorBrowsableState.Never)] - public VisibleTraverser Traverse() => new VisibleTraverser(this); + public VisibleTraverser Traverse() => new(this); /// /// Currently for internal use only - do not use directly. @@ -318,7 +318,7 @@ public bool Find(int hash, ref FindTraverser ft) /// [MethodImpl(MethodImplOptions.AggressiveInlining)] [EditorBrowsable(EditorBrowsableState.Never)] - public InvisibleTraverser TraverseInvisible() => new InvisibleTraverser(this); + public InvisibleTraverser TraverseInvisible() => new(this); [MethodImpl(MethodImplOptions.AggressiveInlining)] private int AllocateValue() @@ -336,7 +336,7 @@ private int AllocateValue() if (this.initialized >= this.capacity) { // No free entries available, so resize. - Grow(); + this.Grow(); } this.count++; @@ -682,14 +682,14 @@ public bool Next(out int index, out int hash) /// [MethodImpl(MethodImplOptions.AggressiveInlining)] [EditorBrowsable(EditorBrowsableState.Never)] - public void Remove() => this.map.Remove(this.currIndex); + public readonly void Remove() => this.map.Remove(this.currIndex); /// /// Currently for internal use only - do not use directly. /// [MethodImpl(MethodImplOptions.AggressiveInlining)] [EditorBrowsable(EditorBrowsableState.Never)] - public void MakeInvisible() => this.map.MakeInvisible(this.currIndex); + public readonly void MakeInvisible() => this.map.MakeInvisible(this.currIndex); } /// diff --git a/Sources/Core/Microsoft.StreamProcessing/Collections/FastStack.cs b/Sources/Core/Microsoft.StreamProcessing/Collections/FastStack.cs index 4c9e5a480..6a212cf5f 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Collections/FastStack.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Collections/FastStack.cs @@ -81,7 +81,7 @@ public T[] Values public int Push() { // If out of space in the stack, then grow. - if (this.count == this.capacity) Grow(); + if (this.count == this.capacity) this.Grow(); return this.count++; } diff --git a/Sources/Core/Microsoft.StreamProcessing/Collections/GlobalColumnPoolManager.cs b/Sources/Core/Microsoft.StreamProcessing/Collections/GlobalColumnPoolManager.cs index 50f65e677..7b13ef3d9 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Collections/GlobalColumnPoolManager.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Collections/GlobalColumnPoolManager.cs @@ -16,17 +16,17 @@ namespace Microsoft.StreamProcessing [EditorBrowsable(EditorBrowsableState.Never)] public static class MemoryManager { - private static readonly SafeConcurrentDictionary doublingArrayPools = new SafeConcurrentDictionary(); - private static readonly SafeConcurrentDictionary columnPools = new SafeConcurrentDictionary(); - private static readonly SafeConcurrentDictionary charArrayPools = new SafeConcurrentDictionary(); - private static readonly SafeConcurrentDictionary> bitvectorPools = new SafeConcurrentDictionary>(); - private static readonly SafeConcurrentDictionary eventBatchPools = new SafeConcurrentDictionary(); - private static readonly SafeConcurrentDictionary memoryPools = new SafeConcurrentDictionary(); + private static readonly SafeConcurrentDictionary doublingArrayPools = new(); + private static readonly SafeConcurrentDictionary columnPools = new(); + private static readonly SafeConcurrentDictionary charArrayPools = new(); + private static readonly SafeConcurrentDictionary> bitvectorPools = new(); + private static readonly SafeConcurrentDictionary eventBatchPools = new(); + private static readonly SafeConcurrentDictionary memoryPools = new(); /// /// Maps pairs TKey, TPayload to the generated memory pool type /// - private static readonly SafeConcurrentDictionary cachedMemoryPools = new SafeConcurrentDictionary(); + private static readonly SafeConcurrentDictionary cachedMemoryPools = new(); internal static DoublingArrayPool GetDoublingArrayPool() => (DoublingArrayPool)doublingArrayPools.GetOrAdd(CacheKey.Create(typeof(T)), key => new DoublingArrayPool()); @@ -85,7 +85,11 @@ public static MemoryPool GetMemoryPool(bool isCo } var lookupKey = CacheKey.Create(typeOfTKey, typeOfTPayload); - var generatedMemoryPool = cachedMemoryPools.GetOrAdd(lookupKey, key => Transformer.GenerateMemoryPoolClass()); + var generatedMemoryPool = cachedMemoryPools.GetOrAddUnlessNull(lookupKey, static key => Transformer.GenerateMemoryPoolClass()); + if (generatedMemoryPool is null) + { + return (MemoryPool)memoryPools.GetOrAdd(cacheKey, key => new MemoryPool(isColumnar)); + } return (MemoryPool)memoryPools.GetOrAdd(cacheKey, t => Activator.CreateInstance(generatedMemoryPool)); } @@ -96,29 +100,29 @@ public static MemoryPool GetMemoryPool(bool isCo [EditorBrowsable(EditorBrowsableState.Never)] public static void Free(bool reset = false) { - foreach (var kvp in doublingArrayPools) + foreach (var (_, pool) in doublingArrayPools) { - kvp.Value.Free(reset); + pool.Free(reset); } - foreach (var kvp in columnPools) + foreach (var (_, pool) in columnPools) { - kvp.Value.Free(reset); + pool.Free(reset); } - foreach (var kvp in bitvectorPools) + foreach (var (_, pool) in bitvectorPools) { - kvp.Value.Free(reset); + pool.Free(reset); } - foreach (var kvp in eventBatchPools) + foreach (var (_, pool) in eventBatchPools) { - kvp.Value.Free(reset); + pool.Free(reset); } - foreach (var kvp in charArrayPools) + foreach (var (_, pool) in charArrayPools) { - kvp.Value.Free(reset); + pool.Free(reset); } } diff --git a/Sources/Core/Microsoft.StreamProcessing/Collections/HashHelpers.cs b/Sources/Core/Microsoft.StreamProcessing/Collections/HashHelpers.cs index 9630bc1c1..b7b54f3e4 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Collections/HashHelpers.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Collections/HashHelpers.cs @@ -4,6 +4,7 @@ // ********************************************************************* using System; using System.ComponentModel; +using System.Runtime.CompilerServices; using System.Runtime.Serialization; namespace Microsoft.StreamProcessing.Internal.Collections @@ -91,14 +92,21 @@ public struct Entry3 internal static class HashHelpers { - public static readonly int[] primes = new int[] - { + /// + /// Byte length of the occupancy bitvector for a table with slots + /// (one bit per slot; see FastDictionary / FastDictionary3). + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int BitvectorByteLength(int primeSize) => 1 + (primeSize >> 3); + + public static readonly int[] primes = + [ 3, 7, 11, 0x11, 0x17, 0x1d, 0x25, 0x2f, 0x3b, 0x47, 0x59, 0x6b, 0x83, 0xa3, 0xc5, 0xef, 0x125, 0x161, 0x1af, 0x209, 0x277, 0x2f9, 0x397, 0x44f, 0x52f, 0x63d, 0x78b, 0x91d, 0xaf1, 0xd2b, 0xfd1, 0x12fd, 0x16cf, 0x1b65, 0x20e3, 0x2777, 0x2f6f, 0x38ff, 0x446f, 0x521f, 0x628d, 0x7655, 0x8e01, 0xaa6b, 0xcc89, 0xf583, 0x126a7, 0x1619b, 0x1a857, 0x1fd3b, 0x26315, 0x2dd67, 0x3701b, 0x42023, 0x4f361, 0x5f0ed, 0x72125, 0x88e31, 0xa443b, 0xc51eb, 0xec8c1, 0x11bdbf, 0x154a3f, 0x198c4f, 0x1ea867, 0x24ca19, 0x2c25c1, 0x34fa1b, 0x3f928f, 0x4c4987, 0x5b8b6f, 0x6dda89 - }; + ]; public static int ExpandPrime(int oldSize) { diff --git a/Sources/Core/Microsoft.StreamProcessing/Collections/MultiSet.cs b/Sources/Core/Microsoft.StreamProcessing/Collections/MultiSet.cs index 150de6cdb..78bcd584f 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Collections/MultiSet.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Collections/MultiSet.cs @@ -20,7 +20,7 @@ public sealed class MultiSet { [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes", Justification = "Used to avoid creating redundant readonly property.")] [DataMember] - private Dictionary Elements = new Dictionary(); + private Dictionary Elements = []; [DataMember] private long count; diff --git a/Sources/Core/Microsoft.StreamProcessing/Collections/PooledCircularBuffer.cs b/Sources/Core/Microsoft.StreamProcessing/Collections/PooledCircularBuffer.cs index 6eabcc754..286697519 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Collections/PooledCircularBuffer.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Collections/PooledCircularBuffer.cs @@ -88,7 +88,7 @@ public void Return() public sealed class PooledElasticCircularBuffer : IEnumerable, IDisposable { private const int Capacity = 0xff; - private readonly LinkedList> buffers = new LinkedList>(); + private readonly LinkedList> buffers = new(); private LinkedListNode> head; private LinkedListNode> tail; private readonly ColumnPool pool; @@ -116,8 +116,7 @@ public void Enqueue(ref T value) { if (this.tail.Value.IsFull()) { - var next = this.tail.Next; - if (next == null) next = this.buffers.First; + var next = this.tail.Next ?? this.buffers.First; if (!next.Value.IsEmpty()) { next = new LinkedListNode>(new PooledCircularBuffer(Capacity, this.pool)); @@ -136,7 +135,7 @@ public void Enqueue(ref T value) /// /// [EditorBrowsable(EditorBrowsableState.Never)] - public void Add(T value) => Enqueue(ref value); + public void Add(T value) => this.Enqueue(ref value); /// /// Currently for internal use only - do not use directly. @@ -182,7 +181,7 @@ public bool TryDequeue(out T value) this.head = this.head.Next; oldHead.Value.Return(); this.buffers.Remove(oldHead); - if (this.head == null) this.head = this.buffers.First; + this.head ??= this.buffers.First; } return true; } @@ -253,7 +252,7 @@ public IEnumerator GetEnumerator() } } - System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() => GetEnumerator(); + System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() => this.GetEnumerator(); /// /// Currently for internal use only - do not use directly. diff --git a/Sources/Core/Microsoft.StreamProcessing/Collections/PrimeFuncs.cs b/Sources/Core/Microsoft.StreamProcessing/Collections/PrimeFuncs.cs index b740393f6..dee337bb0 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Collections/PrimeFuncs.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Collections/PrimeFuncs.cs @@ -11,17 +11,17 @@ namespace Microsoft.StreamProcessing.Internal.Collections internal static class PrimeFuncs { public static readonly int[] Primes = - { + [ 1, 2, 5, 11, 17, 37, 67, 131, 257, 521, 1031, 2053, 4099, 8209, 16411, 32771, 65537, 131101, 262147, 524309, 1048583, 2097169, 4194319, 8388617, 16777259, 33554467, 67108879, 134217757, 268435459, 536870923, 1073741827, 2147483629 - }; + ]; [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int FindIndexOfPrimeGreaterOrEqualTo(int min) { - Contract.Requires(min >= 0 && min < Primes[Primes.Length - 1]); + Contract.Requires(min >= 0 && min < Primes[^1]); int index = Array.BinarySearch(Primes, min); if (index < 0) diff --git a/Sources/Core/Microsoft.StreamProcessing/Collections/PriorityQueue.cs b/Sources/Core/Microsoft.StreamProcessing/Collections/PriorityQueue.cs index e1473d70c..e1972fbb5 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Collections/PriorityQueue.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Collections/PriorityQueue.cs @@ -18,7 +18,7 @@ namespace Microsoft.StreamProcessing public class PriorityQueue : IEnumerable { [DataMember] - private List data = new List(); + private List data = []; private readonly IComparer comp; @@ -48,9 +48,7 @@ public void Enqueue(T item) { int pi = (ci - 1) / 2; // parent index if (this.comp.Compare(this.data[ci], this.data[pi]) >= 0) break; // child item is larger than (or equal) parent so we're done - T tmp = this.data[ci]; - this.data[ci] = this.data[pi]; - this.data[pi] = tmp; + (this.data[pi], this.data[ci]) = (this.data[ci], this.data[pi]); ci = pi; } } @@ -85,9 +83,7 @@ public T Dequeue() if (rc <= li && this.comp.Compare(this.data[rc], this.data[ci]) < 0) // if there is a rc (ci + 1), and it is smaller than left child, use the rc instead ci = rc; if (this.comp.Compare(this.data[pi], this.data[ci]) <= 0) break; // parent is smaller than (or equal to) smallest child so done - var tmp = this.data[pi]; - this.data[pi] = this.data[ci]; - this.data[ci] = tmp; // swap parent and child + (this.data[ci], this.data[pi]) = (this.data[pi], this.data[ci]); pi = ci; } @@ -118,9 +114,9 @@ public T Dequeue() [EditorBrowsable(EditorBrowsableState.Never)] public override string ToString() { - string s = string.Empty; - for (int i = 0; i < this.data.Count; ++i) - s += this.data[i].ToString() + " "; + string s = this.data.Count is 0 + ? string.Empty + : string.Join(' ', this.data) + " "; s += "count = " + this.data.Count; return s; } diff --git a/Sources/Core/Microsoft.StreamProcessing/Collections/RemovableEndPointHeap.cs b/Sources/Core/Microsoft.StreamProcessing/Collections/RemovableEndPointHeap.cs index 5e3c59a3c..802270e60 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Collections/RemovableEndPointHeap.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Collections/RemovableEndPointHeap.cs @@ -114,7 +114,7 @@ public int Capacity public int Insert(long time, int value) { // Get index for this insert, growing if necesarry. - int index = Allocate(); + int index = this.Allocate(); // Find location for new element in heap, default to end. int heapPos = this.count; @@ -122,7 +122,7 @@ public int Insert(long time, int value) // Heapify-up for end of heap. var element = new Element { Time = time, Value = value, Index = index }; - HeapifyUp(ref element, heapPos); + this.HeapifyUp(ref element, heapPos); return index; } @@ -174,7 +174,7 @@ public bool TryGetNext(out long time, out int value) var top = this.heap[0]; time = top.Time; value = top.Value; - RemoveTop(); + this.RemoveTop(); return true; } @@ -207,7 +207,7 @@ public bool TryGetNextInclusive(long maxTime, out long time, out int value) // Return top element and remove top. time = top.Time; value = top.Value; - RemoveTop(); + this.RemoveTop(); return true; } @@ -240,7 +240,7 @@ public bool TryGetNextExclusive(long maxTime, out long time, out int value) // Return top element and remove top. time = top.Time; value = top.Value; - RemoveTop(); + this.RemoveTop(); return true; } @@ -253,11 +253,11 @@ public void RemoveTop() { Contract.Requires(this.Count > 0); int index = this.heap[0].Index; - Free(index); + this.Free(index); this.count--; if (this.count > 0) { - HeapifyDown(ref this.heap[this.count], 0); + this.HeapifyDown(ref this.heap[this.count], 0); } } @@ -271,11 +271,11 @@ public void Remove(int index) { Contract.Assume(index >= 0 && index < this.initialized); int heapPos = this.locations[index]; - Free(index); + this.Free(index); this.count--; if (heapPos < this.count) { - Heapify(ref this.heap[this.count], heapPos); + this.Heapify(ref this.heap[this.count], heapPos); } } @@ -301,13 +301,13 @@ private void Heapify(ref Element element, int heapPos) } if (heapPos == 0) { - HeapifyDown(ref element, 0); + this.HeapifyDown(ref element, 0); } else { - if (!HeapifyUp(ref element, heapPos)) + if (!this.HeapifyUp(ref element, heapPos)) { - HeapifyDown(ref element, heapPos); + this.HeapifyDown(ref element, heapPos); } } } @@ -415,7 +415,7 @@ private int Allocate() if (this.initialized == this.heap.Length) { // Out of capacity, so grow. - Grow(); + this.Grow(); } // Take next element from initialized. diff --git a/Sources/Core/Microsoft.StreamProcessing/Collections/SafeConcurrentDictionary.cs b/Sources/Core/Microsoft.StreamProcessing/Collections/SafeConcurrentDictionary.cs index 9b04f7206..62cef8f52 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Collections/SafeConcurrentDictionary.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Collections/SafeConcurrentDictionary.cs @@ -7,6 +7,7 @@ using System.Collections.Concurrent; using System.Collections.Generic; using System.Runtime.CompilerServices; +using System.Threading; namespace Microsoft.StreamProcessing.Internal.Collections { @@ -16,11 +17,17 @@ namespace Microsoft.StreamProcessing.Internal.Collections /// guarantee atomicity per-key for factory lambdas. /// /// Type of values in the dictionary - internal sealed class SafeConcurrentDictionary : IEnumerable> + internal sealed class SafeConcurrentDictionary : IReadOnlyCollection> { - private readonly ConcurrentDictionary dictionary = new ConcurrentDictionary(); + private static readonly bool isNullable = !typeof(TValue).IsValueType || Nullable.GetUnderlyingType(typeof(TValue)) != null; - private readonly ConcurrentDictionary keyLocks = new ConcurrentDictionary(); + private readonly ConcurrentDictionary dictionary = []; + private readonly ConcurrentDictionary keyLocks = []; + + /// + /// Returns the number of elements in the dictionary. + /// + public int Count { [MethodImpl(MethodImplOptions.AggressiveInlining)] get => this.dictionary.Count; } /// /// Adds a key/value pair to the dictionary if it does not exist. @@ -32,24 +39,76 @@ public TValue GetOrAdd(CacheKey key, Func valueFactory) { return value; } - lock (GetLock(key)) + using (this.GetLock(key).EnterScope()) { return this.dictionary.GetOrAdd(key, valueFactory); } } + /// + /// Like , but when is nullable (reference type or ), + /// a result from is not inserted. An existing entry equal to default + /// (e.g. a poisoned ) is removed under the per-key lock so the factory can run again. + /// For non-nullable value types, default is a valid cached value and is treated like any other value. + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public TValue GetOrAddUnlessNull(CacheKey key, Func valueFactory) + { + if (this.dictionary.TryGetValue(key, out var value)) + { + if (!isNullable || !EqualityComparer.Default.Equals(value, default)) + { + return value; + } + } + + using (this.GetLock(key).EnterScope()) + { + if (this.dictionary.TryGetValue(key, out value)) + { + if (!isNullable || !EqualityComparer.Default.Equals(value, default)) + { + return value; + } + + this.dictionary.TryRemove(key, out _); + } + + var created = valueFactory(key); + if (isNullable && EqualityComparer.Default.Equals(created, default)) + { + return default; + } + + return this.dictionary.GetOrAdd(key, _ => created); + } + } + + /// /// Returns an enumerator of the elements in the dictionary. /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public IEnumerator> GetEnumerator() => this.dictionary.GetEnumerator(); - IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); + /// + /// Clears all entries from the dictionary and the per-key lock table. + /// Marked internal (not private) so that test code can clear the codegen cache + /// (e.g. EquiJoinStreamable.cachedPipes) to ensure deterministic test behavior + /// without relying on reflection. + /// + internal void Clear() + { + this.dictionary.Clear(); + this.keyLocks.Clear(); + } + + IEnumerator IEnumerable.GetEnumerator() => this.GetEnumerator(); /// /// Retrieves lock associated with a key (creating it if it does not exist). /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - private object GetLock(CacheKey key) => this.keyLocks.GetOrAdd(key, v => new object()); + private Lock GetLock(CacheKey key) => this.keyLocks.GetOrAdd(key, static _ => new()); } } diff --git a/Sources/Core/Microsoft.StreamProcessing/Collections/SortedMultiSet.cs b/Sources/Core/Microsoft.StreamProcessing/Collections/SortedMultiSet.cs index 84ff1aeaf..e6d12f5c0 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Collections/SortedMultiSet.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Collections/SortedMultiSet.cs @@ -35,9 +35,9 @@ private static Func, IEnumerable var type = typeof(SortedDictionary); var parameter = Expression.Parameter(type); - var field = type.GetTypeInfo().GetField("_set", BindingFlags.NonPublic | BindingFlags.Instance); + var field = type.GetField("_set", BindingFlags.NonPublic | BindingFlags.Instance); var set = Expression.Field(parameter, field); - var member = set.Type.GetTypeInfo().GetMethod("Reverse"); + var member = set.Type.GetMethod("Reverse"); var reverse = Expression.Call(set, member); return Expression.Lambda, IEnumerable>>>(reverse, parameter).Compile(); @@ -47,7 +47,7 @@ private static Func, IEnumerable /// Creates a new instance of a Sorted Multiset. /// [EditorBrowsable(EditorBrowsableState.Never)] - public SortedMultiSet() : this(() => new SortedDictionary()) { } + public SortedMultiSet() : this(() => []) { } /// /// Creates a new instance of a Sorted Multiset where the underlying dictionary is generated. @@ -153,9 +153,9 @@ public SortedMultiSet Add(T key, long increment) [EditorBrowsable(EditorBrowsableState.Never)] public SortedMultiSet AddAll(SortedMultiSet set) { - Contract.Requires(set != null); + ArgumentNullException.ThrowIfNull(set); foreach (var keyAndCount in set.Elements) - Add(keyAndCount.Key, keyAndCount.Value); + this.Add(keyAndCount.Key, keyAndCount.Value); return this; } @@ -214,9 +214,9 @@ public SortedMultiSet Remove(T key, long decrement) [EditorBrowsable(EditorBrowsableState.Never)] public SortedMultiSet RemoveAll(SortedMultiSet set) { - Contract.Requires(set != null); + ArgumentNullException.ThrowIfNull(set); foreach (var keyAndCount in set.Elements) - Remove(keyAndCount.Key, keyAndCount.Value); + this.Remove(keyAndCount.Key, keyAndCount.Value); return this; } diff --git a/Sources/Core/Microsoft.StreamProcessing/Collections/StreamMessage.cs b/Sources/Core/Microsoft.StreamProcessing/Collections/StreamMessage.cs index 48de4585d..ec5d8ef52 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Collections/StreamMessage.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Collections/StreamMessage.cs @@ -8,6 +8,7 @@ using System.ComponentModel; using System.Diagnostics.Contracts; using System.Globalization; +using System.Numerics; using System.Runtime.CompilerServices; using System.Runtime.Serialization; using System.Text; @@ -73,38 +74,6 @@ public abstract class StreamMessage [EditorBrowsable(EditorBrowsableState.Never)] public class StreamMessage : StreamMessage { - private const int M1 = 0x5555; - - private const int M2 = 0x3333; - - private const int M4 = 0x0F0F; - - // The four values below are used for ComputeCount - private static readonly byte[] SixteenBitHammingWeights = PreCalculateHammingWeights(); - - /// - /// A one time pre-computation of the hamming weights for 16 bit fields, since we aren't exactly short of - /// memory we can use this to vastly speed up our calculations of hamming weights on the 64 - /// bit vector fields at a miniscule cost in memory. - /// - /// - private static byte[] PreCalculateHammingWeights() - { - var sixteenBitHammingWeights = new byte[65536]; - for (int i = 0; i < 65536; ++i) - { - // See http://en.wikipedia.org/wiki/Hamming_weight - var currentValue = i; - currentValue -= (currentValue >> 1) & M1; - currentValue = (currentValue & M2) + ((currentValue >> 2) & M2); - currentValue = (currentValue + (currentValue >> 4)) & M4; - currentValue += currentValue >> 8; - sixteenBitHammingWeights[i] = (byte)(currentValue & 0x7f); - } - - return sixteenBitHammingWeights; - } - /// /// Currently for internal use only - do not use directly. /// @@ -199,7 +168,7 @@ public void Allocate() this.memPool.Get(out this.hash); this.memPool.GetBV(out this.bitvector); this.memPool.GetKey(out this.key); - AllocatePayload(); + this.AllocatePayload(); } /// @@ -215,7 +184,7 @@ public virtual void AssignPool(MemoryPool memPool) this.hash.pool = memPool.intPool; this.bitvector.pool = memPool.bitvectorPool; - AssignPayloadPool(memPool); + this.AssignPayloadPool(memPool); } /// @@ -659,7 +628,7 @@ public virtual void Seal() Contract.Ensures(this.IsSealed); this.isSealed = true; - EnsureConsistency(); + this.EnsureConsistency(); } /// @@ -724,8 +693,8 @@ public override void Inflate() [EditorBrowsable(EditorBrowsableState.Never)] public override void Free() { - Release(); - Return(); + this.Release(); + this.Return(); } /// @@ -756,7 +725,7 @@ public virtual TPayload this[int index] public override string ToString() { var sb = new StringBuilder(); - sb.AppendFormat(CultureInfo.InvariantCulture, "Batch has {0} rows:\n", ComputeCount()); + sb.AppendFormat(CultureInfo.InvariantCulture, "Batch has {0} rows:\n", this.ComputeCount()); sb.AppendFormat(CultureInfo.InvariantCulture, " ###: vSync vOther Key Payload\n"); for (int row = 0; row < this.Count; row++) { @@ -782,7 +751,7 @@ public override string ToString() /// Currently for internal use only - do not use directly. /// [EditorBrowsable(EditorBrowsableState.Never)] - public void Print() => Console.WriteLine(ToString()); + public void Print() => Console.WriteLine(this.ToString()); /* TODO: Everything after this should be made internal - how to do that in the presence of generated subclasses? */ @@ -835,7 +804,7 @@ public virtual void CloneFrom(StreamMessage value, bool swing = value.payload.IncrementRefCount(1); } - CloneFromNoPayload(value, swing); + this.CloneFromNoPayload(value, swing); } /// @@ -880,7 +849,7 @@ public virtual int ComputeCount() { Contract.Ensures(Contract.Result() <= this.Count); - return this.Count == 0 ? 0 : ComputeCount(0, this.Count - 1); + return this.Count == 0 ? 0 : this.ComputeCount(0, this.Count - 1); } /// @@ -901,63 +870,46 @@ public unsafe virtual int ComputeCount(int startIndex, int endIndex) fixed (long* bitVectorColumnLong = this.bitvector.col) { ulong* bitVectorColumn = (ulong*)bitVectorColumnLong; - fixed (byte* sixteenBitHammingWeights = SixteenBitHammingWeights) - { - var startIndexBits = startIndex & 0x3f; - var startIndexBitVectorIndex = startIndex >> 6; + var startIndexBits = startIndex & 0x3f; + var startIndexBitVectorIndex = startIndex >> 6; + + var endIndexBits = endIndex & 0x3f; + var endIndexBitVectorIndex = endIndex >> 6; - var endIndexBits = endIndex & 0x3f; - var endIndexBitVectorIndex = endIndex >> 6; + if (startIndexBitVectorIndex == endIndexBitVectorIndex) + { + var startMask = -1L << startIndexBits; + var endMask = (long)(0xFFFFFFFFFFFFFFFFUL >> (0x3f - endIndexBits)); + var combinedMask = (ulong)(startMask & endMask); + hammingWeight = BitOperations.PopCount(bitVectorColumn[startIndexBitVectorIndex] & combinedMask); + } + else + { + int bitVectorIndex = startIndexBits == 0 ? startIndexBitVectorIndex : startIndexBitVectorIndex + 1; + int exit = endIndexBits == 0x3f ? endIndexBitVectorIndex + 1 : endIndexBitVectorIndex; - if (startIndexBitVectorIndex == endIndexBitVectorIndex) + for (; bitVectorIndex < exit; ++bitVectorIndex) { - var startMask = -1L << startIndexBits; - var endMask = (long)(0xFFFFFFFFFFFFFFFFUL >> (0x3f - endIndexBits)); - var combinedMask = (ulong)(startMask & endMask); - hammingWeight = - CalculateHammingWeight( - bitVectorColumn[startIndexBitVectorIndex] & combinedMask, - sixteenBitHammingWeights); + hammingWeight += BitOperations.PopCount(bitVectorColumn[bitVectorIndex]); } - else - { - int bitVectorIndex = startIndexBits == 0 ? startIndexBitVectorIndex : startIndexBitVectorIndex + 1; - int exit = endIndexBits == 0x3f ? endIndexBitVectorIndex + 1 : endIndexBitVectorIndex; - - for (; bitVectorIndex < exit; ++bitVectorIndex) - { - hammingWeight += CalculateHammingWeight(bitVectorColumn[bitVectorIndex], sixteenBitHammingWeights); - } - - if (startIndexBits > 0) - { - hammingWeight += - CalculateHammingWeight( - bitVectorColumn[startIndexBitVectorIndex] & (ulong)(-1L << startIndexBits), sixteenBitHammingWeights); - } - if (endIndexBits < 0x3f) - { - hammingWeight += - CalculateHammingWeight(bitVectorColumn[endIndexBitVectorIndex] & (0xFFFFFFFFFFFFFFFFUL >> (0x3f - endIndexBits)), sixteenBitHammingWeights); - } + if (startIndexBits > 0) + { + hammingWeight += BitOperations.PopCount( + bitVectorColumn[startIndexBitVectorIndex] & (ulong)(-1L << startIndexBits)); } - return endIndex - startIndex + 1 - hammingWeight; + if (endIndexBits < 0x3f) + { + hammingWeight += BitOperations.PopCount( + bitVectorColumn[endIndexBitVectorIndex] & (0xFFFFFFFFFFFFFFFFUL >> (0x3f - endIndexBits))); + } } + + return endIndex - startIndex + 1 - hammingWeight; } } - // I check for 0 because I'm betting in most cases the vectors are 0 - [MethodImpl(MethodImplOptions.AggressiveInlining)] - private static unsafe int CalculateHammingWeight(ulong bitVectorLong, byte* sixteenBitHammingWeights) - => bitVectorLong > 0 - ? sixteenBitHammingWeights[bitVectorLong & 0xFFFF] - + sixteenBitHammingWeights[bitVectorLong >> 16 & 0xFFFF] - + sixteenBitHammingWeights[bitVectorLong >> 32 & 0xFFFF] - + sixteenBitHammingWeights[bitVectorLong >> 48] - : 0; - /// /// Currently for internal use only - do not use directly. /// @@ -976,10 +928,10 @@ public virtual void Release() { this.vsync.Return(); this.vother.Return(); - ReleaseKey(); + this.ReleaseKey(); this.hash.Return(); this.bitvector.ReturnClear(); - ReleasePayload(); + this.ReleasePayload(); } /// diff --git a/Sources/Core/Microsoft.StreamProcessing/CompoundGroupKeyComparer.cs b/Sources/Core/Microsoft.StreamProcessing/CompoundGroupKeyComparer.cs index 66eda283b..c21fd8f5f 100644 --- a/Sources/Core/Microsoft.StreamProcessing/CompoundGroupKeyComparer.cs +++ b/Sources/Core/Microsoft.StreamProcessing/CompoundGroupKeyComparer.cs @@ -32,7 +32,7 @@ public Expression, CompoundGroupKey< Expression.AndAlso( Expression.Invoke(equalityOnT1, Expression.Field(e1, "outerGroup"), Expression.Field(e2, "outerGroup")), Expression.Invoke(equalityOnT2, Expression.Field(e1, "innerGroup"), Expression.Field(e2, "innerGroup"))), - new ParameterExpression[] { e1, e2 }); + [e1, e2]); } public Expression, int>> GetGetHashCodeExpr() @@ -46,7 +46,7 @@ public Expression, int>> GetGetHashC Expression.ExclusiveOr( Expression.Invoke(hashOnT1, Expression.Field(e1, "outerGroup")), Expression.Invoke(hashOnT2, Expression.Field(e1, "innerGroup"))), - new ParameterExpression[] { e1 }); + [e1]); } } @@ -75,7 +75,7 @@ public Expression>> GetCompare // (e1,e2) => comparerOnT2(e1.innerGroup, e2.innerGroup) return Expression.Lambda>>( Expression.Invoke(comparerOnT2, Expression.Field(e1, "innerGroup"), Expression.Field(e2, "innerGroup")), - new ParameterExpression[] { e1, e2 }); + [e1, e2]); } else { @@ -87,7 +87,7 @@ public Expression>> GetCompare Expression.Constant(0, typeof(int))), Expression.Invoke(comparerOnT1, Expression.Field(e1, "outerGroup"), Expression.Field(e2, "outerGroup")), Expression.Invoke(comparerOnT2, Expression.Field(e1, "innerGroup"), Expression.Field(e2, "innerGroup"))), - new ParameterExpression[] { e1, e2 }); + [e1, e2]); } } } diff --git a/Sources/Core/Microsoft.StreamProcessing/CompoundPayloads.cs b/Sources/Core/Microsoft.StreamProcessing/CompoundPayloads.cs index 4a7007dc8..b40cf94cd 100644 --- a/Sources/Core/Microsoft.StreamProcessing/CompoundPayloads.cs +++ b/Sources/Core/Microsoft.StreamProcessing/CompoundPayloads.cs @@ -43,20 +43,20 @@ public struct CompoundGroupKey /// Currently for internal use only - do not use directly. /// [EditorBrowsable(EditorBrowsableState.Never)] - public TInnerKey InnerGroup => this.innerGroup; + public readonly TInnerKey InnerGroup => this.innerGroup; /// /// Currently for internal use only - do not use directly. /// [EditorBrowsable(EditorBrowsableState.Never)] - public TOuterKey OuterGroup => this.outerGroup; + public readonly TOuterKey OuterGroup => this.outerGroup; /// /// Provides a string representation of the compound grouping key. /// /// A string representation of the compound grouping key. [EditorBrowsable(EditorBrowsableState.Never)] - public override string ToString() => new { this.OuterGroup, this.InnerGroup }.ToString(); + public override readonly string ToString() => new { this.OuterGroup, this.InnerGroup }.ToString(); /// /// Provides a hashcode of the compound grouping key. @@ -64,7 +64,7 @@ public struct CompoundGroupKey /// A hashcode of the compound grouping key. [MethodImpl(MethodImplOptions.AggressiveInlining)] [EditorBrowsable(EditorBrowsableState.Never)] - public override int GetHashCode() => this.hashCode; + public override readonly int GetHashCode() => this.hashCode; } /// @@ -115,7 +115,7 @@ public struct PartitionKey /// /// A hash code for the given partition key. [EditorBrowsable(EditorBrowsableState.Never)] - public override int GetHashCode() => this.Key.GetHashCode(); + public override readonly int GetHashCode() => this.Key.GetHashCode(); } /// @@ -134,12 +134,12 @@ public struct RankedEvent /// /// The rank of the event within the current grouping /// - public int Rank => this.rank; + public readonly int Rank => this.rank; /// /// The actual event associated with the ranking /// - public T Payload => this.payload; + public readonly T Payload => this.payload; internal RankedEvent(int rank, T payload) { @@ -152,6 +152,6 @@ internal RankedEvent(int rank, T payload) /// /// A string representation of the ranked event. [EditorBrowsable(EditorBrowsableState.Never)] - public override string ToString() => $"[Rank={this.rank}, Payload={this.payload}]"; + public override readonly string ToString() => $"[Rank={this.rank}, Payload={this.payload}]"; } } \ No newline at end of file diff --git a/Sources/Core/Microsoft.StreamProcessing/Egress/Atemporal/AtemporalEgress.cs b/Sources/Core/Microsoft.StreamProcessing/Egress/Atemporal/AtemporalEgress.cs index 000bc75d7..cd9a86c2c 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Egress/Atemporal/AtemporalEgress.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Egress/Atemporal/AtemporalEgress.cs @@ -20,7 +20,7 @@ public static partial class Streamable public static IObservable ToAtemporalObservable( this IStreamable stream) { - Invariant.IsNotNull(stream, nameof(stream)); + ArgumentNullException.ThrowIfNull(stream); return stream.ToAtemporalObservable(null, Guid.NewGuid().ToString()); } @@ -38,7 +38,7 @@ public static IObservable RegisterAtemporalOutput( IStreamable stream, string identifier = null) { - Invariant.IsNotNull(stream, nameof(stream)); + ArgumentNullException.ThrowIfNull(stream); return stream.ToAtemporalObservable(container, identifier ?? Guid.NewGuid().ToString()); } @@ -48,7 +48,7 @@ internal static IObservable ToAtemporalObservable( QueryContainer container, string identifier) { - Invariant.IsNotNull(stream, nameof(stream)); + ArgumentNullException.ThrowIfNull(stream); return new MonotonicObservable(stream, container, identifier); } diff --git a/Sources/Core/Microsoft.StreamProcessing/Egress/Atemporal/AtemporalEgress.tt b/Sources/Core/Microsoft.StreamProcessing/Egress/Atemporal/AtemporalEgress.tt index 0d4af98d1..0e1a680e4 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Egress/Atemporal/AtemporalEgress.tt +++ b/Sources/Core/Microsoft.StreamProcessing/Egress/Atemporal/AtemporalEgress.tt @@ -49,7 +49,7 @@ namespace Microsoft.StreamProcessing <# if (!hasContainer) { #>this <# } #>IStreamable stream<# if (hasContainer) { #>, string identifier = null<# } #>) { - Invariant.IsNotNull(stream, nameof(stream)); + ArgumentNullException.ThrowIfNull(stream); return stream.ToAtemporalObservable(<#= hasContainer ? "container" : "null" #>, <# if (hasContainer) { #>identifier ?? <# } #>Guid.NewGuid().ToString()); } @@ -60,7 +60,7 @@ namespace Microsoft.StreamProcessing QueryContainer container, string identifier) { - Invariant.IsNotNull(stream, nameof(stream)); + ArgumentNullException.ThrowIfNull(stream); return new MonotonicObservable(stream, container, identifier); } diff --git a/Sources/Core/Microsoft.StreamProcessing/Egress/Atemporal/AtemporalEgressObservable.cs b/Sources/Core/Microsoft.StreamProcessing/Egress/Atemporal/AtemporalEgressObservable.cs index e7590aa63..abf0d0ada 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Egress/Atemporal/AtemporalEgressObservable.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Egress/Atemporal/AtemporalEgressObservable.cs @@ -18,7 +18,7 @@ public MonotonicObservable( QueryContainer container, string identifier) { - Contract.Requires(source != null); + ArgumentNullException.ThrowIfNull(source); this.source = source; this.container = container; @@ -45,7 +45,7 @@ public ReactiveObservable( QueryContainer container, string identifier) { - Contract.Requires(source != null); + ArgumentNullException.ThrowIfNull(source); this.source = source; this.container = container; diff --git a/Sources/Core/Microsoft.StreamProcessing/Egress/Atemporal/AtemporalEgressPipe.cs b/Sources/Core/Microsoft.StreamProcessing/Egress/Atemporal/AtemporalEgressPipe.cs index 4540cae25..b4299af0a 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Egress/Atemporal/AtemporalEgressPipe.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Egress/Atemporal/AtemporalEgressPipe.cs @@ -14,7 +14,7 @@ namespace Microsoft.StreamProcessing internal sealed class MonotonicEgressPipe : EgressBoundary { [DataMember] - private SortedDictionary> toDelete = new SortedDictionary>(); + private SortedDictionary> toDelete = []; [Obsolete("Used only by serialization. Do not call directly.")] public MonotonicEgressPipe() { } @@ -33,7 +33,7 @@ public override void OnNext(StreamMessage batch) for (int i = 0; i < batch.Count; i++) { var currentSync = col_vsync[i]; - ProcessDeletions(currentSync); + this.ProcessDeletions(currentSync); if ((col_bv[i >> 6] & (1L << (i & 0x3f))) != 0) continue; if (col_vother[i] == StreamEvent.InfinitySyncTime) { @@ -44,7 +44,7 @@ public override void OnNext(StreamMessage batch) { // Interval: create an insertion event now, and a deletion later when time progresses this.observer.OnNext(batch[i]); - EnqueueDelete(col_vother[i], batch[i]); + this.EnqueueDelete(col_vother[i], batch[i]); } else { @@ -64,7 +64,7 @@ private void ProcessDeletions(long timestamp) if (currentTime <= timestamp) { // End edge: throw, because we expect the data to be monotonic - if (queue.Any()) + if (queue.Count != 0) throw new StreamProcessingException("The query has encountered either an end edge or an interval, while the egress point expects only start edges."); this.toDelete.Remove(currentTime); } @@ -76,7 +76,7 @@ private void EnqueueDelete(long currentTime, TPayload payload) { if (!this.toDelete.TryGetValue(currentTime, out List queue)) { - queue = new List(); + queue = []; this.toDelete.Add(currentTime, queue); } queue.Add(payload); diff --git a/Sources/Core/Microsoft.StreamProcessing/Egress/AtemporalArray/AtemporalArrayEgress.cs b/Sources/Core/Microsoft.StreamProcessing/Egress/AtemporalArray/AtemporalArrayEgress.cs index bd4a1246a..236afda09 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Egress/AtemporalArray/AtemporalArrayEgress.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Egress/AtemporalArray/AtemporalArrayEgress.cs @@ -20,7 +20,7 @@ public static partial class Streamable public static IObservable> ToAtemporalArrayObservable( this IStreamable stream) { - Invariant.IsNotNull(stream, nameof(stream)); + ArgumentNullException.ThrowIfNull(stream); return stream.ToAtemporalArrayObservable( () => new TPayload[Config.DataBatchSize], @@ -38,7 +38,7 @@ public static IObservable> ToAtemporalArrayObservable stream, Func generator) { - Invariant.IsNotNull(stream, nameof(stream)); + ArgumentNullException.ThrowIfNull(stream); return stream.ToAtemporalArrayObservable( generator, @@ -58,7 +58,7 @@ public static IObservable> RegisterAtemporalArrayOutput stream, string identifier = null) { - Invariant.IsNotNull(stream, nameof(stream)); + ArgumentNullException.ThrowIfNull(stream); return stream.ToAtemporalArrayObservable( () => new TPayload[Config.DataBatchSize], @@ -80,7 +80,7 @@ public static IObservable> RegisterAtemporalArrayOutput generator, string identifier = null) { - Invariant.IsNotNull(stream, nameof(stream)); + ArgumentNullException.ThrowIfNull(stream); return stream.ToAtemporalArrayObservable( generator, @@ -93,7 +93,7 @@ internal static IObservable> ToAtemporalArrayObservable(stream, generator, container, identifier); } diff --git a/Sources/Core/Microsoft.StreamProcessing/Egress/AtemporalArray/AtemporalArrayEgress.tt b/Sources/Core/Microsoft.StreamProcessing/Egress/AtemporalArray/AtemporalArrayEgress.tt index 05cd6d770..c1f4346d4 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Egress/AtemporalArray/AtemporalArrayEgress.tt +++ b/Sources/Core/Microsoft.StreamProcessing/Egress/AtemporalArray/AtemporalArrayEgress.tt @@ -50,7 +50,7 @@ namespace Microsoft.StreamProcessing Func generator<# } #><# if (hasContainer) { #>, string identifier = null<# } #>) { - Invariant.IsNotNull(stream, nameof(stream)); + ArgumentNullException.ThrowIfNull(stream); return stream.ToAtemporalArrayObservable( <#= hasGenerator ? "generator" : "() => new TPayload[Config.DataBatchSize]" #>, @@ -64,7 +64,7 @@ namespace Microsoft.StreamProcessing QueryContainer container, string identifier) { - Invariant.IsNotNull(stream, nameof(stream)); + ArgumentNullException.ThrowIfNull(stream); return new MonotonicArrayObservable(stream, generator, container, identifier); } diff --git a/Sources/Core/Microsoft.StreamProcessing/Egress/AtemporalArray/AtemporalArrayEgressObservable.cs b/Sources/Core/Microsoft.StreamProcessing/Egress/AtemporalArray/AtemporalArrayEgressObservable.cs index 1dd6dca62..8b698ba0f 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Egress/AtemporalArray/AtemporalArrayEgressObservable.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Egress/AtemporalArray/AtemporalArrayEgressObservable.cs @@ -20,7 +20,7 @@ public MonotonicArrayObservable( QueryContainer container, string identifier) { - Contract.Requires(source != null); + ArgumentNullException.ThrowIfNull(source); this.source = source; this.generator = generator; diff --git a/Sources/Core/Microsoft.StreamProcessing/Egress/AtemporalArray/AtemporalArrayEgressPipe.cs b/Sources/Core/Microsoft.StreamProcessing/Egress/AtemporalArray/AtemporalArrayEgressPipe.cs index 76c7c3a96..15acd1476 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Egress/AtemporalArray/AtemporalArrayEgressPipe.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Egress/AtemporalArray/AtemporalArrayEgressPipe.cs @@ -14,7 +14,7 @@ namespace Microsoft.StreamProcessing internal sealed class MonotonicArrayEgressPipe : EgressBoundary> { [DataMember] - private SortedDictionary> toDelete = new SortedDictionary>(); + private SortedDictionary> toDelete = []; private readonly Func generator; [DataMember] @@ -47,7 +47,7 @@ public override void OnNext(StreamMessage batch) for (int i = 0; i < batch.Count; i++) { var currentSync = col_vsync[i]; - ProcessDeletions(currentSync); + this.ProcessDeletions(currentSync); if ((col_bv[i >> 6] & (1L << (i & 0x3f))) != 0) continue; if (col_vother[i] == StreamEvent.InfinitySyncTime) @@ -73,7 +73,7 @@ public override void OnNext(StreamMessage batch) this.array = this.generator(); this.arrayLength = this.array.Length; } - EnqueueDelete(col_vother[i], batch[i]); + this.EnqueueDelete(col_vother[i], batch[i]); } else { @@ -93,7 +93,7 @@ private void ProcessDeletions(long timestamp) if (currentTime <= timestamp) { // End edge: throw, because we expect the data to be monotonic - if (queue.Any()) + if (queue.Count != 0) throw new StreamProcessingException("The query has encountered either an end edge or an interval, while the egress point expects only start edges."); this.toDelete.Remove(currentTime); } @@ -105,7 +105,7 @@ private void EnqueueDelete(long currentTime, TPayload payload) { if (!this.toDelete.TryGetValue(currentTime, out List queue)) { - queue = new List(); + queue = []; this.toDelete.Add(currentTime, queue); } queue.Add(payload); @@ -113,7 +113,7 @@ private void EnqueueDelete(long currentTime, TPayload payload) public override void OnCompleted() { - OnFlush(); + this.OnFlush(); base.OnCompleted(); } diff --git a/Sources/Core/Microsoft.StreamProcessing/Egress/AtemporalEnumerable/AtemporalEnumerableEgress.cs b/Sources/Core/Microsoft.StreamProcessing/Egress/AtemporalEnumerable/AtemporalEnumerableEgress.cs index 7382d505f..19cd2f252 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Egress/AtemporalEnumerable/AtemporalEnumerableEgress.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Egress/AtemporalEnumerable/AtemporalEnumerableEgress.cs @@ -17,7 +17,7 @@ public static partial class Streamable public static EvolvingStateEnumerable ToEnumerable( this IStreamable stream) { - Invariant.IsNotNull(stream, nameof(stream)); + ArgumentNullException.ThrowIfNull(stream); return stream.ToEnumerable(null, Guid.NewGuid().ToString()); } @@ -32,7 +32,7 @@ public static EvolvingStateEnumerable ToEnumerable( /// An IObservable object of change list events for output data from the query. public static EvolvingStateEnumerable RegisterOutputAsEnumerable(this QueryContainer container, IStreamable stream, string identifier = null) { - Invariant.IsNotNull(stream, nameof(stream)); + ArgumentNullException.ThrowIfNull(stream); return stream.ToEnumerable(container, identifier ?? Guid.NewGuid().ToString()); } @@ -42,7 +42,7 @@ internal static EvolvingStateEnumerable ToEnumerable( QueryContainer container, string identifier) { - Invariant.IsNotNull(stream, nameof(stream)); + ArgumentNullException.ThrowIfNull(stream); return new EvolvingStateEnumerable(stream, container, identifier); } diff --git a/Sources/Core/Microsoft.StreamProcessing/Egress/AtemporalEnumerable/AtemporalEnumerableEgressPipe.cs b/Sources/Core/Microsoft.StreamProcessing/Egress/AtemporalEnumerable/AtemporalEnumerableEgressPipe.cs index be9cb4878..be964ce3f 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Egress/AtemporalEnumerable/AtemporalEnumerableEgressPipe.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Egress/AtemporalEnumerable/AtemporalEnumerableEgressPipe.cs @@ -16,9 +16,9 @@ internal sealed class AtemporalEnumerableEgressPipe : EgressBoundary> toDelete = new SortedDictionary>(); + private SortedDictionary> toDelete = []; [DataMember] - private List> currentVersion = new List>(); + private List> currentVersion = []; [Obsolete("Used only by serialization. Do not call directly.")] public AtemporalEnumerableEgressPipe() { } @@ -35,7 +35,7 @@ public override void OnNext(StreamMessage batch) for (int i = 0; i < batch.Count; i++) { var currentSync = col_vsync[i]; - Process(currentSync); + this.Process(currentSync); if ((col_bv[i >> 6] & (1L << (i & 0x3f))) != 0) continue; if (col_vother[i] == StreamEvent.InfinitySyncTime) @@ -47,7 +47,7 @@ public override void OnNext(StreamMessage batch) { // Interval: create an insertion event now, and a deletion later when time progresses this.currentVersion.Add(ChangeListEvent.CreateInsertion(batch[i])); - EnqueueDelete(col_vother[i], batch[i]); + this.EnqueueDelete(col_vother[i], batch[i]); } else { @@ -86,7 +86,7 @@ private void Process(long timestamp) if (this.currentVersion.Count > 0) { this.observer.OnNext(this.currentVersion); - this.currentVersion = new List>(); + this.currentVersion = []; } } } @@ -95,7 +95,7 @@ private void EnqueueDelete(long currentTime, TPayload payload) { if (!this.toDelete.TryGetValue(currentTime, out List queue)) { - queue = new List(); + queue = []; this.toDelete.Add(currentTime, queue); } queue.Add(payload); diff --git a/Sources/Core/Microsoft.StreamProcessing/Egress/AtemporalEnumerable/EvolvingStateEnumerable.cs b/Sources/Core/Microsoft.StreamProcessing/Egress/AtemporalEnumerable/EvolvingStateEnumerable.cs index dec3c7247..f992c003e 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Egress/AtemporalEnumerable/EvolvingStateEnumerable.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Egress/AtemporalEnumerable/EvolvingStateEnumerable.cs @@ -20,9 +20,9 @@ public sealed class EvolvingStateEnumerable : IEnumerable, I private readonly IStreamable source; private readonly QueryContainer container; private readonly string identifier; - private readonly ConcurrentDictionary data = new ConcurrentDictionary(); + private readonly ConcurrentDictionary data = new(); private volatile bool isComplete; - private readonly object sentinel = new object(); + private readonly Lock sentinel = new(); private readonly IDisposable disposable; /// @@ -36,15 +36,15 @@ public EvolvingStateEnumerable( QueryContainer container, string identifier) { - Contract.Requires(source != null); + ArgumentNullException.ThrowIfNull(source); this.source = source; this.container = container; this.identifier = identifier; - if (this.container != null) this.container.RegisterEgressSite(this.identifier); + this.container?.RegisterEgressSite(this.identifier); var pipe = new AtemporalEnumerableEgressPipe(this, this.container); - if (this.container != null) this.container.RegisterEgressPipe(this.identifier, pipe); + this.container?.RegisterEgressPipe(this.identifier, pipe); this.disposable = this.source.Subscribe(pipe); } @@ -55,18 +55,18 @@ public EvolvingStateEnumerable( IEnumerator IEnumerable.GetEnumerator() { - Monitor.Enter(this.sentinel); + this.sentinel.Enter(); return new InnerEnumerator( this.data.SelectMany(o => Enumerable.Range(0, o.Value).Select(i => o.Key)).GetEnumerator(), - ExitMonitor); + this.sentinel.Exit); } System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { - Monitor.Enter(this.sentinel); + this.sentinel.Enter(); return new InnerEnumerator( this.data.SelectMany(o => Enumerable.Range(0, o.Value).Select(i => o.Key)).GetEnumerator(), - ExitMonitor); + this.sentinel.Exit); } void IObserver>>.OnCompleted() => this.isComplete = true; @@ -75,36 +75,29 @@ System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() void IObserver>>.OnNext(IEnumerable> batch) { - Monitor.Enter(this.sentinel); - try + using Lock.Scope _ = this.sentinel.EnterScope(); + int count; + foreach (var value in batch) { - int count; - foreach (var value in batch) + switch (value.EventKind) { - switch (value.EventKind) - { - case ChangeListEventKind.Insert: - if (this.data.TryGetValue(value.Payload, out count)) - this.data.TryUpdate(value.Payload, count + 1, count); - else - this.data.AddOrUpdate(value.Payload, 1, (p, c) => c + 1); - break; - - case ChangeListEventKind.Delete: - if (!this.data.TryGetValue(value.Payload, out count)) throw new InvalidOperationException("Should not be able to delete a value that does not exist"); - else - this.data.TryUpdate(value.Payload, count - 1, count); - break; - - default: - throw new InvalidOperationException("Switch statement should be exhaustive"); - } + case ChangeListEventKind.Insert: + if (this.data.TryGetValue(value.Payload, out count)) + this.data.TryUpdate(value.Payload, count + 1, count); + else + this.data.AddOrUpdate(value.Payload, 1, (p, c) => c + 1); + break; + + case ChangeListEventKind.Delete: + if (!this.data.TryGetValue(value.Payload, out count)) throw new InvalidOperationException("Should not be able to delete a value that does not exist"); + else + this.data.TryUpdate(value.Payload, count - 1, count); + break; + + default: + throw new InvalidOperationException("Switch statement should be exhaustive"); } } - finally - { - Monitor.Exit(this.sentinel); - } } /// @@ -112,31 +105,19 @@ void IObserver>>.OnNext(IEnumerable public void Dispose() => this.disposable.Dispose(); - private void ExitMonitor() => Monitor.Exit(this.sentinel); - - private sealed class InnerEnumerator : IEnumerator + private sealed class InnerEnumerator(IEnumerator baseEnumerator, Action exitLock) + : IEnumerator { - private readonly Action monitorExit; - private readonly IEnumerator baseEnumerator; - - public InnerEnumerator( - IEnumerator baseEnumerator, - Action monitorExit) - { - this.baseEnumerator = baseEnumerator; - this.monitorExit = monitorExit; - } - void IDisposable.Dispose() { - this.baseEnumerator.Dispose(); - this.monitorExit(); + baseEnumerator.Dispose(); + exitLock(); } - TPayload IEnumerator.Current => this.baseEnumerator.Current; - object System.Collections.IEnumerator.Current => this.baseEnumerator.Current; - bool System.Collections.IEnumerator.MoveNext() => this.baseEnumerator.MoveNext(); - void System.Collections.IEnumerator.Reset() => this.baseEnumerator.Reset(); + TPayload IEnumerator.Current => baseEnumerator.Current; + object System.Collections.IEnumerator.Current => baseEnumerator.Current; + bool System.Collections.IEnumerator.MoveNext() => baseEnumerator.MoveNext(); + void System.Collections.IEnumerator.Reset() => baseEnumerator.Reset(); } } } \ No newline at end of file diff --git a/Sources/Core/Microsoft.StreamProcessing/Egress/EgressPlanNode.cs b/Sources/Core/Microsoft.StreamProcessing/Egress/EgressPlanNode.cs index 208986cf7..da43257ac 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Egress/EgressPlanNode.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Egress/EgressPlanNode.cs @@ -33,7 +33,7 @@ internal override void CollectDormantIngressSites(Dictionary> ToStreamMessageObservable( this IStreamable stream) { - Contract.Requires(stream != null); + ArgumentNullException.ThrowIfNull(stream); return RegisterOutputAsStreamMessages(null, stream, null); } @@ -25,7 +25,7 @@ internal static IObservable> RegisterOutputAsStre IStreamable stream, string identifier = null) { - Contract.Requires(stream != null); + ArgumentNullException.ThrowIfNull(stream); return new StreamMessageEgressObservable(stream, container, identifier ?? Guid.NewGuid().ToString()); } diff --git a/Sources/Core/Microsoft.StreamProcessing/Egress/StreamMessage/StreamMessageEgressObservable.cs b/Sources/Core/Microsoft.StreamProcessing/Egress/StreamMessage/StreamMessageEgressObservable.cs index 4ecd4067f..f7dfbcc44 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Egress/StreamMessage/StreamMessageEgressObservable.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Egress/StreamMessage/StreamMessageEgressObservable.cs @@ -18,7 +18,7 @@ public StreamMessageEgressObservable( QueryContainer container, string identifier) { - Contract.Requires(source != null); + ArgumentNullException.ThrowIfNull(source); this.source = source; this.container = container; diff --git a/Sources/Core/Microsoft.StreamProcessing/Egress/Temporal/TemporalEgress.cs b/Sources/Core/Microsoft.StreamProcessing/Egress/Temporal/TemporalEgress.cs index 5ebac7419..7bb91d93a 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Egress/Temporal/TemporalEgress.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Egress/Temporal/TemporalEgress.cs @@ -23,7 +23,7 @@ public static IObservable> ToStreamEventObservable stream, ReshapingPolicy reshapingPolicy = ReshapingPolicy.None) { - Invariant.IsNotNull(stream, nameof(stream)); + ArgumentNullException.ThrowIfNull(stream); return stream.ToStreamEventObservable( null, Guid.NewGuid().ToString(), reshapingPolicy); @@ -44,7 +44,7 @@ public static IObservable> RegisterOutput( ReshapingPolicy reshapingPolicy = ReshapingPolicy.None, string identifier = null) { - Invariant.IsNotNull(stream, nameof(stream)); + ArgumentNullException.ThrowIfNull(stream); return stream.ToStreamEventObservable( container, identifier ?? Guid.NewGuid().ToString(), reshapingPolicy); @@ -56,7 +56,7 @@ internal static IObservable> ToStreamEventObservable f && f.CanFuseEgressObservable) { @@ -84,7 +84,7 @@ public static IObservable ToTemporalObservable( this IStreamable stream, Expression> constructor) { - Invariant.IsNotNull(stream, nameof(stream)); + ArgumentNullException.ThrowIfNull(stream); return stream.ToTemporalObservable( constructor, null, Guid.NewGuid().ToString()); @@ -107,7 +107,7 @@ public static IObservable RegisterTemporalOutput( Expression> constructor, string identifier = null) { - Invariant.IsNotNull(stream, nameof(stream)); + ArgumentNullException.ThrowIfNull(stream); return stream.ToTemporalObservable( constructor, container, identifier ?? Guid.NewGuid().ToString()); @@ -119,7 +119,7 @@ internal static IObservable ToTemporalObservable( QueryContainer container, string identifier) { - Invariant.IsNotNull(stream, nameof(stream)); + ArgumentNullException.ThrowIfNull(stream); if (stream is IFusibleStreamable f && f.CanFuseEgressObservable) { @@ -145,7 +145,7 @@ public static IObservable ToTemporalObservable( this IStreamable stream, Expression> constructor) { - Invariant.IsNotNull(stream, nameof(stream)); + ArgumentNullException.ThrowIfNull(stream); return stream.ToTemporalObservable( constructor, null, Guid.NewGuid().ToString()); @@ -168,7 +168,7 @@ public static IObservable RegisterTemporalOutput( Expression> constructor, string identifier = null) { - Invariant.IsNotNull(stream, nameof(stream)); + ArgumentNullException.ThrowIfNull(stream); return stream.ToTemporalObservable( constructor, container, identifier ?? Guid.NewGuid().ToString()); @@ -180,7 +180,7 @@ internal static IObservable ToTemporalObservable( QueryContainer container, string identifier) { - Invariant.IsNotNull(stream, nameof(stream)); + ArgumentNullException.ThrowIfNull(stream); if (stream is IFusibleStreamable f && f.CanFuseEgressObservable) { @@ -215,7 +215,7 @@ public static IObservable> ToStreamEventO this IStreamable, TPayload> stream, ReshapingPolicy reshapingPolicy = ReshapingPolicy.None) { - Invariant.IsNotNull(stream, nameof(stream)); + ArgumentNullException.ThrowIfNull(stream); return stream.ToStreamEventObservable( null, Guid.NewGuid().ToString(), reshapingPolicy); @@ -237,7 +237,7 @@ public static IObservable> RegisterOutput ReshapingPolicy reshapingPolicy = ReshapingPolicy.None, string identifier = null) { - Invariant.IsNotNull(stream, nameof(stream)); + ArgumentNullException.ThrowIfNull(stream); return stream.ToStreamEventObservable( container, identifier ?? Guid.NewGuid().ToString(), reshapingPolicy); @@ -249,7 +249,7 @@ internal static IObservable> ToStreamEven string identifier, ReshapingPolicy reshapingPolicy) { - Invariant.IsNotNull(stream, nameof(stream)); + ArgumentNullException.ThrowIfNull(stream); if (stream is IFusibleStreamable, TPayload> f && f.CanFuseEgressObservable) { @@ -278,7 +278,7 @@ public static IObservable ToTemporalObservable this IStreamable, TPayload> stream, Expression> constructor) { - Invariant.IsNotNull(stream, nameof(stream)); + ArgumentNullException.ThrowIfNull(stream); return stream.ToTemporalObservable( constructor, null, Guid.NewGuid().ToString()); @@ -302,7 +302,7 @@ public static IObservable RegisterTemporalOutput> constructor, string identifier = null) { - Invariant.IsNotNull(stream, nameof(stream)); + ArgumentNullException.ThrowIfNull(stream); return stream.ToTemporalObservable( constructor, container, identifier ?? Guid.NewGuid().ToString()); @@ -314,7 +314,7 @@ internal static IObservable ToTemporalObservable, TPayload> f && f.CanFuseEgressObservable) { @@ -349,7 +349,7 @@ public static IObservable ToTemporalObservable this IStreamable, TPayload> stream, Expression> constructor) { - Invariant.IsNotNull(stream, nameof(stream)); + ArgumentNullException.ThrowIfNull(stream); return stream.ToTemporalObservable( constructor, null, Guid.NewGuid().ToString()); @@ -373,7 +373,7 @@ public static IObservable RegisterTemporalOutput> constructor, string identifier = null) { - Invariant.IsNotNull(stream, nameof(stream)); + ArgumentNullException.ThrowIfNull(stream); return stream.ToTemporalObservable( constructor, container, identifier ?? Guid.NewGuid().ToString()); @@ -385,7 +385,7 @@ internal static IObservable ToTemporalObservable, TPayload> f && f.CanFuseEgressObservable) { diff --git a/Sources/Core/Microsoft.StreamProcessing/Egress/Temporal/TemporalEgress.tt b/Sources/Core/Microsoft.StreamProcessing/Egress/Temporal/TemporalEgress.tt index 59f7cfc14..9f1f4e30a 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Egress/Temporal/TemporalEgress.tt +++ b/Sources/Core/Microsoft.StreamProcessing/Egress/Temporal/TemporalEgress.tt @@ -97,7 +97,7 @@ namespace Microsoft.StreamProcessing ReshapingPolicy reshapingPolicy = ReshapingPolicy.None<# } #><# if (hasContainer) { #>, string identifier = null<# } #>) { - Invariant.IsNotNull(stream, nameof(stream)); + ArgumentNullException.ThrowIfNull(stream); return stream.To<#= infixName #>Observable( <#= constructorParameters #><#= hasContainer ? "container" : "null" #>, <# if (hasContainer) { #>identifier ?? <# } #>Guid.NewGuid().ToString()<# if (egressType == "StreamEvent") { #>, reshapingPolicy<# } #>); @@ -116,7 +116,7 @@ namespace Microsoft.StreamProcessing string identifier<# if (egressType == "StreamEvent") { #>, ReshapingPolicy reshapingPolicy<# } #>) { - Invariant.IsNotNull(stream, nameof(stream)); + ArgumentNullException.ThrowIfNull(stream); if (stream is IFusibleStreamable<<#= inputKey #>, TPayload> f && f.CanFuseEgressObservable) { diff --git a/Sources/Core/Microsoft.StreamProcessing/Egress/Temporal/TemporalEgressObservable.cs b/Sources/Core/Microsoft.StreamProcessing/Egress/Temporal/TemporalEgressObservable.cs index 7e8006fb2..fa3d9f8d3 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Egress/Temporal/TemporalEgressObservable.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Egress/Temporal/TemporalEgressObservable.cs @@ -14,7 +14,7 @@ namespace Microsoft.StreamProcessing internal sealed class StreamEventObservable : IObservable> { private static readonly SafeConcurrentDictionary> cachedPipes - = new SafeConcurrentDictionary>(); + = new(); private string errorMessages; internal readonly IStreamable source; @@ -26,7 +26,7 @@ public StreamEventObservable( QueryContainer container, string identifier) { - Contract.Requires(source != null); + ArgumentNullException.ThrowIfNull(source); this.source = source; this.container = container; @@ -38,8 +38,8 @@ public IDisposable Subscribe(IObserver> observer) { EgressBoundary> pipe; - if (!Config.ForceRowBasedExecution && this.source.Properties.IsColumnar && typeof(TPayload).CanRepresentAsColumnar() && CanGenerateColumnar()) - pipe = GetPipe(observer); + if (!Config.ForceRowBasedExecution && this.source.Properties.IsColumnar && typeof(TPayload).CanRepresentAsColumnar() && this.CanGenerateColumnar()) + pipe = this.GetPipe(observer); else { pipe = new StreamEventEgressPipe( @@ -55,9 +55,9 @@ public IDisposable Subscribe(IObserver> observer) private bool CanGenerateColumnar() { if (typeof(TPayload).IsAnonymousTypeName()) return false; - if (!typeof(TPayload).GetTypeInfo().IsVisible) return false; + if (!typeof(TPayload).IsVisible) return false; - var lookupKey = CachedPipeLookupKey(); + var lookupKey = this.CachedPipeLookupKey(); var generatedPipeType = cachedPipes.GetOrAdd(lookupKey, key => TemporalEgressTemplate.Generate(this)); this.errorMessages = generatedPipeType.Item2; @@ -66,7 +66,7 @@ private bool CanGenerateColumnar() private EgressBoundary> GetPipe(IObserver> observer) { - var lookupKey = CachedPipeLookupKey(); + var lookupKey = this.CachedPipeLookupKey(); var generatedPipeType = cachedPipes.GetOrAdd(lookupKey, key => TemporalEgressTemplate.Generate(this)); var instance = Activator.CreateInstance(generatedPipeType.Item1, observer, this.container); @@ -86,7 +86,7 @@ public override string ToString() internal sealed class StartEdgeObservable : IObservable { private static readonly SafeConcurrentDictionary> cachedPipes - = new SafeConcurrentDictionary>(); + = new(); private string errorMessages; internal readonly IStreamable source; @@ -100,7 +100,7 @@ public StartEdgeObservable( QueryContainer container, string identifier) { - Contract.Requires(source != null); + ArgumentNullException.ThrowIfNull(source); this.source = source; this.constructor = constructor; @@ -113,8 +113,8 @@ public IDisposable Subscribe(IObserver observer) { EgressBoundary pipe; - if (!Config.ForceRowBasedExecution && this.source.Properties.IsColumnar && typeof(TPayload).CanRepresentAsColumnar() && CanGenerateColumnar()) - pipe = GetPipe(observer); + if (!Config.ForceRowBasedExecution && this.source.Properties.IsColumnar && typeof(TPayload).CanRepresentAsColumnar() && this.CanGenerateColumnar()) + pipe = this.GetPipe(observer); else { pipe = new StartEdgeEgressPipe( @@ -131,9 +131,9 @@ public IDisposable Subscribe(IObserver observer) private bool CanGenerateColumnar() { if (typeof(TPayload).IsAnonymousTypeName() || typeof(TResult).IsAnonymousTypeName()) return false; - if (!typeof(TPayload).GetTypeInfo().IsVisible || !typeof(TResult).GetTypeInfo().IsVisible) return false; + if (!typeof(TPayload).IsVisible || !typeof(TResult).IsVisible) return false; - var lookupKey = CachedPipeLookupKey(); + var lookupKey = this.CachedPipeLookupKey(); var generatedPipeType = cachedPipes.GetOrAdd(lookupKey, key => TemporalEgressTemplate.Generate(this)); this.errorMessages = generatedPipeType.Item2; @@ -142,7 +142,7 @@ private bool CanGenerateColumnar() private EgressBoundary GetPipe(IObserver observer) { - var lookupKey = CachedPipeLookupKey(); + var lookupKey = this.CachedPipeLookupKey(); var generatedPipeType = cachedPipes.GetOrAdd(lookupKey, key => TemporalEgressTemplate.Generate(this)); var instance = Activator.CreateInstance(generatedPipeType.Item1, observer, this.container); @@ -154,7 +154,7 @@ private EgressBoundary GetPipe(IObserver obse internal sealed class IntervalObservable : IObservable { private static readonly SafeConcurrentDictionary> cachedPipes - = new SafeConcurrentDictionary>(); + = new(); private string errorMessages; internal readonly IStreamable source; @@ -168,7 +168,7 @@ public IntervalObservable( QueryContainer container, string identifier) { - Contract.Requires(source != null); + ArgumentNullException.ThrowIfNull(source); this.source = source; this.constructor = constructor; @@ -181,8 +181,8 @@ public IDisposable Subscribe(IObserver observer) { EgressBoundary pipe; - if (!Config.ForceRowBasedExecution && this.source.Properties.IsColumnar && typeof(TPayload).CanRepresentAsColumnar() && CanGenerateColumnar()) - pipe = GetPipe(observer); + if (!Config.ForceRowBasedExecution && this.source.Properties.IsColumnar && typeof(TPayload).CanRepresentAsColumnar() && this.CanGenerateColumnar()) + pipe = this.GetPipe(observer); else { pipe = new IntervalEgressPipe( @@ -199,9 +199,9 @@ public IDisposable Subscribe(IObserver observer) private bool CanGenerateColumnar() { if (typeof(TPayload).IsAnonymousTypeName() || typeof(TResult).IsAnonymousTypeName()) return false; - if (!typeof(TPayload).GetTypeInfo().IsVisible || !typeof(TResult).GetTypeInfo().IsVisible) return false; + if (!typeof(TPayload).IsVisible || !typeof(TResult).IsVisible) return false; - var lookupKey = CachedPipeLookupKey(); + var lookupKey = this.CachedPipeLookupKey(); var generatedPipeType = cachedPipes.GetOrAdd(lookupKey, key => TemporalEgressTemplate.Generate(this)); this.errorMessages = generatedPipeType.Item2; @@ -210,7 +210,7 @@ private bool CanGenerateColumnar() private EgressBoundary GetPipe(IObserver observer) { - var lookupKey = CachedPipeLookupKey(); + var lookupKey = this.CachedPipeLookupKey(); var generatedPipeType = cachedPipes.GetOrAdd(lookupKey, key => TemporalEgressTemplate.Generate(this)); var instance = Activator.CreateInstance(generatedPipeType.Item1, observer, this.container); @@ -222,7 +222,7 @@ private EgressBoundary GetPipe(IObserver obse internal sealed class PartitionedStreamEventObservable : IObservable> { private static readonly SafeConcurrentDictionary> cachedPipes - = new SafeConcurrentDictionary>(); + = new(); private string errorMessages; internal readonly IStreamable, TPayload> source; @@ -234,7 +234,7 @@ public PartitionedStreamEventObservable( QueryContainer container, string identifier) { - Contract.Requires(source != null); + ArgumentNullException.ThrowIfNull(source); this.source = source; this.container = container; @@ -246,8 +246,8 @@ public IDisposable Subscribe(IObserver> o { EgressBoundary, TPayload, PartitionedStreamEvent> pipe; - if (!Config.ForceRowBasedExecution && this.source.Properties.IsColumnar && typeof(TPayload).CanRepresentAsColumnar() && CanGenerateColumnar()) - pipe = GetPipe(observer); + if (!Config.ForceRowBasedExecution && this.source.Properties.IsColumnar && typeof(TPayload).CanRepresentAsColumnar() && this.CanGenerateColumnar()) + pipe = this.GetPipe(observer); else { pipe = new PartitionedStreamEventEgressPipe( @@ -263,9 +263,9 @@ public IDisposable Subscribe(IObserver> o private bool CanGenerateColumnar() { if (typeof(TKey).IsAnonymousTypeName() || typeof(TPayload).IsAnonymousTypeName()) return false; - if (!typeof(TKey).GetTypeInfo().IsVisible || !typeof(TPayload).GetTypeInfo().IsVisible) return false; + if (!typeof(TKey).IsVisible || !typeof(TPayload).IsVisible) return false; - var lookupKey = CachedPipeLookupKey(); + var lookupKey = this.CachedPipeLookupKey(); var generatedPipeType = cachedPipes.GetOrAdd(lookupKey, key => TemporalEgressTemplate.Generate(this)); this.errorMessages = generatedPipeType.Item2; @@ -274,7 +274,7 @@ private bool CanGenerateColumnar() private EgressBoundary, TPayload, PartitionedStreamEvent> GetPipe(IObserver> observer) { - var lookupKey = CachedPipeLookupKey(); + var lookupKey = this.CachedPipeLookupKey(); var generatedPipeType = cachedPipes.GetOrAdd(lookupKey, key => TemporalEgressTemplate.Generate(this)); var instance = Activator.CreateInstance(generatedPipeType.Item1, observer, this.container); @@ -294,7 +294,7 @@ public override string ToString() internal sealed class PartitionedStartEdgeObservable : IObservable { private static readonly SafeConcurrentDictionary> cachedPipes - = new SafeConcurrentDictionary>(); + = new(); private string errorMessages; internal readonly IStreamable, TPayload> source; @@ -308,7 +308,7 @@ public PartitionedStartEdgeObservable( QueryContainer container, string identifier) { - Contract.Requires(source != null); + ArgumentNullException.ThrowIfNull(source); this.source = source; this.constructor = constructor; @@ -321,8 +321,8 @@ public IDisposable Subscribe(IObserver observer) { EgressBoundary, TPayload, TResult> pipe; - if (!Config.ForceRowBasedExecution && this.source.Properties.IsColumnar && typeof(TPayload).CanRepresentAsColumnar() && CanGenerateColumnar()) - pipe = GetPipe(observer); + if (!Config.ForceRowBasedExecution && this.source.Properties.IsColumnar && typeof(TPayload).CanRepresentAsColumnar() && this.CanGenerateColumnar()) + pipe = this.GetPipe(observer); else { pipe = new PartitionedStartEdgeEgressPipe( @@ -339,9 +339,9 @@ public IDisposable Subscribe(IObserver observer) private bool CanGenerateColumnar() { if (typeof(TKey).IsAnonymousTypeName() || typeof(TPayload).IsAnonymousTypeName() || typeof(TResult).IsAnonymousTypeName()) return false; - if (!typeof(TKey).GetTypeInfo().IsVisible || !typeof(TPayload).GetTypeInfo().IsVisible || !typeof(TResult).GetTypeInfo().IsVisible) return false; + if (!typeof(TKey).IsVisible || !typeof(TPayload).IsVisible || !typeof(TResult).IsVisible) return false; - var lookupKey = CachedPipeLookupKey(); + var lookupKey = this.CachedPipeLookupKey(); var generatedPipeType = cachedPipes.GetOrAdd(lookupKey, key => TemporalEgressTemplate.Generate(this)); this.errorMessages = generatedPipeType.Item2; @@ -350,7 +350,7 @@ private bool CanGenerateColumnar() private EgressBoundary, TPayload, TResult> GetPipe(IObserver observer) { - var lookupKey = CachedPipeLookupKey(); + var lookupKey = this.CachedPipeLookupKey(); var generatedPipeType = cachedPipes.GetOrAdd(lookupKey, key => TemporalEgressTemplate.Generate(this)); var instance = Activator.CreateInstance(generatedPipeType.Item1, observer, this.container); @@ -362,7 +362,7 @@ private EgressBoundary, TPayload, TResult> GetPipe(IObserver< internal sealed class PartitionedIntervalObservable : IObservable { private static readonly SafeConcurrentDictionary> cachedPipes - = new SafeConcurrentDictionary>(); + = new(); private string errorMessages; internal readonly IStreamable, TPayload> source; @@ -376,7 +376,7 @@ public PartitionedIntervalObservable( QueryContainer container, string identifier) { - Contract.Requires(source != null); + ArgumentNullException.ThrowIfNull(source); this.source = source; this.constructor = constructor; @@ -389,8 +389,8 @@ public IDisposable Subscribe(IObserver observer) { EgressBoundary, TPayload, TResult> pipe; - if (!Config.ForceRowBasedExecution && this.source.Properties.IsColumnar && typeof(TPayload).CanRepresentAsColumnar() && CanGenerateColumnar()) - pipe = GetPipe(observer); + if (!Config.ForceRowBasedExecution && this.source.Properties.IsColumnar && typeof(TPayload).CanRepresentAsColumnar() && this.CanGenerateColumnar()) + pipe = this.GetPipe(observer); else { pipe = new PartitionedIntervalEgressPipe( @@ -407,9 +407,9 @@ public IDisposable Subscribe(IObserver observer) private bool CanGenerateColumnar() { if (typeof(TKey).IsAnonymousTypeName() || typeof(TPayload).IsAnonymousTypeName() || typeof(TResult).IsAnonymousTypeName()) return false; - if (!typeof(TKey).GetTypeInfo().IsVisible || !typeof(TPayload).GetTypeInfo().IsVisible || !typeof(TResult).GetTypeInfo().IsVisible) return false; + if (!typeof(TKey).IsVisible || !typeof(TPayload).IsVisible || !typeof(TResult).IsVisible) return false; - var lookupKey = CachedPipeLookupKey(); + var lookupKey = this.CachedPipeLookupKey(); var generatedPipeType = cachedPipes.GetOrAdd(lookupKey, key => TemporalEgressTemplate.Generate(this)); this.errorMessages = generatedPipeType.Item2; @@ -418,7 +418,7 @@ private bool CanGenerateColumnar() private EgressBoundary, TPayload, TResult> GetPipe(IObserver observer) { - var lookupKey = CachedPipeLookupKey(); + var lookupKey = this.CachedPipeLookupKey(); var generatedPipeType = cachedPipes.GetOrAdd(lookupKey, key => TemporalEgressTemplate.Generate(this)); var instance = Activator.CreateInstance(generatedPipeType.Item1, observer, this.container); diff --git a/Sources/Core/Microsoft.StreamProcessing/Egress/Temporal/TemporalEgressObservable.tt b/Sources/Core/Microsoft.StreamProcessing/Egress/Temporal/TemporalEgressObservable.tt index 622552bdd..34f9b2a5c 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Egress/Temporal/TemporalEgressObservable.tt +++ b/Sources/Core/Microsoft.StreamProcessing/Egress/Temporal/TemporalEgressObservable.tt @@ -59,7 +59,7 @@ foreach (string ingressType in new string[] { "StreamEvent", "StartEdge", "Inter QueryContainer container, string identifier) { - Contract.Requires(source != null); + ArgumentNullException.ThrowIfNull(source); this.source = source; <# if (ingressType == "StartEdge" || ingressType == "Interval") @@ -99,7 +99,7 @@ foreach (string ingressType in new string[] { "StreamEvent", "StartEdge", "Inter private bool CanGenerateColumnar() { if (<#= !string.IsNullOrEmpty(partitionString) ? "typeof(TKey).IsAnonymousTypeName() || " : string.Empty #>typeof(TPayload).IsAnonymousTypeName()<#= ingressType != "StreamEvent" ? " || typeof(TResult).IsAnonymousTypeName()" : string.Empty#>) return false; - if (<#= !string.IsNullOrEmpty(partitionString) ? "!typeof(TKey).GetTypeInfo().IsVisible || " : string.Empty #>!typeof(TPayload).GetTypeInfo().IsVisible<#= ingressType != "StreamEvent" ? " || !typeof(TResult).GetTypeInfo().IsVisible" : string.Empty#>) return false; + if (<#= !string.IsNullOrEmpty(partitionString) ? "!typeof(TKey).IsVisible || " : string.Empty #>!typeof(TPayload).IsVisible<#= ingressType != "StreamEvent" ? " || !typeof(TResult).IsVisible" : string.Empty#>) return false; var lookupKey = CachedPipeLookupKey(); var generatedPipeType = cachedPipes.GetOrAdd(lookupKey, key => TemporalEgressTemplate.Generate(this)); diff --git a/Sources/Core/Microsoft.StreamProcessing/Egress/Temporal/TemporalEgressTransformer.cs b/Sources/Core/Microsoft.StreamProcessing/Egress/Temporal/TemporalEgressTransformer.cs index 8ebe005d2..b93d84207 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Egress/Temporal/TemporalEgressTransformer.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Egress/Temporal/TemporalEgressTransformer.cs @@ -75,11 +75,10 @@ internal static Tuple Generate(StreamEventObservable).GetTypeInfo().Assembly); + assemblyReferences.Add(typeof(IStreamable<,>).Assembly); assemblyReferences.Add(Transformer.GeneratedStreamMessageAssembly()); - var a = Transformer.CompileSourceCode(expandedCode, assemblyReferences, out errorMessages); - var t = a.GetType(template.className); + var t = Transformer.CompileSourceCode(expandedCode, assemblyReferences, a => a.GetType(template.className), out errorMessages); return Tuple.Create(t, errorMessages); } catch @@ -112,11 +111,10 @@ internal static Tuple Generate(StartEdgeObserva var expandedCode = template.TransformText(); var assemblyReferences = Transformer.AssemblyReferencesNeededFor(keyType, typeof(TPayload), typeof(TResult)); - assemblyReferences.Add(typeof(IStreamable<,>).GetTypeInfo().Assembly); + assemblyReferences.Add(typeof(IStreamable<,>).Assembly); assemblyReferences.Add(Transformer.GeneratedStreamMessageAssembly()); - var a = Transformer.CompileSourceCode(expandedCode, assemblyReferences, out errorMessages); - var t = a.GetType(template.className); + var t = Transformer.CompileSourceCode(expandedCode, assemblyReferences, a => a.GetType(template.className), out errorMessages); return Tuple.Create(t, errorMessages); } catch @@ -150,11 +148,10 @@ internal static Tuple Generate(IntervalObservab var expandedCode = template.TransformText(); var assemblyReferences = Transformer.AssemblyReferencesNeededFor(keyType, typeof(TPayload), typeof(TResult)); - assemblyReferences.Add(typeof(IStreamable<,>).GetTypeInfo().Assembly); + assemblyReferences.Add(typeof(IStreamable<,>).Assembly); assemblyReferences.Add(Transformer.GeneratedStreamMessageAssembly()); - var a = Transformer.CompileSourceCode(expandedCode, assemblyReferences, out errorMessages); - var t = a.GetType(template.className); + var t = Transformer.CompileSourceCode(expandedCode, assemblyReferences, a => a.GetType(template.className), out errorMessages); return Tuple.Create(t, errorMessages); } catch @@ -178,11 +175,10 @@ internal static Tuple Generate(PartitionedStreamEv var expandedCode = template.TransformText(); var assemblyReferences = Transformer.AssemblyReferencesNeededFor(keyType, typeof(TPayload)); - assemblyReferences.Add(typeof(IStreamable<,>).GetTypeInfo().Assembly); + assemblyReferences.Add(typeof(IStreamable<,>).Assembly); assemblyReferences.Add(Transformer.GeneratedStreamMessageAssembly, TPayload>()); - var a = Transformer.CompileSourceCode(expandedCode, assemblyReferences, out errorMessages); - var t = a.GetType(template.className); + var t = Transformer.CompileSourceCode(expandedCode, assemblyReferences, a => a.GetType(template.className), out errorMessages); return Tuple.Create(t, errorMessages); } catch @@ -216,11 +212,10 @@ internal static Tuple Generate(Partitione var expandedCode = template.TransformText(); var assemblyReferences = Transformer.AssemblyReferencesNeededFor(keyType, typeof(TPayload), typeof(TResult)); - assemblyReferences.Add(typeof(IStreamable<,>).GetTypeInfo().Assembly); + assemblyReferences.Add(typeof(IStreamable<,>).Assembly); assemblyReferences.Add(Transformer.GeneratedStreamMessageAssembly, TPayload>()); - var a = Transformer.CompileSourceCode(expandedCode, assemblyReferences, out errorMessages); - var t = a.GetType(template.className); + var t = Transformer.CompileSourceCode(expandedCode, assemblyReferences, a => a.GetType(template.className), out errorMessages); return Tuple.Create(t, errorMessages); } catch @@ -255,11 +250,10 @@ internal static Tuple Generate(Partitione var expandedCode = template.TransformText(); var assemblyReferences = Transformer.AssemblyReferencesNeededFor(keyType, typeof(TPayload), typeof(TResult)); - assemblyReferences.Add(typeof(IStreamable<,>).GetTypeInfo().Assembly); + assemblyReferences.Add(typeof(IStreamable<,>).Assembly); assemblyReferences.Add(Transformer.GeneratedStreamMessageAssembly, TPayload>()); - var a = Transformer.CompileSourceCode(expandedCode, assemblyReferences, out errorMessages); - var t = a.GetType(template.className); + var t = Transformer.CompileSourceCode(expandedCode, assemblyReferences, a => a.GetType(template.className), out errorMessages); return Tuple.Create(t, errorMessages); } catch diff --git a/Sources/Core/Microsoft.StreamProcessing/Egress/TemporalArray/TemporalArrayEgress.cs b/Sources/Core/Microsoft.StreamProcessing/Egress/TemporalArray/TemporalArrayEgress.cs index e5d75d3f4..7a4093638 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Egress/TemporalArray/TemporalArrayEgress.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Egress/TemporalArray/TemporalArrayEgress.cs @@ -23,7 +23,7 @@ public static IObservable>> ToStreamEventArra this IStreamable stream, ReshapingPolicy reshapingPolicy = ReshapingPolicy.None) { - Invariant.IsNotNull(stream, nameof(stream)); + ArgumentNullException.ThrowIfNull(stream); return stream.ToStreamEventArrayObservable( () => new StreamEvent[Config.DataBatchSize], @@ -45,7 +45,7 @@ public static IObservable>> ToStreamEventArra Func[]> generator, ReshapingPolicy reshapingPolicy = ReshapingPolicy.None) { - Invariant.IsNotNull(stream, nameof(stream)); + ArgumentNullException.ThrowIfNull(stream); return stream.ToStreamEventArrayObservable( generator, @@ -69,7 +69,7 @@ public static IObservable>> RegisterArrayOutp ReshapingPolicy reshapingPolicy = ReshapingPolicy.None, string identifier = null) { - Invariant.IsNotNull(stream, nameof(stream)); + ArgumentNullException.ThrowIfNull(stream); return stream.ToStreamEventArrayObservable( () => new StreamEvent[Config.DataBatchSize], @@ -95,7 +95,7 @@ public static IObservable>> RegisterArrayOutp ReshapingPolicy reshapingPolicy = ReshapingPolicy.None, string identifier = null) { - Invariant.IsNotNull(stream, nameof(stream)); + ArgumentNullException.ThrowIfNull(stream); return stream.ToStreamEventArrayObservable( generator, @@ -111,7 +111,7 @@ internal static IObservable>> ToStreamEventAr string identifer, ReshapingPolicy reshapingPolicy) { - Invariant.IsNotNull(stream, nameof(stream)); + ArgumentNullException.ThrowIfNull(stream); return (reshapingPolicy == ReshapingPolicy.None) ? new StreamEventArrayObservable(stream, generator, container, identifer) @@ -131,7 +131,7 @@ public static IObservable> ToTemporalArrayObservable stream, Expression> constructor) { - Invariant.IsNotNull(stream, nameof(stream)); + ArgumentNullException.ThrowIfNull(stream); return stream.ToTemporalArrayObservable( () => new TResult[Config.DataBatchSize], @@ -154,7 +154,7 @@ public static IObservable> ToTemporalArrayObservable generator, Expression> constructor) { - Invariant.IsNotNull(stream, nameof(stream)); + ArgumentNullException.ThrowIfNull(stream); return stream.ToTemporalArrayObservable( generator, @@ -179,7 +179,7 @@ public static IObservable> RegisterTemporalArrayOutput> constructor, string identifier = null) { - Invariant.IsNotNull(stream, nameof(stream)); + ArgumentNullException.ThrowIfNull(stream); return stream.ToTemporalArrayObservable( () => new TResult[Config.DataBatchSize], @@ -206,7 +206,7 @@ public static IObservable> RegisterTemporalArrayOutput> constructor, string identifier = null) { - Invariant.IsNotNull(stream, nameof(stream)); + ArgumentNullException.ThrowIfNull(stream); return stream.ToTemporalArrayObservable( generator, @@ -221,7 +221,7 @@ internal static IObservable> ToTemporalArrayObservable(stream, generator, constructor, container, identifer); } @@ -239,7 +239,7 @@ public static IObservable> ToTemporalArrayObservable stream, Expression> constructor) { - Invariant.IsNotNull(stream, nameof(stream)); + ArgumentNullException.ThrowIfNull(stream); return stream.ToTemporalArrayObservable( () => new TResult[Config.DataBatchSize], @@ -262,7 +262,7 @@ public static IObservable> ToTemporalArrayObservable generator, Expression> constructor) { - Invariant.IsNotNull(stream, nameof(stream)); + ArgumentNullException.ThrowIfNull(stream); return stream.ToTemporalArrayObservable( generator, @@ -287,7 +287,7 @@ public static IObservable> RegisterTemporalArrayOutput> constructor, string identifier = null) { - Invariant.IsNotNull(stream, nameof(stream)); + ArgumentNullException.ThrowIfNull(stream); return stream.ToTemporalArrayObservable( () => new TResult[Config.DataBatchSize], @@ -314,7 +314,7 @@ public static IObservable> RegisterTemporalArrayOutput> constructor, string identifier = null) { - Invariant.IsNotNull(stream, nameof(stream)); + ArgumentNullException.ThrowIfNull(stream); return stream.ToTemporalArrayObservable( generator, @@ -329,7 +329,7 @@ internal static IObservable> ToTemporalArrayObservable(stream.ToEndEdgeFreeStream(), generator, constructor, container, identifer); } @@ -346,7 +346,7 @@ public static IObservable>> this IStreamable, TPayload> stream, ReshapingPolicy reshapingPolicy = ReshapingPolicy.None) { - Invariant.IsNotNull(stream, nameof(stream)); + ArgumentNullException.ThrowIfNull(stream); return stream.ToStreamEventArrayObservable( () => new PartitionedStreamEvent[Config.DataBatchSize], @@ -369,7 +369,7 @@ public static IObservable>> Func[]> generator, ReshapingPolicy reshapingPolicy = ReshapingPolicy.None) { - Invariant.IsNotNull(stream, nameof(stream)); + ArgumentNullException.ThrowIfNull(stream); return stream.ToStreamEventArrayObservable( generator, @@ -394,7 +394,7 @@ public static IObservable>> ReshapingPolicy reshapingPolicy = ReshapingPolicy.None, string identifier = null) { - Invariant.IsNotNull(stream, nameof(stream)); + ArgumentNullException.ThrowIfNull(stream); return stream.ToStreamEventArrayObservable( () => new PartitionedStreamEvent[Config.DataBatchSize], @@ -421,7 +421,7 @@ public static IObservable>> ReshapingPolicy reshapingPolicy = ReshapingPolicy.None, string identifier = null) { - Invariant.IsNotNull(stream, nameof(stream)); + ArgumentNullException.ThrowIfNull(stream); return stream.ToStreamEventArrayObservable( generator, @@ -437,7 +437,7 @@ internal static IObservable> string identifer, ReshapingPolicy reshapingPolicy) { - Invariant.IsNotNull(stream, nameof(stream)); + ArgumentNullException.ThrowIfNull(stream); return (reshapingPolicy == ReshapingPolicy.None) ? new PartitionedStreamEventArrayObservable(stream, generator, container, identifer) @@ -458,7 +458,7 @@ public static IObservable> ToTemporalArrayObservable, TPayload> stream, Expression> constructor) { - Invariant.IsNotNull(stream, nameof(stream)); + ArgumentNullException.ThrowIfNull(stream); return stream.ToTemporalArrayObservable( () => new TResult[Config.DataBatchSize], @@ -482,7 +482,7 @@ public static IObservable> ToTemporalArrayObservable generator, Expression> constructor) { - Invariant.IsNotNull(stream, nameof(stream)); + ArgumentNullException.ThrowIfNull(stream); return stream.ToTemporalArrayObservable( generator, @@ -508,7 +508,7 @@ public static IObservable> RegisterTemporalArrayOutput> constructor, string identifier = null) { - Invariant.IsNotNull(stream, nameof(stream)); + ArgumentNullException.ThrowIfNull(stream); return stream.ToTemporalArrayObservable( () => new TResult[Config.DataBatchSize], @@ -536,7 +536,7 @@ public static IObservable> RegisterTemporalArrayOutput> constructor, string identifier = null) { - Invariant.IsNotNull(stream, nameof(stream)); + ArgumentNullException.ThrowIfNull(stream); return stream.ToTemporalArrayObservable( generator, @@ -551,7 +551,7 @@ internal static IObservable> ToTemporalArrayObservable(stream, generator, constructor, container, identifer); } @@ -570,7 +570,7 @@ public static IObservable> ToTemporalArrayObservable, TPayload> stream, Expression> constructor) { - Invariant.IsNotNull(stream, nameof(stream)); + ArgumentNullException.ThrowIfNull(stream); return stream.ToTemporalArrayObservable( () => new TResult[Config.DataBatchSize], @@ -594,7 +594,7 @@ public static IObservable> ToTemporalArrayObservable generator, Expression> constructor) { - Invariant.IsNotNull(stream, nameof(stream)); + ArgumentNullException.ThrowIfNull(stream); return stream.ToTemporalArrayObservable( generator, @@ -620,7 +620,7 @@ public static IObservable> RegisterTemporalArrayOutput> constructor, string identifier = null) { - Invariant.IsNotNull(stream, nameof(stream)); + ArgumentNullException.ThrowIfNull(stream); return stream.ToTemporalArrayObservable( () => new TResult[Config.DataBatchSize], @@ -648,7 +648,7 @@ public static IObservable> RegisterTemporalArrayOutput> constructor, string identifier = null) { - Invariant.IsNotNull(stream, nameof(stream)); + ArgumentNullException.ThrowIfNull(stream); return stream.ToTemporalArrayObservable( generator, @@ -663,7 +663,7 @@ internal static IObservable> ToTemporalArrayObservable(stream.ToEndEdgeFreeStream(), generator, constructor, container, identifer); } diff --git a/Sources/Core/Microsoft.StreamProcessing/Egress/TemporalArray/TemporalArrayEgress.tt b/Sources/Core/Microsoft.StreamProcessing/Egress/TemporalArray/TemporalArrayEgress.tt index e992d7e4c..a5a629d27 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Egress/TemporalArray/TemporalArrayEgress.tt +++ b/Sources/Core/Microsoft.StreamProcessing/Egress/TemporalArray/TemporalArrayEgress.tt @@ -123,7 +123,7 @@ foreach (string egressType in new string[] { "StreamEvent", "StartEdge", "Interv { #>, string identifier = null<# } #>) { - Invariant.IsNotNull(stream, nameof(stream)); + ArgumentNullException.ThrowIfNull(stream); return stream.To<#= infixName #>ArrayObservable( <#= hasGenerator ? "generator" : "() => new " + defaultGenerator #>, @@ -147,7 +147,7 @@ foreach (string egressType in new string[] { "StreamEvent", "StartEdge", "Interv ReshapingPolicy reshapingPolicy<# } #>) { - Invariant.IsNotNull(stream, nameof(stream)); + ArgumentNullException.ThrowIfNull(stream); <# // Non-StreamEvent methods do not use reshaping policy at all switch (egressType) diff --git a/Sources/Core/Microsoft.StreamProcessing/Egress/TemporalArray/TemporalArrayEgressObservable.cs b/Sources/Core/Microsoft.StreamProcessing/Egress/TemporalArray/TemporalArrayEgressObservable.cs index b8306cc07..0ab7ab2cd 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Egress/TemporalArray/TemporalArrayEgressObservable.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Egress/TemporalArray/TemporalArrayEgressObservable.cs @@ -22,7 +22,7 @@ public StreamEventArrayObservable( QueryContainer container, string identifier) { - Contract.Requires(source != null); + ArgumentNullException.ThrowIfNull(source); this.source = source; this.generator = generator; @@ -57,7 +57,7 @@ public StartEdgeArrayObservable( QueryContainer container, string identifier) { - Contract.Requires(source != null); + ArgumentNullException.ThrowIfNull(source); this.source = source; this.generator = generator; @@ -94,7 +94,7 @@ public IntervalArrayObservable( QueryContainer container, string identifier) { - Contract.Requires(source != null); + ArgumentNullException.ThrowIfNull(source); this.source = source; this.generator = generator; @@ -129,7 +129,7 @@ public PartitionedStreamEventArrayObservable( QueryContainer container, string identifier) { - Contract.Requires(source != null); + ArgumentNullException.ThrowIfNull(source); this.source = source; this.generator = generator; @@ -164,7 +164,7 @@ public PartitionedStartEdgeArrayObservable( QueryContainer container, string identifier) { - Contract.Requires(source != null); + ArgumentNullException.ThrowIfNull(source); this.source = source; this.generator = generator; @@ -201,7 +201,7 @@ public PartitionedIntervalArrayObservable( QueryContainer container, string identifier) { - Contract.Requires(source != null); + ArgumentNullException.ThrowIfNull(source); this.source = source; this.generator = generator; diff --git a/Sources/Core/Microsoft.StreamProcessing/Egress/TemporalArray/TemporalArrayEgressObservable.tt b/Sources/Core/Microsoft.StreamProcessing/Egress/TemporalArray/TemporalArrayEgressObservable.tt index 88f51aed0..9c4f472f9 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Egress/TemporalArray/TemporalArrayEgressObservable.tt +++ b/Sources/Core/Microsoft.StreamProcessing/Egress/TemporalArray/TemporalArrayEgressObservable.tt @@ -59,7 +59,7 @@ namespace Microsoft.StreamProcessing QueryContainer container, string identifier) { - Contract.Requires(source != null); + ArgumentNullException.ThrowIfNull(source); this.source = source; this.generator = generator; diff --git a/Sources/Core/Microsoft.StreamProcessing/Egress/TemporalArray/TemporalArrayEgressPipe.cs b/Sources/Core/Microsoft.StreamProcessing/Egress/TemporalArray/TemporalArrayEgressPipe.cs index b6df59719..5e88f075c 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Egress/TemporalArray/TemporalArrayEgressPipe.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Egress/TemporalArray/TemporalArrayEgressPipe.cs @@ -62,7 +62,7 @@ public override void OnNext(StreamMessage batch) public override void OnCompleted() { - OnFlush(); + this.OnFlush(); base.OnCompleted(); } @@ -137,7 +137,7 @@ public override void OnNext(StreamMessage batch) public override void OnCompleted() { - OnFlush(); + this.OnFlush(); base.OnCompleted(); } @@ -210,7 +210,7 @@ public override void OnNext(StreamMessage batch) public override void OnCompleted() { - OnFlush(); + this.OnFlush(); base.OnCompleted(); } @@ -285,7 +285,7 @@ public override void OnNext(StreamMessage, TPayload> batch) public override void OnCompleted() { - OnFlush(); + this.OnFlush(); base.OnCompleted(); } @@ -361,7 +361,7 @@ public override void OnNext(StreamMessage, TPayload> batch) public override void OnCompleted() { - OnFlush(); + this.OnFlush(); base.OnCompleted(); } @@ -435,7 +435,7 @@ public override void OnNext(StreamMessage, TPayload> batch) public override void OnCompleted() { - OnFlush(); + this.OnFlush(); base.OnCompleted(); } diff --git a/Sources/Core/Microsoft.StreamProcessing/Egress/TemporalArray/TemporalArrayEgressTransformer.cs b/Sources/Core/Microsoft.StreamProcessing/Egress/TemporalArray/TemporalArrayEgressTransformer.cs index 79ef5b1ec..6f6c74bc2 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Egress/TemporalArray/TemporalArrayEgressTransformer.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Egress/TemporalArray/TemporalArrayEgressTransformer.cs @@ -4,6 +4,9 @@ // ********************************************************************* using System; using System.Collections.Generic; +#if CODEGEN_TIMING +using System.Diagnostics; +#endif using System.Linq.Expressions; using System.Reflection; @@ -79,11 +82,10 @@ internal static Tuple Generate(StreamEventArrayObservabl var expandedCode = template.TransformText(); var assemblyReferences = Transformer.AssemblyReferencesNeededFor(keyType, typeof(TPayload)); - assemblyReferences.Add(typeof(IStreamable<,>).GetTypeInfo().Assembly); + assemblyReferences.Add(typeof(IStreamable<,>).Assembly); assemblyReferences.Add(Transformer.GeneratedStreamMessageAssembly()); - var a = Transformer.CompileSourceCode(expandedCode, assemblyReferences, out errorMessages); - var t = a.GetType(template.className); + var t = Transformer.CompileSourceCode(expandedCode, assemblyReferences, a => a.GetType(template.className), out errorMessages); #if CODEGEN_TIMING sw.Stop(); Console.WriteLine("Time to generate and instantiate a IOOEJ operator: {0}ms", sw.ElapsedMilliseconds); @@ -127,11 +129,10 @@ internal static Tuple Generate(StartEdgeArrayOb var expandedCode = template.TransformText(); var assemblyReferences = Transformer.AssemblyReferencesNeededFor(keyType, typeof(TPayload), typeof(TResult)); - assemblyReferences.Add(typeof(IStreamable<,>).GetTypeInfo().Assembly); + assemblyReferences.Add(typeof(IStreamable<,>).Assembly); assemblyReferences.Add(Transformer.GeneratedStreamMessageAssembly()); - var a = Transformer.CompileSourceCode(expandedCode, assemblyReferences, out errorMessages); - var t = a.GetType(template.className); + var t = Transformer.CompileSourceCode(expandedCode, assemblyReferences, a => a.GetType(template.className), out errorMessages); #if CODEGEN_TIMING sw.Stop(); Console.WriteLine("Time to generate and instantiate a IOOEJ operator: {0}ms", sw.ElapsedMilliseconds); @@ -176,11 +177,10 @@ internal static Tuple Generate(IntervalArrayObs var expandedCode = template.TransformText(); var assemblyReferences = Transformer.AssemblyReferencesNeededFor(keyType, typeof(TPayload), typeof(TResult)); - assemblyReferences.Add(typeof(IStreamable<,>).GetTypeInfo().Assembly); + assemblyReferences.Add(typeof(IStreamable<,>).Assembly); assemblyReferences.Add(Transformer.GeneratedStreamMessageAssembly()); - var a = Transformer.CompileSourceCode(expandedCode, assemblyReferences, out errorMessages); - var t = a.GetType(template.className); + var t = Transformer.CompileSourceCode(expandedCode, assemblyReferences, a => a.GetType(template.className), out errorMessages); #if CODEGEN_TIMING sw.Stop(); Console.WriteLine("Time to generate and instantiate a IOOEJ operator: {0}ms", sw.ElapsedMilliseconds); @@ -215,11 +215,10 @@ internal static Tuple Generate(PartitionedStreamEv var expandedCode = template.TransformText(); var assemblyReferences = Transformer.AssemblyReferencesNeededFor(keyType, typeof(TPayload)); - assemblyReferences.Add(typeof(IStreamable<,>).GetTypeInfo().Assembly); + assemblyReferences.Add(typeof(IStreamable<,>).Assembly); assemblyReferences.Add(Transformer.GeneratedStreamMessageAssembly, TPayload>()); - var a = Transformer.CompileSourceCode(expandedCode, assemblyReferences, out errorMessages); - var t = a.GetType(template.className); + var t = Transformer.CompileSourceCode(expandedCode, assemblyReferences, a => a.GetType(template.className), out errorMessages); #if CODEGEN_TIMING sw.Stop(); Console.WriteLine("Time to generate and instantiate a IOOEJ operator: {0}ms", sw.ElapsedMilliseconds); @@ -264,11 +263,10 @@ internal static Tuple Generate(Partitione var expandedCode = template.TransformText(); var assemblyReferences = Transformer.AssemblyReferencesNeededFor(keyType, typeof(TPayload), typeof(TResult)); - assemblyReferences.Add(typeof(IStreamable<,>).GetTypeInfo().Assembly); + assemblyReferences.Add(typeof(IStreamable<,>).Assembly); assemblyReferences.Add(Transformer.GeneratedStreamMessageAssembly, TPayload>()); - var a = Transformer.CompileSourceCode(expandedCode, assemblyReferences, out errorMessages); - var t = a.GetType(template.className); + var t = Transformer.CompileSourceCode(expandedCode, assemblyReferences, a => a.GetType(template.className), out errorMessages); #if CODEGEN_TIMING sw.Stop(); Console.WriteLine("Time to generate and instantiate a IOOEJ operator: {0}ms", sw.ElapsedMilliseconds); @@ -314,11 +312,10 @@ internal static Tuple Generate(Partitione var expandedCode = template.TransformText(); var assemblyReferences = Transformer.AssemblyReferencesNeededFor(keyType, typeof(TPayload), typeof(TResult)); - assemblyReferences.Add(typeof(IStreamable<,>).GetTypeInfo().Assembly); + assemblyReferences.Add(typeof(IStreamable<,>).Assembly); assemblyReferences.Add(Transformer.GeneratedStreamMessageAssembly, TPayload>()); - var a = Transformer.CompileSourceCode(expandedCode, assemblyReferences, out errorMessages); - var t = a.GetType(template.className); + var t = Transformer.CompileSourceCode(expandedCode, assemblyReferences, a => a.GetType(template.className), out errorMessages); #if CODEGEN_TIMING sw.Stop(); Console.WriteLine("Time to generate and instantiate a IOOEJ operator: {0}ms", sw.ElapsedMilliseconds); diff --git a/Sources/Core/Microsoft.StreamProcessing/Events/StreamEvent.cs b/Sources/Core/Microsoft.StreamProcessing/Events/StreamEvent.cs index 56de09c78..7cd198808 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Events/StreamEvent.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Events/StreamEvent.cs @@ -21,7 +21,7 @@ public int Compare(StreamEvent x, StreamEvent y) /// /// Type of payload for the event [DataContract] - public struct StreamEvent + public readonly struct StreamEvent { /// @@ -32,7 +32,7 @@ public struct StreamEvent /// For a punctuation, sync-time is set to the timetamp of the punctuation, while other-time is set to a negative value /// [DataMember] - internal long SyncTime; + internal readonly long SyncTime; /// /// End-time for the event @@ -42,13 +42,13 @@ public struct StreamEvent /// For a punctuation, sync-time is set to the timetamp of the punctuation, while other-time is set to a negative value /// [DataMember] - internal long OtherTime; + internal readonly long OtherTime; /// /// Payload of the event /// [DataMember] - public TPayload Payload; + public readonly TPayload Payload; /// /// Kind of the event @@ -139,20 +139,15 @@ public StreamEvent(long syncTime, long otherTime, TPayload payload) /// A string representing the event for display public override string ToString() { - switch (this.Kind) + return this.Kind switch { - case StreamEventKind.Start: - return $"[{this.Kind}: {TimeAsString(this.SyncTime)},{this.Payload}]"; - case StreamEventKind.End: - return $"[{this.Kind}: {TimeAsString(this.SyncTime)},{TimeAsString(this.OtherTime)},{this.Payload}]"; - case StreamEventKind.Interval: - return $"[{this.Kind}: {TimeAsString(this.SyncTime)}-{TimeAsString(this.OtherTime)},{this.Payload}]"; - case StreamEventKind.Punctuation: - return $"[{this.Kind}: {TimeAsString(this.SyncTime)}]"; - case StreamEventKind.LowWatermark: - return $"[{this.Kind}: {TimeAsString(this.SyncTime)}]"; - } - return string.Empty; + StreamEventKind.Start => $"[{this.Kind}: {TimeAsString(this.SyncTime)},{this.Payload}]", + StreamEventKind.End => $"[{this.Kind}: {TimeAsString(this.SyncTime)},{TimeAsString(this.OtherTime)},{this.Payload}]", + StreamEventKind.Interval => $"[{this.Kind}: {TimeAsString(this.SyncTime)}-{TimeAsString(this.OtherTime)},{this.Payload}]", + StreamEventKind.Punctuation => $"[{this.Kind}: {TimeAsString(this.SyncTime)}]", + StreamEventKind.LowWatermark => $"[{this.Kind}: {TimeAsString(this.SyncTime)}]", + _ => string.Empty, + }; } private static string TimeAsString(long t) @@ -178,13 +173,13 @@ public int Compare(PartitionedStreamEvent x, PartitionedStreamEv /// Type of payload for the event /// Type of payload for the event [DataContract] - public struct PartitionedStreamEvent + public readonly struct PartitionedStreamEvent { /// /// Partition key for the event /// [DataMember] - public TKey PartitionKey; + public readonly TKey PartitionKey; /// /// Start-time for the event @@ -194,7 +189,7 @@ public struct PartitionedStreamEvent /// For a punctuation, sync-time is set to the timetamp of the punctuation, while other-time is set to a negative value /// [DataMember] - internal long SyncTime; + internal readonly long SyncTime; /// /// End-time for the event @@ -204,13 +199,13 @@ public struct PartitionedStreamEvent /// For a punctuation, sync-time is set to the timetamp of the punctuation, while other-time is set to a negative value /// [DataMember] - internal long OtherTime; + internal readonly long OtherTime; /// /// Payload of the event /// [DataMember] - public TPayload Payload; + public readonly TPayload Payload; /// /// Kind of the event diff --git a/Sources/Core/Microsoft.StreamProcessing/Events/StreamEvent.tt b/Sources/Core/Microsoft.StreamProcessing/Events/StreamEvent.tt index 5063e5e7b..2d5874167 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Events/StreamEvent.tt +++ b/Sources/Core/Microsoft.StreamProcessing/Events/StreamEvent.tt @@ -41,7 +41,7 @@ namespace Microsoft.StreamProcessing <# } #> /// Type of payload for the event [DataContract] - public struct <#= classNames[i] #><<#= genericParameters[i] #>> + public readonly struct <#= classNames[i] #><<#= genericParameters[i] #>> { <# if (partitioned) { #> @@ -49,7 +49,7 @@ namespace Microsoft.StreamProcessing /// Partition key for the event /// [DataMember] - public TKey PartitionKey; + public readonly TKey PartitionKey; <# } #> /// @@ -60,7 +60,7 @@ namespace Microsoft.StreamProcessing /// For a punctuation, sync-time is set to the timetamp of the punctuation, while other-time is set to a negative value /// [DataMember] - internal long SyncTime; + internal readonly long SyncTime; /// /// End-time for the event @@ -70,13 +70,13 @@ namespace Microsoft.StreamProcessing /// For a punctuation, sync-time is set to the timetamp of the punctuation, while other-time is set to a negative value /// [DataMember] - internal long OtherTime; + internal readonly long OtherTime; /// /// Payload of the event /// [DataMember] - public TPayload Payload; + public readonly TPayload Payload; /// /// Kind of the event diff --git a/Sources/Core/Microsoft.StreamProcessing/Fusible/FuseModule.cs b/Sources/Core/Microsoft.StreamProcessing/Fusible/FuseModule.cs index 34b45a8a4..e62ed49db 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Fusible/FuseModule.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Fusible/FuseModule.cs @@ -19,20 +19,20 @@ internal static class PlaceholderMethod internal sealed class FuseModule { - private readonly List expressions = new List(); + private readonly List expressions = []; private Expression durationAdjustment = null; public FuseModule() { } private FuseModule(FuseModule that) { - this.expressions = new List(that.expressions.Select(o => o.Clone())); + this.expressions = [.. that.expressions.Select(o => o.Clone())]; this.durationAdjustment = that.durationAdjustment; } public bool Any => this.expressions.Count > 0; - public FuseModule Clone() => new FuseModule(this); + public FuseModule Clone() => new(this); public Expression[] GetCodeGenExpressions() => this.expressions.Select(profile => (Expression)profile.expression).ToArray(); @@ -50,7 +50,7 @@ public FuseModule FuseSelect(Expression(Expression(Expression(Expression(); + : []; IEnumerable keyParameter; if (prev.hasKey) { - var key = prev.expression.Parameters[prev.expression.Parameters.Count - 2]; + var key = prev.expression.Parameters[^2]; body = ParameterSubstituter.Replace(selector.Parameters[0], key, body); keyParameter = key.Yield(); } @@ -201,7 +201,7 @@ public FuseModule FuseSelectWithKey(Expression(Expression keyParameter; if (prev.hasKey) { - var key = prev.expression.Parameters[prev.expression.Parameters.Count - 2]; + var key = prev.expression.Parameters[^2]; body = ParameterSubstituter.Replace(selector.Parameters[1], key, body); keyParameter = key.Yield(); } @@ -265,7 +265,7 @@ public FuseModule FuseSelectMany(Expression(Expression(Expression(Expression(); + : []; IEnumerable keyParameter; if (prev.hasKey) { - var key = prev.expression.Parameters[prev.expression.Parameters.Count - 2]; + var key = prev.expression.Parameters[^2]; body = ParameterSubstituter.Replace(selector.Parameters[0], key, body); keyParameter = key.Yield(); } @@ -417,7 +417,7 @@ public FuseModule FuseSelectManyWithKey(Expression(Expression keyParameter; if (prev.hasKey) { - var key = prev.expression.Parameters[prev.expression.Parameters.Count - 2]; + var key = prev.expression.Parameters[^2]; body = ParameterSubstituter.Replace(selector.Parameters[1], key, body); keyParameter = key.Yield(); } @@ -471,7 +471,7 @@ public FuseModule FuseSelectManyWithKey(Expression(Expression> expression) { - if (this.expressions.Count == 0 || this.expressions[this.expressions.Count - 1].category != ExpressionCategory.Where) + if (this.expressions.Count == 0 || this.expressions[^1].category != ExpressionCategory.Where) { this.expressions.Add(new ExpressionProfile { @@ -483,7 +483,7 @@ public FuseModule FuseWhere(Expression> expressio return this; } - var prev = this.expressions[this.expressions.Count - 1]; + var prev = this.expressions[^1]; var parameter = prev.expression.Parameters[0]; var replaced = expression.ReplaceParametersInBody(parameter); prev.expression = Expression.Lambda>(Expression.AndAlso(prev.expression.Body, replaced), parameter); @@ -502,6 +502,8 @@ public FuseModule FuseSetDurationConstant(long value) public bool IsEmpty => this.expressions.Count == 0 && this.durationAdjustment == null; + public bool HasDurationAdjustment => this.durationAdjustment != null; + public override string ToString() { string output = string.Empty; @@ -544,11 +546,11 @@ public Expression> Coalesce> Coalesce> Coalesce).GetTypeInfo().MakeGenericType(profile.outputType); - var enumeratorType = typeof(IEnumerator<>).GetTypeInfo().MakeGenericType(profile.outputType); - var enumeratorMethod = enumerableType.GetTypeInfo().GetMethod("GetEnumerator"); + var enumerableType = typeof(IEnumerable<>).MakeGenericType(profile.outputType); + var enumeratorType = typeof(IEnumerator<>).MakeGenericType(profile.outputType); + var enumeratorMethod = enumerableType.GetMethod("GetEnumerator"); var enumeratorParameter = Expression.Variable(enumeratorType, enumerableParameter.Name + "Enumerator"); - var moveNextMethod = typeof(IEnumerator).GetTypeInfo().GetMethod("MoveNext"); - var disposeMethod = typeof(IDisposable).GetTypeInfo().GetMethod("Dispose"); + var moveNextMethod = typeof(IEnumerator).GetMethod("MoveNext"); + var disposeMethod = typeof(IDisposable).GetMethod("Dispose"); currentStatement = Expression.Block( - new[] { enumerableParameter, enumeratorParameter }, + [enumerableParameter, enumeratorParameter], Expression.Assign(enumerableParameter, selectManyBody), Expression.Assign(enumeratorParameter, Expression.Call(enumerableParameter, enumeratorMethod)), Expression.Loop( Expression.Block( - new[] { oldParameter }, + [oldParameter], Expression.IfThen( Expression.Not(Expression.Call(enumeratorParameter, moveNextMethod)), Expression.Break(label)), @@ -648,15 +650,15 @@ public Expression> Coalesce(string startText, string endText, string payloadText, string keyText, out string leadingText, out string trailingText) { Expression> placeholder = (generatedStartTimeVariable, generatedEndTimeVariable, transformedValue, generatedKeyVariable) => PlaceholderMethod.Foo(); - var c = Coalesce(placeholder, false); - var strings = c.Body.ExpressionToCSharp().Split(new string[] { PlaceholderMethod.Text }, StringSplitOptions.None); + var c = this.Coalesce(placeholder, false); + var strings = c.Body.ExpressionToCSharp().Split([PlaceholderMethod.Text], StringSplitOptions.None); var start = "var " + c.Parameters[0].Name + " = " + startText + ";"; var end = "var " + c.Parameters[1].Name + " = " + endText + ";"; var payload = "var " + c.Parameters[2].Name + " = " + payloadText + ";"; var key = "var " + c.Parameters[3].Name + " = " + keyText + ";"; leadingText = string.Join(Environment.NewLine, start, end, payload, key, strings[0]); trailingText = strings[1]; - if (trailingText[0] == ';') trailingText = trailingText.Substring(1).Trim(); + if (trailingText[0] == ';') trailingText = trailingText[1..].Trim(); return placeholder.Parameters[2].Name; } } diff --git a/Sources/Core/Microsoft.StreamProcessing/Fusible/FusedObservable.cs b/Sources/Core/Microsoft.StreamProcessing/Fusible/FusedObservable.cs index 9e3739e91..cc046ecb5 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Fusible/FusedObservable.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Fusible/FusedObservable.cs @@ -49,7 +49,7 @@ public FusedObservable( this.container = container; this.ingressIdentifier = ingressIdentifier; this.egressIdentifier = egressIdentifier; - if (this.container != null) this.container.RegisterEgressSite(egressIdentifier); + this.container?.RegisterEgressSite(egressIdentifier); } public IDisposable Subscribe(IObserver observer) @@ -64,7 +64,7 @@ public IDisposable Subscribe(IObserver observer) Expression onNextPunctuation; var baseType = typeof(TOutput); - if (baseType.GetTypeInfo().IsGenericType) baseType = baseType.GetGenericTypeDefinition(); + if (baseType.IsGenericType) baseType = baseType.GetGenericTypeDefinition(); onNextPunctuation = baseType == typeof(StreamEvent<>) || baseType == typeof(PartitionedStreamEvent<,>) ? Expression.IfThenElse( @@ -75,18 +75,46 @@ public IDisposable Subscribe(IObserver observer) Expression.NotEqual(onNextFused.Parameters[1], Expression.Constant(long.MinValue)), onNextFused.Body); - var onNextReplacedParameters = ParameterSubstituter.Replace( - onNextFused.Parameters, - onNextPunctuation, - this.startEdgeExtractor.Body, - this.endEdgeExtractor.Body, - this.payloadExtractor.Body, - this.keyExtractor.Body); + Expression> onNextFinal; + if (this.fuseModule.HasDurationAdjustment) + { + // Use a mutable local for the end time so that Assign(otherParam, ...) generated + // by FuseModule.Coalesce for duration adjustments compiles correctly even when + // the end-edge extractor targets a readonly field (e.g. StreamEvent.OtherTime). + var otherLocal = Expression.Variable(typeof(long), "_other"); + var onNextReplacedParameters = ParameterSubstituter.Replace( + onNextFused.Parameters, + onNextPunctuation, + this.startEdgeExtractor.Body, + otherLocal, + this.payloadExtractor.Body, + this.keyExtractor.Body); - var onNextFinal = Expression.Lambda>(onNextReplacedParameters, this.inputParameter); + onNextFinal = Expression.Lambda>( + Expression.Block( + [otherLocal], + Expression.Assign(otherLocal, this.endEdgeExtractor.Body), + onNextReplacedParameters + ), + this.inputParameter + ); + } + else + { + // No duration adjustment — no Assign(otherParam) is generated by Coalesce, so we + // can substitute the end-edge extractor body directly without a mutable local. + var onNextReplacedParameters = ParameterSubstituter.Replace( + onNextFused.Parameters, + onNextPunctuation, + this.startEdgeExtractor.Body, + this.endEdgeExtractor.Body, + this.payloadExtractor.Body, + this.keyExtractor.Body); + onNextFinal = Expression.Lambda>(onNextReplacedParameters, this.inputParameter); + } var pipe = new FusedObservablePipe(observer.OnCompleted, observer.OnError, onNextFinal.Compile(), this.ingressIdentifier); - if (this.container != null) this.container.RegisterEgressPipe(this.egressIdentifier, pipe); + this.container?.RegisterEgressPipe(this.egressIdentifier, pipe); return this.observable.Subscribe(pipe); } } diff --git a/Sources/Core/Microsoft.StreamProcessing/Fusible/FusedObservablePipe.cs b/Sources/Core/Microsoft.StreamProcessing/Fusible/FusedObservablePipe.cs index 0bce072bb..1eba29aac 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Fusible/FusedObservablePipe.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Fusible/FusedObservablePipe.cs @@ -5,64 +5,57 @@ using System; using System.IO; -namespace Microsoft.StreamProcessing +namespace Microsoft.StreamProcessing; + +internal sealed class FusedObservablePipe( + Action onCompleted, + Action onError, + Action onNext, + string ingressIdentifier +) : IObserver, IIngressStreamObserver, IEgressStreamObserver { - internal sealed class FusedObservablePipe : IObserver, IIngressStreamObserver, IEgressStreamObserver - { - private readonly Action onCompleted; - private readonly Action onError; - private readonly Action onNext; - private string egressIdentifier; - private Process activeProcess; - - public FusedObservablePipe(Action onCompleted, Action onError, Action onNext, string ingressIdentifier) - { - this.onCompleted = onCompleted; - this.onError = onError; - this.onNext = onNext; - this.IngressSiteIdentifier = ingressIdentifier; - } + private string egressIdentifier; + private Process activeProcess; - public Guid ClassId { get; } = Guid.NewGuid(); + public Guid ClassId { get; } = Guid.NewGuid(); - public int CurrentlyBufferedOutputCount => 0; + public int CurrentlyBufferedOutputCount => 0; - public int CurrentlyBufferedInputCount => 0; + public int CurrentlyBufferedInputCount => 0; - public int CurrentlyBufferedReorderCount => 0; + public int CurrentlyBufferedReorderCount => 0; - public int CurrentlyBufferedStartEdgeCount => 0; + public int CurrentlyBufferedStartEdgeCount => 0; - public string IngressSiteIdentifier { get; } + public string IngressSiteIdentifier => ingressIdentifier; - public IDisposable DelayedDisposable => Utility.EmptyDisposable; + public IDisposable DelayedDisposable => Utility.EmptyDisposable; - public void AttachProcess(string identifier, Process p) - { - this.egressIdentifier = identifier; - this.activeProcess = p; - } + public void AttachProcess(string identifier, Process p) + { + this.egressIdentifier = identifier; + this.activeProcess = p; + } - public void Checkpoint(Stream stream) { } + public void Checkpoint(Stream stream) { } - public void Dispose() { } + public void Dispose() { } - public void OnFlush() { } + public void OnFlush() { } - public void Enable() { } + public void Enable() { } - public void OnCompleted() => this.onCompleted(); + public void OnCompleted() => onCompleted(); - public void OnError(Exception error) => this.onError(error); + public void OnError(Exception error) => onError(error); - public void OnNext(TInput value) => this.onNext(value); + public void OnNext(TInput value) => onNext(value); - public void ProduceQueryPlan(PlanNode previous) - => this.activeProcess.RegisterQueryPlan(this.egressIdentifier, new FusedPlanNode( - this, typeof(Empty), typeof(TInput), false, null)); + public void ProduceQueryPlan(PlanNode previous) + => this.activeProcess.RegisterQueryPlan(this.egressIdentifier, new FusedPlanNode( + this, typeof(Empty), typeof(TInput), false, null)); - public void Reset() { } + public void Reset() { } - public void Restore(Stream stream) { } - } + public void Restore(Stream stream) { } } diff --git a/Sources/Core/Microsoft.StreamProcessing/Fusible/FusedPlanNode.cs b/Sources/Core/Microsoft.StreamProcessing/Fusible/FusedPlanNode.cs index d47f7516c..9fa69ddf9 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Fusible/FusedPlanNode.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Fusible/FusedPlanNode.cs @@ -28,7 +28,7 @@ internal override void CollectDormantIngressSites(Dictionary diff --git a/Sources/Core/Microsoft.StreamProcessing/Ingress/Atemporal/AtemporalIngressStreamable.cs b/Sources/Core/Microsoft.StreamProcessing/Ingress/Atemporal/AtemporalIngressStreamable.cs index 5545a4268..e22c8431b 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Ingress/Atemporal/AtemporalIngressStreamable.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Ingress/Atemporal/AtemporalIngressStreamable.cs @@ -29,8 +29,8 @@ public MonotonicIngressStreamable( ? StreamProperties.Default.ToRowBased() : StreamProperties.Default).ToConstantDuration(true, StreamEvent.InfinitySyncTime).SetQueryContainer(container)) { - Contract.Requires(observable != null); - Contract.Requires(identifier != null); + ArgumentNullException.ThrowIfNull(observable); + ArgumentNullException.ThrowIfNull(identifier); this.IngressSiteIdentifier = identifier; this.observable = observable; diff --git a/Sources/Core/Microsoft.StreamProcessing/Ingress/Atemporal/AtemporalIngressSubscription.cs b/Sources/Core/Microsoft.StreamProcessing/Ingress/Atemporal/AtemporalIngressSubscription.cs index 3f0a721c8..5076d4b6d 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Ingress/Atemporal/AtemporalIngressSubscription.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Ingress/Atemporal/AtemporalIngressSubscription.cs @@ -13,7 +13,7 @@ namespace Microsoft.StreamProcessing [DataContract] internal sealed class MonotonicSubscriptionWallClock : ObserverSubscriptionBase { - private readonly object sentinel = new object(); + private readonly object sentinel = new(); private IDisposable timer; public MonotonicSubscriptionWallClock() { } @@ -39,18 +39,15 @@ public MonotonicSubscriptionWallClock( null) { if (timelinePolicy.punctuationInterval > default(TimeSpan)) - this.timer = new Timer(EmitPunctuation, null, new TimeSpan(0), timelinePolicy.punctuationInterval); + this.timer = new Timer(this.EmitPunctuation, null, new TimeSpan(0), timelinePolicy.punctuationInterval); } public override void OnCompleted() { lock (this.sentinel) { - if (this.timer != null) - { - this.timer.Dispose(); - this.timer = null; - } + this.timer?.Dispose(); + this.timer = null; base.OnCompleted(); } @@ -64,7 +61,7 @@ public override void OnNext(TPayload value) this.currentTime = Math.Max(DateTimeOffset.UtcNow.Ticks, this.currentTime); this.currentBatch.Add(this.currentTime, StreamEvent.InfinitySyncTime, Empty.Default, value); - if (this.currentBatch.Count == Config.DataBatchSize) FlushContents(); + if (this.currentBatch.Count == Config.DataBatchSize) this.FlushContents(); } } @@ -76,7 +73,7 @@ private void EmitPunctuation(object state) { var time = DateTimeOffset.UtcNow.Ticks; this.currentTime = Math.Max(time, this.currentTime); - OnPunctuation(StreamEvent.CreatePunctuation(this.currentTime)); + this.OnPunctuation(StreamEvent.CreatePunctuation(this.currentTime)); } } } @@ -85,11 +82,8 @@ protected override void DisposeState() { lock (this.sentinel) { - if (this.timer != null) - { - this.timer.Dispose(); - this.timer = null; - } + this.timer?.Dispose(); + this.timer = null; base.DisposeState(); } @@ -97,10 +91,10 @@ protected override void DisposeState() protected override void OnCompleted(long punctuationTime) { - FlushContents(); - OnPunctuation(StreamEvent.CreatePunctuation(punctuationTime)); + this.FlushContents(); + this.OnPunctuation(StreamEvent.CreatePunctuation(punctuationTime)); if (this.flushPolicy != FlushPolicy.FlushOnPunctuation) - OnFlush(); + this.OnFlush(); } } @@ -143,7 +137,7 @@ public override void OnNext(TPayload value) Contract.EnsuresOnThrow(true); this.currentBatch.Add(this.currentTime, StreamEvent.InfinitySyncTime, Empty.Default, value); - if (this.currentBatch.Count == Config.DataBatchSize) FlushContents(); + if (this.currentBatch.Count == Config.DataBatchSize) this.FlushContents(); this.eventCount++; if (this.eventCount == this.eventsPerSample) @@ -151,17 +145,17 @@ public override void OnNext(TPayload value) this.eventCount = 0; this.currentTime++; - FlushContents(); - OnPunctuation(StreamEvent.CreatePunctuation(this.currentTime)); + this.FlushContents(); + this.OnPunctuation(StreamEvent.CreatePunctuation(this.currentTime)); } } protected override void OnCompleted(long punctuationTime) { - FlushContents(); - OnPunctuation(StreamEvent.CreatePunctuation(punctuationTime)); + this.FlushContents(); + this.OnPunctuation(StreamEvent.CreatePunctuation(punctuationTime)); if (this.flushPolicy != FlushPolicy.FlushOnPunctuation) - OnFlush(); + this.OnFlush(); } } diff --git a/Sources/Core/Microsoft.StreamProcessing/Ingress/AtemporalArray/AtemporalArrayIngressStreamable.cs b/Sources/Core/Microsoft.StreamProcessing/Ingress/AtemporalArray/AtemporalArrayIngressStreamable.cs index 362490d39..87016b09b 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Ingress/AtemporalArray/AtemporalArrayIngressStreamable.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Ingress/AtemporalArray/AtemporalArrayIngressStreamable.cs @@ -25,8 +25,8 @@ public MonotonicArrayIngressStreamable( ? StreamProperties.Default.ToRowBased() : StreamProperties.Default).ToConstantDuration(true, StreamEvent.InfinitySyncTime).SetQueryContainer(container)) { - Contract.Requires(observable != null); - Contract.Requires(identifier != null); + ArgumentNullException.ThrowIfNull(observable); + ArgumentNullException.ThrowIfNull(identifier); this.IngressSiteIdentifier = identifier; this.observable = observable; diff --git a/Sources/Core/Microsoft.StreamProcessing/Ingress/AtemporalArray/AtemporalArrayIngressSubscription.cs b/Sources/Core/Microsoft.StreamProcessing/Ingress/AtemporalArray/AtemporalArrayIngressSubscription.cs index f67c7e0bd..5febe1cbd 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Ingress/AtemporalArray/AtemporalArrayIngressSubscription.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Ingress/AtemporalArray/AtemporalArrayIngressSubscription.cs @@ -60,15 +60,15 @@ public override void OnNext(ArraySegment value) if (full) { System.Array.Clear(this.currentBatch.hash.col, 0, this.currentBatch.hash.col.Length); - FlushContents(); + this.FlushContents(); } } } protected override void OnCompleted(long punctuationTime) { - FlushContents(); - OnPunctuation(StreamEvent.CreatePunctuation(punctuationTime)); + this.FlushContents(); + this.OnPunctuation(StreamEvent.CreatePunctuation(punctuationTime)); } } @@ -132,21 +132,21 @@ public override void OnNext(ArraySegment value) { var current = StreamEvent.CreatePunctuation(this.currentTime); System.Array.Clear(this.currentBatch.hash.col, 0, this.currentBatch.hash.col.Length); - OnPunctuation(current); + this.OnPunctuation(current); offset++; } else if (full) { System.Array.Clear(this.currentBatch.hash.col, 0, this.currentBatch.hash.col.Length); - FlushContents(); + this.FlushContents(); } } } protected override void OnCompleted(long punctuationTime) { - FlushContents(); - OnPunctuation(StreamEvent.CreatePunctuation(punctuationTime)); + this.FlushContents(); + this.OnPunctuation(StreamEvent.CreatePunctuation(punctuationTime)); } } diff --git a/Sources/Core/Microsoft.StreamProcessing/Ingress/Binary/BinaryIngressReader.cs b/Sources/Core/Microsoft.StreamProcessing/Ingress/Binary/BinaryIngressReader.cs index ee54665e6..b8dc9c503 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Ingress/Binary/BinaryIngressReader.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Ingress/Binary/BinaryIngressReader.cs @@ -48,9 +48,9 @@ public override void ProduceQueryPlan(PlanNode previous) protected override IDisposable Action(IStreamObserver observer) { if (this.scheduler == null) - Ingress(observer); // ingress data on current thread + this.Ingress(observer); // ingress data on current thread else - this.scheduler.Schedule(() => Ingress(observer)); // ingress data on user-specified scheduler + this.scheduler.Schedule(() => this.Ingress(observer)); // ingress data on user-specified scheduler return Utility.EmptyDisposable; } diff --git a/Sources/Core/Microsoft.StreamProcessing/Ingress/Binary/BinaryIngressStreamable.cs b/Sources/Core/Microsoft.StreamProcessing/Ingress/Binary/BinaryIngressStreamable.cs index b74f30b7f..0501ae161 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Ingress/Binary/BinaryIngressStreamable.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Ingress/Binary/BinaryIngressStreamable.cs @@ -71,7 +71,7 @@ public override IDisposable Subscribe(IStreamObserver observer) this.subscriptionActive = true; var subscription = new BinaryIngressReader( - this.IngressSiteIdentifier, this, observer, this.numMessages, this.stream, this.scheduler, this.delayed, OnSubscriptionCompleted); + this.IngressSiteIdentifier, this, observer, this.numMessages, this.stream, this.scheduler, this.delayed, this.OnSubscriptionCompleted); if (this.delayed) { diff --git a/Sources/Core/Microsoft.StreamProcessing/Ingress/Binary/BinaryIngressStreamablePassive.cs b/Sources/Core/Microsoft.StreamProcessing/Ingress/Binary/BinaryIngressStreamablePassive.cs index c05b2e5f6..f52491e50 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Ingress/Binary/BinaryIngressStreamablePassive.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Ingress/Binary/BinaryIngressStreamablePassive.cs @@ -55,7 +55,7 @@ public BinaryIngressStreamablePassive(Stream binaryStream, StreamProperties(StreamProperties props) - => new SerializedProperties + => new() { IsColumnar = props.IsColumnar, IsConstantDuration = props.IsConstantDuration, @@ -27,13 +27,13 @@ public static SerializedProperties FromStreamProperties(StreamPr }; public StreamProperties ToStreamProperties() - => new StreamProperties(this.IsColumnar, this.IsConstantDuration, this.ConstantDurationLength, this.IsConstantHop, this.ConstantHopLength, this.ConstantHopOffset, this.IsIntervalFree, this.IsSyncTimeSimultaneityFree, + => new(this.IsColumnar, this.IsConstantDuration, this.ConstantDurationLength, this.IsConstantHop, this.ConstantHopLength, this.ConstantHopOffset, this.IsIntervalFree, this.IsSyncTimeSimultaneityFree, false, this.IsEventOverlappingFree, EqualityComparerExpression.Default, EqualityComparerExpression.Default, null, null, - new Dictionary(), - new Dictionary(), + [], + [], null); public bool IsColumnar; diff --git a/Sources/Core/Microsoft.StreamProcessing/Ingress/DiagnosticObservable.cs b/Sources/Core/Microsoft.StreamProcessing/Ingress/DiagnosticObservable.cs index c5fb8f4c3..8b3904745 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Ingress/DiagnosticObservable.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Ingress/DiagnosticObservable.cs @@ -10,7 +10,7 @@ namespace Microsoft.StreamProcessing { internal sealed class DiagnosticObservable : IObservable>, IObserver>, IDisposable { - private List>> observers = new List>>(); + private List>> observers = []; public IDisposable Subscribe(IObserver> observer) { @@ -78,12 +78,13 @@ public static class OutOfOrderStreamEvent /// The amount of time that the event was out of order. /// public static OutOfOrderStreamEvent Create(StreamEvent e, long? delta) - => new OutOfOrderStreamEvent { Event = e, TimeAdjustment = delta }; + => new() + { Event = e, TimeAdjustment = delta }; } internal sealed class PartitionedDiagnosticObservable : IObservable>, IObserver>, IDisposable { - private List>> observers = new List>>(); + private List>> observers = []; public IDisposable Subscribe(IObserver> observer) { @@ -153,7 +154,8 @@ public static class OutOfOrderPartitionedStreamEvent /// The amount of time that the event was out of order. /// public static OutOfOrderPartitionedStreamEvent Create(PartitionedStreamEvent e, long? delta) - => new OutOfOrderPartitionedStreamEvent { Event = e, TimeAdjustment = delta }; + => new() + { Event = e, TimeAdjustment = delta }; } } \ No newline at end of file diff --git a/Sources/Core/Microsoft.StreamProcessing/Ingress/ImpatienceSorter.cs b/Sources/Core/Microsoft.StreamProcessing/Ingress/ImpatienceSorter.cs index d260f3fe8..d32469791 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Ingress/ImpatienceSorter.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Ingress/ImpatienceSorter.cs @@ -35,7 +35,7 @@ public sealed class ImpatienceSorter : IDisposable private DataStructurePool>> ecbPool; private List>> toReturn = - new List>>(); + []; /// /// Currently for internal use only - do not use directly. @@ -44,7 +44,7 @@ public sealed class ImpatienceSorter : IDisposable public ImpatienceSorter() { this.Tails = new long[this.MaxFibers]; - this.Fibers = new List>>(); + this.Fibers = []; this.MergeSource = new PooledElasticCircularBuffer>[this.MaxFibers]; this.NextAffectingSyncTime = StreamEvent.InfinitySyncTime; this.ecbPool = new DataStructurePool>>(); @@ -62,7 +62,7 @@ public void Enqueue(ref StreamEvent streamEvent) if (streamEvent.SyncTime >= this.Tails[0]) loc = 0; else - loc = BinarySearch(streamEvent.SyncTime); + loc = this.BinarySearch(streamEvent.SyncTime); // Add a new queue if (loc == this.NumFibers) @@ -414,6 +414,8 @@ public void Dispose() { this.sorters.entries[index].value.Dispose(); } + + this.sorters.Dispose(); } /// @@ -442,7 +444,7 @@ private sealed class ImpatienceSorter : IDisposable private DataStructurePool>> ecbPool; private List>> toReturn = - new List>>(); + []; /// /// Currently for internal use only - do not use directly. @@ -451,7 +453,7 @@ private sealed class ImpatienceSorter : IDisposable public ImpatienceSorter() { this.Tails = new long[this.MaxFibers]; - this.Fibers = new List>>(); + this.Fibers = []; this.MergeSource = new PooledElasticCircularBuffer>[this.MaxFibers]; this.NextAffectingSyncTime = StreamEvent.InfinitySyncTime; this.ecbPool = new DataStructurePool>>(); @@ -469,7 +471,7 @@ public void Enqueue(ref PartitionedStreamEvent streamEvent) if (streamEvent.SyncTime >= this.Tails[0]) loc = 0; else - loc = BinarySearch(streamEvent.SyncTime); + loc = this.BinarySearch(streamEvent.SyncTime); // Add a new queue if (loc == this.NumFibers) diff --git a/Sources/Core/Microsoft.StreamProcessing/Ingress/Policies/DisorderPolicy.cs b/Sources/Core/Microsoft.StreamProcessing/Ingress/Policies/DisorderPolicy.cs index 472927cbc..ef8bff7d5 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Ingress/Policies/DisorderPolicy.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Ingress/Policies/DisorderPolicy.cs @@ -47,7 +47,7 @@ internal DisorderPolicy(DisorderPolicyType type, long reorderLatency) /// events are well-ordered. /// /// An instance of the disorder policy - public static DisorderPolicy Throw() => new DisorderPolicy(DisorderPolicyType.Throw); + public static DisorderPolicy Throw() => new(DisorderPolicyType.Throw); /// /// Throw if you see disordered events. Use this when you know that your input @@ -55,14 +55,14 @@ internal DisorderPolicy(DisorderPolicyType type, long reorderLatency) /// /// Tolerable latency bound (in application time) for reordering data at ingress /// An instance of the disorder policy - public static DisorderPolicy Throw(long reorderLatency) => new DisorderPolicy(DisorderPolicyType.Throw, reorderLatency); + public static DisorderPolicy Throw(long reorderLatency) => new(DisorderPolicyType.Throw, reorderLatency); /// /// When an out-of-order event appears in the stream, adjust its /// start time to be the start time of immediately previous event. /// /// An instance of the disorder policy - public static DisorderPolicy Adjust() => new DisorderPolicy(DisorderPolicyType.Adjust); + public static DisorderPolicy Adjust() => new(DisorderPolicyType.Adjust); /// /// When an out-of-order event appears in the stream, adjust its @@ -70,14 +70,14 @@ internal DisorderPolicy(DisorderPolicyType type, long reorderLatency) /// /// Tolerable latency bound (in application time) for reordering data at ingress /// An instance of the disorder policy - public static DisorderPolicy Adjust(long reorderLatency) => new DisorderPolicy(DisorderPolicyType.Adjust, reorderLatency); + public static DisorderPolicy Adjust(long reorderLatency) => new(DisorderPolicyType.Adjust, reorderLatency); /// /// When an out-of-order event appears in the stream, /// drop it and don't include it in the output. /// /// An instance of the disorder policy - public static DisorderPolicy Drop() => new DisorderPolicy(DisorderPolicyType.Drop); + public static DisorderPolicy Drop() => new(DisorderPolicyType.Drop); /// /// When an out-of-order event appears in the stream, @@ -85,7 +85,7 @@ internal DisorderPolicy(DisorderPolicyType type, long reorderLatency) /// /// Tolerable latency bound (in application time) for reordering data at ingress /// An instance of the disorder policy - public static DisorderPolicy Drop(long reorderLatency) => new DisorderPolicy(DisorderPolicyType.Drop, reorderLatency); + public static DisorderPolicy Drop(long reorderLatency) => new(DisorderPolicyType.Drop, reorderLatency); /// /// Determines whether two Disorder Policies have the same constituent parts. diff --git a/Sources/Core/Microsoft.StreamProcessing/Ingress/Policies/PeriodicLowWatermarkPolicy.cs b/Sources/Core/Microsoft.StreamProcessing/Ingress/Policies/PeriodicLowWatermarkPolicy.cs index bcc8ce9d1..76076e0cf 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Ingress/Policies/PeriodicLowWatermarkPolicy.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Ingress/Policies/PeriodicLowWatermarkPolicy.cs @@ -46,7 +46,7 @@ internal PeriodicLowWatermarkPolicy(PeriodicLowWatermarkPolicyType type, ulong g /// Don't inject any low watermarks. This is the default policy. /// /// An instance of PeriodicLowWatermarkPolicy - public static PeriodicLowWatermarkPolicy None() => new PeriodicLowWatermarkPolicy(); + public static PeriodicLowWatermarkPolicy None() => new(); /// /// Inject low watermarks every time ticks, rounded down to the previous @@ -65,10 +65,7 @@ public static PeriodicLowWatermarkPolicy Time(ulong generationPeriod, ulong lowW { Contract.Requires(lowWatermarkTimestampLag <= long.MaxValue); - if (lowWatermarkTimestampLag > long.MaxValue) - { - throw new ArgumentOutOfRangeException(nameof(lowWatermarkTimestampLag)); - } + ArgumentOutOfRangeException.ThrowIfGreaterThan(lowWatermarkTimestampLag, long.MaxValue); return new PeriodicLowWatermarkPolicy(PeriodicLowWatermarkPolicyType.Time, generationPeriod, (long)lowWatermarkTimestampLag); } @@ -86,15 +83,12 @@ public override int GetHashCode() /// A string representation for the PeriodicLowWatermarkPolicy object. public override string ToString() { - switch (this.type) + return this.type switch { - case PeriodicLowWatermarkPolicyType.None: - return "PeriodicLowWatermarkPolicy.None"; - case PeriodicLowWatermarkPolicyType.Time: - return $"PeriodicLowWatermarkPolicy.Time({this.generationPeriod}, {this.lowWatermarkTimestampLag})"; - default: - return "Unknown PeriodicLowWatermarkPolicy (" + this.type.ToString() + ")"; - } + PeriodicLowWatermarkPolicyType.None => "PeriodicLowWatermarkPolicy.None", + PeriodicLowWatermarkPolicyType.Time => $"PeriodicLowWatermarkPolicy.Time({this.generationPeriod}, {this.lowWatermarkTimestampLag})", + _ => "Unknown PeriodicLowWatermarkPolicy (" + this.type.ToString() + ")", + }; } } } \ No newline at end of file diff --git a/Sources/Core/Microsoft.StreamProcessing/Ingress/Policies/PeriodicPunctuationPolicy.cs b/Sources/Core/Microsoft.StreamProcessing/Ingress/Policies/PeriodicPunctuationPolicy.cs index aeb658f7d..18b910c50 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Ingress/Policies/PeriodicPunctuationPolicy.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Ingress/Policies/PeriodicPunctuationPolicy.cs @@ -43,7 +43,7 @@ internal PeriodicPunctuationPolicy(PeriodicPunctuationPolicyType type, ulong gen /// /// An instance of the punctuation policy public static PeriodicPunctuationPolicy None() - => new PeriodicPunctuationPolicy(PeriodicPunctuationPolicyType.None, 0); + => new(PeriodicPunctuationPolicyType.None, 0); /// /// Inject punctuations every time ticks, rounded down to the previous diff --git a/Sources/Core/Microsoft.StreamProcessing/Ingress/Policies/TimelinePolicy.cs b/Sources/Core/Microsoft.StreamProcessing/Ingress/Policies/TimelinePolicy.cs index d7c7629eb..ded9521be 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Ingress/Policies/TimelinePolicy.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Ingress/Policies/TimelinePolicy.cs @@ -50,7 +50,7 @@ internal TimelinePolicy(TimelineEnum timelineEnum) /// Describes how much time should progress before creating a punctuation event and flushing contents. /// A policy object to be used in ingress methods. public static TimelinePolicy WallClock(TimeSpan punctuationInterval = default) - => new TimelinePolicy(TimelineEnum.WallClock) { punctuationInterval = punctuationInterval }; + => new(TimelineEnum.WallClock) { punctuationInterval = punctuationInterval }; /// /// Create a new Timeline Policy based on assigning temporal values to events based on a monotonically increasing counter. diff --git a/Sources/Core/Microsoft.StreamProcessing/Ingress/StreamMessage/StreamMessageIngress.cs b/Sources/Core/Microsoft.StreamProcessing/Ingress/StreamMessage/StreamMessageIngress.cs index 757fc3ae5..b13e7cde4 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Ingress/StreamMessage/StreamMessageIngress.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Ingress/StreamMessage/StreamMessageIngress.cs @@ -15,7 +15,7 @@ public static partial class Streamable /// internal static IStreamable CreateStreamable(this IObservable> source) { - Contract.Requires(source != null); + ArgumentNullException.ThrowIfNull(source); var p = StreamProperties.Default; if (Config.ForceRowBasedExecution || !typeof(TPayload).CanRepresentAsColumnar()) @@ -29,7 +29,7 @@ internal static IStreamable CreateStreamable(this IOb /// internal static IStreamable RegisterInput(this QueryContainer container, IObservable> source, string identifier = null) { - Contract.Requires(source != null); + ArgumentNullException.ThrowIfNull(source); var p = StreamProperties.Default; if (Config.ForceRowBasedExecution || !typeof(TPayload).CanRepresentAsColumnar()) diff --git a/Sources/Core/Microsoft.StreamProcessing/Ingress/StreamMessage/StreamMessageIngressStreamable.cs b/Sources/Core/Microsoft.StreamProcessing/Ingress/StreamMessage/StreamMessageIngressStreamable.cs index ad59be422..16c0f125f 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Ingress/StreamMessage/StreamMessageIngressStreamable.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Ingress/StreamMessage/StreamMessageIngressStreamable.cs @@ -18,7 +18,7 @@ internal sealed class StreamMessageIngressStreamable : Streamable> source, StreamProperties properties, QueryContainer container, string identifier) : base(properties.SetQueryContainer(container)) { - Contract.Requires(source != null); + ArgumentNullException.ThrowIfNull(source); this.source = source; this.container = container; diff --git a/Sources/Core/Microsoft.StreamProcessing/Ingress/StreamMessageIngressBase.cs b/Sources/Core/Microsoft.StreamProcessing/Ingress/StreamMessageIngressBase.cs index ddd9fb767..689d70074 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Ingress/StreamMessageIngressBase.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Ingress/StreamMessageIngressBase.cs @@ -44,7 +44,7 @@ protected StreamMessageIngressBase( public override void Restore(Stream stream) { if (stream != null) base.Restore(stream); - Enable(); + this.Enable(); } public void Enable() => this.subscription.Enable(); @@ -67,12 +67,12 @@ public DelayedSubscription( public void Enable() { this.inner = this.current.Action(this.observer); - if (this.disposed) DisposeInternal(); + if (this.disposed) this.DisposeInternal(); } public void Dispose() { - if (this.inner != null) DisposeInternal(); + if (this.inner != null) this.DisposeInternal(); this.disposed = true; } diff --git a/Sources/Core/Microsoft.StreamProcessing/Ingress/SubscriptionBase.cs b/Sources/Core/Microsoft.StreamProcessing/Ingress/SubscriptionBase.cs index bb48d50f5..4b5d2fc46 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Ingress/SubscriptionBase.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Ingress/SubscriptionBase.cs @@ -67,7 +67,7 @@ protected DisorderedObserverSubscriptionBase( onCompletedPolicy, diagnosticOutput) { - Contract.Requires(observable != null); + ArgumentNullException.ThrowIfNull(observable); this.primaryAction = () => observable.Subscribe(this); } @@ -176,7 +176,7 @@ public abstract class DisorderedSubscriptionBase [EditorBrowsable(EditorBrowsableState.Never)] [DataMember] - protected Dictionary, ElasticCircularBuffer> startEventInformation = new Dictionary, ElasticCircularBuffer>(1); + protected Dictionary, ElasticCircularBuffer> startEventInformation = new(1); /// /// Currently for internal use only - do not use directly. @@ -246,8 +246,8 @@ protected DisorderedSubscriptionBase( IObserver> diagnosticOutput) : base(streamable, observer) { - Contract.Requires(observer != null); - Contract.Requires(punctuationPolicy != null); + ArgumentNullException.ThrowIfNull(observer); + ArgumentNullException.ThrowIfNull(punctuationPolicy); this.IngressSiteIdentifier = identifier; this.disorderString = disorderPolicy.ToString(); @@ -271,7 +271,7 @@ protected DisorderedSubscriptionBase( this.currentBatch.Allocate(); this.errorMessages = streamable.ErrorMessages; - this.subscription = new DelayedSubscription(PrimaryAction); + this.subscription = new DelayedSubscription(this.PrimaryAction); } /// @@ -312,11 +312,11 @@ protected void OnPunctuation(StreamEvent value) if (this.flushPolicy == FlushPolicy.FlushOnPunctuation || (this.flushPolicy == FlushPolicy.FlushOnBatchBoundary && this.currentBatch.Count == Config.DataBatchSize)) { - OnFlush(); + this.OnFlush(); } else if (this.currentBatch.Count == Config.DataBatchSize) { - FlushContents(); + this.FlushContents(); } } @@ -340,7 +340,7 @@ public override void OnCompleted() { if (this.onCompletedPolicy != OnCompletedPolicy.None) { - OnCompleted(this.onCompletedPolicy == OnCompletedPolicy.Flush ? this.currentTime : StreamEvent.InfinitySyncTime); + this.OnCompleted(this.onCompletedPolicy == OnCompletedPolicy.Flush ? this.currentTime : StreamEvent.InfinitySyncTime); } base.OnCompleted(); @@ -394,7 +394,7 @@ protected override void DisposeState() /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1063:ImplementIDisposableCorrectly")] [EditorBrowsable(EditorBrowsableState.Never)] - public virtual void Dispose(bool managed) => Dispose(); + public virtual void Dispose(bool managed) => this.Dispose(); /// /// Currently for internal use only - do not use directly. @@ -510,7 +510,7 @@ protected sealed class DelayedSubscription : IDisposable public void Enable() { this.inner = this.func(); - if (this.disposed) DisposeInternal(); + if (this.disposed) this.DisposeInternal(); } /// @@ -519,7 +519,7 @@ public void Enable() [EditorBrowsable(EditorBrowsableState.Never)] public void Dispose() { - if (this.inner != null) DisposeInternal(); + if (this.inner != null) this.DisposeInternal(); this.disposed = true; } @@ -580,7 +580,7 @@ protected ObserverSubscriptionBase( onCompletedPolicy, diagnosticOutput) { - Contract.Requires(observable != null); + ArgumentNullException.ThrowIfNull(observable); this.primaryAction = () => observable.Subscribe(this); } @@ -689,7 +689,7 @@ public abstract class SubscriptionBase : P /// [EditorBrowsable(EditorBrowsableState.Never)] [DataMember] - protected Dictionary, ElasticCircularBuffer> startEventInformation = new Dictionary, ElasticCircularBuffer>(1); + protected Dictionary, ElasticCircularBuffer> startEventInformation = new(1); /// /// Currently for internal use only - do not use directly. @@ -759,8 +759,8 @@ protected SubscriptionBase( IObserver> diagnosticOutput) : base(streamable, observer) { - Contract.Requires(observer != null); - Contract.Requires(punctuationPolicy != null); + ArgumentNullException.ThrowIfNull(observer); + ArgumentNullException.ThrowIfNull(punctuationPolicy); this.IngressSiteIdentifier = identifier; this.disorderString = disorderPolicy.ToString(); @@ -784,7 +784,7 @@ protected SubscriptionBase( this.currentBatch.Allocate(); this.errorMessages = streamable.ErrorMessages; - this.subscription = new DelayedSubscription(PrimaryAction); + this.subscription = new DelayedSubscription(this.PrimaryAction); } /// @@ -825,11 +825,11 @@ protected void OnPunctuation(StreamEvent value) if (this.flushPolicy == FlushPolicy.FlushOnPunctuation || (this.flushPolicy == FlushPolicy.FlushOnBatchBoundary && this.currentBatch.Count == Config.DataBatchSize)) { - OnFlush(); + this.OnFlush(); } else if (this.currentBatch.Count == Config.DataBatchSize) { - FlushContents(); + this.FlushContents(); } } @@ -853,7 +853,7 @@ public override void OnCompleted() { if (this.onCompletedPolicy != OnCompletedPolicy.None) { - OnCompleted(this.onCompletedPolicy == OnCompletedPolicy.Flush ? this.currentTime : StreamEvent.InfinitySyncTime); + this.OnCompleted(this.onCompletedPolicy == OnCompletedPolicy.Flush ? this.currentTime : StreamEvent.InfinitySyncTime); } base.OnCompleted(); @@ -907,7 +907,7 @@ protected override void DisposeState() /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1063:ImplementIDisposableCorrectly")] [EditorBrowsable(EditorBrowsableState.Never)] - public virtual void Dispose(bool managed) => Dispose(); + public virtual void Dispose(bool managed) => this.Dispose(); /// /// Currently for internal use only - do not use directly. @@ -1023,7 +1023,7 @@ protected sealed class DelayedSubscription : IDisposable public void Enable() { this.inner = this.func(); - if (this.disposed) DisposeInternal(); + if (this.disposed) this.DisposeInternal(); } /// @@ -1032,7 +1032,7 @@ public void Enable() [EditorBrowsable(EditorBrowsableState.Never)] public void Dispose() { - if (this.inner != null) DisposeInternal(); + if (this.inner != null) this.DisposeInternal(); this.disposed = true; } @@ -1097,7 +1097,7 @@ protected DisorderedPartitionedObserverSubscriptionBase( onCompletedPolicy, diagnosticOutput) { - Contract.Requires(observable != null); + ArgumentNullException.ThrowIfNull(observable); this.primaryAction = () => observable.Subscribe(this); } @@ -1130,8 +1130,6 @@ protected DisorderedPartitionedObserverSubscriptionBase( /// /// [EditorBrowsable(EditorBrowsableState.Never)] - [System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.SpacingRules", "SA1008:OpeningParenthesisMustBeSpacedCorrectly", Justification = "ValueTuples")] - [System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.SpacingRules", "SA1009:ClosingParenthesisMustBeSpacedCorrectly", Justification = "ValueTuples")] public abstract class DisorderedPartitionedSubscriptionBase : Pipe, TResult>, IIngressStreamObserver { private readonly string errorMessages; @@ -1212,7 +1210,7 @@ public abstract class DisorderedPartitionedSubscriptionBase [EditorBrowsable(EditorBrowsableState.Never)] [DataMember] - protected Dictionary currentTime = new Dictionary(); + protected Dictionary currentTime = []; #if DEBUG /// @@ -1221,7 +1219,7 @@ public abstract class DisorderedPartitionedSubscriptionBase [EditorBrowsable(EditorBrowsableState.Never)] [DataMember] - protected Dictionary lastEventTime = new Dictionary(); + protected Dictionary lastEventTime = []; #endif /// @@ -1229,13 +1227,13 @@ public abstract class DisorderedPartitionedSubscriptionBase [EditorBrowsable(EditorBrowsableState.Never)] [DataMember] - protected Dictionary, ElasticCircularBuffer> startEventInformation = new Dictionary, ElasticCircularBuffer>(1); + protected Dictionary, ElasticCircularBuffer> startEventInformation = new(1); /// /// Currently for internal use only - do not use directly. /// [DataMember] - protected Dictionary lastPunctuationTime = new Dictionary(); + protected Dictionary lastPunctuationTime = []; /// /// Currently for internal use only - do not use directly. @@ -1251,7 +1249,7 @@ public abstract class DisorderedPartitionedSubscriptionBase [EditorBrowsable(EditorBrowsableState.Never)] [DataMember] - protected Dictionary partitionHighWatermarks = new Dictionary(); + protected Dictionary partitionHighWatermarks = []; /// /// Currently for internal use only - do not use directly. @@ -1260,7 +1258,7 @@ public abstract class DisorderedPartitionedSubscriptionBase [EditorBrowsable(EditorBrowsableState.Never)] - protected SortedDictionary> highWatermarkToPartitionsMap = new SortedDictionary>(); + protected SortedDictionary> highWatermarkToPartitionsMap = []; /// /// Currently for internal use only - do not use directly. @@ -1339,9 +1337,9 @@ protected DisorderedPartitionedSubscriptionBase( IObserver> diagnosticOutput) : base(streamable, observer) { - Contract.Requires(observer != null); - Contract.Requires(punctuationPolicy != null); - Contract.Requires(lowWatermarkPolicy != null); + ArgumentNullException.ThrowIfNull(observer); + ArgumentNullException.ThrowIfNull(punctuationPolicy); + ArgumentNullException.ThrowIfNull(lowWatermarkPolicy); this.IngressSiteIdentifier = identifier; this.disorderString = disorderPolicy.ToString(); @@ -1369,7 +1367,7 @@ protected DisorderedPartitionedSubscriptionBase( this.currentBatch.Allocate(); this.errorMessages = streamable.ErrorMessages; - this.subscription = new DelayedSubscription(PrimaryAction); + this.subscription = new DelayedSubscription(this.PrimaryAction); } /// @@ -1396,7 +1394,7 @@ protected void OnPunctuation(PartitionedStreamEvent value) if (this.punctuationPolicyType == PeriodicPunctuationPolicyType.Time) { - UpdatePunctuation(value.PartitionKey, value.SyncTime); + this.UpdatePunctuation(value.PartitionKey, value.SyncTime); } var count = this.currentBatch.Count; @@ -1404,8 +1402,8 @@ protected void OnPunctuation(PartitionedStreamEvent value) this.currentBatch.bitvector.col[count >> 6] |= (1L << (count & 0x3f)); if (this.currentBatch.Count == Config.DataBatchSize) { - if (this.flushPolicy == PartitionedFlushPolicy.FlushOnBatchBoundary) OnFlush(); - else FlushContents(); + if (this.flushPolicy == PartitionedFlushPolicy.FlushOnBatchBoundary) this.OnFlush(); + else this.FlushContents(); } } @@ -1474,7 +1472,7 @@ public override void OnCompleted() { if (this.onCompletedPolicy != OnCompletedPolicy.None) { - OnCompleted(this.onCompletedPolicy == OnCompletedPolicy.Flush ? this.currentTime.Values.Max() : StreamEvent.InfinitySyncTime); + this.OnCompleted(this.onCompletedPolicy == OnCompletedPolicy.Flush ? this.currentTime.Values.Max() : StreamEvent.InfinitySyncTime); } base.OnCompleted(); @@ -1528,7 +1526,7 @@ protected override void DisposeState() /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1063:ImplementIDisposableCorrectly")] [EditorBrowsable(EditorBrowsableState.Never)] - public virtual void Dispose(bool managed) => Dispose(); + public virtual void Dispose(bool managed) => this.Dispose(); /// /// Currently for internal use only - do not use directly. @@ -1644,7 +1642,7 @@ protected sealed class DelayedSubscription : IDisposable public void Enable() { this.inner = this.func(); - if (this.disposed) DisposeInternal(); + if (this.disposed) this.DisposeInternal(); } /// @@ -1653,7 +1651,7 @@ public void Enable() [EditorBrowsable(EditorBrowsableState.Never)] public void Dispose() { - if (this.inner != null) DisposeInternal(); + if (this.inner != null) this.DisposeInternal(); this.disposed = true; } @@ -1718,7 +1716,7 @@ protected PartitionedObserverSubscriptionBase( onCompletedPolicy, diagnosticOutput) { - Contract.Requires(observable != null); + ArgumentNullException.ThrowIfNull(observable); this.primaryAction = () => observable.Subscribe(this); } @@ -1751,8 +1749,6 @@ protected PartitionedObserverSubscriptionBase( /// /// [EditorBrowsable(EditorBrowsableState.Never)] - [System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.SpacingRules", "SA1008:OpeningParenthesisMustBeSpacedCorrectly", Justification = "ValueTuples")] - [System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.SpacingRules", "SA1009:ClosingParenthesisMustBeSpacedCorrectly", Justification = "ValueTuples")] public abstract class PartitionedSubscriptionBase : Pipe, TResult>, IIngressStreamObserver { private readonly string errorMessages; @@ -1833,7 +1829,7 @@ public abstract class PartitionedSubscriptionBase [EditorBrowsable(EditorBrowsableState.Never)] [DataMember] - protected Dictionary currentTime = new Dictionary(); + protected Dictionary currentTime = []; #if DEBUG /// @@ -1842,7 +1838,7 @@ public abstract class PartitionedSubscriptionBase [EditorBrowsable(EditorBrowsableState.Never)] [DataMember] - protected Dictionary lastEventTime = new Dictionary(); + protected Dictionary lastEventTime = []; #endif /// @@ -1850,13 +1846,13 @@ public abstract class PartitionedSubscriptionBase [EditorBrowsable(EditorBrowsableState.Never)] [DataMember] - protected Dictionary, ElasticCircularBuffer> startEventInformation = new Dictionary, ElasticCircularBuffer>(1); + protected Dictionary, ElasticCircularBuffer> startEventInformation = new(1); /// /// Currently for internal use only - do not use directly. /// [DataMember] - protected Dictionary lastPunctuationTime = new Dictionary(); + protected Dictionary lastPunctuationTime = []; /// /// Currently for internal use only - do not use directly. @@ -1872,7 +1868,7 @@ public abstract class PartitionedSubscriptionBase [EditorBrowsable(EditorBrowsableState.Never)] [DataMember] - protected Dictionary partitionHighWatermarks = new Dictionary(); + protected Dictionary partitionHighWatermarks = []; /// /// Currently for internal use only - do not use directly. @@ -1881,7 +1877,7 @@ public abstract class PartitionedSubscriptionBase [EditorBrowsable(EditorBrowsableState.Never)] - protected SortedDictionary> highWatermarkToPartitionsMap = new SortedDictionary>(); + protected SortedDictionary> highWatermarkToPartitionsMap = []; /// /// Currently for internal use only - do not use directly. @@ -1960,9 +1956,9 @@ protected PartitionedSubscriptionBase( IObserver> diagnosticOutput) : base(streamable, observer) { - Contract.Requires(observer != null); - Contract.Requires(punctuationPolicy != null); - Contract.Requires(lowWatermarkPolicy != null); + ArgumentNullException.ThrowIfNull(observer); + ArgumentNullException.ThrowIfNull(punctuationPolicy); + ArgumentNullException.ThrowIfNull(lowWatermarkPolicy); this.IngressSiteIdentifier = identifier; this.disorderString = disorderPolicy.ToString(); @@ -1990,7 +1986,7 @@ protected PartitionedSubscriptionBase( this.currentBatch.Allocate(); this.errorMessages = streamable.ErrorMessages; - this.subscription = new DelayedSubscription(PrimaryAction); + this.subscription = new DelayedSubscription(this.PrimaryAction); } /// @@ -2017,7 +2013,7 @@ protected void OnPunctuation(PartitionedStreamEvent value) if (this.punctuationPolicyType == PeriodicPunctuationPolicyType.Time) { - UpdatePunctuation(value.PartitionKey, value.SyncTime); + this.UpdatePunctuation(value.PartitionKey, value.SyncTime); } var count = this.currentBatch.Count; @@ -2025,8 +2021,8 @@ protected void OnPunctuation(PartitionedStreamEvent value) this.currentBatch.bitvector.col[count >> 6] |= (1L << (count & 0x3f)); if (this.currentBatch.Count == Config.DataBatchSize) { - if (this.flushPolicy == PartitionedFlushPolicy.FlushOnBatchBoundary) OnFlush(); - else FlushContents(); + if (this.flushPolicy == PartitionedFlushPolicy.FlushOnBatchBoundary) this.OnFlush(); + else this.FlushContents(); } } @@ -2095,7 +2091,7 @@ public override void OnCompleted() { if (this.onCompletedPolicy != OnCompletedPolicy.None) { - OnCompleted(this.onCompletedPolicy == OnCompletedPolicy.Flush ? this.currentTime.Values.Max() : StreamEvent.InfinitySyncTime); + this.OnCompleted(this.onCompletedPolicy == OnCompletedPolicy.Flush ? this.currentTime.Values.Max() : StreamEvent.InfinitySyncTime); } base.OnCompleted(); @@ -2149,7 +2145,7 @@ protected override void DisposeState() /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1063:ImplementIDisposableCorrectly")] [EditorBrowsable(EditorBrowsableState.Never)] - public virtual void Dispose(bool managed) => Dispose(); + public virtual void Dispose(bool managed) => this.Dispose(); /// /// Currently for internal use only - do not use directly. @@ -2265,7 +2261,7 @@ protected sealed class DelayedSubscription : IDisposable public void Enable() { this.inner = this.func(); - if (this.disposed) DisposeInternal(); + if (this.disposed) this.DisposeInternal(); } /// @@ -2274,7 +2270,7 @@ public void Enable() [EditorBrowsable(EditorBrowsableState.Never)] public void Dispose() { - if (this.inner != null) DisposeInternal(); + if (this.inner != null) this.DisposeInternal(); this.disposed = true; } diff --git a/Sources/Core/Microsoft.StreamProcessing/Ingress/SubscriptionBase.tt b/Sources/Core/Microsoft.StreamProcessing/Ingress/SubscriptionBase.tt index 24a48ff78..b1038c505 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Ingress/SubscriptionBase.tt +++ b/Sources/Core/Microsoft.StreamProcessing/Ingress/SubscriptionBase.tt @@ -100,7 +100,7 @@ foreach (bool disordered in new[] { true, false }) onCompletedPolicy, diagnosticOutput) { - Contract.Requires(observable != null); + ArgumentNullException.ThrowIfNull(observable); this.primaryAction = () => observable.Subscribe(this); } @@ -135,10 +135,6 @@ foreach (bool disordered in new[] { true, false }) /// /// [EditorBrowsable(EditorBrowsableState.Never)] -<# if (partitioned) { #> - [System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.SpacingRules", "SA1008:OpeningParenthesisMustBeSpacedCorrectly", Justification = "ValueTuples")] - [System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.SpacingRules", "SA1009:ClosingParenthesisMustBeSpacedCorrectly", Justification = "ValueTuples")] -<# } #> public abstract class <#= disordered ? "Disordered" : string.Empty #><#= partitionString #>SubscriptionBase<<#= genericArgument #>TIngressStructure, TPayload, TResult> : Pipe<<#= baseType #>, TResult>, IIngressStreamObserver { private readonly string errorMessages; @@ -368,10 +364,10 @@ foreach (bool disordered in new[] { true, false }) IObserverStreamEvent<<#= genericArgument #>TPayload>> diagnosticOutput) : base(streamable, observer) { - Contract.Requires(observer != null); - Contract.Requires(punctuationPolicy != null); + ArgumentNullException.ThrowIfNull(observer); + ArgumentNullException.ThrowIfNull(punctuationPolicy); <# if (partitioned) { #> - Contract.Requires(lowWatermarkPolicy != null); + ArgumentNullException.ThrowIfNull(lowWatermarkPolicy); <# } #> this.IngressSiteIdentifier = identifier; diff --git a/Sources/Core/Microsoft.StreamProcessing/Ingress/Temporal/TemporalIngressStreamable.cs b/Sources/Core/Microsoft.StreamProcessing/Ingress/Temporal/TemporalIngressStreamable.cs index 119b8a924..567e1b82a 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Ingress/Temporal/TemporalIngressStreamable.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Ingress/Temporal/TemporalIngressStreamable.cs @@ -33,8 +33,8 @@ public StreamEventIngressStreamable( string identifier) : base(StreamProperties.Default.SetQueryContainer(container)) { - Contract.Requires(observable != null); - Contract.Requires(identifier != null); + ArgumentNullException.ThrowIfNull(observable); + ArgumentNullException.ThrowIfNull(identifier); this.IngressSiteIdentifier = identifier; this.observable = observable; @@ -51,24 +51,24 @@ public StreamEventIngressStreamable( || !typeof(TPayload).CanRepresentAsColumnar() || typeof(TPayload).IsAnonymousTypeName()) { - this.properties = properties.ToRowBased(); + this.properties = this.properties.ToRowBased(); } - else this.properties = properties.ToDelayedColumnar(CanGenerateColumnar); + else this.properties = this.properties.ToDelayedColumnar(this.CanGenerateColumnar); } - public void Dispose() => diagnosticOutput?.Dispose(); + public void Dispose() => this.diagnosticOutput?.Dispose(); [ContractInvariantMethod] [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic", Justification = "Required for code contracts.")] private void ObjectInvariant() { - Contract.Invariant(observable != null); + Contract.Invariant(this.observable != null); } public IObservable> GetDroppedAdjustedEventsDiagnostic() { - if (diagnosticOutput == null) diagnosticOutput = new DiagnosticObservable(); - return diagnosticOutput; + if (this.diagnosticOutput == null) this.diagnosticOutput = new DiagnosticObservable(); + return this.diagnosticOutput; } public override IDisposable Subscribe(IStreamObserver observer) @@ -76,25 +76,25 @@ public override IDisposable Subscribe(IStreamObserver observer) Contract.EnsuresOnThrow(true); IIngressStreamObserver pipe = null; - if (properties.IsColumnar) pipe = GetPipe(observer); + if (this.properties.IsColumnar) pipe = this.GetPipe(observer); else { pipe = StreamEventSubscriptionCreator.CreateSubscription( - observable, + this.observable, this.IngressSiteIdentifier, this, observer, - disorderPolicy, - flushPolicy, - punctuationPolicy, - onCompletedPolicy, - diagnosticOutput, - fuseModule); + this.disorderPolicy, + this.flushPolicy, + this.punctuationPolicy, + this.onCompletedPolicy, + this.diagnosticOutput, + this.fuseModule); } if (this.delayed) { - container.RegisterIngressPipe(this.IngressSiteIdentifier, pipe); + this.container.RegisterIngressPipe(this.IngressSiteIdentifier, pipe); return pipe.DelayedDisposable; } else @@ -107,26 +107,26 @@ public override IDisposable Subscribe(IStreamObserver observer) public string IngressSiteIdentifier { get; private set; } = Guid.NewGuid().ToString(); private static readonly SafeConcurrentDictionary> cachedPipes - = new SafeConcurrentDictionary>(); + = new(); private bool CanGenerateColumnar() { var lookupKey = CacheKey.Create( Tuple.Create( - fuseModule.ToString(), + this.fuseModule.ToString(), Config.AllowFloatingReorderPolicy, - punctuationPolicy.ToString(), - disorderPolicy.ToString(), - (disorderPolicy.type != DisorderPolicyType.Throw && diagnosticOutput != null ? "WithDiagnostic" : string.Empty))); + this.punctuationPolicy.ToString(), + this.disorderPolicy.ToString(), + (this.disorderPolicy.type != DisorderPolicyType.Throw && this.diagnosticOutput != null ? "WithDiagnostic" : string.Empty))); var generatedPipeType = cachedPipes.GetOrAdd( lookupKey, key => TemporalIngressTemplate.Generate( - disorderPolicy.reorderLatency > 0 ? "WithLatency" : string.Empty, - disorderPolicy.type != DisorderPolicyType.Throw && diagnosticOutput != null ? "WithDiagnostic" : string.Empty, - fuseModule)); + this.disorderPolicy.reorderLatency > 0 ? "WithLatency" : string.Empty, + this.disorderPolicy.type != DisorderPolicyType.Throw && this.diagnosticOutput != null ? "WithDiagnostic" : string.Empty, + this.fuseModule)); - errorMessages = generatedPipeType.Item2; + this.errorMessages = generatedPipeType.Item2; return generatedPipeType.Item1 != null; } @@ -134,32 +134,32 @@ private IIngressStreamObserver GetPipe(IStreamObserver observer { var lookupKey = CacheKey.Create( Tuple.Create( - fuseModule.ToString(), + this.fuseModule.ToString(), Config.AllowFloatingReorderPolicy, - punctuationPolicy.ToString(), - disorderPolicy.ToString(), - (disorderPolicy.type != DisorderPolicyType.Throw && diagnosticOutput != null ? "WithDiagnostic" : string.Empty))); + this.punctuationPolicy.ToString(), + this.disorderPolicy.ToString(), + (this.disorderPolicy.type != DisorderPolicyType.Throw && this.diagnosticOutput != null ? "WithDiagnostic" : string.Empty))); object instance; var generatedPipeType = cachedPipes.GetOrAdd( lookupKey, key => TemporalIngressTemplate.Generate( - disorderPolicy.reorderLatency > 0 ? "WithLatency" : string.Empty, - disorderPolicy.type != DisorderPolicyType.Throw && diagnosticOutput != null ? "WithDiagnostic" : string.Empty, - fuseModule)); + this.disorderPolicy.reorderLatency > 0 ? "WithLatency" : string.Empty, + this.disorderPolicy.type != DisorderPolicyType.Throw && this.diagnosticOutput != null ? "WithDiagnostic" : string.Empty, + this.fuseModule)); instance = Activator.CreateInstance( generatedPipeType.Item1, - observable, this.IngressSiteIdentifier, this, observer, disorderPolicy, flushPolicy, punctuationPolicy, onCompletedPolicy, diagnosticOutput); + this.observable, this.IngressSiteIdentifier, this, observer, this.disorderPolicy, this.flushPolicy, this.punctuationPolicy, this.onCompletedPolicy, this.diagnosticOutput); var returnValue = (IIngressStreamObserver)instance; return returnValue; } public override string ToString() { - if (container != null) - return "RegisterInput({0}, " + disorderPolicy.ToString() + ", " + flushPolicy.ToString() + ", " + punctuationPolicy.ToString() + ", " + onCompletedPolicy.ToString() + ")"; + if (this.container != null) + return "RegisterInput({0}, " + this.disorderPolicy.ToString() + ", " + this.flushPolicy.ToString() + ", " + this.punctuationPolicy.ToString() + ", " + this.onCompletedPolicy.ToString() + ")"; else - return "ToStreamable(" + disorderPolicy.ToString() + ", " + flushPolicy.ToString() + ", " + punctuationPolicy.ToString() + ", " + onCompletedPolicy.ToString() + ")"; + return "ToStreamable(" + this.disorderPolicy.ToString() + ", " + this.flushPolicy.ToString() + ", " + this.punctuationPolicy.ToString() + ", " + this.onCompletedPolicy.ToString() + ")"; } public bool CanFuseSelect(LambdaExpression expression, bool hasStart, bool hasKey) => true; @@ -167,61 +167,61 @@ public override string ToString() public IFusibleStreamable FuseSelect(Expression> expression) { return new StreamEventIngressStreamableFused( - observable, - disorderPolicy, - flushPolicy, - punctuationPolicy, - onCompletedPolicy, - container, - this.IngressSiteIdentifier, - fuseModule.Clone().FuseSelect(expression), + this.observable, + this.disorderPolicy, + this.flushPolicy, + this.punctuationPolicy, + this.onCompletedPolicy, + this.container, + this.IngressSiteIdentifier, + this.fuseModule.Clone().FuseSelect(expression), this, - Properties.Select(expression, false, false)); + this.Properties.Select(expression, false, false)); } public IFusibleStreamable FuseSelect(Expression> expression) { return new StreamEventIngressStreamableFused( - observable, - disorderPolicy, - flushPolicy, - punctuationPolicy, - onCompletedPolicy, - container, - this.IngressSiteIdentifier, - fuseModule.Clone().FuseSelect(expression), + this.observable, + this.disorderPolicy, + this.flushPolicy, + this.punctuationPolicy, + this.onCompletedPolicy, + this.container, + this.IngressSiteIdentifier, + this.fuseModule.Clone().FuseSelect(expression), this, - Properties.Select(expression, true, false, true)); + this.Properties.Select(expression, true, false, true)); } public IFusibleStreamable FuseSelectWithKey(Expression> expression) { return new StreamEventIngressStreamableFused( - observable, - disorderPolicy, - flushPolicy, - punctuationPolicy, - onCompletedPolicy, - container, - this.IngressSiteIdentifier, - fuseModule.Clone().FuseSelectWithKey(expression), + this.observable, + this.disorderPolicy, + this.flushPolicy, + this.punctuationPolicy, + this.onCompletedPolicy, + this.container, + this.IngressSiteIdentifier, + this.fuseModule.Clone().FuseSelectWithKey(expression), this, - Properties.Select(expression, false, true)); + this.Properties.Select(expression, false, true)); } public IFusibleStreamable FuseSelectWithKey(Expression> expression) { return new StreamEventIngressStreamableFused( - observable, - disorderPolicy, - flushPolicy, - punctuationPolicy, - onCompletedPolicy, - container, - this.IngressSiteIdentifier, - fuseModule.Clone().FuseSelectWithKey(expression), + this.observable, + this.disorderPolicy, + this.flushPolicy, + this.punctuationPolicy, + this.onCompletedPolicy, + this.container, + this.IngressSiteIdentifier, + this.fuseModule.Clone().FuseSelectWithKey(expression), this, - Properties.Select(expression, true, true)); + this.Properties.Select(expression, true, true)); } public bool CanFuseSelectMany(LambdaExpression expression, bool hasStart, bool hasKey) => true; @@ -229,102 +229,102 @@ public IFusibleStreamable FuseSelectWithKey(Expre public IFusibleStreamable FuseSelectMany(Expression>> expression) { return new StreamEventIngressStreamableFused( - observable, - disorderPolicy, - flushPolicy, - punctuationPolicy, - onCompletedPolicy, - container, - this.IngressSiteIdentifier, - fuseModule.Clone().FuseSelectMany(expression), + this.observable, + this.disorderPolicy, + this.flushPolicy, + this.punctuationPolicy, + this.onCompletedPolicy, + this.container, + this.IngressSiteIdentifier, + this.fuseModule.Clone().FuseSelectMany(expression), this, - Properties.SelectMany(expression)); + this.Properties.SelectMany(expression)); } public IFusibleStreamable FuseSelectMany(Expression>> expression) { return new StreamEventIngressStreamableFused( - observable, - disorderPolicy, - flushPolicy, - punctuationPolicy, - onCompletedPolicy, - container, - this.IngressSiteIdentifier, - fuseModule.Clone().FuseSelectMany(expression), + this.observable, + this.disorderPolicy, + this.flushPolicy, + this.punctuationPolicy, + this.onCompletedPolicy, + this.container, + this.IngressSiteIdentifier, + this.fuseModule.Clone().FuseSelectMany(expression), this, - Properties.SelectMany(expression)); + this.Properties.SelectMany(expression)); } public IFusibleStreamable FuseSelectManyWithKey(Expression>> expression) { return new StreamEventIngressStreamableFused( - observable, - disorderPolicy, - flushPolicy, - punctuationPolicy, - onCompletedPolicy, - container, - this.IngressSiteIdentifier, - fuseModule.Clone().FuseSelectManyWithKey(expression), + this.observable, + this.disorderPolicy, + this.flushPolicy, + this.punctuationPolicy, + this.onCompletedPolicy, + this.container, + this.IngressSiteIdentifier, + this.fuseModule.Clone().FuseSelectManyWithKey(expression), this, - Properties.SelectMany(expression)); + this.Properties.SelectMany(expression)); } public IFusibleStreamable FuseSelectManyWithKey(Expression>> expression) { return new StreamEventIngressStreamableFused( - observable, - disorderPolicy, - flushPolicy, - punctuationPolicy, - onCompletedPolicy, - container, - this.IngressSiteIdentifier, - fuseModule.Clone().FuseSelectManyWithKey(expression), + this.observable, + this.disorderPolicy, + this.flushPolicy, + this.punctuationPolicy, + this.onCompletedPolicy, + this.container, + this.IngressSiteIdentifier, + this.fuseModule.Clone().FuseSelectManyWithKey(expression), this, - Properties.SelectMany(expression)); + this.Properties.SelectMany(expression)); } public IFusibleStreamable FuseWhere(Expression> expression) { return new StreamEventIngressStreamableFused( - observable, - disorderPolicy, - flushPolicy, - punctuationPolicy, - onCompletedPolicy, - container, - this.IngressSiteIdentifier, - fuseModule.Clone().FuseWhere(expression), + this.observable, + this.disorderPolicy, + this.flushPolicy, + this.punctuationPolicy, + this.onCompletedPolicy, + this.container, + this.IngressSiteIdentifier, + this.fuseModule.Clone().FuseWhere(expression), this, - Properties.Where(expression)); + this.Properties.Where(expression)); } public IFusibleStreamable FuseSetDurationConstant(long value) { return new StreamEventIngressStreamableFused( - observable, - disorderPolicy, - flushPolicy, - punctuationPolicy, - onCompletedPolicy, - container, - this.IngressSiteIdentifier, - fuseModule.Clone().FuseSetDurationConstant(value), + this.observable, + this.disorderPolicy, + this.flushPolicy, + this.punctuationPolicy, + this.onCompletedPolicy, + this.container, + this.IngressSiteIdentifier, + this.fuseModule.Clone().FuseSetDurationConstant(value), this, - Properties.ToConstantDuration(true, value)); + this.Properties.ToConstantDuration(true, value)); } public IObservable FuseEgressObservable(Expression> expression, QueryContainer container, string identifier) { return new FusedObservable, TPayload, TPayload, TNewResult>( - observable, + this.observable, (o) => o.SyncTime, (o) => o.OtherTime, (o) => Empty.Default, (o) => o.Payload, - fuseModule, + this.fuseModule, expression, container, this.IngressSiteIdentifier, @@ -362,8 +362,8 @@ public IntervalIngressStreamable( string identifier) : base(StreamProperties.DefaultIngress(startEdgeExtractor, endEdgeExtractor).SetQueryContainer(container)) { - Contract.Requires(observable != null); - Contract.Requires(identifier != null); + ArgumentNullException.ThrowIfNull(observable); + ArgumentNullException.ThrowIfNull(identifier); this.IngressSiteIdentifier = identifier; this.observable = observable; @@ -382,24 +382,24 @@ public IntervalIngressStreamable( || !typeof(TPayload).CanRepresentAsColumnar() || typeof(TPayload).IsAnonymousTypeName()) { - this.properties = properties.ToRowBased(); + this.properties = this.properties.ToRowBased(); } - else this.properties = properties.ToDelayedColumnar(CanGenerateColumnar); + else this.properties = this.properties.ToDelayedColumnar(this.CanGenerateColumnar); } - public void Dispose() => diagnosticOutput?.Dispose(); + public void Dispose() => this.diagnosticOutput?.Dispose(); [ContractInvariantMethod] [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic", Justification = "Required for code contracts.")] private void ObjectInvariant() { - Contract.Invariant(observable != null); + Contract.Invariant(this.observable != null); } public IObservable> GetDroppedAdjustedEventsDiagnostic() { - if (diagnosticOutput == null) diagnosticOutput = new DiagnosticObservable(); - return diagnosticOutput; + if (this.diagnosticOutput == null) this.diagnosticOutput = new DiagnosticObservable(); + return this.diagnosticOutput; } public override IDisposable Subscribe(IStreamObserver observer) @@ -407,27 +407,27 @@ public override IDisposable Subscribe(IStreamObserver observer) Contract.EnsuresOnThrow(true); IIngressStreamObserver pipe = null; - if (properties.IsColumnar) pipe = GetPipe(observer); + if (this.properties.IsColumnar) pipe = this.GetPipe(observer); else { pipe = IntervalSubscriptionCreator.CreateSubscription( - observable, - startEdgeExtractor, - endEdgeExtractor, + this.observable, + this.startEdgeExtractor, + this.endEdgeExtractor, this.IngressSiteIdentifier, this, observer, - disorderPolicy, - flushPolicy, - punctuationPolicy, - onCompletedPolicy, - diagnosticOutput, - fuseModule); + this.disorderPolicy, + this.flushPolicy, + this.punctuationPolicy, + this.onCompletedPolicy, + this.diagnosticOutput, + this.fuseModule); } if (this.delayed) { - container.RegisterIngressPipe(this.IngressSiteIdentifier, pipe); + this.container.RegisterIngressPipe(this.IngressSiteIdentifier, pipe); return pipe.DelayedDisposable; } else @@ -440,31 +440,31 @@ public override IDisposable Subscribe(IStreamObserver observer) public string IngressSiteIdentifier { get; private set; } = Guid.NewGuid().ToString(); private static readonly SafeConcurrentDictionary> cachedPipes - = new SafeConcurrentDictionary>(); + = new(); private bool CanGenerateColumnar() { var lookupKey = CacheKey.Create( Tuple.Create( - startEdgeExtractor.ExpressionToCSharp(), - endEdgeExtractor != null ? endEdgeExtractor.ExpressionToCSharp() : string.Empty), + this.startEdgeExtractor.ExpressionToCSharp(), + this.endEdgeExtractor != null ? this.endEdgeExtractor.ExpressionToCSharp() : string.Empty), Tuple.Create( - fuseModule.ToString(), + this.fuseModule.ToString(), Config.AllowFloatingReorderPolicy, - punctuationPolicy.ToString(), - disorderPolicy.ToString(), - (disorderPolicy.type != DisorderPolicyType.Throw && diagnosticOutput != null ? "WithDiagnostic" : string.Empty))); + this.punctuationPolicy.ToString(), + this.disorderPolicy.ToString(), + (this.disorderPolicy.type != DisorderPolicyType.Throw && this.diagnosticOutput != null ? "WithDiagnostic" : string.Empty))); var generatedPipeType = cachedPipes.GetOrAdd( lookupKey, key => TemporalIngressTemplate.Generate( - startEdgeExtractor, - endEdgeExtractor, - disorderPolicy.reorderLatency > 0 ? "WithLatency" : string.Empty, - disorderPolicy.type != DisorderPolicyType.Throw && diagnosticOutput != null ? "WithDiagnostic" : string.Empty, - fuseModule)); + this.startEdgeExtractor, + this.endEdgeExtractor, + this.disorderPolicy.reorderLatency > 0 ? "WithLatency" : string.Empty, + this.disorderPolicy.type != DisorderPolicyType.Throw && this.diagnosticOutput != null ? "WithDiagnostic" : string.Empty, + this.fuseModule)); - errorMessages = generatedPipeType.Item2; + this.errorMessages = generatedPipeType.Item2; return generatedPipeType.Item1 != null; } @@ -472,27 +472,27 @@ private IIngressStreamObserver GetPipe(IStreamObserver observer { var lookupKey = CacheKey.Create( Tuple.Create( - startEdgeExtractor.ExpressionToCSharp(), - endEdgeExtractor != null ? endEdgeExtractor.ExpressionToCSharp() : string.Empty), + this.startEdgeExtractor.ExpressionToCSharp(), + this.endEdgeExtractor != null ? this.endEdgeExtractor.ExpressionToCSharp() : string.Empty), Tuple.Create( - fuseModule.ToString(), + this.fuseModule.ToString(), Config.AllowFloatingReorderPolicy, - punctuationPolicy.ToString(), - disorderPolicy.ToString(), - (disorderPolicy.type != DisorderPolicyType.Throw && diagnosticOutput != null ? "WithDiagnostic" : string.Empty))); + this.punctuationPolicy.ToString(), + this.disorderPolicy.ToString(), + (this.disorderPolicy.type != DisorderPolicyType.Throw && this.diagnosticOutput != null ? "WithDiagnostic" : string.Empty))); object instance; var generatedPipeType = cachedPipes.GetOrAdd( lookupKey, key => TemporalIngressTemplate.Generate( - startEdgeExtractor, - endEdgeExtractor, - disorderPolicy.reorderLatency > 0 ? "WithLatency" : string.Empty, - disorderPolicy.type != DisorderPolicyType.Throw && diagnosticOutput != null ? "WithDiagnostic" : string.Empty, - fuseModule)); + this.startEdgeExtractor, + this.endEdgeExtractor, + this.disorderPolicy.reorderLatency > 0 ? "WithLatency" : string.Empty, + this.disorderPolicy.type != DisorderPolicyType.Throw && this.diagnosticOutput != null ? "WithDiagnostic" : string.Empty, + this.fuseModule)); instance = Activator.CreateInstance( generatedPipeType.Item1, - observable, this.IngressSiteIdentifier, this, observer, disorderPolicy, flushPolicy, punctuationPolicy, onCompletedPolicy, diagnosticOutput); + this.observable, this.IngressSiteIdentifier, this, observer, this.disorderPolicy, this.flushPolicy, this.punctuationPolicy, this.onCompletedPolicy, this.diagnosticOutput); var returnValue = (IIngressStreamObserver)instance; return returnValue; } @@ -502,69 +502,69 @@ private IIngressStreamObserver GetPipe(IStreamObserver observer public IFusibleStreamable FuseSelect(Expression> expression) { return new IntervalIngressStreamableFused( - observable, - startEdgeExtractor, - endEdgeExtractor, - disorderPolicy, - flushPolicy, - punctuationPolicy, - onCompletedPolicy, - container, - this.IngressSiteIdentifier, - fuseModule.Clone().FuseSelect(expression), + this.observable, + this.startEdgeExtractor, + this.endEdgeExtractor, + this.disorderPolicy, + this.flushPolicy, + this.punctuationPolicy, + this.onCompletedPolicy, + this.container, + this.IngressSiteIdentifier, + this.fuseModule.Clone().FuseSelect(expression), this, - Properties.Select(expression, false, false)); + this.Properties.Select(expression, false, false)); } public IFusibleStreamable FuseSelect(Expression> expression) { return new IntervalIngressStreamableFused( - observable, - startEdgeExtractor, - endEdgeExtractor, - disorderPolicy, - flushPolicy, - punctuationPolicy, - onCompletedPolicy, - container, - this.IngressSiteIdentifier, - fuseModule.Clone().FuseSelect(expression), + this.observable, + this.startEdgeExtractor, + this.endEdgeExtractor, + this.disorderPolicy, + this.flushPolicy, + this.punctuationPolicy, + this.onCompletedPolicy, + this.container, + this.IngressSiteIdentifier, + this.fuseModule.Clone().FuseSelect(expression), this, - Properties.Select(expression, true, false, true)); + this.Properties.Select(expression, true, false, true)); } public IFusibleStreamable FuseSelectWithKey(Expression> expression) { return new IntervalIngressStreamableFused( - observable, - startEdgeExtractor, - endEdgeExtractor, - disorderPolicy, - flushPolicy, - punctuationPolicy, - onCompletedPolicy, - container, - this.IngressSiteIdentifier, - fuseModule.Clone().FuseSelectWithKey(expression), + this.observable, + this.startEdgeExtractor, + this.endEdgeExtractor, + this.disorderPolicy, + this.flushPolicy, + this.punctuationPolicy, + this.onCompletedPolicy, + this.container, + this.IngressSiteIdentifier, + this.fuseModule.Clone().FuseSelectWithKey(expression), this, - Properties.Select(expression, false, true)); + this.Properties.Select(expression, false, true)); } public IFusibleStreamable FuseSelectWithKey(Expression> expression) { return new IntervalIngressStreamableFused( - observable, - startEdgeExtractor, - endEdgeExtractor, - disorderPolicy, - flushPolicy, - punctuationPolicy, - onCompletedPolicy, - container, - this.IngressSiteIdentifier, - fuseModule.Clone().FuseSelectWithKey(expression), + this.observable, + this.startEdgeExtractor, + this.endEdgeExtractor, + this.disorderPolicy, + this.flushPolicy, + this.punctuationPolicy, + this.onCompletedPolicy, + this.container, + this.IngressSiteIdentifier, + this.fuseModule.Clone().FuseSelectWithKey(expression), this, - Properties.Select(expression, true, true)); + this.Properties.Select(expression, true, true)); } public bool CanFuseSelectMany(LambdaExpression expression, bool hasStart, bool hasKey) => true; @@ -572,114 +572,114 @@ public IFusibleStreamable FuseSelectWithKey(Expre public IFusibleStreamable FuseSelectMany(Expression>> expression) { return new IntervalIngressStreamableFused( - observable, - startEdgeExtractor, - endEdgeExtractor, - disorderPolicy, - flushPolicy, - punctuationPolicy, - onCompletedPolicy, - container, - this.IngressSiteIdentifier, - fuseModule.Clone().FuseSelectMany(expression), + this.observable, + this.startEdgeExtractor, + this.endEdgeExtractor, + this.disorderPolicy, + this.flushPolicy, + this.punctuationPolicy, + this.onCompletedPolicy, + this.container, + this.IngressSiteIdentifier, + this.fuseModule.Clone().FuseSelectMany(expression), this, - Properties.SelectMany(expression)); + this.Properties.SelectMany(expression)); } public IFusibleStreamable FuseSelectMany(Expression>> expression) { return new IntervalIngressStreamableFused( - observable, - startEdgeExtractor, - endEdgeExtractor, - disorderPolicy, - flushPolicy, - punctuationPolicy, - onCompletedPolicy, - container, - this.IngressSiteIdentifier, - fuseModule.Clone().FuseSelectMany(expression), + this.observable, + this.startEdgeExtractor, + this.endEdgeExtractor, + this.disorderPolicy, + this.flushPolicy, + this.punctuationPolicy, + this.onCompletedPolicy, + this.container, + this.IngressSiteIdentifier, + this.fuseModule.Clone().FuseSelectMany(expression), this, - Properties.SelectMany(expression)); + this.Properties.SelectMany(expression)); } public IFusibleStreamable FuseSelectManyWithKey(Expression>> expression) { return new IntervalIngressStreamableFused( - observable, - startEdgeExtractor, - endEdgeExtractor, - disorderPolicy, - flushPolicy, - punctuationPolicy, - onCompletedPolicy, - container, - this.IngressSiteIdentifier, - fuseModule.Clone().FuseSelectManyWithKey(expression), + this.observable, + this.startEdgeExtractor, + this.endEdgeExtractor, + this.disorderPolicy, + this.flushPolicy, + this.punctuationPolicy, + this.onCompletedPolicy, + this.container, + this.IngressSiteIdentifier, + this.fuseModule.Clone().FuseSelectManyWithKey(expression), this, - Properties.SelectMany(expression)); + this.Properties.SelectMany(expression)); } public IFusibleStreamable FuseSelectManyWithKey(Expression>> expression) { return new IntervalIngressStreamableFused( - observable, - startEdgeExtractor, - endEdgeExtractor, - disorderPolicy, - flushPolicy, - punctuationPolicy, - onCompletedPolicy, - container, - this.IngressSiteIdentifier, - fuseModule.Clone().FuseSelectManyWithKey(expression), + this.observable, + this.startEdgeExtractor, + this.endEdgeExtractor, + this.disorderPolicy, + this.flushPolicy, + this.punctuationPolicy, + this.onCompletedPolicy, + this.container, + this.IngressSiteIdentifier, + this.fuseModule.Clone().FuseSelectManyWithKey(expression), this, - Properties.SelectMany(expression)); + this.Properties.SelectMany(expression)); } public IFusibleStreamable FuseWhere(Expression> expression) { return new IntervalIngressStreamableFused( - observable, - startEdgeExtractor, - endEdgeExtractor, - disorderPolicy, - flushPolicy, - punctuationPolicy, - onCompletedPolicy, - container, - this.IngressSiteIdentifier, - fuseModule.Clone().FuseWhere(expression), + this.observable, + this.startEdgeExtractor, + this.endEdgeExtractor, + this.disorderPolicy, + this.flushPolicy, + this.punctuationPolicy, + this.onCompletedPolicy, + this.container, + this.IngressSiteIdentifier, + this.fuseModule.Clone().FuseWhere(expression), this, - Properties.Where(expression)); + this.Properties.Where(expression)); } public IFusibleStreamable FuseSetDurationConstant(long value) { return new IntervalIngressStreamableFused( - observable, - startEdgeExtractor, - endEdgeExtractor, - disorderPolicy, - flushPolicy, - punctuationPolicy, - onCompletedPolicy, - container, - this.IngressSiteIdentifier, - fuseModule.Clone().FuseSetDurationConstant(value), + this.observable, + this.startEdgeExtractor, + this.endEdgeExtractor, + this.disorderPolicy, + this.flushPolicy, + this.punctuationPolicy, + this.onCompletedPolicy, + this.container, + this.IngressSiteIdentifier, + this.fuseModule.Clone().FuseSetDurationConstant(value), this, - Properties.ToConstantDuration(true, value)); + this.Properties.ToConstantDuration(true, value)); } public IObservable FuseEgressObservable(Expression> expression, QueryContainer container, string identifier) { return new FusedObservable( - observable, - startEdgeExtractor, - endEdgeExtractor, + this.observable, + this.startEdgeExtractor, + this.endEdgeExtractor, (o) => Empty.Default, (o) => o, - fuseModule, + this.fuseModule, expression, container, this.IngressSiteIdentifier, @@ -715,8 +715,8 @@ public PartitionedStreamEventIngressStreamable( string identifier) : base(StreamProperties, TPayload>.Default.SetQueryContainer(container)) { - Contract.Requires(observable != null); - Contract.Requires(identifier != null); + ArgumentNullException.ThrowIfNull(observable); + ArgumentNullException.ThrowIfNull(identifier); this.IngressSiteIdentifier = identifier; this.observable = observable; @@ -730,22 +730,22 @@ public PartitionedStreamEventIngressStreamable( this.fuseModule = new FuseModule(); if (this.delayed) container.RegisterIngressSite(this.IngressSiteIdentifier); - this.properties = properties.ToRowBased(); + this.properties = this.properties.ToRowBased(); } - public void Dispose() => diagnosticOutput?.Dispose(); + public void Dispose() => this.diagnosticOutput?.Dispose(); [ContractInvariantMethod] [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic", Justification = "Required for code contracts.")] private void ObjectInvariant() { - Contract.Invariant(observable != null); + Contract.Invariant(this.observable != null); } public IObservable> GetDroppedAdjustedEventsDiagnostic() { - if (diagnosticOutput == null) diagnosticOutput = new PartitionedDiagnosticObservable(); - return diagnosticOutput; + if (this.diagnosticOutput == null) this.diagnosticOutput = new PartitionedDiagnosticObservable(); + return this.diagnosticOutput; } public override IDisposable Subscribe(IStreamObserver, TPayload> observer) @@ -753,26 +753,26 @@ public override IDisposable Subscribe(IStreamObserver(true); IIngressStreamObserver pipe = null; - if (properties.IsColumnar) pipe = GetPipe(observer); + if (this.properties.IsColumnar) pipe = this.GetPipe(observer); else { pipe = PartitionedStreamEventSubscriptionCreator.CreateSubscription( - observable, + this.observable, this.IngressSiteIdentifier, this, observer, - disorderPolicy, - flushPolicy, - punctuationPolicy, - lowWatermarkPolicy, - onCompletedPolicy, - diagnosticOutput, - fuseModule); + this.disorderPolicy, + this.flushPolicy, + this.punctuationPolicy, + this.lowWatermarkPolicy, + this.onCompletedPolicy, + this.diagnosticOutput, + this.fuseModule); } if (this.delayed) { - container.RegisterIngressPipe(this.IngressSiteIdentifier, pipe); + this.container.RegisterIngressPipe(this.IngressSiteIdentifier, pipe); return pipe.DelayedDisposable; } else @@ -785,27 +785,27 @@ public override IDisposable Subscribe(IStreamObserver> cachedPipes - = new SafeConcurrentDictionary>(); + = new(); private bool CanGenerateColumnar() { var lookupKey = CacheKey.Create( Tuple.Create( - fuseModule.ToString(), + this.fuseModule.ToString(), Config.AllowFloatingReorderPolicy, - punctuationPolicy.ToString(), - lowWatermarkPolicy.ToString(), - disorderPolicy.ToString(), - (disorderPolicy.type != DisorderPolicyType.Throw && diagnosticOutput != null ? "WithDiagnostic" : string.Empty))); + this.punctuationPolicy.ToString(), + this.lowWatermarkPolicy.ToString(), + this.disorderPolicy.ToString(), + (this.disorderPolicy.type != DisorderPolicyType.Throw && this.diagnosticOutput != null ? "WithDiagnostic" : string.Empty))); var generatedPipeType = cachedPipes.GetOrAdd( lookupKey, key => TemporalIngressTemplate.Generate( - disorderPolicy.reorderLatency > 0 ? "WithLatency" : string.Empty, - disorderPolicy.type != DisorderPolicyType.Throw && diagnosticOutput != null ? "WithDiagnostic" : string.Empty, - fuseModule)); + this.disorderPolicy.reorderLatency > 0 ? "WithLatency" : string.Empty, + this.disorderPolicy.type != DisorderPolicyType.Throw && this.diagnosticOutput != null ? "WithDiagnostic" : string.Empty, + this.fuseModule)); - errorMessages = generatedPipeType.Item2; + this.errorMessages = generatedPipeType.Item2; return generatedPipeType.Item1 != null; } @@ -813,33 +813,33 @@ private IIngressStreamObserver GetPipe(IStreamObserver TemporalIngressTemplate.Generate( - disorderPolicy.reorderLatency > 0 ? "WithLatency" : string.Empty, - disorderPolicy.type != DisorderPolicyType.Throw && diagnosticOutput != null ? "WithDiagnostic" : string.Empty, - fuseModule)); + this.disorderPolicy.reorderLatency > 0 ? "WithLatency" : string.Empty, + this.disorderPolicy.type != DisorderPolicyType.Throw && this.diagnosticOutput != null ? "WithDiagnostic" : string.Empty, + this.fuseModule)); instance = Activator.CreateInstance( generatedPipeType.Item1, - observable, this.IngressSiteIdentifier, this, observer, disorderPolicy, flushPolicy, punctuationPolicy, lowWatermarkPolicy, onCompletedPolicy, diagnosticOutput); + this.observable, this.IngressSiteIdentifier, this, observer, this.disorderPolicy, this.flushPolicy, this.punctuationPolicy, this.lowWatermarkPolicy, this.onCompletedPolicy, this.diagnosticOutput); var returnValue = (IIngressStreamObserver)instance; return returnValue; } public override string ToString() { - if (container != null) - return "RegisterInput({0}, " + disorderPolicy.ToString() + ", " + flushPolicy.ToString() + ", " + punctuationPolicy.ToString() + ", " + lowWatermarkPolicy.ToString() + ", " + onCompletedPolicy.ToString() + ")"; + if (this.container != null) + return "RegisterInput({0}, " + this.disorderPolicy.ToString() + ", " + this.flushPolicy.ToString() + ", " + this.punctuationPolicy.ToString() + ", " + this.lowWatermarkPolicy.ToString() + ", " + this.onCompletedPolicy.ToString() + ")"; else - return "ToStreamable(" + disorderPolicy.ToString() + ", " + flushPolicy.ToString() + ", " + punctuationPolicy.ToString() + ", " + lowWatermarkPolicy.ToString() + ", " + onCompletedPolicy.ToString() + ")"; + return "ToStreamable(" + this.disorderPolicy.ToString() + ", " + this.flushPolicy.ToString() + ", " + this.punctuationPolicy.ToString() + ", " + this.lowWatermarkPolicy.ToString() + ", " + this.onCompletedPolicy.ToString() + ")"; } public bool CanFuseSelect(LambdaExpression expression, bool hasStart, bool hasKey) => true; @@ -847,65 +847,65 @@ public override string ToString() public IFusibleStreamable, TNewResult> FuseSelect(Expression> expression) { return new PartitionedStreamEventIngressStreamableFused( - observable, - disorderPolicy, - flushPolicy, - punctuationPolicy, - lowWatermarkPolicy, - onCompletedPolicy, - container, - this.IngressSiteIdentifier, - fuseModule.Clone().FuseSelect(expression), + this.observable, + this.disorderPolicy, + this.flushPolicy, + this.punctuationPolicy, + this.lowWatermarkPolicy, + this.onCompletedPolicy, + this.container, + this.IngressSiteIdentifier, + this.fuseModule.Clone().FuseSelect(expression), this, - Properties.Select(expression, false, false)); + this.Properties.Select(expression, false, false)); } public IFusibleStreamable, TNewResult> FuseSelect(Expression> expression) { return new PartitionedStreamEventIngressStreamableFused( - observable, - disorderPolicy, - flushPolicy, - punctuationPolicy, - lowWatermarkPolicy, - onCompletedPolicy, - container, - this.IngressSiteIdentifier, - fuseModule.Clone().FuseSelect(expression), + this.observable, + this.disorderPolicy, + this.flushPolicy, + this.punctuationPolicy, + this.lowWatermarkPolicy, + this.onCompletedPolicy, + this.container, + this.IngressSiteIdentifier, + this.fuseModule.Clone().FuseSelect(expression), this, - Properties.Select(expression, true, false, true)); + this.Properties.Select(expression, true, false, true)); } public IFusibleStreamable, TNewResult> FuseSelectWithKey(Expression, TPayload, TNewResult>> expression) { return new PartitionedStreamEventIngressStreamableFused( - observable, - disorderPolicy, - flushPolicy, - punctuationPolicy, - lowWatermarkPolicy, - onCompletedPolicy, - container, - this.IngressSiteIdentifier, - fuseModule.Clone().FuseSelectWithKey(expression), + this.observable, + this.disorderPolicy, + this.flushPolicy, + this.punctuationPolicy, + this.lowWatermarkPolicy, + this.onCompletedPolicy, + this.container, + this.IngressSiteIdentifier, + this.fuseModule.Clone().FuseSelectWithKey(expression), this, - Properties.Select(expression, false, true)); + this.Properties.Select(expression, false, true)); } public IFusibleStreamable, TNewResult> FuseSelectWithKey(Expression, TPayload, TNewResult>> expression) { return new PartitionedStreamEventIngressStreamableFused( - observable, - disorderPolicy, - flushPolicy, - punctuationPolicy, - lowWatermarkPolicy, - onCompletedPolicy, - container, - this.IngressSiteIdentifier, - fuseModule.Clone().FuseSelectWithKey(expression), + this.observable, + this.disorderPolicy, + this.flushPolicy, + this.punctuationPolicy, + this.lowWatermarkPolicy, + this.onCompletedPolicy, + this.container, + this.IngressSiteIdentifier, + this.fuseModule.Clone().FuseSelectWithKey(expression), this, - Properties.Select(expression, true, true)); + this.Properties.Select(expression, true, true)); } public bool CanFuseSelectMany(LambdaExpression expression, bool hasStart, bool hasKey) => true; @@ -913,108 +913,108 @@ public IFusibleStreamable, TNewResult> FuseSelectWit public IFusibleStreamable, TNewResult> FuseSelectMany(Expression>> expression) { return new PartitionedStreamEventIngressStreamableFused( - observable, - disorderPolicy, - flushPolicy, - punctuationPolicy, - lowWatermarkPolicy, - onCompletedPolicy, - container, - this.IngressSiteIdentifier, - fuseModule.Clone().FuseSelectMany(expression), + this.observable, + this.disorderPolicy, + this.flushPolicy, + this.punctuationPolicy, + this.lowWatermarkPolicy, + this.onCompletedPolicy, + this.container, + this.IngressSiteIdentifier, + this.fuseModule.Clone().FuseSelectMany(expression), this, - Properties.SelectMany(expression)); + this.Properties.SelectMany(expression)); } public IFusibleStreamable, TNewResult> FuseSelectMany(Expression>> expression) { return new PartitionedStreamEventIngressStreamableFused( - observable, - disorderPolicy, - flushPolicy, - punctuationPolicy, - lowWatermarkPolicy, - onCompletedPolicy, - container, - this.IngressSiteIdentifier, - fuseModule.Clone().FuseSelectMany(expression), + this.observable, + this.disorderPolicy, + this.flushPolicy, + this.punctuationPolicy, + this.lowWatermarkPolicy, + this.onCompletedPolicy, + this.container, + this.IngressSiteIdentifier, + this.fuseModule.Clone().FuseSelectMany(expression), this, - Properties.SelectMany(expression)); + this.Properties.SelectMany(expression)); } public IFusibleStreamable, TNewResult> FuseSelectManyWithKey(Expression, TPayload, System.Collections.Generic.IEnumerable>> expression) { return new PartitionedStreamEventIngressStreamableFused( - observable, - disorderPolicy, - flushPolicy, - punctuationPolicy, - lowWatermarkPolicy, - onCompletedPolicy, - container, - this.IngressSiteIdentifier, - fuseModule.Clone().FuseSelectManyWithKey(expression), + this.observable, + this.disorderPolicy, + this.flushPolicy, + this.punctuationPolicy, + this.lowWatermarkPolicy, + this.onCompletedPolicy, + this.container, + this.IngressSiteIdentifier, + this.fuseModule.Clone().FuseSelectManyWithKey(expression), this, - Properties.SelectMany(expression)); + this.Properties.SelectMany(expression)); } public IFusibleStreamable, TNewResult> FuseSelectManyWithKey(Expression, TPayload, System.Collections.Generic.IEnumerable>> expression) { return new PartitionedStreamEventIngressStreamableFused( - observable, - disorderPolicy, - flushPolicy, - punctuationPolicy, - lowWatermarkPolicy, - onCompletedPolicy, - container, - this.IngressSiteIdentifier, - fuseModule.Clone().FuseSelectManyWithKey(expression), + this.observable, + this.disorderPolicy, + this.flushPolicy, + this.punctuationPolicy, + this.lowWatermarkPolicy, + this.onCompletedPolicy, + this.container, + this.IngressSiteIdentifier, + this.fuseModule.Clone().FuseSelectManyWithKey(expression), this, - Properties.SelectMany(expression)); + this.Properties.SelectMany(expression)); } public IFusibleStreamable, TPayload> FuseWhere(Expression> expression) { return new PartitionedStreamEventIngressStreamableFused( - observable, - disorderPolicy, - flushPolicy, - punctuationPolicy, - lowWatermarkPolicy, - onCompletedPolicy, - container, - this.IngressSiteIdentifier, - fuseModule.Clone().FuseWhere(expression), + this.observable, + this.disorderPolicy, + this.flushPolicy, + this.punctuationPolicy, + this.lowWatermarkPolicy, + this.onCompletedPolicy, + this.container, + this.IngressSiteIdentifier, + this.fuseModule.Clone().FuseWhere(expression), this, - Properties.Where(expression)); + this.Properties.Where(expression)); } public IFusibleStreamable, TPayload> FuseSetDurationConstant(long value) { return new PartitionedStreamEventIngressStreamableFused( - observable, - disorderPolicy, - flushPolicy, - punctuationPolicy, - lowWatermarkPolicy, - onCompletedPolicy, - container, - this.IngressSiteIdentifier, - fuseModule.Clone().FuseSetDurationConstant(value), + this.observable, + this.disorderPolicy, + this.flushPolicy, + this.punctuationPolicy, + this.lowWatermarkPolicy, + this.onCompletedPolicy, + this.container, + this.IngressSiteIdentifier, + this.fuseModule.Clone().FuseSetDurationConstant(value), this, - Properties.ToConstantDuration(true, value)); + this.Properties.ToConstantDuration(true, value)); } public IObservable FuseEgressObservable(Expression, TNewResult>> expression, QueryContainer container, string identifier) { return new FusedObservable, PartitionedStreamEvent, TPayload, TPayload, TNewResult>( - observable, + this.observable, (o) => o.SyncTime, (o) => o.OtherTime, (o) => new PartitionKey(o.PartitionKey), (o) => o.Payload, - fuseModule, + this.fuseModule, expression, container, this.IngressSiteIdentifier, @@ -1056,8 +1056,8 @@ public PartitionedIntervalIngressStreamable( string identifier) : base(StreamProperties, TPayload>.DefaultIngress(startEdgeExtractor, endEdgeExtractor).SetQueryContainer(container)) { - Contract.Requires(observable != null); - Contract.Requires(identifier != null); + ArgumentNullException.ThrowIfNull(observable); + ArgumentNullException.ThrowIfNull(identifier); this.IngressSiteIdentifier = identifier; this.observable = observable; @@ -1074,22 +1074,22 @@ public PartitionedIntervalIngressStreamable( this.fuseModule = new FuseModule(); if (this.delayed) container.RegisterIngressSite(this.IngressSiteIdentifier); - this.properties = properties.ToRowBased(); + this.properties = this.properties.ToRowBased(); } - public void Dispose() => diagnosticOutput?.Dispose(); + public void Dispose() => this.diagnosticOutput?.Dispose(); [ContractInvariantMethod] [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic", Justification = "Required for code contracts.")] private void ObjectInvariant() { - Contract.Invariant(observable != null); + Contract.Invariant(this.observable != null); } public IObservable> GetDroppedAdjustedEventsDiagnostic() { - if (diagnosticOutput == null) diagnosticOutput = new PartitionedDiagnosticObservable(); - return diagnosticOutput; + if (this.diagnosticOutput == null) this.diagnosticOutput = new PartitionedDiagnosticObservable(); + return this.diagnosticOutput; } public override IDisposable Subscribe(IStreamObserver, TPayload> observer) @@ -1097,29 +1097,29 @@ public override IDisposable Subscribe(IStreamObserver(true); IIngressStreamObserver pipe = null; - if (properties.IsColumnar) pipe = GetPipe(observer); + if (this.properties.IsColumnar) pipe = this.GetPipe(observer); else { pipe = PartitionedIntervalSubscriptionCreator.CreateSubscription( - observable, - partitionExtractor, - startEdgeExtractor, - endEdgeExtractor, + this.observable, + this.partitionExtractor, + this.startEdgeExtractor, + this.endEdgeExtractor, this.IngressSiteIdentifier, this, observer, - disorderPolicy, - flushPolicy, - punctuationPolicy, - lowWatermarkPolicy, - onCompletedPolicy, - diagnosticOutput, - fuseModule); + this.disorderPolicy, + this.flushPolicy, + this.punctuationPolicy, + this.lowWatermarkPolicy, + this.onCompletedPolicy, + this.diagnosticOutput, + this.fuseModule); } if (this.delayed) { - container.RegisterIngressPipe(this.IngressSiteIdentifier, pipe); + this.container.RegisterIngressPipe(this.IngressSiteIdentifier, pipe); return pipe.DelayedDisposable; } else @@ -1132,34 +1132,34 @@ public override IDisposable Subscribe(IStreamObserver> cachedPipes - = new SafeConcurrentDictionary>(); + = new(); private bool CanGenerateColumnar() { var lookupKey = CacheKey.Create( Tuple.Create( - startEdgeExtractor.ExpressionToCSharp(), - endEdgeExtractor != null ? endEdgeExtractor.ExpressionToCSharp() : string.Empty, - partitionExtractor.ExpressionToCSharp()), + this.startEdgeExtractor.ExpressionToCSharp(), + this.endEdgeExtractor != null ? this.endEdgeExtractor.ExpressionToCSharp() : string.Empty, + this.partitionExtractor.ExpressionToCSharp()), Tuple.Create( - fuseModule.ToString(), + this.fuseModule.ToString(), Config.AllowFloatingReorderPolicy, - punctuationPolicy.ToString(), - lowWatermarkPolicy.ToString(), - disorderPolicy.ToString(), - (disorderPolicy.type != DisorderPolicyType.Throw && diagnosticOutput != null ? "WithDiagnostic" : string.Empty))); + this.punctuationPolicy.ToString(), + this.lowWatermarkPolicy.ToString(), + this.disorderPolicy.ToString(), + (this.disorderPolicy.type != DisorderPolicyType.Throw && this.diagnosticOutput != null ? "WithDiagnostic" : string.Empty))); var generatedPipeType = cachedPipes.GetOrAdd( lookupKey, key => TemporalIngressTemplate.Generate( - partitionExtractor, - startEdgeExtractor, - endEdgeExtractor, - disorderPolicy.reorderLatency > 0 ? "WithLatency" : string.Empty, - disorderPolicy.type != DisorderPolicyType.Throw && diagnosticOutput != null ? "WithDiagnostic" : string.Empty, - fuseModule)); - - errorMessages = generatedPipeType.Item2; + this.partitionExtractor, + this.startEdgeExtractor, + this.endEdgeExtractor, + this.disorderPolicy.reorderLatency > 0 ? "WithLatency" : string.Empty, + this.disorderPolicy.type != DisorderPolicyType.Throw && this.diagnosticOutput != null ? "WithDiagnostic" : string.Empty, + this.fuseModule)); + + this.errorMessages = generatedPipeType.Item2; return generatedPipeType.Item1 != null; } @@ -1167,30 +1167,30 @@ private IIngressStreamObserver GetPipe(IStreamObserver TemporalIngressTemplate.Generate( - partitionExtractor, - startEdgeExtractor, - endEdgeExtractor, - disorderPolicy.reorderLatency > 0 ? "WithLatency" : string.Empty, - disorderPolicy.type != DisorderPolicyType.Throw && diagnosticOutput != null ? "WithDiagnostic" : string.Empty, - fuseModule)); + this.partitionExtractor, + this.startEdgeExtractor, + this.endEdgeExtractor, + this.disorderPolicy.reorderLatency > 0 ? "WithLatency" : string.Empty, + this.disorderPolicy.type != DisorderPolicyType.Throw && this.diagnosticOutput != null ? "WithDiagnostic" : string.Empty, + this.fuseModule)); instance = Activator.CreateInstance( generatedPipeType.Item1, - observable, this.IngressSiteIdentifier, this, observer, disorderPolicy, flushPolicy, punctuationPolicy, lowWatermarkPolicy, onCompletedPolicy, diagnosticOutput); + this.observable, this.IngressSiteIdentifier, this, observer, this.disorderPolicy, this.flushPolicy, this.punctuationPolicy, this.lowWatermarkPolicy, this.onCompletedPolicy, this.diagnosticOutput); var returnValue = (IIngressStreamObserver)instance; return returnValue; } @@ -1200,77 +1200,77 @@ private IIngressStreamObserver GetPipe(IStreamObserver, TNewResult> FuseSelect(Expression> expression) { return new PartitionedIntervalIngressStreamableFused( - observable, - partitionExtractor, - startEdgeExtractor, - endEdgeExtractor, - disorderPolicy, - flushPolicy, - punctuationPolicy, - lowWatermarkPolicy, - onCompletedPolicy, - container, - this.IngressSiteIdentifier, - fuseModule.Clone().FuseSelect(expression), + this.observable, + this.partitionExtractor, + this.startEdgeExtractor, + this.endEdgeExtractor, + this.disorderPolicy, + this.flushPolicy, + this.punctuationPolicy, + this.lowWatermarkPolicy, + this.onCompletedPolicy, + this.container, + this.IngressSiteIdentifier, + this.fuseModule.Clone().FuseSelect(expression), this, - Properties.Select(expression, false, false)); + this.Properties.Select(expression, false, false)); } public IFusibleStreamable, TNewResult> FuseSelect(Expression> expression) { return new PartitionedIntervalIngressStreamableFused( - observable, - partitionExtractor, - startEdgeExtractor, - endEdgeExtractor, - disorderPolicy, - flushPolicy, - punctuationPolicy, - lowWatermarkPolicy, - onCompletedPolicy, - container, - this.IngressSiteIdentifier, - fuseModule.Clone().FuseSelect(expression), + this.observable, + this.partitionExtractor, + this.startEdgeExtractor, + this.endEdgeExtractor, + this.disorderPolicy, + this.flushPolicy, + this.punctuationPolicy, + this.lowWatermarkPolicy, + this.onCompletedPolicy, + this.container, + this.IngressSiteIdentifier, + this.fuseModule.Clone().FuseSelect(expression), this, - Properties.Select(expression, true, false, true)); + this.Properties.Select(expression, true, false, true)); } public IFusibleStreamable, TNewResult> FuseSelectWithKey(Expression, TPayload, TNewResult>> expression) { return new PartitionedIntervalIngressStreamableFused( - observable, - partitionExtractor, - startEdgeExtractor, - endEdgeExtractor, - disorderPolicy, - flushPolicy, - punctuationPolicy, - lowWatermarkPolicy, - onCompletedPolicy, - container, - this.IngressSiteIdentifier, - fuseModule.Clone().FuseSelectWithKey(expression), + this.observable, + this.partitionExtractor, + this.startEdgeExtractor, + this.endEdgeExtractor, + this.disorderPolicy, + this.flushPolicy, + this.punctuationPolicy, + this.lowWatermarkPolicy, + this.onCompletedPolicy, + this.container, + this.IngressSiteIdentifier, + this.fuseModule.Clone().FuseSelectWithKey(expression), this, - Properties.Select(expression, false, true)); + this.Properties.Select(expression, false, true)); } public IFusibleStreamable, TNewResult> FuseSelectWithKey(Expression, TPayload, TNewResult>> expression) { return new PartitionedIntervalIngressStreamableFused( - observable, - partitionExtractor, - startEdgeExtractor, - endEdgeExtractor, - disorderPolicy, - flushPolicy, - punctuationPolicy, - lowWatermarkPolicy, - onCompletedPolicy, - container, - this.IngressSiteIdentifier, - fuseModule.Clone().FuseSelectWithKey(expression), + this.observable, + this.partitionExtractor, + this.startEdgeExtractor, + this.endEdgeExtractor, + this.disorderPolicy, + this.flushPolicy, + this.punctuationPolicy, + this.lowWatermarkPolicy, + this.onCompletedPolicy, + this.container, + this.IngressSiteIdentifier, + this.fuseModule.Clone().FuseSelectWithKey(expression), this, - Properties.Select(expression, true, true)); + this.Properties.Select(expression, true, true)); } public bool CanFuseSelectMany(LambdaExpression expression, bool hasStart, bool hasKey) => true; @@ -1278,126 +1278,126 @@ public IFusibleStreamable, TNewResult> FuseSelectWit public IFusibleStreamable, TNewResult> FuseSelectMany(Expression>> expression) { return new PartitionedIntervalIngressStreamableFused( - observable, - partitionExtractor, - startEdgeExtractor, - endEdgeExtractor, - disorderPolicy, - flushPolicy, - punctuationPolicy, - lowWatermarkPolicy, - onCompletedPolicy, - container, - this.IngressSiteIdentifier, - fuseModule.Clone().FuseSelectMany(expression), + this.observable, + this.partitionExtractor, + this.startEdgeExtractor, + this.endEdgeExtractor, + this.disorderPolicy, + this.flushPolicy, + this.punctuationPolicy, + this.lowWatermarkPolicy, + this.onCompletedPolicy, + this.container, + this.IngressSiteIdentifier, + this.fuseModule.Clone().FuseSelectMany(expression), this, - Properties.SelectMany(expression)); + this.Properties.SelectMany(expression)); } public IFusibleStreamable, TNewResult> FuseSelectMany(Expression>> expression) { return new PartitionedIntervalIngressStreamableFused( - observable, - partitionExtractor, - startEdgeExtractor, - endEdgeExtractor, - disorderPolicy, - flushPolicy, - punctuationPolicy, - lowWatermarkPolicy, - onCompletedPolicy, - container, - this.IngressSiteIdentifier, - fuseModule.Clone().FuseSelectMany(expression), + this.observable, + this.partitionExtractor, + this.startEdgeExtractor, + this.endEdgeExtractor, + this.disorderPolicy, + this.flushPolicy, + this.punctuationPolicy, + this.lowWatermarkPolicy, + this.onCompletedPolicy, + this.container, + this.IngressSiteIdentifier, + this.fuseModule.Clone().FuseSelectMany(expression), this, - Properties.SelectMany(expression)); + this.Properties.SelectMany(expression)); } public IFusibleStreamable, TNewResult> FuseSelectManyWithKey(Expression, TPayload, System.Collections.Generic.IEnumerable>> expression) { return new PartitionedIntervalIngressStreamableFused( - observable, - partitionExtractor, - startEdgeExtractor, - endEdgeExtractor, - disorderPolicy, - flushPolicy, - punctuationPolicy, - lowWatermarkPolicy, - onCompletedPolicy, - container, - this.IngressSiteIdentifier, - fuseModule.Clone().FuseSelectManyWithKey(expression), + this.observable, + this.partitionExtractor, + this.startEdgeExtractor, + this.endEdgeExtractor, + this.disorderPolicy, + this.flushPolicy, + this.punctuationPolicy, + this.lowWatermarkPolicy, + this.onCompletedPolicy, + this.container, + this.IngressSiteIdentifier, + this.fuseModule.Clone().FuseSelectManyWithKey(expression), this, - Properties.SelectMany(expression)); + this.Properties.SelectMany(expression)); } public IFusibleStreamable, TNewResult> FuseSelectManyWithKey(Expression, TPayload, System.Collections.Generic.IEnumerable>> expression) { return new PartitionedIntervalIngressStreamableFused( - observable, - partitionExtractor, - startEdgeExtractor, - endEdgeExtractor, - disorderPolicy, - flushPolicy, - punctuationPolicy, - lowWatermarkPolicy, - onCompletedPolicy, - container, - this.IngressSiteIdentifier, - fuseModule.Clone().FuseSelectManyWithKey(expression), + this.observable, + this.partitionExtractor, + this.startEdgeExtractor, + this.endEdgeExtractor, + this.disorderPolicy, + this.flushPolicy, + this.punctuationPolicy, + this.lowWatermarkPolicy, + this.onCompletedPolicy, + this.container, + this.IngressSiteIdentifier, + this.fuseModule.Clone().FuseSelectManyWithKey(expression), this, - Properties.SelectMany(expression)); + this.Properties.SelectMany(expression)); } public IFusibleStreamable, TPayload> FuseWhere(Expression> expression) { return new PartitionedIntervalIngressStreamableFused( - observable, - partitionExtractor, - startEdgeExtractor, - endEdgeExtractor, - disorderPolicy, - flushPolicy, - punctuationPolicy, - lowWatermarkPolicy, - onCompletedPolicy, - container, - this.IngressSiteIdentifier, - fuseModule.Clone().FuseWhere(expression), + this.observable, + this.partitionExtractor, + this.startEdgeExtractor, + this.endEdgeExtractor, + this.disorderPolicy, + this.flushPolicy, + this.punctuationPolicy, + this.lowWatermarkPolicy, + this.onCompletedPolicy, + this.container, + this.IngressSiteIdentifier, + this.fuseModule.Clone().FuseWhere(expression), this, - Properties.Where(expression)); + this.Properties.Where(expression)); } public IFusibleStreamable, TPayload> FuseSetDurationConstant(long value) { return new PartitionedIntervalIngressStreamableFused( - observable, - partitionExtractor, - startEdgeExtractor, - endEdgeExtractor, - disorderPolicy, - flushPolicy, - punctuationPolicy, - lowWatermarkPolicy, - onCompletedPolicy, - container, - this.IngressSiteIdentifier, - fuseModule.Clone().FuseSetDurationConstant(value), + this.observable, + this.partitionExtractor, + this.startEdgeExtractor, + this.endEdgeExtractor, + this.disorderPolicy, + this.flushPolicy, + this.punctuationPolicy, + this.lowWatermarkPolicy, + this.onCompletedPolicy, + this.container, + this.IngressSiteIdentifier, + this.fuseModule.Clone().FuseSetDurationConstant(value), this, - Properties.ToConstantDuration(true, value)); + this.Properties.ToConstantDuration(true, value)); } public IObservable FuseEgressObservable(Expression, TNewResult>> expression, QueryContainer container, string identifier) { return new FusedObservable, TPayload, TPayload, TPayload, TNewResult>( - observable, - startEdgeExtractor, - endEdgeExtractor, - ParameterSubstituter.AddPartitionKey(partitionExtractor), + this.observable, + this.startEdgeExtractor, + this.endEdgeExtractor, + ParameterSubstituter.AddPartitionKey(this.partitionExtractor), (o) => o, - fuseModule, + this.fuseModule, expression, container, this.IngressSiteIdentifier, @@ -1433,8 +1433,8 @@ public StreamEventIngressStreamableFused( StreamProperties properties) : base(properties) { - Contract.Requires(observable != null); - Contract.Requires(identifier != null); + ArgumentNullException.ThrowIfNull(observable); + ArgumentNullException.ThrowIfNull(identifier); this.IngressSiteIdentifier = identifier; this.observable = observable; @@ -1455,21 +1455,21 @@ public StreamEventIngressStreamableFused( { this.properties = properties.ToRowBased(); } - else this.properties = properties.ToDelayedColumnar(CanGenerateColumnar); + else this.properties = properties.ToDelayedColumnar(this.CanGenerateColumnar); } - public void Dispose() => entryPoint?.Dispose(); + public void Dispose() => this.entryPoint?.Dispose(); [ContractInvariantMethod] [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic", Justification = "Required for code contracts.")] private void ObjectInvariant() { - Contract.Invariant(observable != null); + Contract.Invariant(this.observable != null); } public IObservable> GetDroppedAdjustedEventsDiagnostic() { - return entryPoint.GetDroppedAdjustedEventsDiagnostic(); + return this.entryPoint.GetDroppedAdjustedEventsDiagnostic(); } public override IDisposable Subscribe(IStreamObserver observer) @@ -1477,25 +1477,25 @@ public override IDisposable Subscribe(IStreamObserver observer) Contract.EnsuresOnThrow(true); IIngressStreamObserver pipe = null; - if (properties.IsColumnar) pipe = GetPipe(observer); + if (this.properties.IsColumnar) pipe = this.GetPipe(observer); else { pipe = StreamEventSubscriptionCreator.CreateSubscription( - observable, + this.observable, this.IngressSiteIdentifier, this, observer, - disorderPolicy, - flushPolicy, - punctuationPolicy, - onCompletedPolicy, - entryPoint.diagnosticOutput, - fuseModule); + this.disorderPolicy, + this.flushPolicy, + this.punctuationPolicy, + this.onCompletedPolicy, + this.entryPoint.diagnosticOutput, + this.fuseModule); } if (this.delayed) { - container.RegisterIngressPipe(this.IngressSiteIdentifier, pipe); + this.container.RegisterIngressPipe(this.IngressSiteIdentifier, pipe); return pipe.DelayedDisposable; } else @@ -1508,26 +1508,26 @@ public override IDisposable Subscribe(IStreamObserver observer) public string IngressSiteIdentifier { get; private set; } = Guid.NewGuid().ToString(); private static readonly SafeConcurrentDictionary> cachedPipes - = new SafeConcurrentDictionary>(); + = new(); private bool CanGenerateColumnar() { var lookupKey = CacheKey.Create( Tuple.Create( - fuseModule.ToString(), + this.fuseModule.ToString(), Config.AllowFloatingReorderPolicy, - punctuationPolicy.ToString(), - disorderPolicy.ToString(), - (disorderPolicy.type != DisorderPolicyType.Throw && entryPoint.diagnosticOutput != null ? "WithDiagnostic" : string.Empty))); + this.punctuationPolicy.ToString(), + this.disorderPolicy.ToString(), + (this.disorderPolicy.type != DisorderPolicyType.Throw && this.entryPoint.diagnosticOutput != null ? "WithDiagnostic" : string.Empty))); var generatedPipeType = cachedPipes.GetOrAdd( lookupKey, key => TemporalIngressTemplate.GenerateFused( - disorderPolicy.reorderLatency > 0 ? "WithLatency" : string.Empty, - disorderPolicy.type != DisorderPolicyType.Throw && entryPoint.diagnosticOutput != null ? "WithDiagnostic" : string.Empty, - fuseModule)); + this.disorderPolicy.reorderLatency > 0 ? "WithLatency" : string.Empty, + this.disorderPolicy.type != DisorderPolicyType.Throw && this.entryPoint.diagnosticOutput != null ? "WithDiagnostic" : string.Empty, + this.fuseModule)); - errorMessages = generatedPipeType.Item2; + this.errorMessages = generatedPipeType.Item2; return generatedPipeType.Item1 != null; } @@ -1535,32 +1535,32 @@ private IIngressStreamObserver GetPipe(IStreamObserver observer) { var lookupKey = CacheKey.Create( Tuple.Create( - fuseModule.ToString(), + this.fuseModule.ToString(), Config.AllowFloatingReorderPolicy, - punctuationPolicy.ToString(), - disorderPolicy.ToString(), - (disorderPolicy.type != DisorderPolicyType.Throw && entryPoint.diagnosticOutput != null ? "WithDiagnostic" : string.Empty))); + this.punctuationPolicy.ToString(), + this.disorderPolicy.ToString(), + (this.disorderPolicy.type != DisorderPolicyType.Throw && this.entryPoint.diagnosticOutput != null ? "WithDiagnostic" : string.Empty))); object instance; var generatedPipeType = cachedPipes.GetOrAdd( lookupKey, key => TemporalIngressTemplate.GenerateFused( - disorderPolicy.reorderLatency > 0 ? "WithLatency" : string.Empty, - disorderPolicy.type != DisorderPolicyType.Throw && entryPoint.diagnosticOutput != null ? "WithDiagnostic" : string.Empty, - fuseModule)); + this.disorderPolicy.reorderLatency > 0 ? "WithLatency" : string.Empty, + this.disorderPolicy.type != DisorderPolicyType.Throw && this.entryPoint.diagnosticOutput != null ? "WithDiagnostic" : string.Empty, + this.fuseModule)); instance = Activator.CreateInstance( generatedPipeType.Item1, - observable, this.IngressSiteIdentifier, this, observer, disorderPolicy, flushPolicy, punctuationPolicy, onCompletedPolicy, entryPoint.diagnosticOutput); + this.observable, this.IngressSiteIdentifier, this, observer, this.disorderPolicy, this.flushPolicy, this.punctuationPolicy, this.onCompletedPolicy, this.entryPoint.diagnosticOutput); var returnValue = (IIngressStreamObserver)instance; return returnValue; } public override string ToString() { - if (container != null) - return "RegisterInput({0}, " + disorderPolicy.ToString() + ", " + flushPolicy.ToString() + ", " + punctuationPolicy.ToString() + ", " + onCompletedPolicy.ToString() + ")"; + if (this.container != null) + return "RegisterInput({0}, " + this.disorderPolicy.ToString() + ", " + this.flushPolicy.ToString() + ", " + this.punctuationPolicy.ToString() + ", " + this.onCompletedPolicy.ToString() + ")"; else - return "ToStreamable(" + disorderPolicy.ToString() + ", " + flushPolicy.ToString() + ", " + punctuationPolicy.ToString() + ", " + onCompletedPolicy.ToString() + ")"; + return "ToStreamable(" + this.disorderPolicy.ToString() + ", " + this.flushPolicy.ToString() + ", " + this.punctuationPolicy.ToString() + ", " + this.onCompletedPolicy.ToString() + ")"; } public bool CanFuseSelect(LambdaExpression expression, bool hasStart, bool hasKey) => true; @@ -1568,61 +1568,61 @@ public override string ToString() public IFusibleStreamable FuseSelect(Expression> expression) { return new StreamEventIngressStreamableFused( - observable, - disorderPolicy, - flushPolicy, - punctuationPolicy, - onCompletedPolicy, - container, + this.observable, + this.disorderPolicy, + this.flushPolicy, + this.punctuationPolicy, + this.onCompletedPolicy, + this.container, this.IngressSiteIdentifier, - fuseModule.Clone().FuseSelect(expression), - entryPoint, - Properties.Select(expression, false, false)); + this.fuseModule.Clone().FuseSelect(expression), + this.entryPoint, + this.Properties.Select(expression, false, false)); } public IFusibleStreamable FuseSelect(Expression> expression) { return new StreamEventIngressStreamableFused( - observable, - disorderPolicy, - flushPolicy, - punctuationPolicy, - onCompletedPolicy, - container, + this.observable, + this.disorderPolicy, + this.flushPolicy, + this.punctuationPolicy, + this.onCompletedPolicy, + this.container, this.IngressSiteIdentifier, - fuseModule.Clone().FuseSelect(expression), - entryPoint, - Properties.Select(expression, true, false, true)); + this.fuseModule.Clone().FuseSelect(expression), + this.entryPoint, + this.Properties.Select(expression, true, false, true)); } public IFusibleStreamable FuseSelectWithKey(Expression> expression) { return new StreamEventIngressStreamableFused( - observable, - disorderPolicy, - flushPolicy, - punctuationPolicy, - onCompletedPolicy, - container, + this.observable, + this.disorderPolicy, + this.flushPolicy, + this.punctuationPolicy, + this.onCompletedPolicy, + this.container, this.IngressSiteIdentifier, - fuseModule.Clone().FuseSelectWithKey(expression), - entryPoint, - Properties.Select(expression, false, true)); + this.fuseModule.Clone().FuseSelectWithKey(expression), + this.entryPoint, + this.Properties.Select(expression, false, true)); } public IFusibleStreamable FuseSelectWithKey(Expression> expression) { return new StreamEventIngressStreamableFused( - observable, - disorderPolicy, - flushPolicy, - punctuationPolicy, - onCompletedPolicy, - container, + this.observable, + this.disorderPolicy, + this.flushPolicy, + this.punctuationPolicy, + this.onCompletedPolicy, + this.container, this.IngressSiteIdentifier, - fuseModule.Clone().FuseSelectWithKey(expression), - entryPoint, - Properties.Select(expression, true, true)); + this.fuseModule.Clone().FuseSelectWithKey(expression), + this.entryPoint, + this.Properties.Select(expression, true, true)); } public bool CanFuseSelectMany(LambdaExpression expression, bool hasStart, bool hasKey) => true; @@ -1630,102 +1630,102 @@ public IFusibleStreamable FuseSelectWithKey(Expre public IFusibleStreamable FuseSelectMany(Expression>> expression) { return new StreamEventIngressStreamableFused( - observable, - disorderPolicy, - flushPolicy, - punctuationPolicy, - onCompletedPolicy, - container, + this.observable, + this.disorderPolicy, + this.flushPolicy, + this.punctuationPolicy, + this.onCompletedPolicy, + this.container, this.IngressSiteIdentifier, - fuseModule.Clone().FuseSelectMany(expression), - entryPoint, - Properties.SelectMany(expression)); + this.fuseModule.Clone().FuseSelectMany(expression), + this.entryPoint, + this.Properties.SelectMany(expression)); } public IFusibleStreamable FuseSelectMany(Expression>> expression) { return new StreamEventIngressStreamableFused( - observable, - disorderPolicy, - flushPolicy, - punctuationPolicy, - onCompletedPolicy, - container, + this.observable, + this.disorderPolicy, + this.flushPolicy, + this.punctuationPolicy, + this.onCompletedPolicy, + this.container, this.IngressSiteIdentifier, - fuseModule.Clone().FuseSelectMany(expression), - entryPoint, - Properties.SelectMany(expression)); + this.fuseModule.Clone().FuseSelectMany(expression), + this.entryPoint, + this.Properties.SelectMany(expression)); } public IFusibleStreamable FuseSelectManyWithKey(Expression>> expression) { return new StreamEventIngressStreamableFused( - observable, - disorderPolicy, - flushPolicy, - punctuationPolicy, - onCompletedPolicy, - container, + this.observable, + this.disorderPolicy, + this.flushPolicy, + this.punctuationPolicy, + this.onCompletedPolicy, + this.container, this.IngressSiteIdentifier, - fuseModule.Clone().FuseSelectManyWithKey(expression), - entryPoint, - Properties.SelectMany(expression)); + this.fuseModule.Clone().FuseSelectManyWithKey(expression), + this.entryPoint, + this.Properties.SelectMany(expression)); } public IFusibleStreamable FuseSelectManyWithKey(Expression>> expression) { return new StreamEventIngressStreamableFused( - observable, - disorderPolicy, - flushPolicy, - punctuationPolicy, - onCompletedPolicy, - container, + this.observable, + this.disorderPolicy, + this.flushPolicy, + this.punctuationPolicy, + this.onCompletedPolicy, + this.container, this.IngressSiteIdentifier, - fuseModule.Clone().FuseSelectManyWithKey(expression), - entryPoint, - Properties.SelectMany(expression)); + this.fuseModule.Clone().FuseSelectManyWithKey(expression), + this.entryPoint, + this.Properties.SelectMany(expression)); } public IFusibleStreamable FuseWhere(Expression> expression) { return new StreamEventIngressStreamableFused( - observable, - disorderPolicy, - flushPolicy, - punctuationPolicy, - onCompletedPolicy, - container, + this.observable, + this.disorderPolicy, + this.flushPolicy, + this.punctuationPolicy, + this.onCompletedPolicy, + this.container, this.IngressSiteIdentifier, - fuseModule.Clone().FuseWhere(expression), - entryPoint, - Properties.Where(expression)); + this.fuseModule.Clone().FuseWhere(expression), + this.entryPoint, + this.Properties.Where(expression)); } public IFusibleStreamable FuseSetDurationConstant(long value) { return new StreamEventIngressStreamableFused( - observable, - disorderPolicy, - flushPolicy, - punctuationPolicy, - onCompletedPolicy, - container, + this.observable, + this.disorderPolicy, + this.flushPolicy, + this.punctuationPolicy, + this.onCompletedPolicy, + this.container, this.IngressSiteIdentifier, - fuseModule.Clone().FuseSetDurationConstant(value), - entryPoint, - Properties.ToConstantDuration(true, value)); + this.fuseModule.Clone().FuseSetDurationConstant(value), + this.entryPoint, + this.Properties.ToConstantDuration(true, value)); } public IObservable FuseEgressObservable(Expression> expression, QueryContainer container, string identifier) { return new FusedObservable, TPayload, TResult, TNewResult>( - observable, + this.observable, (o) => o.SyncTime, (o) => o.OtherTime, (o) => Empty.Default, (o) => o.Payload, - fuseModule, + this.fuseModule, expression, container, this.IngressSiteIdentifier, @@ -1765,8 +1765,8 @@ public IntervalIngressStreamableFused( StreamProperties properties) : base(properties) { - Contract.Requires(observable != null); - Contract.Requires(identifier != null); + ArgumentNullException.ThrowIfNull(observable); + ArgumentNullException.ThrowIfNull(identifier); this.IngressSiteIdentifier = identifier; this.observable = observable; @@ -1789,21 +1789,21 @@ public IntervalIngressStreamableFused( { this.properties = properties.ToRowBased(); } - else this.properties = properties.ToDelayedColumnar(CanGenerateColumnar); + else this.properties = properties.ToDelayedColumnar(this.CanGenerateColumnar); } - public void Dispose() => entryPoint?.Dispose(); + public void Dispose() => this.entryPoint?.Dispose(); [ContractInvariantMethod] [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic", Justification = "Required for code contracts.")] private void ObjectInvariant() { - Contract.Invariant(observable != null); + Contract.Invariant(this.observable != null); } public IObservable> GetDroppedAdjustedEventsDiagnostic() { - return entryPoint.GetDroppedAdjustedEventsDiagnostic(); + return this.entryPoint.GetDroppedAdjustedEventsDiagnostic(); } public override IDisposable Subscribe(IStreamObserver observer) @@ -1811,27 +1811,27 @@ public override IDisposable Subscribe(IStreamObserver observer) Contract.EnsuresOnThrow(true); IIngressStreamObserver pipe = null; - if (properties.IsColumnar) pipe = GetPipe(observer); + if (this.properties.IsColumnar) pipe = this.GetPipe(observer); else { pipe = IntervalSubscriptionCreator.CreateSubscription( - observable, - startEdgeExtractor, - endEdgeExtractor, + this.observable, + this.startEdgeExtractor, + this.endEdgeExtractor, this.IngressSiteIdentifier, this, observer, - disorderPolicy, - flushPolicy, - punctuationPolicy, - onCompletedPolicy, - entryPoint.diagnosticOutput, - fuseModule); + this.disorderPolicy, + this.flushPolicy, + this.punctuationPolicy, + this.onCompletedPolicy, + this.entryPoint.diagnosticOutput, + this.fuseModule); } if (this.delayed) { - container.RegisterIngressPipe(this.IngressSiteIdentifier, pipe); + this.container.RegisterIngressPipe(this.IngressSiteIdentifier, pipe); return pipe.DelayedDisposable; } else @@ -1844,31 +1844,31 @@ public override IDisposable Subscribe(IStreamObserver observer) public string IngressSiteIdentifier { get; private set; } = Guid.NewGuid().ToString(); private static readonly SafeConcurrentDictionary> cachedPipes - = new SafeConcurrentDictionary>(); + = new(); private bool CanGenerateColumnar() { var lookupKey = CacheKey.Create( Tuple.Create( - startEdgeExtractor.ExpressionToCSharp(), - endEdgeExtractor != null ? endEdgeExtractor.ExpressionToCSharp() : string.Empty), + this.startEdgeExtractor.ExpressionToCSharp(), + this.endEdgeExtractor != null ? this.endEdgeExtractor.ExpressionToCSharp() : string.Empty), Tuple.Create( - fuseModule.ToString(), + this.fuseModule.ToString(), Config.AllowFloatingReorderPolicy, - punctuationPolicy.ToString(), - disorderPolicy.ToString(), - (disorderPolicy.type != DisorderPolicyType.Throw && entryPoint.diagnosticOutput != null ? "WithDiagnostic" : string.Empty))); + this.punctuationPolicy.ToString(), + this.disorderPolicy.ToString(), + (this.disorderPolicy.type != DisorderPolicyType.Throw && this.entryPoint.diagnosticOutput != null ? "WithDiagnostic" : string.Empty))); var generatedPipeType = cachedPipes.GetOrAdd( lookupKey, key => TemporalIngressTemplate.GenerateFused( - startEdgeExtractor, - endEdgeExtractor, - disorderPolicy.reorderLatency > 0 ? "WithLatency" : string.Empty, - disorderPolicy.type != DisorderPolicyType.Throw && entryPoint.diagnosticOutput != null ? "WithDiagnostic" : string.Empty, - fuseModule)); + this.startEdgeExtractor, + this.endEdgeExtractor, + this.disorderPolicy.reorderLatency > 0 ? "WithLatency" : string.Empty, + this.disorderPolicy.type != DisorderPolicyType.Throw && this.entryPoint.diagnosticOutput != null ? "WithDiagnostic" : string.Empty, + this.fuseModule)); - errorMessages = generatedPipeType.Item2; + this.errorMessages = generatedPipeType.Item2; return generatedPipeType.Item1 != null; } @@ -1876,27 +1876,27 @@ private IIngressStreamObserver GetPipe(IStreamObserver observer) { var lookupKey = CacheKey.Create( Tuple.Create( - startEdgeExtractor.ExpressionToCSharp(), - endEdgeExtractor != null ? endEdgeExtractor.ExpressionToCSharp() : string.Empty), + this.startEdgeExtractor.ExpressionToCSharp(), + this.endEdgeExtractor != null ? this.endEdgeExtractor.ExpressionToCSharp() : string.Empty), Tuple.Create( - fuseModule.ToString(), + this.fuseModule.ToString(), Config.AllowFloatingReorderPolicy, - punctuationPolicy.ToString(), - disorderPolicy.ToString(), - (disorderPolicy.type != DisorderPolicyType.Throw && entryPoint.diagnosticOutput != null ? "WithDiagnostic" : string.Empty))); + this.punctuationPolicy.ToString(), + this.disorderPolicy.ToString(), + (this.disorderPolicy.type != DisorderPolicyType.Throw && this.entryPoint.diagnosticOutput != null ? "WithDiagnostic" : string.Empty))); object instance; var generatedPipeType = cachedPipes.GetOrAdd( lookupKey, key => TemporalIngressTemplate.GenerateFused( - startEdgeExtractor, - endEdgeExtractor, - disorderPolicy.reorderLatency > 0 ? "WithLatency" : string.Empty, - disorderPolicy.type != DisorderPolicyType.Throw && entryPoint.diagnosticOutput != null ? "WithDiagnostic" : string.Empty, - fuseModule)); + this.startEdgeExtractor, + this.endEdgeExtractor, + this.disorderPolicy.reorderLatency > 0 ? "WithLatency" : string.Empty, + this.disorderPolicy.type != DisorderPolicyType.Throw && this.entryPoint.diagnosticOutput != null ? "WithDiagnostic" : string.Empty, + this.fuseModule)); instance = Activator.CreateInstance( generatedPipeType.Item1, - observable, this.IngressSiteIdentifier, this, observer, disorderPolicy, flushPolicy, punctuationPolicy, onCompletedPolicy, entryPoint.diagnosticOutput); + this.observable, this.IngressSiteIdentifier, this, observer, this.disorderPolicy, this.flushPolicy, this.punctuationPolicy, this.onCompletedPolicy, this.entryPoint.diagnosticOutput); var returnValue = (IIngressStreamObserver)instance; return returnValue; } @@ -1906,69 +1906,69 @@ private IIngressStreamObserver GetPipe(IStreamObserver observer) public IFusibleStreamable FuseSelect(Expression> expression) { return new IntervalIngressStreamableFused( - observable, - startEdgeExtractor, - endEdgeExtractor, - disorderPolicy, - flushPolicy, - punctuationPolicy, - onCompletedPolicy, - container, + this.observable, + this.startEdgeExtractor, + this.endEdgeExtractor, + this.disorderPolicy, + this.flushPolicy, + this.punctuationPolicy, + this.onCompletedPolicy, + this.container, this.IngressSiteIdentifier, - fuseModule.Clone().FuseSelect(expression), - entryPoint, - Properties.Select(expression, false, false)); + this.fuseModule.Clone().FuseSelect(expression), + this.entryPoint, + this.Properties.Select(expression, false, false)); } public IFusibleStreamable FuseSelect(Expression> expression) { return new IntervalIngressStreamableFused( - observable, - startEdgeExtractor, - endEdgeExtractor, - disorderPolicy, - flushPolicy, - punctuationPolicy, - onCompletedPolicy, - container, + this.observable, + this.startEdgeExtractor, + this.endEdgeExtractor, + this.disorderPolicy, + this.flushPolicy, + this.punctuationPolicy, + this.onCompletedPolicy, + this.container, this.IngressSiteIdentifier, - fuseModule.Clone().FuseSelect(expression), - entryPoint, - Properties.Select(expression, true, false, true)); + this.fuseModule.Clone().FuseSelect(expression), + this.entryPoint, + this.Properties.Select(expression, true, false, true)); } public IFusibleStreamable FuseSelectWithKey(Expression> expression) { return new IntervalIngressStreamableFused( - observable, - startEdgeExtractor, - endEdgeExtractor, - disorderPolicy, - flushPolicy, - punctuationPolicy, - onCompletedPolicy, - container, + this.observable, + this.startEdgeExtractor, + this.endEdgeExtractor, + this.disorderPolicy, + this.flushPolicy, + this.punctuationPolicy, + this.onCompletedPolicy, + this.container, this.IngressSiteIdentifier, - fuseModule.Clone().FuseSelectWithKey(expression), - entryPoint, - Properties.Select(expression, false, true)); + this.fuseModule.Clone().FuseSelectWithKey(expression), + this.entryPoint, + this.Properties.Select(expression, false, true)); } public IFusibleStreamable FuseSelectWithKey(Expression> expression) { return new IntervalIngressStreamableFused( - observable, - startEdgeExtractor, - endEdgeExtractor, - disorderPolicy, - flushPolicy, - punctuationPolicy, - onCompletedPolicy, - container, + this.observable, + this.startEdgeExtractor, + this.endEdgeExtractor, + this.disorderPolicy, + this.flushPolicy, + this.punctuationPolicy, + this.onCompletedPolicy, + this.container, this.IngressSiteIdentifier, - fuseModule.Clone().FuseSelectWithKey(expression), - entryPoint, - Properties.Select(expression, true, true)); + this.fuseModule.Clone().FuseSelectWithKey(expression), + this.entryPoint, + this.Properties.Select(expression, true, true)); } public bool CanFuseSelectMany(LambdaExpression expression, bool hasStart, bool hasKey) => true; @@ -1976,114 +1976,114 @@ public IFusibleStreamable FuseSelectWithKey(Expre public IFusibleStreamable FuseSelectMany(Expression>> expression) { return new IntervalIngressStreamableFused( - observable, - startEdgeExtractor, - endEdgeExtractor, - disorderPolicy, - flushPolicy, - punctuationPolicy, - onCompletedPolicy, - container, + this.observable, + this.startEdgeExtractor, + this.endEdgeExtractor, + this.disorderPolicy, + this.flushPolicy, + this.punctuationPolicy, + this.onCompletedPolicy, + this.container, this.IngressSiteIdentifier, - fuseModule.Clone().FuseSelectMany(expression), - entryPoint, - Properties.SelectMany(expression)); + this.fuseModule.Clone().FuseSelectMany(expression), + this.entryPoint, + this.Properties.SelectMany(expression)); } public IFusibleStreamable FuseSelectMany(Expression>> expression) { return new IntervalIngressStreamableFused( - observable, - startEdgeExtractor, - endEdgeExtractor, - disorderPolicy, - flushPolicy, - punctuationPolicy, - onCompletedPolicy, - container, + this.observable, + this.startEdgeExtractor, + this.endEdgeExtractor, + this.disorderPolicy, + this.flushPolicy, + this.punctuationPolicy, + this.onCompletedPolicy, + this.container, this.IngressSiteIdentifier, - fuseModule.Clone().FuseSelectMany(expression), - entryPoint, - Properties.SelectMany(expression)); + this.fuseModule.Clone().FuseSelectMany(expression), + this.entryPoint, + this.Properties.SelectMany(expression)); } public IFusibleStreamable FuseSelectManyWithKey(Expression>> expression) { return new IntervalIngressStreamableFused( - observable, - startEdgeExtractor, - endEdgeExtractor, - disorderPolicy, - flushPolicy, - punctuationPolicy, - onCompletedPolicy, - container, + this.observable, + this.startEdgeExtractor, + this.endEdgeExtractor, + this.disorderPolicy, + this.flushPolicy, + this.punctuationPolicy, + this.onCompletedPolicy, + this.container, this.IngressSiteIdentifier, - fuseModule.Clone().FuseSelectManyWithKey(expression), - entryPoint, - Properties.SelectMany(expression)); + this.fuseModule.Clone().FuseSelectManyWithKey(expression), + this.entryPoint, + this.Properties.SelectMany(expression)); } public IFusibleStreamable FuseSelectManyWithKey(Expression>> expression) { return new IntervalIngressStreamableFused( - observable, - startEdgeExtractor, - endEdgeExtractor, - disorderPolicy, - flushPolicy, - punctuationPolicy, - onCompletedPolicy, - container, + this.observable, + this.startEdgeExtractor, + this.endEdgeExtractor, + this.disorderPolicy, + this.flushPolicy, + this.punctuationPolicy, + this.onCompletedPolicy, + this.container, this.IngressSiteIdentifier, - fuseModule.Clone().FuseSelectManyWithKey(expression), - entryPoint, - Properties.SelectMany(expression)); + this.fuseModule.Clone().FuseSelectManyWithKey(expression), + this.entryPoint, + this.Properties.SelectMany(expression)); } public IFusibleStreamable FuseWhere(Expression> expression) { return new IntervalIngressStreamableFused( - observable, - startEdgeExtractor, - endEdgeExtractor, - disorderPolicy, - flushPolicy, - punctuationPolicy, - onCompletedPolicy, - container, + this.observable, + this.startEdgeExtractor, + this.endEdgeExtractor, + this.disorderPolicy, + this.flushPolicy, + this.punctuationPolicy, + this.onCompletedPolicy, + this.container, this.IngressSiteIdentifier, - fuseModule.Clone().FuseWhere(expression), - entryPoint, - Properties.Where(expression)); + this.fuseModule.Clone().FuseWhere(expression), + this.entryPoint, + this.Properties.Where(expression)); } public IFusibleStreamable FuseSetDurationConstant(long value) { return new IntervalIngressStreamableFused( - observable, - startEdgeExtractor, - endEdgeExtractor, - disorderPolicy, - flushPolicy, - punctuationPolicy, - onCompletedPolicy, - container, + this.observable, + this.startEdgeExtractor, + this.endEdgeExtractor, + this.disorderPolicy, + this.flushPolicy, + this.punctuationPolicy, + this.onCompletedPolicy, + this.container, this.IngressSiteIdentifier, - fuseModule.Clone().FuseSetDurationConstant(value), - entryPoint, - Properties.ToConstantDuration(true, value)); + this.fuseModule.Clone().FuseSetDurationConstant(value), + this.entryPoint, + this.Properties.ToConstantDuration(true, value)); } public IObservable FuseEgressObservable(Expression> expression, QueryContainer container, string identifier) { return new FusedObservable( - observable, - startEdgeExtractor, - endEdgeExtractor, + this.observable, + this.startEdgeExtractor, + this.endEdgeExtractor, (o) => Empty.Default, (o) => o, - fuseModule, + this.fuseModule, expression, container, this.IngressSiteIdentifier, @@ -2121,8 +2121,8 @@ public PartitionedStreamEventIngressStreamableFused( StreamProperties, TResult> properties) : base(properties) { - Contract.Requires(observable != null); - Contract.Requires(identifier != null); + ArgumentNullException.ThrowIfNull(observable); + ArgumentNullException.ThrowIfNull(identifier); this.IngressSiteIdentifier = identifier; this.observable = observable; @@ -2139,18 +2139,18 @@ public PartitionedStreamEventIngressStreamableFused( this.properties = properties.ToRowBased(); } - public void Dispose() => entryPoint?.Dispose(); + public void Dispose() => this.entryPoint?.Dispose(); [ContractInvariantMethod] [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic", Justification = "Required for code contracts.")] private void ObjectInvariant() { - Contract.Invariant(observable != null); + Contract.Invariant(this.observable != null); } public IObservable> GetDroppedAdjustedEventsDiagnostic() { - return entryPoint.GetDroppedAdjustedEventsDiagnostic(); + return this.entryPoint.GetDroppedAdjustedEventsDiagnostic(); } public override IDisposable Subscribe(IStreamObserver, TResult> observer) @@ -2158,26 +2158,26 @@ public override IDisposable Subscribe(IStreamObserver(true); IIngressStreamObserver pipe = null; - if (properties.IsColumnar) pipe = GetPipe(observer); + if (this.properties.IsColumnar) pipe = this.GetPipe(observer); else { pipe = PartitionedStreamEventSubscriptionCreator.CreateSubscription( - observable, + this.observable, this.IngressSiteIdentifier, this, observer, - disorderPolicy, - flushPolicy, - punctuationPolicy, - lowWatermarkPolicy, - onCompletedPolicy, - entryPoint.diagnosticOutput, - fuseModule); + this.disorderPolicy, + this.flushPolicy, + this.punctuationPolicy, + this.lowWatermarkPolicy, + this.onCompletedPolicy, + this.entryPoint.diagnosticOutput, + this.fuseModule); } if (this.delayed) { - container.RegisterIngressPipe(this.IngressSiteIdentifier, pipe); + this.container.RegisterIngressPipe(this.IngressSiteIdentifier, pipe); return pipe.DelayedDisposable; } else @@ -2190,27 +2190,27 @@ public override IDisposable Subscribe(IStreamObserver> cachedPipes - = new SafeConcurrentDictionary>(); + = new(); private bool CanGenerateColumnar() { var lookupKey = CacheKey.Create( Tuple.Create( - fuseModule.ToString(), + this.fuseModule.ToString(), Config.AllowFloatingReorderPolicy, - punctuationPolicy.ToString(), - lowWatermarkPolicy.ToString(), - disorderPolicy.ToString(), - (disorderPolicy.type != DisorderPolicyType.Throw && entryPoint.diagnosticOutput != null ? "WithDiagnostic" : string.Empty))); + this.punctuationPolicy.ToString(), + this.lowWatermarkPolicy.ToString(), + this.disorderPolicy.ToString(), + (this.disorderPolicy.type != DisorderPolicyType.Throw && this.entryPoint.diagnosticOutput != null ? "WithDiagnostic" : string.Empty))); var generatedPipeType = cachedPipes.GetOrAdd( lookupKey, key => TemporalIngressTemplate.GenerateFused( - disorderPolicy.reorderLatency > 0 ? "WithLatency" : string.Empty, - disorderPolicy.type != DisorderPolicyType.Throw && entryPoint.diagnosticOutput != null ? "WithDiagnostic" : string.Empty, - fuseModule)); + this.disorderPolicy.reorderLatency > 0 ? "WithLatency" : string.Empty, + this.disorderPolicy.type != DisorderPolicyType.Throw && this.entryPoint.diagnosticOutput != null ? "WithDiagnostic" : string.Empty, + this.fuseModule)); - errorMessages = generatedPipeType.Item2; + this.errorMessages = generatedPipeType.Item2; return generatedPipeType.Item1 != null; } @@ -2218,33 +2218,33 @@ private IIngressStreamObserver GetPipe(IStreamObserver TemporalIngressTemplate.GenerateFused( - disorderPolicy.reorderLatency > 0 ? "WithLatency" : string.Empty, - disorderPolicy.type != DisorderPolicyType.Throw && entryPoint.diagnosticOutput != null ? "WithDiagnostic" : string.Empty, - fuseModule)); + this.disorderPolicy.reorderLatency > 0 ? "WithLatency" : string.Empty, + this.disorderPolicy.type != DisorderPolicyType.Throw && this.entryPoint.diagnosticOutput != null ? "WithDiagnostic" : string.Empty, + this.fuseModule)); instance = Activator.CreateInstance( generatedPipeType.Item1, - observable, this.IngressSiteIdentifier, this, observer, disorderPolicy, flushPolicy, punctuationPolicy, lowWatermarkPolicy, onCompletedPolicy, entryPoint.diagnosticOutput); + this.observable, this.IngressSiteIdentifier, this, observer, this.disorderPolicy, this.flushPolicy, this.punctuationPolicy, this.lowWatermarkPolicy, this.onCompletedPolicy, this.entryPoint.diagnosticOutput); var returnValue = (IIngressStreamObserver)instance; return returnValue; } public override string ToString() { - if (container != null) - return "RegisterInput({0}, " + disorderPolicy.ToString() + ", " + flushPolicy.ToString() + ", " + punctuationPolicy.ToString() + ", " + lowWatermarkPolicy.ToString() + ", " + onCompletedPolicy.ToString() + ")"; + if (this.container != null) + return "RegisterInput({0}, " + this.disorderPolicy.ToString() + ", " + this.flushPolicy.ToString() + ", " + this.punctuationPolicy.ToString() + ", " + this.lowWatermarkPolicy.ToString() + ", " + this.onCompletedPolicy.ToString() + ")"; else - return "ToStreamable(" + disorderPolicy.ToString() + ", " + flushPolicy.ToString() + ", " + punctuationPolicy.ToString() + ", " + lowWatermarkPolicy.ToString() + ", " + onCompletedPolicy.ToString() + ")"; + return "ToStreamable(" + this.disorderPolicy.ToString() + ", " + this.flushPolicy.ToString() + ", " + this.punctuationPolicy.ToString() + ", " + this.lowWatermarkPolicy.ToString() + ", " + this.onCompletedPolicy.ToString() + ")"; } public bool CanFuseSelect(LambdaExpression expression, bool hasStart, bool hasKey) => true; @@ -2252,65 +2252,65 @@ public override string ToString() public IFusibleStreamable, TNewResult> FuseSelect(Expression> expression) { return new PartitionedStreamEventIngressStreamableFused( - observable, - disorderPolicy, - flushPolicy, - punctuationPolicy, - lowWatermarkPolicy, - onCompletedPolicy, - container, + this.observable, + this.disorderPolicy, + this.flushPolicy, + this.punctuationPolicy, + this.lowWatermarkPolicy, + this.onCompletedPolicy, + this.container, this.IngressSiteIdentifier, - fuseModule.Clone().FuseSelect(expression), - entryPoint, - Properties.Select(expression, false, false)); + this.fuseModule.Clone().FuseSelect(expression), + this.entryPoint, + this.Properties.Select(expression, false, false)); } public IFusibleStreamable, TNewResult> FuseSelect(Expression> expression) { return new PartitionedStreamEventIngressStreamableFused( - observable, - disorderPolicy, - flushPolicy, - punctuationPolicy, - lowWatermarkPolicy, - onCompletedPolicy, - container, + this.observable, + this.disorderPolicy, + this.flushPolicy, + this.punctuationPolicy, + this.lowWatermarkPolicy, + this.onCompletedPolicy, + this.container, this.IngressSiteIdentifier, - fuseModule.Clone().FuseSelect(expression), - entryPoint, - Properties.Select(expression, true, false, true)); + this.fuseModule.Clone().FuseSelect(expression), + this.entryPoint, + this.Properties.Select(expression, true, false, true)); } public IFusibleStreamable, TNewResult> FuseSelectWithKey(Expression, TResult, TNewResult>> expression) { return new PartitionedStreamEventIngressStreamableFused( - observable, - disorderPolicy, - flushPolicy, - punctuationPolicy, - lowWatermarkPolicy, - onCompletedPolicy, - container, + this.observable, + this.disorderPolicy, + this.flushPolicy, + this.punctuationPolicy, + this.lowWatermarkPolicy, + this.onCompletedPolicy, + this.container, this.IngressSiteIdentifier, - fuseModule.Clone().FuseSelectWithKey(expression), - entryPoint, - Properties.Select(expression, false, true)); + this.fuseModule.Clone().FuseSelectWithKey(expression), + this.entryPoint, + this.Properties.Select(expression, false, true)); } public IFusibleStreamable, TNewResult> FuseSelectWithKey(Expression, TResult, TNewResult>> expression) { return new PartitionedStreamEventIngressStreamableFused( - observable, - disorderPolicy, - flushPolicy, - punctuationPolicy, - lowWatermarkPolicy, - onCompletedPolicy, - container, + this.observable, + this.disorderPolicy, + this.flushPolicy, + this.punctuationPolicy, + this.lowWatermarkPolicy, + this.onCompletedPolicy, + this.container, this.IngressSiteIdentifier, - fuseModule.Clone().FuseSelectWithKey(expression), - entryPoint, - Properties.Select(expression, true, true)); + this.fuseModule.Clone().FuseSelectWithKey(expression), + this.entryPoint, + this.Properties.Select(expression, true, true)); } public bool CanFuseSelectMany(LambdaExpression expression, bool hasStart, bool hasKey) => true; @@ -2318,108 +2318,108 @@ public IFusibleStreamable, TNewResult> FuseSelectWit public IFusibleStreamable, TNewResult> FuseSelectMany(Expression>> expression) { return new PartitionedStreamEventIngressStreamableFused( - observable, - disorderPolicy, - flushPolicy, - punctuationPolicy, - lowWatermarkPolicy, - onCompletedPolicy, - container, + this.observable, + this.disorderPolicy, + this.flushPolicy, + this.punctuationPolicy, + this.lowWatermarkPolicy, + this.onCompletedPolicy, + this.container, this.IngressSiteIdentifier, - fuseModule.Clone().FuseSelectMany(expression), - entryPoint, - Properties.SelectMany(expression)); + this.fuseModule.Clone().FuseSelectMany(expression), + this.entryPoint, + this.Properties.SelectMany(expression)); } public IFusibleStreamable, TNewResult> FuseSelectMany(Expression>> expression) { return new PartitionedStreamEventIngressStreamableFused( - observable, - disorderPolicy, - flushPolicy, - punctuationPolicy, - lowWatermarkPolicy, - onCompletedPolicy, - container, + this.observable, + this.disorderPolicy, + this.flushPolicy, + this.punctuationPolicy, + this.lowWatermarkPolicy, + this.onCompletedPolicy, + this.container, this.IngressSiteIdentifier, - fuseModule.Clone().FuseSelectMany(expression), - entryPoint, - Properties.SelectMany(expression)); + this.fuseModule.Clone().FuseSelectMany(expression), + this.entryPoint, + this.Properties.SelectMany(expression)); } public IFusibleStreamable, TNewResult> FuseSelectManyWithKey(Expression, TResult, System.Collections.Generic.IEnumerable>> expression) { return new PartitionedStreamEventIngressStreamableFused( - observable, - disorderPolicy, - flushPolicy, - punctuationPolicy, - lowWatermarkPolicy, - onCompletedPolicy, - container, + this.observable, + this.disorderPolicy, + this.flushPolicy, + this.punctuationPolicy, + this.lowWatermarkPolicy, + this.onCompletedPolicy, + this.container, this.IngressSiteIdentifier, - fuseModule.Clone().FuseSelectManyWithKey(expression), - entryPoint, - Properties.SelectMany(expression)); + this.fuseModule.Clone().FuseSelectManyWithKey(expression), + this.entryPoint, + this.Properties.SelectMany(expression)); } public IFusibleStreamable, TNewResult> FuseSelectManyWithKey(Expression, TResult, System.Collections.Generic.IEnumerable>> expression) { return new PartitionedStreamEventIngressStreamableFused( - observable, - disorderPolicy, - flushPolicy, - punctuationPolicy, - lowWatermarkPolicy, - onCompletedPolicy, - container, + this.observable, + this.disorderPolicy, + this.flushPolicy, + this.punctuationPolicy, + this.lowWatermarkPolicy, + this.onCompletedPolicy, + this.container, this.IngressSiteIdentifier, - fuseModule.Clone().FuseSelectManyWithKey(expression), - entryPoint, - Properties.SelectMany(expression)); + this.fuseModule.Clone().FuseSelectManyWithKey(expression), + this.entryPoint, + this.Properties.SelectMany(expression)); } public IFusibleStreamable, TResult> FuseWhere(Expression> expression) { return new PartitionedStreamEventIngressStreamableFused( - observable, - disorderPolicy, - flushPolicy, - punctuationPolicy, - lowWatermarkPolicy, - onCompletedPolicy, - container, + this.observable, + this.disorderPolicy, + this.flushPolicy, + this.punctuationPolicy, + this.lowWatermarkPolicy, + this.onCompletedPolicy, + this.container, this.IngressSiteIdentifier, - fuseModule.Clone().FuseWhere(expression), - entryPoint, - Properties.Where(expression)); + this.fuseModule.Clone().FuseWhere(expression), + this.entryPoint, + this.Properties.Where(expression)); } public IFusibleStreamable, TResult> FuseSetDurationConstant(long value) { return new PartitionedStreamEventIngressStreamableFused( - observable, - disorderPolicy, - flushPolicy, - punctuationPolicy, - lowWatermarkPolicy, - onCompletedPolicy, - container, + this.observable, + this.disorderPolicy, + this.flushPolicy, + this.punctuationPolicy, + this.lowWatermarkPolicy, + this.onCompletedPolicy, + this.container, this.IngressSiteIdentifier, - fuseModule.Clone().FuseSetDurationConstant(value), - entryPoint, - Properties.ToConstantDuration(true, value)); + this.fuseModule.Clone().FuseSetDurationConstant(value), + this.entryPoint, + this.Properties.ToConstantDuration(true, value)); } public IObservable FuseEgressObservable(Expression, TNewResult>> expression, QueryContainer container, string identifier) { return new FusedObservable, PartitionedStreamEvent, TPayload, TResult, TNewResult>( - observable, + this.observable, (o) => o.SyncTime, (o) => o.OtherTime, (o) => new PartitionKey(o.PartitionKey), (o) => o.Payload, - fuseModule, + this.fuseModule, expression, container, this.IngressSiteIdentifier, @@ -2463,8 +2463,8 @@ public PartitionedIntervalIngressStreamableFused( StreamProperties, TResult> properties) : base(properties) { - Contract.Requires(observable != null); - Contract.Requires(identifier != null); + ArgumentNullException.ThrowIfNull(observable); + ArgumentNullException.ThrowIfNull(identifier); this.IngressSiteIdentifier = identifier; this.observable = observable; @@ -2484,18 +2484,18 @@ public PartitionedIntervalIngressStreamableFused( this.properties = properties.ToRowBased(); } - public void Dispose() => entryPoint?.Dispose(); + public void Dispose() => this.entryPoint?.Dispose(); [ContractInvariantMethod] [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic", Justification = "Required for code contracts.")] private void ObjectInvariant() { - Contract.Invariant(observable != null); + Contract.Invariant(this.observable != null); } public IObservable> GetDroppedAdjustedEventsDiagnostic() { - return entryPoint.GetDroppedAdjustedEventsDiagnostic(); + return this.entryPoint.GetDroppedAdjustedEventsDiagnostic(); } public override IDisposable Subscribe(IStreamObserver, TResult> observer) @@ -2503,29 +2503,29 @@ public override IDisposable Subscribe(IStreamObserver(true); IIngressStreamObserver pipe = null; - if (properties.IsColumnar) pipe = GetPipe(observer); + if (this.properties.IsColumnar) pipe = this.GetPipe(observer); else { pipe = PartitionedIntervalSubscriptionCreator.CreateSubscription( - observable, - partitionExtractor, - startEdgeExtractor, - endEdgeExtractor, + this.observable, + this.partitionExtractor, + this.startEdgeExtractor, + this.endEdgeExtractor, this.IngressSiteIdentifier, this, observer, - disorderPolicy, - flushPolicy, - punctuationPolicy, - lowWatermarkPolicy, - onCompletedPolicy, - entryPoint.diagnosticOutput, - fuseModule); + this.disorderPolicy, + this.flushPolicy, + this.punctuationPolicy, + this.lowWatermarkPolicy, + this.onCompletedPolicy, + this.entryPoint.diagnosticOutput, + this.fuseModule); } if (this.delayed) { - container.RegisterIngressPipe(this.IngressSiteIdentifier, pipe); + this.container.RegisterIngressPipe(this.IngressSiteIdentifier, pipe); return pipe.DelayedDisposable; } else @@ -2538,34 +2538,34 @@ public override IDisposable Subscribe(IStreamObserver> cachedPipes - = new SafeConcurrentDictionary>(); + = new(); private bool CanGenerateColumnar() { var lookupKey = CacheKey.Create( Tuple.Create( - startEdgeExtractor.ExpressionToCSharp(), - endEdgeExtractor != null ? endEdgeExtractor.ExpressionToCSharp() : string.Empty, - partitionExtractor.ExpressionToCSharp()), + this.startEdgeExtractor.ExpressionToCSharp(), + this.endEdgeExtractor != null ? this.endEdgeExtractor.ExpressionToCSharp() : string.Empty, + this.partitionExtractor.ExpressionToCSharp()), Tuple.Create( - fuseModule.ToString(), + this.fuseModule.ToString(), Config.AllowFloatingReorderPolicy, - punctuationPolicy.ToString(), - lowWatermarkPolicy.ToString(), - disorderPolicy.ToString(), - (disorderPolicy.type != DisorderPolicyType.Throw && entryPoint.diagnosticOutput != null ? "WithDiagnostic" : string.Empty))); + this.punctuationPolicy.ToString(), + this.lowWatermarkPolicy.ToString(), + this.disorderPolicy.ToString(), + (this.disorderPolicy.type != DisorderPolicyType.Throw && this.entryPoint.diagnosticOutput != null ? "WithDiagnostic" : string.Empty))); var generatedPipeType = cachedPipes.GetOrAdd( lookupKey, key => TemporalIngressTemplate.GenerateFused( - partitionExtractor, - startEdgeExtractor, - endEdgeExtractor, - disorderPolicy.reorderLatency > 0 ? "WithLatency" : string.Empty, - disorderPolicy.type != DisorderPolicyType.Throw && entryPoint.diagnosticOutput != null ? "WithDiagnostic" : string.Empty, - fuseModule)); - - errorMessages = generatedPipeType.Item2; + this.partitionExtractor, + this.startEdgeExtractor, + this.endEdgeExtractor, + this.disorderPolicy.reorderLatency > 0 ? "WithLatency" : string.Empty, + this.disorderPolicy.type != DisorderPolicyType.Throw && this.entryPoint.diagnosticOutput != null ? "WithDiagnostic" : string.Empty, + this.fuseModule)); + + this.errorMessages = generatedPipeType.Item2; return generatedPipeType.Item1 != null; } @@ -2573,30 +2573,30 @@ private IIngressStreamObserver GetPipe(IStreamObserver TemporalIngressTemplate.GenerateFused( - partitionExtractor, - startEdgeExtractor, - endEdgeExtractor, - disorderPolicy.reorderLatency > 0 ? "WithLatency" : string.Empty, - disorderPolicy.type != DisorderPolicyType.Throw && entryPoint.diagnosticOutput != null ? "WithDiagnostic" : string.Empty, - fuseModule)); + this.partitionExtractor, + this.startEdgeExtractor, + this.endEdgeExtractor, + this.disorderPolicy.reorderLatency > 0 ? "WithLatency" : string.Empty, + this.disorderPolicy.type != DisorderPolicyType.Throw && this.entryPoint.diagnosticOutput != null ? "WithDiagnostic" : string.Empty, + this.fuseModule)); instance = Activator.CreateInstance( generatedPipeType.Item1, - observable, this.IngressSiteIdentifier, this, observer, disorderPolicy, flushPolicy, punctuationPolicy, lowWatermarkPolicy, onCompletedPolicy, entryPoint.diagnosticOutput); + this.observable, this.IngressSiteIdentifier, this, observer, this.disorderPolicy, this.flushPolicy, this.punctuationPolicy, this.lowWatermarkPolicy, this.onCompletedPolicy, this.entryPoint.diagnosticOutput); var returnValue = (IIngressStreamObserver)instance; return returnValue; } @@ -2606,77 +2606,77 @@ private IIngressStreamObserver GetPipe(IStreamObserver, TNewResult> FuseSelect(Expression> expression) { return new PartitionedIntervalIngressStreamableFused( - observable, - partitionExtractor, - startEdgeExtractor, - endEdgeExtractor, - disorderPolicy, - flushPolicy, - punctuationPolicy, - lowWatermarkPolicy, - onCompletedPolicy, - container, - this.IngressSiteIdentifier, - fuseModule.Clone().FuseSelect(expression), - entryPoint, - Properties.Select(expression, false, false)); + this.observable, + this.partitionExtractor, + this.startEdgeExtractor, + this.endEdgeExtractor, + this.disorderPolicy, + this.flushPolicy, + this.punctuationPolicy, + this.lowWatermarkPolicy, + this.onCompletedPolicy, + this.container, + this.IngressSiteIdentifier, + this.fuseModule.Clone().FuseSelect(expression), + this.entryPoint, + this.Properties.Select(expression, false, false)); } public IFusibleStreamable, TNewResult> FuseSelect(Expression> expression) { return new PartitionedIntervalIngressStreamableFused( - observable, - partitionExtractor, - startEdgeExtractor, - endEdgeExtractor, - disorderPolicy, - flushPolicy, - punctuationPolicy, - lowWatermarkPolicy, - onCompletedPolicy, - container, - this.IngressSiteIdentifier, - fuseModule.Clone().FuseSelect(expression), - entryPoint, - Properties.Select(expression, true, false, true)); + this.observable, + this.partitionExtractor, + this.startEdgeExtractor, + this.endEdgeExtractor, + this.disorderPolicy, + this.flushPolicy, + this.punctuationPolicy, + this.lowWatermarkPolicy, + this.onCompletedPolicy, + this.container, + this.IngressSiteIdentifier, + this.fuseModule.Clone().FuseSelect(expression), + this.entryPoint, + this.Properties.Select(expression, true, false, true)); } public IFusibleStreamable, TNewResult> FuseSelectWithKey(Expression, TResult, TNewResult>> expression) { return new PartitionedIntervalIngressStreamableFused( - observable, - partitionExtractor, - startEdgeExtractor, - endEdgeExtractor, - disorderPolicy, - flushPolicy, - punctuationPolicy, - lowWatermarkPolicy, - onCompletedPolicy, - container, - this.IngressSiteIdentifier, - fuseModule.Clone().FuseSelectWithKey(expression), - entryPoint, - Properties.Select(expression, false, true)); + this.observable, + this.partitionExtractor, + this.startEdgeExtractor, + this.endEdgeExtractor, + this.disorderPolicy, + this.flushPolicy, + this.punctuationPolicy, + this.lowWatermarkPolicy, + this.onCompletedPolicy, + this.container, + this.IngressSiteIdentifier, + this.fuseModule.Clone().FuseSelectWithKey(expression), + this.entryPoint, + this.Properties.Select(expression, false, true)); } public IFusibleStreamable, TNewResult> FuseSelectWithKey(Expression, TResult, TNewResult>> expression) { return new PartitionedIntervalIngressStreamableFused( - observable, - partitionExtractor, - startEdgeExtractor, - endEdgeExtractor, - disorderPolicy, - flushPolicy, - punctuationPolicy, - lowWatermarkPolicy, - onCompletedPolicy, - container, - this.IngressSiteIdentifier, - fuseModule.Clone().FuseSelectWithKey(expression), - entryPoint, - Properties.Select(expression, true, true)); + this.observable, + this.partitionExtractor, + this.startEdgeExtractor, + this.endEdgeExtractor, + this.disorderPolicy, + this.flushPolicy, + this.punctuationPolicy, + this.lowWatermarkPolicy, + this.onCompletedPolicy, + this.container, + this.IngressSiteIdentifier, + this.fuseModule.Clone().FuseSelectWithKey(expression), + this.entryPoint, + this.Properties.Select(expression, true, true)); } public bool CanFuseSelectMany(LambdaExpression expression, bool hasStart, bool hasKey) => true; @@ -2684,126 +2684,126 @@ public IFusibleStreamable, TNewResult> FuseSelectWit public IFusibleStreamable, TNewResult> FuseSelectMany(Expression>> expression) { return new PartitionedIntervalIngressStreamableFused( - observable, - partitionExtractor, - startEdgeExtractor, - endEdgeExtractor, - disorderPolicy, - flushPolicy, - punctuationPolicy, - lowWatermarkPolicy, - onCompletedPolicy, - container, - this.IngressSiteIdentifier, - fuseModule.Clone().FuseSelectMany(expression), - entryPoint, - Properties.SelectMany(expression)); + this.observable, + this.partitionExtractor, + this.startEdgeExtractor, + this.endEdgeExtractor, + this.disorderPolicy, + this.flushPolicy, + this.punctuationPolicy, + this.lowWatermarkPolicy, + this.onCompletedPolicy, + this.container, + this.IngressSiteIdentifier, + this.fuseModule.Clone().FuseSelectMany(expression), + this.entryPoint, + this.Properties.SelectMany(expression)); } public IFusibleStreamable, TNewResult> FuseSelectMany(Expression>> expression) { return new PartitionedIntervalIngressStreamableFused( - observable, - partitionExtractor, - startEdgeExtractor, - endEdgeExtractor, - disorderPolicy, - flushPolicy, - punctuationPolicy, - lowWatermarkPolicy, - onCompletedPolicy, - container, - this.IngressSiteIdentifier, - fuseModule.Clone().FuseSelectMany(expression), - entryPoint, - Properties.SelectMany(expression)); + this.observable, + this.partitionExtractor, + this.startEdgeExtractor, + this.endEdgeExtractor, + this.disorderPolicy, + this.flushPolicy, + this.punctuationPolicy, + this.lowWatermarkPolicy, + this.onCompletedPolicy, + this.container, + this.IngressSiteIdentifier, + this.fuseModule.Clone().FuseSelectMany(expression), + this.entryPoint, + this.Properties.SelectMany(expression)); } public IFusibleStreamable, TNewResult> FuseSelectManyWithKey(Expression, TResult, System.Collections.Generic.IEnumerable>> expression) { return new PartitionedIntervalIngressStreamableFused( - observable, - partitionExtractor, - startEdgeExtractor, - endEdgeExtractor, - disorderPolicy, - flushPolicy, - punctuationPolicy, - lowWatermarkPolicy, - onCompletedPolicy, - container, - this.IngressSiteIdentifier, - fuseModule.Clone().FuseSelectManyWithKey(expression), - entryPoint, - Properties.SelectMany(expression)); + this.observable, + this.partitionExtractor, + this.startEdgeExtractor, + this.endEdgeExtractor, + this.disorderPolicy, + this.flushPolicy, + this.punctuationPolicy, + this.lowWatermarkPolicy, + this.onCompletedPolicy, + this.container, + this.IngressSiteIdentifier, + this.fuseModule.Clone().FuseSelectManyWithKey(expression), + this.entryPoint, + this.Properties.SelectMany(expression)); } public IFusibleStreamable, TNewResult> FuseSelectManyWithKey(Expression, TResult, System.Collections.Generic.IEnumerable>> expression) { return new PartitionedIntervalIngressStreamableFused( - observable, - partitionExtractor, - startEdgeExtractor, - endEdgeExtractor, - disorderPolicy, - flushPolicy, - punctuationPolicy, - lowWatermarkPolicy, - onCompletedPolicy, - container, - this.IngressSiteIdentifier, - fuseModule.Clone().FuseSelectManyWithKey(expression), - entryPoint, - Properties.SelectMany(expression)); + this.observable, + this.partitionExtractor, + this.startEdgeExtractor, + this.endEdgeExtractor, + this.disorderPolicy, + this.flushPolicy, + this.punctuationPolicy, + this.lowWatermarkPolicy, + this.onCompletedPolicy, + this.container, + this.IngressSiteIdentifier, + this.fuseModule.Clone().FuseSelectManyWithKey(expression), + this.entryPoint, + this.Properties.SelectMany(expression)); } public IFusibleStreamable, TResult> FuseWhere(Expression> expression) { return new PartitionedIntervalIngressStreamableFused( - observable, - partitionExtractor, - startEdgeExtractor, - endEdgeExtractor, - disorderPolicy, - flushPolicy, - punctuationPolicy, - lowWatermarkPolicy, - onCompletedPolicy, - container, - this.IngressSiteIdentifier, - fuseModule.Clone().FuseWhere(expression), - entryPoint, - Properties.Where(expression)); + this.observable, + this.partitionExtractor, + this.startEdgeExtractor, + this.endEdgeExtractor, + this.disorderPolicy, + this.flushPolicy, + this.punctuationPolicy, + this.lowWatermarkPolicy, + this.onCompletedPolicy, + this.container, + this.IngressSiteIdentifier, + this.fuseModule.Clone().FuseWhere(expression), + this.entryPoint, + this.Properties.Where(expression)); } public IFusibleStreamable, TResult> FuseSetDurationConstant(long value) { return new PartitionedIntervalIngressStreamableFused( - observable, - partitionExtractor, - startEdgeExtractor, - endEdgeExtractor, - disorderPolicy, - flushPolicy, - punctuationPolicy, - lowWatermarkPolicy, - onCompletedPolicy, - container, - this.IngressSiteIdentifier, - fuseModule.Clone().FuseSetDurationConstant(value), - entryPoint, - Properties.ToConstantDuration(true, value)); + this.observable, + this.partitionExtractor, + this.startEdgeExtractor, + this.endEdgeExtractor, + this.disorderPolicy, + this.flushPolicy, + this.punctuationPolicy, + this.lowWatermarkPolicy, + this.onCompletedPolicy, + this.container, + this.IngressSiteIdentifier, + this.fuseModule.Clone().FuseSetDurationConstant(value), + this.entryPoint, + this.Properties.ToConstantDuration(true, value)); } public IObservable FuseEgressObservable(Expression, TNewResult>> expression, QueryContainer container, string identifier) { return new FusedObservable, TPayload, TPayload, TResult, TNewResult>( - observable, - startEdgeExtractor, - endEdgeExtractor, - ParameterSubstituter.AddPartitionKey(partitionExtractor), + this.observable, + this.startEdgeExtractor, + this.endEdgeExtractor, + ParameterSubstituter.AddPartitionKey(this.partitionExtractor), (o) => o, - fuseModule, + this.fuseModule, expression, container, this.IngressSiteIdentifier, diff --git a/Sources/Core/Microsoft.StreamProcessing/Ingress/Temporal/TemporalIngressStreamable.tt b/Sources/Core/Microsoft.StreamProcessing/Ingress/Temporal/TemporalIngressStreamable.tt index 13951e6e3..ae4e99565 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Ingress/Temporal/TemporalIngressStreamable.tt +++ b/Sources/Core/Microsoft.StreamProcessing/Ingress/Temporal/TemporalIngressStreamable.tt @@ -92,8 +92,8 @@ foreach (var m in new [] { "StreamEvent", "Interval" }) : base(StreamProperties<<#= keyType #>, <#= outputType #>>.Default<#= (m == "Interval") ? "Ingress(startEdgeExtractor, endEdgeExtractor)" : string.Empty #>.SetQueryContainer(container)) <# } #> { - Contract.Requires(observable != null); - Contract.Requires(identifier != null); + ArgumentNullException.ThrowIfNull(observable); + ArgumentNullException.ThrowIfNull(identifier); this.IngressSiteIdentifier = identifier; this.observable = observable; diff --git a/Sources/Core/Microsoft.StreamProcessing/Ingress/Temporal/TemporalIngressSubscription.cs b/Sources/Core/Microsoft.StreamProcessing/Ingress/Temporal/TemporalIngressSubscription.cs index 3673529e5..a81be52f9 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Ingress/Temporal/TemporalIngressSubscription.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Ingress/Temporal/TemporalIngressSubscription.cs @@ -272,7 +272,7 @@ public override void OnNext(StreamEvent value) if (value.IsPunctuation) { - GenerateAndProcessPunctuation(value.SyncTime); + this.GenerateAndProcessPunctuation(value.SyncTime); return; } @@ -282,7 +282,7 @@ public override void OnNext(StreamEvent value) // Events at the reorder boundary or earlier - are handled using default processing policies if (value.SyncTime <= moveFrom) { - Process(ref value); + this.Process(ref value); return; } @@ -305,7 +305,7 @@ public override void OnNext(StreamEvent value) while ((!this.priorityQueueSorter.IsEmpty()) && this.priorityQueueSorter.Peek().SyncTime <= moveTo) { resultEvent = this.priorityQueueSorter.Dequeue(); - Process(ref resultEvent); + this.Process(ref resultEvent); } } else @@ -319,7 +319,7 @@ public override void OnNext(StreamEvent value) while ((streamEvents.Count > 0) && ((!recheck) || (streamEvents.PeekFirst().SyncTime <= moveTo))) { resultEvent = streamEvents.Dequeue(); - Process(ref resultEvent); + this.Process(ref resultEvent); } } @@ -330,7 +330,7 @@ public override void OnNext(StreamEvent value) if (value.SyncTime == moveTo) { - Process(ref value); + this.Process(ref value); return; } @@ -338,7 +338,7 @@ public override void OnNext(StreamEvent value) if (this.priorityQueueSorter != null) this.priorityQueueSorter.Enqueue(value); else this.impatienceSorter.Enqueue(ref value); - UpdateCurrentTime(moveTo, fromEvent: false); + this.UpdateCurrentTime(moveTo, fromEvent: false); } [System.Diagnostics.CodeAnalysis.SuppressMessage( @@ -351,7 +351,7 @@ private void Process(ref StreamEvent value) if (value.IsPunctuation) { - GenerateAndProcessPunctuation(value.SyncTime); + this.GenerateAndProcessPunctuation(value.SyncTime); return; } @@ -380,7 +380,7 @@ private void Process(ref StreamEvent value) key = Tuple.Create(value.SyncTime, value.Payload); if (!this.startEventInformation.TryGetValue(key, out q)) { - q = new ElasticCircularBuffer(); + q = []; this.startEventInformation.Add(key, q); var x = new AdjustInfo(current); q.Enqueue(ref x); @@ -487,20 +487,20 @@ private void Process(ref StreamEvent value) // SyncTime is sufficiently high to generate a new punctuation, but first snap it to the nearest generationPeriod boundary var punctuationTimeQuantized = value.SyncTime.SnapToLeftBoundary((long)this.punctuationGenerationPeriod); #if DEBUG - Debug.Assert(punctuationTimeQuantized >= LastEventTime(), "Bug in punctuation quantization logic"); + Debug.Assert(punctuationTimeQuantized >= this.LastEventTime(), "Bug in punctuation quantization logic"); #endif - OnPunctuation(StreamEvent.CreatePunctuation(punctuationTimeQuantized)); + this.OnPunctuation(StreamEvent.CreatePunctuation(punctuationTimeQuantized)); } } this.currentBatch.Add(value.SyncTime, value.OtherTime, Empty.Default, value.Payload); if (this.currentBatch.Count == Config.DataBatchSize) { - if (this.flushPolicy == FlushPolicy.FlushOnBatchBoundary) OnFlush(); - else FlushContents(); + if (this.flushPolicy == FlushPolicy.FlushOnBatchBoundary) this.OnFlush(); + else this.FlushContents(); } - UpdateCurrentTime(value.SyncTime); + this.UpdateCurrentTime(value.SyncTime); } [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -538,7 +538,7 @@ private void GenerateAndProcessPunctuation(long syncTime) while ((!this.priorityQueueSorter.IsEmpty()) && this.priorityQueueSorter.Peek().SyncTime <= syncTime) { resultEvent = this.priorityQueueSorter.Dequeue(); - Process(ref resultEvent); + this.Process(ref resultEvent); } } else @@ -550,7 +550,7 @@ private void GenerateAndProcessPunctuation(long syncTime) while ((streamEvents.Count > 0) && ((!recheck) || (streamEvents.PeekFirst().SyncTime <= syncTime))) { resultEvent = streamEvents.Dequeue(); - Process(ref resultEvent); + this.Process(ref resultEvent); } if (!recheck) this.impatienceSorter.Return(streamEvents); } @@ -558,7 +558,7 @@ private void GenerateAndProcessPunctuation(long syncTime) // Update cached global times this.highWatermark = Math.Max(syncTime, this.highWatermark); - UpdateCurrentTime(syncTime); + this.UpdateCurrentTime(syncTime); this.lastPunctuationTime = Math.Max( syncTime.SnapToLeftBoundary((long)this.punctuationGenerationPeriod), this.lastPunctuationTime); @@ -577,21 +577,21 @@ private void GenerateAndProcessPunctuation(long syncTime) if (this.flushPolicy == FlushPolicy.FlushOnPunctuation || (this.flushPolicy == FlushPolicy.FlushOnBatchBoundary && this.currentBatch.Count == Config.DataBatchSize)) { - OnFlush(); + this.OnFlush(); } else if (this.currentBatch.Count == Config.DataBatchSize) { - FlushContents(); + this.FlushContents(); } } protected override void OnCompleted(long punctuationTime) { - GenerateAndProcessPunctuation(punctuationTime); + this.GenerateAndProcessPunctuation(punctuationTime); // Flush, but if we just flushed due to the punctuation generated above if (this.flushPolicy != FlushPolicy.FlushOnPunctuation) - OnFlush(); + this.OnFlush(); } } @@ -627,7 +627,7 @@ public FusedStreamEventSubscriptionWithLatency( { this.fuseModule = fuseModule; Expression> statement = (s, e, p, k) => this.currentBatch.Add(s, e, k, p); - Expression flush = () => FlushContents(); + Expression flush = () => this.FlushContents(); Expression> test = () => this.currentBatch.Count == Config.DataBatchSize; var full = Expression.Lambda>( Expression.Block( @@ -655,7 +655,7 @@ public override void OnNext(StreamEvent value) if (value.IsPunctuation) { - GenerateAndProcessPunctuation(value.SyncTime); + this.GenerateAndProcessPunctuation(value.SyncTime); return; } @@ -665,7 +665,7 @@ public override void OnNext(StreamEvent value) // Events at the reorder boundary or earlier - are handled using default processing policies if (value.SyncTime <= moveFrom) { - Process(ref value); + this.Process(ref value); return; } @@ -688,7 +688,7 @@ public override void OnNext(StreamEvent value) while ((!this.priorityQueueSorter.IsEmpty()) && this.priorityQueueSorter.Peek().SyncTime <= moveTo) { resultEvent = this.priorityQueueSorter.Dequeue(); - Process(ref resultEvent); + this.Process(ref resultEvent); } } else @@ -702,7 +702,7 @@ public override void OnNext(StreamEvent value) while ((streamEvents.Count > 0) && ((!recheck) || (streamEvents.PeekFirst().SyncTime <= moveTo))) { resultEvent = streamEvents.Dequeue(); - Process(ref resultEvent); + this.Process(ref resultEvent); } } @@ -713,7 +713,7 @@ public override void OnNext(StreamEvent value) if (value.SyncTime == moveTo) { - Process(ref value); + this.Process(ref value); return; } @@ -721,7 +721,7 @@ public override void OnNext(StreamEvent value) if (this.priorityQueueSorter != null) this.priorityQueueSorter.Enqueue(value); else this.impatienceSorter.Enqueue(ref value); - UpdateCurrentTime(moveTo, fromEvent: false); + this.UpdateCurrentTime(moveTo, fromEvent: false); } [System.Diagnostics.CodeAnalysis.SuppressMessage( @@ -734,7 +734,7 @@ private void Process(ref StreamEvent value) if (value.IsPunctuation) { - GenerateAndProcessPunctuation(value.SyncTime); + this.GenerateAndProcessPunctuation(value.SyncTime); return; } @@ -763,7 +763,7 @@ private void Process(ref StreamEvent value) key = Tuple.Create(value.SyncTime, value.Payload); if (!this.startEventInformation.TryGetValue(key, out q)) { - q = new ElasticCircularBuffer(); + q = []; this.startEventInformation.Add(key, q); var x = new AdjustInfo(current); q.Enqueue(ref x); @@ -870,15 +870,15 @@ private void Process(ref StreamEvent value) // SyncTime is sufficiently high to generate a new punctuation, but first snap it to the nearest generationPeriod boundary var punctuationTimeQuantized = value.SyncTime.SnapToLeftBoundary((long)this.punctuationGenerationPeriod); #if DEBUG - Debug.Assert(punctuationTimeQuantized >= LastEventTime(), "Bug in punctuation quantization logic"); + Debug.Assert(punctuationTimeQuantized >= this.LastEventTime(), "Bug in punctuation quantization logic"); #endif - OnPunctuation(StreamEvent.CreatePunctuation(punctuationTimeQuantized)); + this.OnPunctuation(StreamEvent.CreatePunctuation(punctuationTimeQuantized)); } } this.action(value.SyncTime, value.OtherTime, value.Payload, Empty.Default); - UpdateCurrentTime(value.SyncTime); + this.UpdateCurrentTime(value.SyncTime); } [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -916,7 +916,7 @@ private void GenerateAndProcessPunctuation(long syncTime) while ((!this.priorityQueueSorter.IsEmpty()) && this.priorityQueueSorter.Peek().SyncTime <= syncTime) { resultEvent = this.priorityQueueSorter.Dequeue(); - Process(ref resultEvent); + this.Process(ref resultEvent); } } else @@ -928,7 +928,7 @@ private void GenerateAndProcessPunctuation(long syncTime) while ((streamEvents.Count > 0) && ((!recheck) || (streamEvents.PeekFirst().SyncTime <= syncTime))) { resultEvent = streamEvents.Dequeue(); - Process(ref resultEvent); + this.Process(ref resultEvent); } if (!recheck) this.impatienceSorter.Return(streamEvents); } @@ -936,7 +936,7 @@ private void GenerateAndProcessPunctuation(long syncTime) // Update cached global times this.highWatermark = Math.Max(syncTime, this.highWatermark); - UpdateCurrentTime(syncTime); + this.UpdateCurrentTime(syncTime); this.lastPunctuationTime = Math.Max( syncTime.SnapToLeftBoundary((long)this.punctuationGenerationPeriod), this.lastPunctuationTime); @@ -955,21 +955,21 @@ private void GenerateAndProcessPunctuation(long syncTime) if (this.flushPolicy == FlushPolicy.FlushOnPunctuation || (this.flushPolicy == FlushPolicy.FlushOnBatchBoundary && this.currentBatch.Count == Config.DataBatchSize)) { - OnFlush(); + this.OnFlush(); } else if (this.currentBatch.Count == Config.DataBatchSize) { - FlushContents(); + this.FlushContents(); } } protected override void OnCompleted(long punctuationTime) { - GenerateAndProcessPunctuation(punctuationTime); + this.GenerateAndProcessPunctuation(punctuationTime); // Flush, but if we just flushed due to the punctuation generated above if (this.flushPolicy != FlushPolicy.FlushOnPunctuation) - OnFlush(); + this.OnFlush(); } } @@ -1004,7 +1004,7 @@ public DisorderedStreamEventSubscriptionWithLatency( diagnosticOutput) { this.fuseModule = fuseModule; - Expression> statement = (s, e, p, k) => Action(s, e, p, k); + Expression> statement = (s, e, p, k) => this.Action(s, e, p, k); var actionExp = fuseModule.Coalesce(statement, true); this.action = actionExp.Compile(); } @@ -1036,7 +1036,7 @@ private void Action(long start, long end, TResult payload, Empty actionKey) if (value.IsPunctuation) { - GenerateAndProcessPunctuation(value.SyncTime); + this.GenerateAndProcessPunctuation(value.SyncTime); return; } @@ -1046,7 +1046,7 @@ private void Action(long start, long end, TResult payload, Empty actionKey) // Events at the reorder boundary or earlier - are handled using default processing policies if (value.SyncTime <= moveFrom) { - Process(ref value); + this.Process(ref value); return; } @@ -1069,7 +1069,7 @@ private void Action(long start, long end, TResult payload, Empty actionKey) while ((!this.priorityQueueSorter.IsEmpty()) && this.priorityQueueSorter.Peek().SyncTime <= moveTo) { resultEvent = this.priorityQueueSorter.Dequeue(); - Process(ref resultEvent); + this.Process(ref resultEvent); } } else @@ -1083,7 +1083,7 @@ private void Action(long start, long end, TResult payload, Empty actionKey) while ((streamEvents.Count > 0) && ((!recheck) || (streamEvents.PeekFirst().SyncTime <= moveTo))) { resultEvent = streamEvents.Dequeue(); - Process(ref resultEvent); + this.Process(ref resultEvent); } } @@ -1094,7 +1094,7 @@ private void Action(long start, long end, TResult payload, Empty actionKey) if (value.SyncTime == moveTo) { - Process(ref value); + this.Process(ref value); return; } @@ -1102,7 +1102,7 @@ private void Action(long start, long end, TResult payload, Empty actionKey) if (this.priorityQueueSorter != null) this.priorityQueueSorter.Enqueue(value); else this.impatienceSorter.Enqueue(ref value); - UpdateCurrentTime(moveTo, fromEvent: false); + this.UpdateCurrentTime(moveTo, fromEvent: false); } [System.Diagnostics.CodeAnalysis.SuppressMessage( @@ -1115,7 +1115,7 @@ private void Process(ref StreamEvent value) if (value.IsPunctuation) { - GenerateAndProcessPunctuation(value.SyncTime); + this.GenerateAndProcessPunctuation(value.SyncTime); return; } @@ -1144,7 +1144,7 @@ private void Process(ref StreamEvent value) key = Tuple.Create(value.SyncTime, value.Payload); if (!this.startEventInformation.TryGetValue(key, out q)) { - q = new ElasticCircularBuffer(); + q = []; this.startEventInformation.Add(key, q); var x = new AdjustInfo(current); q.Enqueue(ref x); @@ -1251,20 +1251,20 @@ private void Process(ref StreamEvent value) // SyncTime is sufficiently high to generate a new punctuation, but first snap it to the nearest generationPeriod boundary var punctuationTimeQuantized = value.SyncTime.SnapToLeftBoundary((long)this.punctuationGenerationPeriod); #if DEBUG - Debug.Assert(punctuationTimeQuantized >= LastEventTime(), "Bug in punctuation quantization logic"); + Debug.Assert(punctuationTimeQuantized >= this.LastEventTime(), "Bug in punctuation quantization logic"); #endif - OnPunctuation(StreamEvent.CreatePunctuation(punctuationTimeQuantized)); + this.OnPunctuation(StreamEvent.CreatePunctuation(punctuationTimeQuantized)); } } this.currentBatch.Add(value.SyncTime, value.OtherTime, Empty.Default, value.Payload); if (this.currentBatch.Count == Config.DataBatchSize) { - if (this.flushPolicy == FlushPolicy.FlushOnBatchBoundary) OnFlush(); - else FlushContents(); + if (this.flushPolicy == FlushPolicy.FlushOnBatchBoundary) this.OnFlush(); + else this.FlushContents(); } - UpdateCurrentTime(value.SyncTime); + this.UpdateCurrentTime(value.SyncTime); } [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -1302,7 +1302,7 @@ private void GenerateAndProcessPunctuation(long syncTime) while ((!this.priorityQueueSorter.IsEmpty()) && this.priorityQueueSorter.Peek().SyncTime <= syncTime) { resultEvent = this.priorityQueueSorter.Dequeue(); - Process(ref resultEvent); + this.Process(ref resultEvent); } } else @@ -1314,7 +1314,7 @@ private void GenerateAndProcessPunctuation(long syncTime) while ((streamEvents.Count > 0) && ((!recheck) || (streamEvents.PeekFirst().SyncTime <= syncTime))) { resultEvent = streamEvents.Dequeue(); - Process(ref resultEvent); + this.Process(ref resultEvent); } if (!recheck) this.impatienceSorter.Return(streamEvents); } @@ -1322,7 +1322,7 @@ private void GenerateAndProcessPunctuation(long syncTime) // Update cached global times this.highWatermark = Math.Max(syncTime, this.highWatermark); - UpdateCurrentTime(syncTime); + this.UpdateCurrentTime(syncTime); this.lastPunctuationTime = Math.Max( syncTime.SnapToLeftBoundary((long)this.punctuationGenerationPeriod), this.lastPunctuationTime); @@ -1341,21 +1341,21 @@ private void GenerateAndProcessPunctuation(long syncTime) if (this.flushPolicy == FlushPolicy.FlushOnPunctuation || (this.flushPolicy == FlushPolicy.FlushOnBatchBoundary && this.currentBatch.Count == Config.DataBatchSize)) { - OnFlush(); + this.OnFlush(); } else if (this.currentBatch.Count == Config.DataBatchSize) { - FlushContents(); + this.FlushContents(); } } protected override void OnCompleted(long punctuationTime) { - GenerateAndProcessPunctuation(punctuationTime); + this.GenerateAndProcessPunctuation(punctuationTime); // Flush, but if we just flushed due to the punctuation generated above if (this.flushPolicy != FlushPolicy.FlushOnPunctuation) - OnFlush(); + this.OnFlush(); } } @@ -1404,7 +1404,7 @@ public override void OnNext(StreamEvent value) if (value.IsPunctuation) { - GenerateAndProcessPunctuation(value.SyncTime); + this.GenerateAndProcessPunctuation(value.SyncTime); return; } @@ -1435,7 +1435,7 @@ public override void OnNext(StreamEvent value) key = Tuple.Create(value.SyncTime, value.Payload); if (!this.startEventInformation.TryGetValue(key, out q)) { - q = new ElasticCircularBuffer(); + q = []; this.startEventInformation.Add(key, q); var x = new AdjustInfo(current); q.Enqueue(ref x); @@ -1542,20 +1542,20 @@ public override void OnNext(StreamEvent value) // SyncTime is sufficiently high to generate a new punctuation, but first snap it to the nearest generationPeriod boundary var punctuationTimeQuantized = value.SyncTime.SnapToLeftBoundary((long)this.punctuationGenerationPeriod); #if DEBUG - Debug.Assert(punctuationTimeQuantized >= LastEventTime(), "Bug in punctuation quantization logic"); + Debug.Assert(punctuationTimeQuantized >= this.LastEventTime(), "Bug in punctuation quantization logic"); #endif - OnPunctuation(StreamEvent.CreatePunctuation(punctuationTimeQuantized)); + this.OnPunctuation(StreamEvent.CreatePunctuation(punctuationTimeQuantized)); } } this.currentBatch.Add(value.SyncTime, value.OtherTime, Empty.Default, value.Payload); if (this.currentBatch.Count == Config.DataBatchSize) { - if (this.flushPolicy == FlushPolicy.FlushOnBatchBoundary) OnFlush(); - else FlushContents(); + if (this.flushPolicy == FlushPolicy.FlushOnBatchBoundary) this.OnFlush(); + else this.FlushContents(); } - UpdateCurrentTime(value.SyncTime); + this.UpdateCurrentTime(value.SyncTime); } [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -1587,7 +1587,7 @@ private void GenerateAndProcessPunctuation(long syncTime) // Update cached global times this.highWatermark = Math.Max(syncTime, this.highWatermark); - UpdateCurrentTime(syncTime); + this.UpdateCurrentTime(syncTime); this.lastPunctuationTime = Math.Max( syncTime.SnapToLeftBoundary((long)this.punctuationGenerationPeriod), this.lastPunctuationTime); @@ -1606,21 +1606,21 @@ private void GenerateAndProcessPunctuation(long syncTime) if (this.flushPolicy == FlushPolicy.FlushOnPunctuation || (this.flushPolicy == FlushPolicy.FlushOnBatchBoundary && this.currentBatch.Count == Config.DataBatchSize)) { - OnFlush(); + this.OnFlush(); } else if (this.currentBatch.Count == Config.DataBatchSize) { - FlushContents(); + this.FlushContents(); } } protected override void OnCompleted(long punctuationTime) { - GenerateAndProcessPunctuation(punctuationTime); + this.GenerateAndProcessPunctuation(punctuationTime); // Flush, but if we just flushed due to the punctuation generated above if (this.flushPolicy != FlushPolicy.FlushOnPunctuation) - OnFlush(); + this.OnFlush(); } } @@ -1656,7 +1656,7 @@ public FusedStreamEventSubscription( { this.fuseModule = fuseModule; Expression> statement = (s, e, p, k) => this.currentBatch.Add(s, e, k, p); - Expression flush = () => FlushContents(); + Expression flush = () => this.FlushContents(); Expression> test = () => this.currentBatch.Count == Config.DataBatchSize; var full = Expression.Lambda>( Expression.Block( @@ -1684,7 +1684,7 @@ public override void OnNext(StreamEvent value) if (value.IsPunctuation) { - GenerateAndProcessPunctuation(value.SyncTime); + this.GenerateAndProcessPunctuation(value.SyncTime); return; } @@ -1715,7 +1715,7 @@ public override void OnNext(StreamEvent value) key = Tuple.Create(value.SyncTime, value.Payload); if (!this.startEventInformation.TryGetValue(key, out q)) { - q = new ElasticCircularBuffer(); + q = []; this.startEventInformation.Add(key, q); var x = new AdjustInfo(current); q.Enqueue(ref x); @@ -1822,15 +1822,15 @@ public override void OnNext(StreamEvent value) // SyncTime is sufficiently high to generate a new punctuation, but first snap it to the nearest generationPeriod boundary var punctuationTimeQuantized = value.SyncTime.SnapToLeftBoundary((long)this.punctuationGenerationPeriod); #if DEBUG - Debug.Assert(punctuationTimeQuantized >= LastEventTime(), "Bug in punctuation quantization logic"); + Debug.Assert(punctuationTimeQuantized >= this.LastEventTime(), "Bug in punctuation quantization logic"); #endif - OnPunctuation(StreamEvent.CreatePunctuation(punctuationTimeQuantized)); + this.OnPunctuation(StreamEvent.CreatePunctuation(punctuationTimeQuantized)); } } this.action(value.SyncTime, value.OtherTime, value.Payload, Empty.Default); - UpdateCurrentTime(value.SyncTime); + this.UpdateCurrentTime(value.SyncTime); } [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -1862,7 +1862,7 @@ private void GenerateAndProcessPunctuation(long syncTime) // Update cached global times this.highWatermark = Math.Max(syncTime, this.highWatermark); - UpdateCurrentTime(syncTime); + this.UpdateCurrentTime(syncTime); this.lastPunctuationTime = Math.Max( syncTime.SnapToLeftBoundary((long)this.punctuationGenerationPeriod), this.lastPunctuationTime); @@ -1881,21 +1881,21 @@ private void GenerateAndProcessPunctuation(long syncTime) if (this.flushPolicy == FlushPolicy.FlushOnPunctuation || (this.flushPolicy == FlushPolicy.FlushOnBatchBoundary && this.currentBatch.Count == Config.DataBatchSize)) { - OnFlush(); + this.OnFlush(); } else if (this.currentBatch.Count == Config.DataBatchSize) { - FlushContents(); + this.FlushContents(); } } protected override void OnCompleted(long punctuationTime) { - GenerateAndProcessPunctuation(punctuationTime); + this.GenerateAndProcessPunctuation(punctuationTime); // Flush, but if we just flushed due to the punctuation generated above if (this.flushPolicy != FlushPolicy.FlushOnPunctuation) - OnFlush(); + this.OnFlush(); } } @@ -1930,7 +1930,7 @@ public DisorderedStreamEventSubscription( diagnosticOutput) { this.fuseModule = fuseModule; - Expression> statement = (s, e, p, k) => Action(s, e, p, k); + Expression> statement = (s, e, p, k) => this.Action(s, e, p, k); var actionExp = fuseModule.Coalesce(statement, true); this.action = actionExp.Compile(); } @@ -1962,7 +1962,7 @@ private void Action(long start, long end, TResult payload, Empty actionKey) if (value.IsPunctuation) { - GenerateAndProcessPunctuation(value.SyncTime); + this.GenerateAndProcessPunctuation(value.SyncTime); return; } @@ -1993,7 +1993,7 @@ private void Action(long start, long end, TResult payload, Empty actionKey) key = Tuple.Create(value.SyncTime, value.Payload); if (!this.startEventInformation.TryGetValue(key, out q)) { - q = new ElasticCircularBuffer(); + q = []; this.startEventInformation.Add(key, q); var x = new AdjustInfo(current); q.Enqueue(ref x); @@ -2100,20 +2100,20 @@ private void Action(long start, long end, TResult payload, Empty actionKey) // SyncTime is sufficiently high to generate a new punctuation, but first snap it to the nearest generationPeriod boundary var punctuationTimeQuantized = value.SyncTime.SnapToLeftBoundary((long)this.punctuationGenerationPeriod); #if DEBUG - Debug.Assert(punctuationTimeQuantized >= LastEventTime(), "Bug in punctuation quantization logic"); + Debug.Assert(punctuationTimeQuantized >= this.LastEventTime(), "Bug in punctuation quantization logic"); #endif - OnPunctuation(StreamEvent.CreatePunctuation(punctuationTimeQuantized)); + this.OnPunctuation(StreamEvent.CreatePunctuation(punctuationTimeQuantized)); } } this.currentBatch.Add(value.SyncTime, value.OtherTime, Empty.Default, value.Payload); if (this.currentBatch.Count == Config.DataBatchSize) { - if (this.flushPolicy == FlushPolicy.FlushOnBatchBoundary) OnFlush(); - else FlushContents(); + if (this.flushPolicy == FlushPolicy.FlushOnBatchBoundary) this.OnFlush(); + else this.FlushContents(); } - UpdateCurrentTime(value.SyncTime); + this.UpdateCurrentTime(value.SyncTime); } [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -2145,7 +2145,7 @@ private void GenerateAndProcessPunctuation(long syncTime) // Update cached global times this.highWatermark = Math.Max(syncTime, this.highWatermark); - UpdateCurrentTime(syncTime); + this.UpdateCurrentTime(syncTime); this.lastPunctuationTime = Math.Max( syncTime.SnapToLeftBoundary((long)this.punctuationGenerationPeriod), this.lastPunctuationTime); @@ -2164,21 +2164,21 @@ private void GenerateAndProcessPunctuation(long syncTime) if (this.flushPolicy == FlushPolicy.FlushOnPunctuation || (this.flushPolicy == FlushPolicy.FlushOnBatchBoundary && this.currentBatch.Count == Config.DataBatchSize)) { - OnFlush(); + this.OnFlush(); } else if (this.currentBatch.Count == Config.DataBatchSize) { - FlushContents(); + this.FlushContents(); } } protected override void OnCompleted(long punctuationTime) { - GenerateAndProcessPunctuation(punctuationTime); + this.GenerateAndProcessPunctuation(punctuationTime); // Flush, but if we just flushed due to the punctuation generated above if (this.flushPolicy != FlushPolicy.FlushOnPunctuation) - OnFlush(); + this.OnFlush(); } } @@ -2240,7 +2240,7 @@ public override void OnNext(TPayload inputValue) if (value.IsPunctuation) { - GenerateAndProcessPunctuation(value.SyncTime); + this.GenerateAndProcessPunctuation(value.SyncTime); return; } @@ -2250,7 +2250,7 @@ public override void OnNext(TPayload inputValue) // Events at the reorder boundary or earlier - are handled using default processing policies if (value.SyncTime <= moveFrom) { - Process(ref value); + this.Process(ref value); return; } @@ -2273,7 +2273,7 @@ public override void OnNext(TPayload inputValue) while ((!this.priorityQueueSorter.IsEmpty()) && this.priorityQueueSorter.Peek().SyncTime <= moveTo) { resultEvent = this.priorityQueueSorter.Dequeue(); - Process(ref resultEvent); + this.Process(ref resultEvent); } } else @@ -2287,7 +2287,7 @@ public override void OnNext(TPayload inputValue) while ((streamEvents.Count > 0) && ((!recheck) || (streamEvents.PeekFirst().SyncTime <= moveTo))) { resultEvent = streamEvents.Dequeue(); - Process(ref resultEvent); + this.Process(ref resultEvent); } } @@ -2298,7 +2298,7 @@ public override void OnNext(TPayload inputValue) if (value.SyncTime == moveTo) { - Process(ref value); + this.Process(ref value); return; } @@ -2306,7 +2306,7 @@ public override void OnNext(TPayload inputValue) if (this.priorityQueueSorter != null) this.priorityQueueSorter.Enqueue(value); else this.impatienceSorter.Enqueue(ref value); - UpdateCurrentTime(moveTo, fromEvent: false); + this.UpdateCurrentTime(moveTo, fromEvent: false); } [System.Diagnostics.CodeAnalysis.SuppressMessage( @@ -2358,20 +2358,20 @@ private void Process(ref StreamEvent value) // SyncTime is sufficiently high to generate a new punctuation, but first snap it to the nearest generationPeriod boundary var punctuationTimeQuantized = value.SyncTime.SnapToLeftBoundary((long)this.punctuationGenerationPeriod); #if DEBUG - Debug.Assert(punctuationTimeQuantized >= LastEventTime(), "Bug in punctuation quantization logic"); + Debug.Assert(punctuationTimeQuantized >= this.LastEventTime(), "Bug in punctuation quantization logic"); #endif - OnPunctuation(StreamEvent.CreatePunctuation(punctuationTimeQuantized)); + this.OnPunctuation(StreamEvent.CreatePunctuation(punctuationTimeQuantized)); } } this.currentBatch.Add(value.SyncTime, value.OtherTime, Empty.Default, value.Payload); if (this.currentBatch.Count == Config.DataBatchSize) { - if (this.flushPolicy == FlushPolicy.FlushOnBatchBoundary) OnFlush(); - else FlushContents(); + if (this.flushPolicy == FlushPolicy.FlushOnBatchBoundary) this.OnFlush(); + else this.FlushContents(); } - UpdateCurrentTime(value.SyncTime); + this.UpdateCurrentTime(value.SyncTime); } [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -2409,7 +2409,7 @@ private void GenerateAndProcessPunctuation(long syncTime) while ((!this.priorityQueueSorter.IsEmpty()) && this.priorityQueueSorter.Peek().SyncTime <= syncTime) { resultEvent = this.priorityQueueSorter.Dequeue(); - Process(ref resultEvent); + this.Process(ref resultEvent); } } else @@ -2421,7 +2421,7 @@ private void GenerateAndProcessPunctuation(long syncTime) while ((streamEvents.Count > 0) && ((!recheck) || (streamEvents.PeekFirst().SyncTime <= syncTime))) { resultEvent = streamEvents.Dequeue(); - Process(ref resultEvent); + this.Process(ref resultEvent); } if (!recheck) this.impatienceSorter.Return(streamEvents); } @@ -2429,7 +2429,7 @@ private void GenerateAndProcessPunctuation(long syncTime) // Update cached global times this.highWatermark = Math.Max(syncTime, this.highWatermark); - UpdateCurrentTime(syncTime); + this.UpdateCurrentTime(syncTime); this.lastPunctuationTime = Math.Max( syncTime.SnapToLeftBoundary((long)this.punctuationGenerationPeriod), this.lastPunctuationTime); @@ -2448,21 +2448,21 @@ private void GenerateAndProcessPunctuation(long syncTime) if (this.flushPolicy == FlushPolicy.FlushOnPunctuation || (this.flushPolicy == FlushPolicy.FlushOnBatchBoundary && this.currentBatch.Count == Config.DataBatchSize)) { - OnFlush(); + this.OnFlush(); } else if (this.currentBatch.Count == Config.DataBatchSize) { - FlushContents(); + this.FlushContents(); } } protected override void OnCompleted(long punctuationTime) { - GenerateAndProcessPunctuation(punctuationTime); + this.GenerateAndProcessPunctuation(punctuationTime); // Flush, but if we just flushed due to the punctuation generated above if (this.flushPolicy != FlushPolicy.FlushOnPunctuation) - OnFlush(); + this.OnFlush(); } } @@ -2506,7 +2506,7 @@ public FusedIntervalSubscriptionWithLatency( { this.fuseModule = fuseModule; Expression> statement = (s, e, p, k) => this.currentBatch.Add(s, e, k, p); - Expression flush = () => FlushContents(); + Expression flush = () => this.FlushContents(); Expression> test = () => this.currentBatch.Count == Config.DataBatchSize; var full = Expression.Lambda>( Expression.Block( @@ -2539,7 +2539,7 @@ public override void OnNext(TPayload inputValue) if (value.IsPunctuation) { - GenerateAndProcessPunctuation(value.SyncTime); + this.GenerateAndProcessPunctuation(value.SyncTime); return; } @@ -2549,7 +2549,7 @@ public override void OnNext(TPayload inputValue) // Events at the reorder boundary or earlier - are handled using default processing policies if (value.SyncTime <= moveFrom) { - Process(ref value); + this.Process(ref value); return; } @@ -2572,7 +2572,7 @@ public override void OnNext(TPayload inputValue) while ((!this.priorityQueueSorter.IsEmpty()) && this.priorityQueueSorter.Peek().SyncTime <= moveTo) { resultEvent = this.priorityQueueSorter.Dequeue(); - Process(ref resultEvent); + this.Process(ref resultEvent); } } else @@ -2586,7 +2586,7 @@ public override void OnNext(TPayload inputValue) while ((streamEvents.Count > 0) && ((!recheck) || (streamEvents.PeekFirst().SyncTime <= moveTo))) { resultEvent = streamEvents.Dequeue(); - Process(ref resultEvent); + this.Process(ref resultEvent); } } @@ -2597,7 +2597,7 @@ public override void OnNext(TPayload inputValue) if (value.SyncTime == moveTo) { - Process(ref value); + this.Process(ref value); return; } @@ -2605,7 +2605,7 @@ public override void OnNext(TPayload inputValue) if (this.priorityQueueSorter != null) this.priorityQueueSorter.Enqueue(value); else this.impatienceSorter.Enqueue(ref value); - UpdateCurrentTime(moveTo, fromEvent: false); + this.UpdateCurrentTime(moveTo, fromEvent: false); } [System.Diagnostics.CodeAnalysis.SuppressMessage( @@ -2657,15 +2657,15 @@ private void Process(ref StreamEvent value) // SyncTime is sufficiently high to generate a new punctuation, but first snap it to the nearest generationPeriod boundary var punctuationTimeQuantized = value.SyncTime.SnapToLeftBoundary((long)this.punctuationGenerationPeriod); #if DEBUG - Debug.Assert(punctuationTimeQuantized >= LastEventTime(), "Bug in punctuation quantization logic"); + Debug.Assert(punctuationTimeQuantized >= this.LastEventTime(), "Bug in punctuation quantization logic"); #endif - OnPunctuation(StreamEvent.CreatePunctuation(punctuationTimeQuantized)); + this.OnPunctuation(StreamEvent.CreatePunctuation(punctuationTimeQuantized)); } } this.action(value.SyncTime, value.OtherTime, value.Payload, Empty.Default); - UpdateCurrentTime(value.SyncTime); + this.UpdateCurrentTime(value.SyncTime); } [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -2703,7 +2703,7 @@ private void GenerateAndProcessPunctuation(long syncTime) while ((!this.priorityQueueSorter.IsEmpty()) && this.priorityQueueSorter.Peek().SyncTime <= syncTime) { resultEvent = this.priorityQueueSorter.Dequeue(); - Process(ref resultEvent); + this.Process(ref resultEvent); } } else @@ -2715,7 +2715,7 @@ private void GenerateAndProcessPunctuation(long syncTime) while ((streamEvents.Count > 0) && ((!recheck) || (streamEvents.PeekFirst().SyncTime <= syncTime))) { resultEvent = streamEvents.Dequeue(); - Process(ref resultEvent); + this.Process(ref resultEvent); } if (!recheck) this.impatienceSorter.Return(streamEvents); } @@ -2723,7 +2723,7 @@ private void GenerateAndProcessPunctuation(long syncTime) // Update cached global times this.highWatermark = Math.Max(syncTime, this.highWatermark); - UpdateCurrentTime(syncTime); + this.UpdateCurrentTime(syncTime); this.lastPunctuationTime = Math.Max( syncTime.SnapToLeftBoundary((long)this.punctuationGenerationPeriod), this.lastPunctuationTime); @@ -2742,21 +2742,21 @@ private void GenerateAndProcessPunctuation(long syncTime) if (this.flushPolicy == FlushPolicy.FlushOnPunctuation || (this.flushPolicy == FlushPolicy.FlushOnBatchBoundary && this.currentBatch.Count == Config.DataBatchSize)) { - OnFlush(); + this.OnFlush(); } else if (this.currentBatch.Count == Config.DataBatchSize) { - FlushContents(); + this.FlushContents(); } } protected override void OnCompleted(long punctuationTime) { - GenerateAndProcessPunctuation(punctuationTime); + this.GenerateAndProcessPunctuation(punctuationTime); // Flush, but if we just flushed due to the punctuation generated above if (this.flushPolicy != FlushPolicy.FlushOnPunctuation) - OnFlush(); + this.OnFlush(); } } @@ -2799,7 +2799,7 @@ public DisorderedIntervalSubscriptionWithLatency( diagnosticOutput) { this.fuseModule = fuseModule; - Expression> statement = (s, e, p, k) => Action(s, e, p, k); + Expression> statement = (s, e, p, k) => this.Action(s, e, p, k); var actionExp = fuseModule.Coalesce(statement); this.action = actionExp.Compile(); this.startEdgeExtractor = startEdgeExtractor; @@ -2835,7 +2835,7 @@ private void Action(long start, long end, TResult payload, Empty actionKey) if (value.IsPunctuation) { - GenerateAndProcessPunctuation(value.SyncTime); + this.GenerateAndProcessPunctuation(value.SyncTime); return; } @@ -2845,7 +2845,7 @@ private void Action(long start, long end, TResult payload, Empty actionKey) // Events at the reorder boundary or earlier - are handled using default processing policies if (value.SyncTime <= moveFrom) { - Process(ref value); + this.Process(ref value); return; } @@ -2868,7 +2868,7 @@ private void Action(long start, long end, TResult payload, Empty actionKey) while ((!this.priorityQueueSorter.IsEmpty()) && this.priorityQueueSorter.Peek().SyncTime <= moveTo) { resultEvent = this.priorityQueueSorter.Dequeue(); - Process(ref resultEvent); + this.Process(ref resultEvent); } } else @@ -2882,7 +2882,7 @@ private void Action(long start, long end, TResult payload, Empty actionKey) while ((streamEvents.Count > 0) && ((!recheck) || (streamEvents.PeekFirst().SyncTime <= moveTo))) { resultEvent = streamEvents.Dequeue(); - Process(ref resultEvent); + this.Process(ref resultEvent); } } @@ -2893,7 +2893,7 @@ private void Action(long start, long end, TResult payload, Empty actionKey) if (value.SyncTime == moveTo) { - Process(ref value); + this.Process(ref value); return; } @@ -2901,7 +2901,7 @@ private void Action(long start, long end, TResult payload, Empty actionKey) if (this.priorityQueueSorter != null) this.priorityQueueSorter.Enqueue(value); else this.impatienceSorter.Enqueue(ref value); - UpdateCurrentTime(moveTo, fromEvent: false); + this.UpdateCurrentTime(moveTo, fromEvent: false); } [System.Diagnostics.CodeAnalysis.SuppressMessage( @@ -2953,20 +2953,20 @@ private void Process(ref StreamEvent value) // SyncTime is sufficiently high to generate a new punctuation, but first snap it to the nearest generationPeriod boundary var punctuationTimeQuantized = value.SyncTime.SnapToLeftBoundary((long)this.punctuationGenerationPeriod); #if DEBUG - Debug.Assert(punctuationTimeQuantized >= LastEventTime(), "Bug in punctuation quantization logic"); + Debug.Assert(punctuationTimeQuantized >= this.LastEventTime(), "Bug in punctuation quantization logic"); #endif - OnPunctuation(StreamEvent.CreatePunctuation(punctuationTimeQuantized)); + this.OnPunctuation(StreamEvent.CreatePunctuation(punctuationTimeQuantized)); } } this.currentBatch.Add(value.SyncTime, value.OtherTime, Empty.Default, value.Payload); if (this.currentBatch.Count == Config.DataBatchSize) { - if (this.flushPolicy == FlushPolicy.FlushOnBatchBoundary) OnFlush(); - else FlushContents(); + if (this.flushPolicy == FlushPolicy.FlushOnBatchBoundary) this.OnFlush(); + else this.FlushContents(); } - UpdateCurrentTime(value.SyncTime); + this.UpdateCurrentTime(value.SyncTime); } [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -3004,7 +3004,7 @@ private void GenerateAndProcessPunctuation(long syncTime) while ((!this.priorityQueueSorter.IsEmpty()) && this.priorityQueueSorter.Peek().SyncTime <= syncTime) { resultEvent = this.priorityQueueSorter.Dequeue(); - Process(ref resultEvent); + this.Process(ref resultEvent); } } else @@ -3016,7 +3016,7 @@ private void GenerateAndProcessPunctuation(long syncTime) while ((streamEvents.Count > 0) && ((!recheck) || (streamEvents.PeekFirst().SyncTime <= syncTime))) { resultEvent = streamEvents.Dequeue(); - Process(ref resultEvent); + this.Process(ref resultEvent); } if (!recheck) this.impatienceSorter.Return(streamEvents); } @@ -3024,7 +3024,7 @@ private void GenerateAndProcessPunctuation(long syncTime) // Update cached global times this.highWatermark = Math.Max(syncTime, this.highWatermark); - UpdateCurrentTime(syncTime); + this.UpdateCurrentTime(syncTime); this.lastPunctuationTime = Math.Max( syncTime.SnapToLeftBoundary((long)this.punctuationGenerationPeriod), this.lastPunctuationTime); @@ -3043,21 +3043,21 @@ private void GenerateAndProcessPunctuation(long syncTime) if (this.flushPolicy == FlushPolicy.FlushOnPunctuation || (this.flushPolicy == FlushPolicy.FlushOnBatchBoundary && this.currentBatch.Count == Config.DataBatchSize)) { - OnFlush(); + this.OnFlush(); } else if (this.currentBatch.Count == Config.DataBatchSize) { - FlushContents(); + this.FlushContents(); } } protected override void OnCompleted(long punctuationTime) { - GenerateAndProcessPunctuation(punctuationTime); + this.GenerateAndProcessPunctuation(punctuationTime); // Flush, but if we just flushed due to the punctuation generated above if (this.flushPolicy != FlushPolicy.FlushOnPunctuation) - OnFlush(); + this.OnFlush(); } } @@ -3119,7 +3119,7 @@ public override void OnNext(TPayload inputValue) if (value.IsPunctuation) { - GenerateAndProcessPunctuation(value.SyncTime); + this.GenerateAndProcessPunctuation(value.SyncTime); return; } @@ -3166,20 +3166,20 @@ public override void OnNext(TPayload inputValue) // SyncTime is sufficiently high to generate a new punctuation, but first snap it to the nearest generationPeriod boundary var punctuationTimeQuantized = value.SyncTime.SnapToLeftBoundary((long)this.punctuationGenerationPeriod); #if DEBUG - Debug.Assert(punctuationTimeQuantized >= LastEventTime(), "Bug in punctuation quantization logic"); + Debug.Assert(punctuationTimeQuantized >= this.LastEventTime(), "Bug in punctuation quantization logic"); #endif - OnPunctuation(StreamEvent.CreatePunctuation(punctuationTimeQuantized)); + this.OnPunctuation(StreamEvent.CreatePunctuation(punctuationTimeQuantized)); } } this.currentBatch.Add(value.SyncTime, value.OtherTime, Empty.Default, value.Payload); if (this.currentBatch.Count == Config.DataBatchSize) { - if (this.flushPolicy == FlushPolicy.FlushOnBatchBoundary) OnFlush(); - else FlushContents(); + if (this.flushPolicy == FlushPolicy.FlushOnBatchBoundary) this.OnFlush(); + else this.FlushContents(); } - UpdateCurrentTime(value.SyncTime); + this.UpdateCurrentTime(value.SyncTime); } [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -3211,7 +3211,7 @@ private void GenerateAndProcessPunctuation(long syncTime) // Update cached global times this.highWatermark = Math.Max(syncTime, this.highWatermark); - UpdateCurrentTime(syncTime); + this.UpdateCurrentTime(syncTime); this.lastPunctuationTime = Math.Max( syncTime.SnapToLeftBoundary((long)this.punctuationGenerationPeriod), this.lastPunctuationTime); @@ -3230,21 +3230,21 @@ private void GenerateAndProcessPunctuation(long syncTime) if (this.flushPolicy == FlushPolicy.FlushOnPunctuation || (this.flushPolicy == FlushPolicy.FlushOnBatchBoundary && this.currentBatch.Count == Config.DataBatchSize)) { - OnFlush(); + this.OnFlush(); } else if (this.currentBatch.Count == Config.DataBatchSize) { - FlushContents(); + this.FlushContents(); } } protected override void OnCompleted(long punctuationTime) { - GenerateAndProcessPunctuation(punctuationTime); + this.GenerateAndProcessPunctuation(punctuationTime); // Flush, but if we just flushed due to the punctuation generated above if (this.flushPolicy != FlushPolicy.FlushOnPunctuation) - OnFlush(); + this.OnFlush(); } } @@ -3288,7 +3288,7 @@ public FusedIntervalSubscription( { this.fuseModule = fuseModule; Expression> statement = (s, e, p, k) => this.currentBatch.Add(s, e, k, p); - Expression flush = () => FlushContents(); + Expression flush = () => this.FlushContents(); Expression> test = () => this.currentBatch.Count == Config.DataBatchSize; var full = Expression.Lambda>( Expression.Block( @@ -3321,7 +3321,7 @@ public override void OnNext(TPayload inputValue) if (value.IsPunctuation) { - GenerateAndProcessPunctuation(value.SyncTime); + this.GenerateAndProcessPunctuation(value.SyncTime); return; } @@ -3368,15 +3368,15 @@ public override void OnNext(TPayload inputValue) // SyncTime is sufficiently high to generate a new punctuation, but first snap it to the nearest generationPeriod boundary var punctuationTimeQuantized = value.SyncTime.SnapToLeftBoundary((long)this.punctuationGenerationPeriod); #if DEBUG - Debug.Assert(punctuationTimeQuantized >= LastEventTime(), "Bug in punctuation quantization logic"); + Debug.Assert(punctuationTimeQuantized >= this.LastEventTime(), "Bug in punctuation quantization logic"); #endif - OnPunctuation(StreamEvent.CreatePunctuation(punctuationTimeQuantized)); + this.OnPunctuation(StreamEvent.CreatePunctuation(punctuationTimeQuantized)); } } this.action(value.SyncTime, value.OtherTime, value.Payload, Empty.Default); - UpdateCurrentTime(value.SyncTime); + this.UpdateCurrentTime(value.SyncTime); } [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -3408,7 +3408,7 @@ private void GenerateAndProcessPunctuation(long syncTime) // Update cached global times this.highWatermark = Math.Max(syncTime, this.highWatermark); - UpdateCurrentTime(syncTime); + this.UpdateCurrentTime(syncTime); this.lastPunctuationTime = Math.Max( syncTime.SnapToLeftBoundary((long)this.punctuationGenerationPeriod), this.lastPunctuationTime); @@ -3427,21 +3427,21 @@ private void GenerateAndProcessPunctuation(long syncTime) if (this.flushPolicy == FlushPolicy.FlushOnPunctuation || (this.flushPolicy == FlushPolicy.FlushOnBatchBoundary && this.currentBatch.Count == Config.DataBatchSize)) { - OnFlush(); + this.OnFlush(); } else if (this.currentBatch.Count == Config.DataBatchSize) { - FlushContents(); + this.FlushContents(); } } protected override void OnCompleted(long punctuationTime) { - GenerateAndProcessPunctuation(punctuationTime); + this.GenerateAndProcessPunctuation(punctuationTime); // Flush, but if we just flushed due to the punctuation generated above if (this.flushPolicy != FlushPolicy.FlushOnPunctuation) - OnFlush(); + this.OnFlush(); } } @@ -3484,7 +3484,7 @@ public DisorderedIntervalSubscription( diagnosticOutput) { this.fuseModule = fuseModule; - Expression> statement = (s, e, p, k) => Action(s, e, p, k); + Expression> statement = (s, e, p, k) => this.Action(s, e, p, k); var actionExp = fuseModule.Coalesce(statement); this.action = actionExp.Compile(); this.startEdgeExtractor = startEdgeExtractor; @@ -3520,7 +3520,7 @@ private void Action(long start, long end, TResult payload, Empty actionKey) if (value.IsPunctuation) { - GenerateAndProcessPunctuation(value.SyncTime); + this.GenerateAndProcessPunctuation(value.SyncTime); return; } @@ -3567,20 +3567,20 @@ private void Action(long start, long end, TResult payload, Empty actionKey) // SyncTime is sufficiently high to generate a new punctuation, but first snap it to the nearest generationPeriod boundary var punctuationTimeQuantized = value.SyncTime.SnapToLeftBoundary((long)this.punctuationGenerationPeriod); #if DEBUG - Debug.Assert(punctuationTimeQuantized >= LastEventTime(), "Bug in punctuation quantization logic"); + Debug.Assert(punctuationTimeQuantized >= this.LastEventTime(), "Bug in punctuation quantization logic"); #endif - OnPunctuation(StreamEvent.CreatePunctuation(punctuationTimeQuantized)); + this.OnPunctuation(StreamEvent.CreatePunctuation(punctuationTimeQuantized)); } } this.currentBatch.Add(value.SyncTime, value.OtherTime, Empty.Default, value.Payload); if (this.currentBatch.Count == Config.DataBatchSize) { - if (this.flushPolicy == FlushPolicy.FlushOnBatchBoundary) OnFlush(); - else FlushContents(); + if (this.flushPolicy == FlushPolicy.FlushOnBatchBoundary) this.OnFlush(); + else this.FlushContents(); } - UpdateCurrentTime(value.SyncTime); + this.UpdateCurrentTime(value.SyncTime); } [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -3612,7 +3612,7 @@ private void GenerateAndProcessPunctuation(long syncTime) // Update cached global times this.highWatermark = Math.Max(syncTime, this.highWatermark); - UpdateCurrentTime(syncTime); + this.UpdateCurrentTime(syncTime); this.lastPunctuationTime = Math.Max( syncTime.SnapToLeftBoundary((long)this.punctuationGenerationPeriod), this.lastPunctuationTime); @@ -3631,21 +3631,21 @@ private void GenerateAndProcessPunctuation(long syncTime) if (this.flushPolicy == FlushPolicy.FlushOnPunctuation || (this.flushPolicy == FlushPolicy.FlushOnBatchBoundary && this.currentBatch.Count == Config.DataBatchSize)) { - OnFlush(); + this.OnFlush(); } else if (this.currentBatch.Count == Config.DataBatchSize) { - FlushContents(); + this.FlushContents(); } } protected override void OnCompleted(long punctuationTime) { - GenerateAndProcessPunctuation(punctuationTime); + this.GenerateAndProcessPunctuation(punctuationTime); // Flush, but if we just flushed due to the punctuation generated above if (this.flushPolicy != FlushPolicy.FlushOnPunctuation) - OnFlush(); + this.OnFlush(); } } @@ -3695,7 +3695,7 @@ public override void OnNext(PartitionedStreamEvent value) if (value.IsLowWatermark) { - GenerateAndProcessLowWatermark(value.SyncTime); + this.GenerateAndProcessLowWatermark(value.SyncTime); return; } @@ -3708,7 +3708,7 @@ public override void OnNext(PartitionedStreamEvent value) { // SyncTime is sufficiently high to generate a new watermark, but first snap it to the nearest generationPeriod boundary var newLowWatermarkSnapped = newLowWatermark.SnapToLeftBoundary((long)this.lowWatermarkGenerationPeriod); - GenerateAndProcessLowWatermark(newLowWatermarkSnapped); + this.GenerateAndProcessLowWatermark(newLowWatermarkSnapped); } } @@ -3722,14 +3722,14 @@ public override void OnNext(PartitionedStreamEvent value) this.partitionHighWatermarks.Add(value.PartitionKey, this.lowWatermark.rawValue); if (this.highWatermarkToPartitionsMap.TryGetValue(this.lowWatermark.rawValue, out HashSet keySet)) keySet.Add(value.PartitionKey); - else this.highWatermarkToPartitionsMap.Add(this.lowWatermark.rawValue, new HashSet { value.PartitionKey }); + else this.highWatermarkToPartitionsMap.Add(this.lowWatermark.rawValue, [value.PartitionKey]); } long moveTo = moveFrom; // Events at the reorder boundary or earlier - are handled using default processing policies if (value.SyncTime <= moveFrom) { - Process(ref value); + this.Process(ref value); return; } @@ -3743,7 +3743,7 @@ public override void OnNext(PartitionedStreamEvent value) else oldSet.Remove(value.PartitionKey); if (this.highWatermarkToPartitionsMap.TryGetValue(value.SyncTime, out HashSet set)) set.Add(value.PartitionKey); - else this.highWatermarkToPartitionsMap.Add(value.SyncTime, new HashSet { value.PartitionKey }); + else this.highWatermarkToPartitionsMap.Add(value.SyncTime, [value.PartitionKey]); if (value.IsData) { @@ -3768,7 +3768,7 @@ public override void OnNext(PartitionedStreamEvent value) while ((!this.priorityQueueSorter.IsEmpty()) && this.priorityQueueSorter.Peek().SyncTime <= moveTo) { resultEvent = this.priorityQueueSorter.Dequeue(); - Process(ref resultEvent); + this.Process(ref resultEvent); } } else @@ -3782,7 +3782,7 @@ public override void OnNext(PartitionedStreamEvent value) while ((streamEvents.Count > 0) && ((!recheck) || (streamEvents.PeekFirst().SyncTime <= moveTo))) { resultEvent = streamEvents.Dequeue(); - Process(ref resultEvent); + this.Process(ref resultEvent); } } @@ -3793,7 +3793,7 @@ public override void OnNext(PartitionedStreamEvent value) if (value.SyncTime == moveTo) { - Process(ref value); + this.Process(ref value); return; } @@ -3801,7 +3801,7 @@ public override void OnNext(PartitionedStreamEvent value) if (this.priorityQueueSorter != null) this.priorityQueueSorter.Enqueue(value); else this.impatienceSorter.Enqueue(ref value); - UpdateCurrentTime(value.PartitionKey, moveTo, fromEvent: false); + this.UpdateCurrentTime(value.PartitionKey, moveTo, fromEvent: false); } [System.Diagnostics.CodeAnalysis.SuppressMessage( @@ -3814,7 +3814,7 @@ private void Process(ref PartitionedStreamEvent value) if (value.IsLowWatermark) { - GenerateAndProcessLowWatermark(value.SyncTime); + this.GenerateAndProcessLowWatermark(value.SyncTime); return; } @@ -3822,7 +3822,7 @@ private void Process(ref PartitionedStreamEvent value) this.highWatermark = Math.Max(this.highWatermark, value.SyncTime); if (this.punctuationPolicyType == PeriodicPunctuationPolicyType.Time && !this.lastPunctuationTime.ContainsKey(value.PartitionKey)) - UpdatePunctuation(value.PartitionKey, this.lowWatermark.rawValue, this.lowWatermark.quantizedForPunctuationGeneration); + this.UpdatePunctuation(value.PartitionKey, this.lowWatermark.rawValue, this.lowWatermark.quantizedForPunctuationGeneration); // Retrieve current time for this partition, updating currentTime if necessary if (!this.currentTime.TryGetValue(value.PartitionKey, out long current)) @@ -3832,7 +3832,7 @@ private void Process(ref PartitionedStreamEvent value) else if (current < this.lowWatermark.rawValue) { current = this.lowWatermark.rawValue; - UpdateCurrentTime(value.PartitionKey, this.lowWatermark.rawValue); + this.UpdateCurrentTime(value.PartitionKey, this.lowWatermark.rawValue); } var outOfOrder = value.SyncTime < current; @@ -3840,7 +3840,7 @@ private void Process(ref PartitionedStreamEvent value) // check for out of order event if (value.IsPunctuation) { - OnPunctuation(value.CreatePunctuation(outOfOrder ? current : value.SyncTime)); + this.OnPunctuation(value.CreatePunctuation(outOfOrder ? current : value.SyncTime)); } else { @@ -3864,7 +3864,7 @@ private void Process(ref PartitionedStreamEvent value) key = Tuple.Create(value.SyncTime, value.Payload); if (!this.startEventInformation.TryGetValue(key, out q)) { - q = new ElasticCircularBuffer(); + q = []; this.startEventInformation.Add(key, q); var x = new AdjustInfo(current); q.Enqueue(ref x); @@ -3975,9 +3975,9 @@ private void Process(ref PartitionedStreamEvent value) // SyncTime is sufficiently high to generate a new punctuation, but first snap it to the nearest generationPeriod boundary var punctuationTimeQuantized = value.SyncTime.SnapToLeftBoundary((long)this.punctuationGenerationPeriod); #if DEBUG - Debug.Assert(punctuationTimeQuantized >= LastEventTime(value.PartitionKey), "Bug in punctuation quantization logic"); - #endif - OnPunctuation(value.CreatePunctuation(punctuationTimeQuantized)); + Debug.Assert(punctuationTimeQuantized >= this.LastEventTime(value.PartitionKey), "Bug in punctuation quantization logic"); +#endif + this.OnPunctuation(value.CreatePunctuation(punctuationTimeQuantized)); } } } @@ -3985,12 +3985,12 @@ private void Process(ref PartitionedStreamEvent value) this.currentBatch.Add(value.SyncTime, value.OtherTime, new PartitionKey(value.PartitionKey), value.Payload); if (this.currentBatch.Count == Config.DataBatchSize) { - if (this.flushPolicy == PartitionedFlushPolicy.FlushOnBatchBoundary) OnFlush(); - else FlushContents(); + if (this.flushPolicy == PartitionedFlushPolicy.FlushOnBatchBoundary) this.OnFlush(); + else this.FlushContents(); } } - UpdateCurrentTime(value.PartitionKey, value.SyncTime); + this.UpdateCurrentTime(value.PartitionKey, value.SyncTime); } [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -4023,7 +4023,7 @@ private void GenerateAndProcessLowWatermark(long syncTime) while ((!this.priorityQueueSorter.IsEmpty()) && this.priorityQueueSorter.Peek().SyncTime <= syncTime) { resultEvent = this.priorityQueueSorter.Dequeue(); - Process(ref resultEvent); + this.Process(ref resultEvent); } } else @@ -4043,7 +4043,7 @@ private void GenerateAndProcessLowWatermark(long syncTime) while ((streamEvents.Count > 0) && ((!recheck) || (streamEvents.PeekFirst().SyncTime <= syncTime))) { resultEvent = streamEvents.Dequeue(); - Process(ref resultEvent); + this.Process(ref resultEvent); } if (!recheck) this.impatienceSorter.Return(entry.key, streamEvents); } @@ -4054,7 +4054,7 @@ private void GenerateAndProcessLowWatermark(long syncTime) this.highWatermark = Math.Max(syncTime, this.highWatermark); if (this.lowWatermark.rawValue < syncTime) { - UpdateLowWatermark(syncTime); + this.UpdateLowWatermark(syncTime); // Gather keys whose high watermarks are before the new low watermark var expiredWatermarkKVPs = new List>>(); @@ -4099,11 +4099,11 @@ private void GenerateAndProcessLowWatermark(long syncTime) if (this.flushPolicy == PartitionedFlushPolicy.FlushOnLowWatermark || (this.flushPolicy == PartitionedFlushPolicy.FlushOnBatchBoundary && this.currentBatch.Count == Config.DataBatchSize)) { - OnFlush(); + this.OnFlush(); } else if (this.currentBatch.Count == Config.DataBatchSize) { - FlushContents(); + this.FlushContents(); } } @@ -4114,17 +4114,17 @@ protected override void UpdatePointers() if (this.highWatermarkToPartitionsMap.TryGetValue(kvp.Value, out HashSet set)) set.Add(kvp.Key); else - this.highWatermarkToPartitionsMap.Add(kvp.Value, new HashSet { kvp.Key }); + this.highWatermarkToPartitionsMap.Add(kvp.Value, [kvp.Key]); } } protected override void OnCompleted(long punctuationTime) { - GenerateAndProcessLowWatermark(punctuationTime); + this.GenerateAndProcessLowWatermark(punctuationTime); // Flush, but if we just flushed due to the punctuation generated above if (this.flushPolicy != PartitionedFlushPolicy.FlushOnLowWatermark) - OnFlush(); + this.OnFlush(); } } @@ -4162,7 +4162,7 @@ public FusedPartitionedStreamEventSubscriptionWithLatency( { this.fuseModule = fuseModule; Expression>> statement = (s, e, p, k) => this.currentBatch.Add(s, e, k, p); - Expression flush = () => FlushContents(); + Expression flush = () => this.FlushContents(); Expression> test = () => this.currentBatch.Count == Config.DataBatchSize; var full = Expression.Lambda>>( Expression.Block( @@ -4189,7 +4189,7 @@ public override void OnNext(PartitionedStreamEvent value) if (value.IsLowWatermark) { - GenerateAndProcessLowWatermark(value.SyncTime); + this.GenerateAndProcessLowWatermark(value.SyncTime); return; } @@ -4202,7 +4202,7 @@ public override void OnNext(PartitionedStreamEvent value) { // SyncTime is sufficiently high to generate a new watermark, but first snap it to the nearest generationPeriod boundary var newLowWatermarkSnapped = newLowWatermark.SnapToLeftBoundary((long)this.lowWatermarkGenerationPeriod); - GenerateAndProcessLowWatermark(newLowWatermarkSnapped); + this.GenerateAndProcessLowWatermark(newLowWatermarkSnapped); } } @@ -4216,14 +4216,14 @@ public override void OnNext(PartitionedStreamEvent value) this.partitionHighWatermarks.Add(value.PartitionKey, this.lowWatermark.rawValue); if (this.highWatermarkToPartitionsMap.TryGetValue(this.lowWatermark.rawValue, out HashSet keySet)) keySet.Add(value.PartitionKey); - else this.highWatermarkToPartitionsMap.Add(this.lowWatermark.rawValue, new HashSet { value.PartitionKey }); + else this.highWatermarkToPartitionsMap.Add(this.lowWatermark.rawValue, [value.PartitionKey]); } long moveTo = moveFrom; // Events at the reorder boundary or earlier - are handled using default processing policies if (value.SyncTime <= moveFrom) { - Process(ref value); + this.Process(ref value); return; } @@ -4237,7 +4237,7 @@ public override void OnNext(PartitionedStreamEvent value) else oldSet.Remove(value.PartitionKey); if (this.highWatermarkToPartitionsMap.TryGetValue(value.SyncTime, out HashSet set)) set.Add(value.PartitionKey); - else this.highWatermarkToPartitionsMap.Add(value.SyncTime, new HashSet { value.PartitionKey }); + else this.highWatermarkToPartitionsMap.Add(value.SyncTime, [value.PartitionKey]); if (value.IsData) { @@ -4262,7 +4262,7 @@ public override void OnNext(PartitionedStreamEvent value) while ((!this.priorityQueueSorter.IsEmpty()) && this.priorityQueueSorter.Peek().SyncTime <= moveTo) { resultEvent = this.priorityQueueSorter.Dequeue(); - Process(ref resultEvent); + this.Process(ref resultEvent); } } else @@ -4276,7 +4276,7 @@ public override void OnNext(PartitionedStreamEvent value) while ((streamEvents.Count > 0) && ((!recheck) || (streamEvents.PeekFirst().SyncTime <= moveTo))) { resultEvent = streamEvents.Dequeue(); - Process(ref resultEvent); + this.Process(ref resultEvent); } } @@ -4287,7 +4287,7 @@ public override void OnNext(PartitionedStreamEvent value) if (value.SyncTime == moveTo) { - Process(ref value); + this.Process(ref value); return; } @@ -4295,7 +4295,7 @@ public override void OnNext(PartitionedStreamEvent value) if (this.priorityQueueSorter != null) this.priorityQueueSorter.Enqueue(value); else this.impatienceSorter.Enqueue(ref value); - UpdateCurrentTime(value.PartitionKey, moveTo, fromEvent: false); + this.UpdateCurrentTime(value.PartitionKey, moveTo, fromEvent: false); } [System.Diagnostics.CodeAnalysis.SuppressMessage( @@ -4308,7 +4308,7 @@ private void Process(ref PartitionedStreamEvent value) if (value.IsLowWatermark) { - GenerateAndProcessLowWatermark(value.SyncTime); + this.GenerateAndProcessLowWatermark(value.SyncTime); return; } @@ -4316,7 +4316,7 @@ private void Process(ref PartitionedStreamEvent value) this.highWatermark = Math.Max(this.highWatermark, value.SyncTime); if (this.punctuationPolicyType == PeriodicPunctuationPolicyType.Time && !this.lastPunctuationTime.ContainsKey(value.PartitionKey)) - UpdatePunctuation(value.PartitionKey, this.lowWatermark.rawValue, this.lowWatermark.quantizedForPunctuationGeneration); + this.UpdatePunctuation(value.PartitionKey, this.lowWatermark.rawValue, this.lowWatermark.quantizedForPunctuationGeneration); // Retrieve current time for this partition, updating currentTime if necessary if (!this.currentTime.TryGetValue(value.PartitionKey, out long current)) @@ -4326,7 +4326,7 @@ private void Process(ref PartitionedStreamEvent value) else if (current < this.lowWatermark.rawValue) { current = this.lowWatermark.rawValue; - UpdateCurrentTime(value.PartitionKey, this.lowWatermark.rawValue); + this.UpdateCurrentTime(value.PartitionKey, this.lowWatermark.rawValue); } var outOfOrder = value.SyncTime < current; @@ -4334,7 +4334,7 @@ private void Process(ref PartitionedStreamEvent value) // check for out of order event if (value.IsPunctuation) { - OnPunctuation(value.CreatePunctuation(outOfOrder ? current : value.SyncTime)); + this.OnPunctuation(value.CreatePunctuation(outOfOrder ? current : value.SyncTime)); } else { @@ -4358,7 +4358,7 @@ private void Process(ref PartitionedStreamEvent value) key = Tuple.Create(value.SyncTime, value.Payload); if (!this.startEventInformation.TryGetValue(key, out q)) { - q = new ElasticCircularBuffer(); + q = []; this.startEventInformation.Add(key, q); var x = new AdjustInfo(current); q.Enqueue(ref x); @@ -4469,9 +4469,9 @@ private void Process(ref PartitionedStreamEvent value) // SyncTime is sufficiently high to generate a new punctuation, but first snap it to the nearest generationPeriod boundary var punctuationTimeQuantized = value.SyncTime.SnapToLeftBoundary((long)this.punctuationGenerationPeriod); #if DEBUG - Debug.Assert(punctuationTimeQuantized >= LastEventTime(value.PartitionKey), "Bug in punctuation quantization logic"); - #endif - OnPunctuation(value.CreatePunctuation(punctuationTimeQuantized)); + Debug.Assert(punctuationTimeQuantized >= this.LastEventTime(value.PartitionKey), "Bug in punctuation quantization logic"); +#endif + this.OnPunctuation(value.CreatePunctuation(punctuationTimeQuantized)); } } } @@ -4479,7 +4479,7 @@ private void Process(ref PartitionedStreamEvent value) this.action(value.SyncTime, value.OtherTime, value.Payload, new PartitionKey(value.PartitionKey)); } - UpdateCurrentTime(value.PartitionKey, value.SyncTime); + this.UpdateCurrentTime(value.PartitionKey, value.SyncTime); } [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -4512,7 +4512,7 @@ private void GenerateAndProcessLowWatermark(long syncTime) while ((!this.priorityQueueSorter.IsEmpty()) && this.priorityQueueSorter.Peek().SyncTime <= syncTime) { resultEvent = this.priorityQueueSorter.Dequeue(); - Process(ref resultEvent); + this.Process(ref resultEvent); } } else @@ -4532,7 +4532,7 @@ private void GenerateAndProcessLowWatermark(long syncTime) while ((streamEvents.Count > 0) && ((!recheck) || (streamEvents.PeekFirst().SyncTime <= syncTime))) { resultEvent = streamEvents.Dequeue(); - Process(ref resultEvent); + this.Process(ref resultEvent); } if (!recheck) this.impatienceSorter.Return(entry.key, streamEvents); } @@ -4543,7 +4543,7 @@ private void GenerateAndProcessLowWatermark(long syncTime) this.highWatermark = Math.Max(syncTime, this.highWatermark); if (this.lowWatermark.rawValue < syncTime) { - UpdateLowWatermark(syncTime); + this.UpdateLowWatermark(syncTime); // Gather keys whose high watermarks are before the new low watermark var expiredWatermarkKVPs = new List>>(); @@ -4588,11 +4588,11 @@ private void GenerateAndProcessLowWatermark(long syncTime) if (this.flushPolicy == PartitionedFlushPolicy.FlushOnLowWatermark || (this.flushPolicy == PartitionedFlushPolicy.FlushOnBatchBoundary && this.currentBatch.Count == Config.DataBatchSize)) { - OnFlush(); + this.OnFlush(); } else if (this.currentBatch.Count == Config.DataBatchSize) { - FlushContents(); + this.FlushContents(); } } @@ -4603,17 +4603,17 @@ protected override void UpdatePointers() if (this.highWatermarkToPartitionsMap.TryGetValue(kvp.Value, out HashSet set)) set.Add(kvp.Key); else - this.highWatermarkToPartitionsMap.Add(kvp.Value, new HashSet { kvp.Key }); + this.highWatermarkToPartitionsMap.Add(kvp.Value, [kvp.Key]); } } protected override void OnCompleted(long punctuationTime) { - GenerateAndProcessLowWatermark(punctuationTime); + this.GenerateAndProcessLowWatermark(punctuationTime); // Flush, but if we just flushed due to the punctuation generated above if (this.flushPolicy != PartitionedFlushPolicy.FlushOnLowWatermark) - OnFlush(); + this.OnFlush(); } } @@ -4650,7 +4650,7 @@ public DisorderedPartitionedStreamEventSubscriptionWithLatency( diagnosticOutput) { this.fuseModule = fuseModule; - Expression>> statement = (s, e, p, k) => Action(s, e, p, k); + Expression>> statement = (s, e, p, k) => this.Action(s, e, p, k); var actionExp = fuseModule.Coalesce>(statement, true); this.action = actionExp.Compile(); } @@ -4681,7 +4681,7 @@ private void Action(long start, long end, TResult payload, PartitionKey ac if (value.IsLowWatermark) { - GenerateAndProcessLowWatermark(value.SyncTime); + this.GenerateAndProcessLowWatermark(value.SyncTime); return; } @@ -4694,7 +4694,7 @@ private void Action(long start, long end, TResult payload, PartitionKey ac { // SyncTime is sufficiently high to generate a new watermark, but first snap it to the nearest generationPeriod boundary var newLowWatermarkSnapped = newLowWatermark.SnapToLeftBoundary((long)this.lowWatermarkGenerationPeriod); - GenerateAndProcessLowWatermark(newLowWatermarkSnapped); + this.GenerateAndProcessLowWatermark(newLowWatermarkSnapped); } } @@ -4708,14 +4708,14 @@ private void Action(long start, long end, TResult payload, PartitionKey ac this.partitionHighWatermarks.Add(value.PartitionKey, this.lowWatermark.rawValue); if (this.highWatermarkToPartitionsMap.TryGetValue(this.lowWatermark.rawValue, out HashSet keySet)) keySet.Add(value.PartitionKey); - else this.highWatermarkToPartitionsMap.Add(this.lowWatermark.rawValue, new HashSet { value.PartitionKey }); + else this.highWatermarkToPartitionsMap.Add(this.lowWatermark.rawValue, [value.PartitionKey]); } long moveTo = moveFrom; // Events at the reorder boundary or earlier - are handled using default processing policies if (value.SyncTime <= moveFrom) { - Process(ref value); + this.Process(ref value); return; } @@ -4729,7 +4729,7 @@ private void Action(long start, long end, TResult payload, PartitionKey ac else oldSet.Remove(value.PartitionKey); if (this.highWatermarkToPartitionsMap.TryGetValue(value.SyncTime, out HashSet set)) set.Add(value.PartitionKey); - else this.highWatermarkToPartitionsMap.Add(value.SyncTime, new HashSet { value.PartitionKey }); + else this.highWatermarkToPartitionsMap.Add(value.SyncTime, [value.PartitionKey]); if (value.IsData) { @@ -4754,7 +4754,7 @@ private void Action(long start, long end, TResult payload, PartitionKey ac while ((!this.priorityQueueSorter.IsEmpty()) && this.priorityQueueSorter.Peek().SyncTime <= moveTo) { resultEvent = this.priorityQueueSorter.Dequeue(); - Process(ref resultEvent); + this.Process(ref resultEvent); } } else @@ -4768,7 +4768,7 @@ private void Action(long start, long end, TResult payload, PartitionKey ac while ((streamEvents.Count > 0) && ((!recheck) || (streamEvents.PeekFirst().SyncTime <= moveTo))) { resultEvent = streamEvents.Dequeue(); - Process(ref resultEvent); + this.Process(ref resultEvent); } } @@ -4779,7 +4779,7 @@ private void Action(long start, long end, TResult payload, PartitionKey ac if (value.SyncTime == moveTo) { - Process(ref value); + this.Process(ref value); return; } @@ -4787,7 +4787,7 @@ private void Action(long start, long end, TResult payload, PartitionKey ac if (this.priorityQueueSorter != null) this.priorityQueueSorter.Enqueue(value); else this.impatienceSorter.Enqueue(ref value); - UpdateCurrentTime(value.PartitionKey, moveTo, fromEvent: false); + this.UpdateCurrentTime(value.PartitionKey, moveTo, fromEvent: false); } [System.Diagnostics.CodeAnalysis.SuppressMessage( @@ -4800,7 +4800,7 @@ private void Process(ref PartitionedStreamEvent value) if (value.IsLowWatermark) { - GenerateAndProcessLowWatermark(value.SyncTime); + this.GenerateAndProcessLowWatermark(value.SyncTime); return; } @@ -4808,7 +4808,7 @@ private void Process(ref PartitionedStreamEvent value) this.highWatermark = Math.Max(this.highWatermark, value.SyncTime); if (this.punctuationPolicyType == PeriodicPunctuationPolicyType.Time && !this.lastPunctuationTime.ContainsKey(value.PartitionKey)) - UpdatePunctuation(value.PartitionKey, this.lowWatermark.rawValue, this.lowWatermark.quantizedForPunctuationGeneration); + this.UpdatePunctuation(value.PartitionKey, this.lowWatermark.rawValue, this.lowWatermark.quantizedForPunctuationGeneration); // Retrieve current time for this partition, updating currentTime if necessary if (!this.currentTime.TryGetValue(value.PartitionKey, out long current)) @@ -4818,7 +4818,7 @@ private void Process(ref PartitionedStreamEvent value) else if (current < this.lowWatermark.rawValue) { current = this.lowWatermark.rawValue; - UpdateCurrentTime(value.PartitionKey, this.lowWatermark.rawValue); + this.UpdateCurrentTime(value.PartitionKey, this.lowWatermark.rawValue); } var outOfOrder = value.SyncTime < current; @@ -4826,7 +4826,7 @@ private void Process(ref PartitionedStreamEvent value) // check for out of order event if (value.IsPunctuation) { - OnPunctuation(value.CreatePunctuation(outOfOrder ? current : value.SyncTime)); + this.OnPunctuation(value.CreatePunctuation(outOfOrder ? current : value.SyncTime)); } else { @@ -4850,7 +4850,7 @@ private void Process(ref PartitionedStreamEvent value) key = Tuple.Create(value.SyncTime, value.Payload); if (!this.startEventInformation.TryGetValue(key, out q)) { - q = new ElasticCircularBuffer(); + q = []; this.startEventInformation.Add(key, q); var x = new AdjustInfo(current); q.Enqueue(ref x); @@ -4961,9 +4961,9 @@ private void Process(ref PartitionedStreamEvent value) // SyncTime is sufficiently high to generate a new punctuation, but first snap it to the nearest generationPeriod boundary var punctuationTimeQuantized = value.SyncTime.SnapToLeftBoundary((long)this.punctuationGenerationPeriod); #if DEBUG - Debug.Assert(punctuationTimeQuantized >= LastEventTime(value.PartitionKey), "Bug in punctuation quantization logic"); - #endif - OnPunctuation(value.CreatePunctuation(punctuationTimeQuantized)); + Debug.Assert(punctuationTimeQuantized >= this.LastEventTime(value.PartitionKey), "Bug in punctuation quantization logic"); +#endif + this.OnPunctuation(value.CreatePunctuation(punctuationTimeQuantized)); } } } @@ -4971,12 +4971,12 @@ private void Process(ref PartitionedStreamEvent value) this.currentBatch.Add(value.SyncTime, value.OtherTime, new PartitionKey(value.PartitionKey), value.Payload); if (this.currentBatch.Count == Config.DataBatchSize) { - if (this.flushPolicy == PartitionedFlushPolicy.FlushOnBatchBoundary) OnFlush(); - else FlushContents(); + if (this.flushPolicy == PartitionedFlushPolicy.FlushOnBatchBoundary) this.OnFlush(); + else this.FlushContents(); } } - UpdateCurrentTime(value.PartitionKey, value.SyncTime); + this.UpdateCurrentTime(value.PartitionKey, value.SyncTime); } [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -5009,7 +5009,7 @@ private void GenerateAndProcessLowWatermark(long syncTime) while ((!this.priorityQueueSorter.IsEmpty()) && this.priorityQueueSorter.Peek().SyncTime <= syncTime) { resultEvent = this.priorityQueueSorter.Dequeue(); - Process(ref resultEvent); + this.Process(ref resultEvent); } } else @@ -5029,7 +5029,7 @@ private void GenerateAndProcessLowWatermark(long syncTime) while ((streamEvents.Count > 0) && ((!recheck) || (streamEvents.PeekFirst().SyncTime <= syncTime))) { resultEvent = streamEvents.Dequeue(); - Process(ref resultEvent); + this.Process(ref resultEvent); } if (!recheck) this.impatienceSorter.Return(entry.key, streamEvents); } @@ -5040,7 +5040,7 @@ private void GenerateAndProcessLowWatermark(long syncTime) this.highWatermark = Math.Max(syncTime, this.highWatermark); if (this.lowWatermark.rawValue < syncTime) { - UpdateLowWatermark(syncTime); + this.UpdateLowWatermark(syncTime); // Gather keys whose high watermarks are before the new low watermark var expiredWatermarkKVPs = new List>>(); @@ -5085,11 +5085,11 @@ private void GenerateAndProcessLowWatermark(long syncTime) if (this.flushPolicy == PartitionedFlushPolicy.FlushOnLowWatermark || (this.flushPolicy == PartitionedFlushPolicy.FlushOnBatchBoundary && this.currentBatch.Count == Config.DataBatchSize)) { - OnFlush(); + this.OnFlush(); } else if (this.currentBatch.Count == Config.DataBatchSize) { - FlushContents(); + this.FlushContents(); } } @@ -5100,17 +5100,17 @@ protected override void UpdatePointers() if (this.highWatermarkToPartitionsMap.TryGetValue(kvp.Value, out HashSet set)) set.Add(kvp.Key); else - this.highWatermarkToPartitionsMap.Add(kvp.Value, new HashSet { kvp.Key }); + this.highWatermarkToPartitionsMap.Add(kvp.Value, [kvp.Key]); } } protected override void OnCompleted(long punctuationTime) { - GenerateAndProcessLowWatermark(punctuationTime); + this.GenerateAndProcessLowWatermark(punctuationTime); // Flush, but if we just flushed due to the punctuation generated above if (this.flushPolicy != PartitionedFlushPolicy.FlushOnLowWatermark) - OnFlush(); + this.OnFlush(); } } @@ -5160,7 +5160,7 @@ public override void OnNext(PartitionedStreamEvent value) if (value.IsLowWatermark) { - GenerateAndProcessLowWatermark(value.SyncTime); + this.GenerateAndProcessLowWatermark(value.SyncTime); return; } @@ -5173,7 +5173,7 @@ public override void OnNext(PartitionedStreamEvent value) { // SyncTime is sufficiently high to generate a new watermark, but first snap it to the nearest generationPeriod boundary var newLowWatermarkSnapped = newLowWatermark.SnapToLeftBoundary((long)this.lowWatermarkGenerationPeriod); - GenerateAndProcessLowWatermark(newLowWatermarkSnapped); + this.GenerateAndProcessLowWatermark(newLowWatermarkSnapped); } } @@ -5183,7 +5183,7 @@ public override void OnNext(PartitionedStreamEvent value) this.highWatermark = Math.Max(this.highWatermark, value.SyncTime); if (this.punctuationPolicyType == PeriodicPunctuationPolicyType.Time && !this.lastPunctuationTime.ContainsKey(value.PartitionKey)) - UpdatePunctuation(value.PartitionKey, this.lowWatermark.rawValue, this.lowWatermark.quantizedForPunctuationGeneration); + this.UpdatePunctuation(value.PartitionKey, this.lowWatermark.rawValue, this.lowWatermark.quantizedForPunctuationGeneration); // Retrieve current time for this partition, updating currentTime if necessary if (!this.currentTime.TryGetValue(value.PartitionKey, out long current)) @@ -5193,7 +5193,7 @@ public override void OnNext(PartitionedStreamEvent value) else if (current < this.lowWatermark.rawValue) { current = this.lowWatermark.rawValue; - UpdateCurrentTime(value.PartitionKey, this.lowWatermark.rawValue); + this.UpdateCurrentTime(value.PartitionKey, this.lowWatermark.rawValue); } var outOfOrder = value.SyncTime < current; @@ -5201,7 +5201,7 @@ public override void OnNext(PartitionedStreamEvent value) // check for out of order event if (value.IsPunctuation) { - OnPunctuation(value.CreatePunctuation(outOfOrder ? current : value.SyncTime)); + this.OnPunctuation(value.CreatePunctuation(outOfOrder ? current : value.SyncTime)); } else { @@ -5225,7 +5225,7 @@ public override void OnNext(PartitionedStreamEvent value) key = Tuple.Create(value.SyncTime, value.Payload); if (!this.startEventInformation.TryGetValue(key, out q)) { - q = new ElasticCircularBuffer(); + q = []; this.startEventInformation.Add(key, q); var x = new AdjustInfo(current); q.Enqueue(ref x); @@ -5336,9 +5336,9 @@ public override void OnNext(PartitionedStreamEvent value) // SyncTime is sufficiently high to generate a new punctuation, but first snap it to the nearest generationPeriod boundary var punctuationTimeQuantized = value.SyncTime.SnapToLeftBoundary((long)this.punctuationGenerationPeriod); #if DEBUG - Debug.Assert(punctuationTimeQuantized >= LastEventTime(value.PartitionKey), "Bug in punctuation quantization logic"); - #endif - OnPunctuation(value.CreatePunctuation(punctuationTimeQuantized)); + Debug.Assert(punctuationTimeQuantized >= this.LastEventTime(value.PartitionKey), "Bug in punctuation quantization logic"); +#endif + this.OnPunctuation(value.CreatePunctuation(punctuationTimeQuantized)); } } } @@ -5346,12 +5346,12 @@ public override void OnNext(PartitionedStreamEvent value) this.currentBatch.Add(value.SyncTime, value.OtherTime, new PartitionKey(value.PartitionKey), value.Payload); if (this.currentBatch.Count == Config.DataBatchSize) { - if (this.flushPolicy == PartitionedFlushPolicy.FlushOnBatchBoundary) OnFlush(); - else FlushContents(); + if (this.flushPolicy == PartitionedFlushPolicy.FlushOnBatchBoundary) this.OnFlush(); + else this.FlushContents(); } } - UpdateCurrentTime(value.PartitionKey, value.SyncTime); + this.UpdateCurrentTime(value.PartitionKey, value.SyncTime); } [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -5381,7 +5381,7 @@ private void GenerateAndProcessLowWatermark(long syncTime) this.highWatermark = Math.Max(syncTime, this.highWatermark); if (this.lowWatermark.rawValue < syncTime) { - UpdateLowWatermark(syncTime); + this.UpdateLowWatermark(syncTime); } // Add LowWatermark to batch @@ -5398,21 +5398,21 @@ private void GenerateAndProcessLowWatermark(long syncTime) if (this.flushPolicy == PartitionedFlushPolicy.FlushOnLowWatermark || (this.flushPolicy == PartitionedFlushPolicy.FlushOnBatchBoundary && this.currentBatch.Count == Config.DataBatchSize)) { - OnFlush(); + this.OnFlush(); } else if (this.currentBatch.Count == Config.DataBatchSize) { - FlushContents(); + this.FlushContents(); } } protected override void OnCompleted(long punctuationTime) { - GenerateAndProcessLowWatermark(punctuationTime); + this.GenerateAndProcessLowWatermark(punctuationTime); // Flush, but if we just flushed due to the punctuation generated above if (this.flushPolicy != PartitionedFlushPolicy.FlushOnLowWatermark) - OnFlush(); + this.OnFlush(); } } @@ -5450,7 +5450,7 @@ public FusedPartitionedStreamEventSubscription( { this.fuseModule = fuseModule; Expression>> statement = (s, e, p, k) => this.currentBatch.Add(s, e, k, p); - Expression flush = () => FlushContents(); + Expression flush = () => this.FlushContents(); Expression> test = () => this.currentBatch.Count == Config.DataBatchSize; var full = Expression.Lambda>>( Expression.Block( @@ -5477,7 +5477,7 @@ public override void OnNext(PartitionedStreamEvent value) if (value.IsLowWatermark) { - GenerateAndProcessLowWatermark(value.SyncTime); + this.GenerateAndProcessLowWatermark(value.SyncTime); return; } @@ -5490,7 +5490,7 @@ public override void OnNext(PartitionedStreamEvent value) { // SyncTime is sufficiently high to generate a new watermark, but first snap it to the nearest generationPeriod boundary var newLowWatermarkSnapped = newLowWatermark.SnapToLeftBoundary((long)this.lowWatermarkGenerationPeriod); - GenerateAndProcessLowWatermark(newLowWatermarkSnapped); + this.GenerateAndProcessLowWatermark(newLowWatermarkSnapped); } } @@ -5500,7 +5500,7 @@ public override void OnNext(PartitionedStreamEvent value) this.highWatermark = Math.Max(this.highWatermark, value.SyncTime); if (this.punctuationPolicyType == PeriodicPunctuationPolicyType.Time && !this.lastPunctuationTime.ContainsKey(value.PartitionKey)) - UpdatePunctuation(value.PartitionKey, this.lowWatermark.rawValue, this.lowWatermark.quantizedForPunctuationGeneration); + this.UpdatePunctuation(value.PartitionKey, this.lowWatermark.rawValue, this.lowWatermark.quantizedForPunctuationGeneration); // Retrieve current time for this partition, updating currentTime if necessary if (!this.currentTime.TryGetValue(value.PartitionKey, out long current)) @@ -5510,7 +5510,7 @@ public override void OnNext(PartitionedStreamEvent value) else if (current < this.lowWatermark.rawValue) { current = this.lowWatermark.rawValue; - UpdateCurrentTime(value.PartitionKey, this.lowWatermark.rawValue); + this.UpdateCurrentTime(value.PartitionKey, this.lowWatermark.rawValue); } var outOfOrder = value.SyncTime < current; @@ -5518,7 +5518,7 @@ public override void OnNext(PartitionedStreamEvent value) // check for out of order event if (value.IsPunctuation) { - OnPunctuation(value.CreatePunctuation(outOfOrder ? current : value.SyncTime)); + this.OnPunctuation(value.CreatePunctuation(outOfOrder ? current : value.SyncTime)); } else { @@ -5542,7 +5542,7 @@ public override void OnNext(PartitionedStreamEvent value) key = Tuple.Create(value.SyncTime, value.Payload); if (!this.startEventInformation.TryGetValue(key, out q)) { - q = new ElasticCircularBuffer(); + q = []; this.startEventInformation.Add(key, q); var x = new AdjustInfo(current); q.Enqueue(ref x); @@ -5653,9 +5653,9 @@ public override void OnNext(PartitionedStreamEvent value) // SyncTime is sufficiently high to generate a new punctuation, but first snap it to the nearest generationPeriod boundary var punctuationTimeQuantized = value.SyncTime.SnapToLeftBoundary((long)this.punctuationGenerationPeriod); #if DEBUG - Debug.Assert(punctuationTimeQuantized >= LastEventTime(value.PartitionKey), "Bug in punctuation quantization logic"); - #endif - OnPunctuation(value.CreatePunctuation(punctuationTimeQuantized)); + Debug.Assert(punctuationTimeQuantized >= this.LastEventTime(value.PartitionKey), "Bug in punctuation quantization logic"); +#endif + this.OnPunctuation(value.CreatePunctuation(punctuationTimeQuantized)); } } } @@ -5663,7 +5663,7 @@ public override void OnNext(PartitionedStreamEvent value) this.action(value.SyncTime, value.OtherTime, value.Payload, new PartitionKey(value.PartitionKey)); } - UpdateCurrentTime(value.PartitionKey, value.SyncTime); + this.UpdateCurrentTime(value.PartitionKey, value.SyncTime); } [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -5693,7 +5693,7 @@ private void GenerateAndProcessLowWatermark(long syncTime) this.highWatermark = Math.Max(syncTime, this.highWatermark); if (this.lowWatermark.rawValue < syncTime) { - UpdateLowWatermark(syncTime); + this.UpdateLowWatermark(syncTime); } // Add LowWatermark to batch @@ -5710,21 +5710,21 @@ private void GenerateAndProcessLowWatermark(long syncTime) if (this.flushPolicy == PartitionedFlushPolicy.FlushOnLowWatermark || (this.flushPolicy == PartitionedFlushPolicy.FlushOnBatchBoundary && this.currentBatch.Count == Config.DataBatchSize)) { - OnFlush(); + this.OnFlush(); } else if (this.currentBatch.Count == Config.DataBatchSize) { - FlushContents(); + this.FlushContents(); } } protected override void OnCompleted(long punctuationTime) { - GenerateAndProcessLowWatermark(punctuationTime); + this.GenerateAndProcessLowWatermark(punctuationTime); // Flush, but if we just flushed due to the punctuation generated above if (this.flushPolicy != PartitionedFlushPolicy.FlushOnLowWatermark) - OnFlush(); + this.OnFlush(); } } @@ -5761,7 +5761,7 @@ public DisorderedPartitionedStreamEventSubscription( diagnosticOutput) { this.fuseModule = fuseModule; - Expression>> statement = (s, e, p, k) => Action(s, e, p, k); + Expression>> statement = (s, e, p, k) => this.Action(s, e, p, k); var actionExp = fuseModule.Coalesce>(statement, true); this.action = actionExp.Compile(); } @@ -5792,7 +5792,7 @@ private void Action(long start, long end, TResult payload, PartitionKey ac if (value.IsLowWatermark) { - GenerateAndProcessLowWatermark(value.SyncTime); + this.GenerateAndProcessLowWatermark(value.SyncTime); return; } @@ -5805,7 +5805,7 @@ private void Action(long start, long end, TResult payload, PartitionKey ac { // SyncTime is sufficiently high to generate a new watermark, but first snap it to the nearest generationPeriod boundary var newLowWatermarkSnapped = newLowWatermark.SnapToLeftBoundary((long)this.lowWatermarkGenerationPeriod); - GenerateAndProcessLowWatermark(newLowWatermarkSnapped); + this.GenerateAndProcessLowWatermark(newLowWatermarkSnapped); } } @@ -5815,7 +5815,7 @@ private void Action(long start, long end, TResult payload, PartitionKey ac this.highWatermark = Math.Max(this.highWatermark, value.SyncTime); if (this.punctuationPolicyType == PeriodicPunctuationPolicyType.Time && !this.lastPunctuationTime.ContainsKey(value.PartitionKey)) - UpdatePunctuation(value.PartitionKey, this.lowWatermark.rawValue, this.lowWatermark.quantizedForPunctuationGeneration); + this.UpdatePunctuation(value.PartitionKey, this.lowWatermark.rawValue, this.lowWatermark.quantizedForPunctuationGeneration); // Retrieve current time for this partition, updating currentTime if necessary if (!this.currentTime.TryGetValue(value.PartitionKey, out long current)) @@ -5825,7 +5825,7 @@ private void Action(long start, long end, TResult payload, PartitionKey ac else if (current < this.lowWatermark.rawValue) { current = this.lowWatermark.rawValue; - UpdateCurrentTime(value.PartitionKey, this.lowWatermark.rawValue); + this.UpdateCurrentTime(value.PartitionKey, this.lowWatermark.rawValue); } var outOfOrder = value.SyncTime < current; @@ -5833,7 +5833,7 @@ private void Action(long start, long end, TResult payload, PartitionKey ac // check for out of order event if (value.IsPunctuation) { - OnPunctuation(value.CreatePunctuation(outOfOrder ? current : value.SyncTime)); + this.OnPunctuation(value.CreatePunctuation(outOfOrder ? current : value.SyncTime)); } else { @@ -5857,7 +5857,7 @@ private void Action(long start, long end, TResult payload, PartitionKey ac key = Tuple.Create(value.SyncTime, value.Payload); if (!this.startEventInformation.TryGetValue(key, out q)) { - q = new ElasticCircularBuffer(); + q = []; this.startEventInformation.Add(key, q); var x = new AdjustInfo(current); q.Enqueue(ref x); @@ -5968,9 +5968,9 @@ private void Action(long start, long end, TResult payload, PartitionKey ac // SyncTime is sufficiently high to generate a new punctuation, but first snap it to the nearest generationPeriod boundary var punctuationTimeQuantized = value.SyncTime.SnapToLeftBoundary((long)this.punctuationGenerationPeriod); #if DEBUG - Debug.Assert(punctuationTimeQuantized >= LastEventTime(value.PartitionKey), "Bug in punctuation quantization logic"); - #endif - OnPunctuation(value.CreatePunctuation(punctuationTimeQuantized)); + Debug.Assert(punctuationTimeQuantized >= this.LastEventTime(value.PartitionKey), "Bug in punctuation quantization logic"); +#endif + this.OnPunctuation(value.CreatePunctuation(punctuationTimeQuantized)); } } } @@ -5978,12 +5978,12 @@ private void Action(long start, long end, TResult payload, PartitionKey ac this.currentBatch.Add(value.SyncTime, value.OtherTime, new PartitionKey(value.PartitionKey), value.Payload); if (this.currentBatch.Count == Config.DataBatchSize) { - if (this.flushPolicy == PartitionedFlushPolicy.FlushOnBatchBoundary) OnFlush(); - else FlushContents(); + if (this.flushPolicy == PartitionedFlushPolicy.FlushOnBatchBoundary) this.OnFlush(); + else this.FlushContents(); } } - UpdateCurrentTime(value.PartitionKey, value.SyncTime); + this.UpdateCurrentTime(value.PartitionKey, value.SyncTime); } [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -6013,7 +6013,7 @@ private void GenerateAndProcessLowWatermark(long syncTime) this.highWatermark = Math.Max(syncTime, this.highWatermark); if (this.lowWatermark.rawValue < syncTime) { - UpdateLowWatermark(syncTime); + this.UpdateLowWatermark(syncTime); } // Add LowWatermark to batch @@ -6030,21 +6030,21 @@ private void GenerateAndProcessLowWatermark(long syncTime) if (this.flushPolicy == PartitionedFlushPolicy.FlushOnLowWatermark || (this.flushPolicy == PartitionedFlushPolicy.FlushOnBatchBoundary && this.currentBatch.Count == Config.DataBatchSize)) { - OnFlush(); + this.OnFlush(); } else if (this.currentBatch.Count == Config.DataBatchSize) { - FlushContents(); + this.FlushContents(); } } protected override void OnCompleted(long punctuationTime) { - GenerateAndProcessLowWatermark(punctuationTime); + this.GenerateAndProcessLowWatermark(punctuationTime); // Flush, but if we just flushed due to the punctuation generated above if (this.flushPolicy != PartitionedFlushPolicy.FlushOnLowWatermark) - OnFlush(); + this.OnFlush(); } } @@ -6113,7 +6113,7 @@ public override void OnNext(TPayload inputValue) if (value.IsLowWatermark) { - GenerateAndProcessLowWatermark(value.SyncTime); + this.GenerateAndProcessLowWatermark(value.SyncTime); return; } @@ -6126,7 +6126,7 @@ public override void OnNext(TPayload inputValue) { // SyncTime is sufficiently high to generate a new watermark, but first snap it to the nearest generationPeriod boundary var newLowWatermarkSnapped = newLowWatermark.SnapToLeftBoundary((long)this.lowWatermarkGenerationPeriod); - GenerateAndProcessLowWatermark(newLowWatermarkSnapped); + this.GenerateAndProcessLowWatermark(newLowWatermarkSnapped); } } @@ -6140,14 +6140,14 @@ public override void OnNext(TPayload inputValue) this.partitionHighWatermarks.Add(value.PartitionKey, this.lowWatermark.rawValue); if (this.highWatermarkToPartitionsMap.TryGetValue(this.lowWatermark.rawValue, out HashSet keySet)) keySet.Add(value.PartitionKey); - else this.highWatermarkToPartitionsMap.Add(this.lowWatermark.rawValue, new HashSet { value.PartitionKey }); + else this.highWatermarkToPartitionsMap.Add(this.lowWatermark.rawValue, [value.PartitionKey]); } long moveTo = moveFrom; // Events at the reorder boundary or earlier - are handled using default processing policies if (value.SyncTime <= moveFrom) { - Process(ref value); + this.Process(ref value); return; } @@ -6161,7 +6161,7 @@ public override void OnNext(TPayload inputValue) else oldSet.Remove(value.PartitionKey); if (this.highWatermarkToPartitionsMap.TryGetValue(value.SyncTime, out HashSet set)) set.Add(value.PartitionKey); - else this.highWatermarkToPartitionsMap.Add(value.SyncTime, new HashSet { value.PartitionKey }); + else this.highWatermarkToPartitionsMap.Add(value.SyncTime, [value.PartitionKey]); moveTo = value.SyncTime - this.reorderLatency; if (moveTo < StreamEvent.MinSyncTime) moveTo = StreamEvent.MinSyncTime; @@ -6177,7 +6177,7 @@ public override void OnNext(TPayload inputValue) while ((!this.priorityQueueSorter.IsEmpty()) && this.priorityQueueSorter.Peek().SyncTime <= moveTo) { resultEvent = this.priorityQueueSorter.Dequeue(); - Process(ref resultEvent); + this.Process(ref resultEvent); } } else @@ -6191,7 +6191,7 @@ public override void OnNext(TPayload inputValue) while ((streamEvents.Count > 0) && ((!recheck) || (streamEvents.PeekFirst().SyncTime <= moveTo))) { resultEvent = streamEvents.Dequeue(); - Process(ref resultEvent); + this.Process(ref resultEvent); } } @@ -6202,7 +6202,7 @@ public override void OnNext(TPayload inputValue) if (value.SyncTime == moveTo) { - Process(ref value); + this.Process(ref value); return; } @@ -6210,7 +6210,7 @@ public override void OnNext(TPayload inputValue) if (this.priorityQueueSorter != null) this.priorityQueueSorter.Enqueue(value); else this.impatienceSorter.Enqueue(ref value); - UpdateCurrentTime(value.PartitionKey, moveTo, fromEvent: false); + this.UpdateCurrentTime(value.PartitionKey, moveTo, fromEvent: false); } [System.Diagnostics.CodeAnalysis.SuppressMessage( @@ -6223,7 +6223,7 @@ private void Process(ref PartitionedStreamEvent value) this.highWatermark = Math.Max(this.highWatermark, value.SyncTime); if (this.punctuationPolicyType == PeriodicPunctuationPolicyType.Time && !this.lastPunctuationTime.ContainsKey(value.PartitionKey)) - UpdatePunctuation(value.PartitionKey, this.lowWatermark.rawValue, this.lowWatermark.quantizedForPunctuationGeneration); + this.UpdatePunctuation(value.PartitionKey, this.lowWatermark.rawValue, this.lowWatermark.quantizedForPunctuationGeneration); // Retrieve current time for this partition, updating currentTime if necessary if (!this.currentTime.TryGetValue(value.PartitionKey, out long current)) @@ -6233,7 +6233,7 @@ private void Process(ref PartitionedStreamEvent value) else if (current < this.lowWatermark.rawValue) { current = this.lowWatermark.rawValue; - UpdateCurrentTime(value.PartitionKey, this.lowWatermark.rawValue); + this.UpdateCurrentTime(value.PartitionKey, this.lowWatermark.rawValue); } var outOfOrder = value.SyncTime < current; @@ -6281,9 +6281,9 @@ private void Process(ref PartitionedStreamEvent value) // SyncTime is sufficiently high to generate a new punctuation, but first snap it to the nearest generationPeriod boundary var punctuationTimeQuantized = value.SyncTime.SnapToLeftBoundary((long)this.punctuationGenerationPeriod); #if DEBUG - Debug.Assert(punctuationTimeQuantized >= LastEventTime(value.PartitionKey), "Bug in punctuation quantization logic"); + Debug.Assert(punctuationTimeQuantized >= this.LastEventTime(value.PartitionKey), "Bug in punctuation quantization logic"); #endif - OnPunctuation(value.CreatePunctuation(punctuationTimeQuantized)); + this.OnPunctuation(value.CreatePunctuation(punctuationTimeQuantized)); } } } @@ -6291,11 +6291,11 @@ private void Process(ref PartitionedStreamEvent value) this.currentBatch.Add(value.SyncTime, value.OtherTime, new PartitionKey(value.PartitionKey), value.Payload); if (this.currentBatch.Count == Config.DataBatchSize) { - if (this.flushPolicy == PartitionedFlushPolicy.FlushOnBatchBoundary) OnFlush(); - else FlushContents(); + if (this.flushPolicy == PartitionedFlushPolicy.FlushOnBatchBoundary) this.OnFlush(); + else this.FlushContents(); } - UpdateCurrentTime(value.PartitionKey, value.SyncTime); + this.UpdateCurrentTime(value.PartitionKey, value.SyncTime); } [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -6328,7 +6328,7 @@ private void GenerateAndProcessLowWatermark(long syncTime) while ((!this.priorityQueueSorter.IsEmpty()) && this.priorityQueueSorter.Peek().SyncTime <= syncTime) { resultEvent = this.priorityQueueSorter.Dequeue(); - Process(ref resultEvent); + this.Process(ref resultEvent); } } else @@ -6348,7 +6348,7 @@ private void GenerateAndProcessLowWatermark(long syncTime) while ((streamEvents.Count > 0) && ((!recheck) || (streamEvents.PeekFirst().SyncTime <= syncTime))) { resultEvent = streamEvents.Dequeue(); - Process(ref resultEvent); + this.Process(ref resultEvent); } if (!recheck) this.impatienceSorter.Return(entry.key, streamEvents); } @@ -6359,7 +6359,7 @@ private void GenerateAndProcessLowWatermark(long syncTime) this.highWatermark = Math.Max(syncTime, this.highWatermark); if (this.lowWatermark.rawValue < syncTime) { - UpdateLowWatermark(syncTime); + this.UpdateLowWatermark(syncTime); // Gather keys whose high watermarks are before the new low watermark var expiredWatermarkKVPs = new List>>(); @@ -6404,11 +6404,11 @@ private void GenerateAndProcessLowWatermark(long syncTime) if (this.flushPolicy == PartitionedFlushPolicy.FlushOnLowWatermark || (this.flushPolicy == PartitionedFlushPolicy.FlushOnBatchBoundary && this.currentBatch.Count == Config.DataBatchSize)) { - OnFlush(); + this.OnFlush(); } else if (this.currentBatch.Count == Config.DataBatchSize) { - FlushContents(); + this.FlushContents(); } } @@ -6419,17 +6419,17 @@ protected override void UpdatePointers() if (this.highWatermarkToPartitionsMap.TryGetValue(kvp.Value, out HashSet set)) set.Add(kvp.Key); else - this.highWatermarkToPartitionsMap.Add(kvp.Value, new HashSet { kvp.Key }); + this.highWatermarkToPartitionsMap.Add(kvp.Value, [kvp.Key]); } } protected override void OnCompleted(long punctuationTime) { - GenerateAndProcessLowWatermark(punctuationTime); + this.GenerateAndProcessLowWatermark(punctuationTime); // Flush, but if we just flushed due to the punctuation generated above if (this.flushPolicy != PartitionedFlushPolicy.FlushOnLowWatermark) - OnFlush(); + this.OnFlush(); } } @@ -6479,7 +6479,7 @@ public FusedPartitionedIntervalSubscriptionWithLatency( { this.fuseModule = fuseModule; Expression>> statement = (s, e, p, k) => this.currentBatch.Add(s, e, k, p); - Expression flush = () => FlushContents(); + Expression flush = () => this.FlushContents(); Expression> test = () => this.currentBatch.Count == Config.DataBatchSize; var full = Expression.Lambda>>( Expression.Block( @@ -6513,7 +6513,7 @@ public override void OnNext(TPayload inputValue) if (value.IsLowWatermark) { - GenerateAndProcessLowWatermark(value.SyncTime); + this.GenerateAndProcessLowWatermark(value.SyncTime); return; } @@ -6526,7 +6526,7 @@ public override void OnNext(TPayload inputValue) { // SyncTime is sufficiently high to generate a new watermark, but first snap it to the nearest generationPeriod boundary var newLowWatermarkSnapped = newLowWatermark.SnapToLeftBoundary((long)this.lowWatermarkGenerationPeriod); - GenerateAndProcessLowWatermark(newLowWatermarkSnapped); + this.GenerateAndProcessLowWatermark(newLowWatermarkSnapped); } } @@ -6540,14 +6540,14 @@ public override void OnNext(TPayload inputValue) this.partitionHighWatermarks.Add(value.PartitionKey, this.lowWatermark.rawValue); if (this.highWatermarkToPartitionsMap.TryGetValue(this.lowWatermark.rawValue, out HashSet keySet)) keySet.Add(value.PartitionKey); - else this.highWatermarkToPartitionsMap.Add(this.lowWatermark.rawValue, new HashSet { value.PartitionKey }); + else this.highWatermarkToPartitionsMap.Add(this.lowWatermark.rawValue, [value.PartitionKey]); } long moveTo = moveFrom; // Events at the reorder boundary or earlier - are handled using default processing policies if (value.SyncTime <= moveFrom) { - Process(ref value); + this.Process(ref value); return; } @@ -6561,7 +6561,7 @@ public override void OnNext(TPayload inputValue) else oldSet.Remove(value.PartitionKey); if (this.highWatermarkToPartitionsMap.TryGetValue(value.SyncTime, out HashSet set)) set.Add(value.PartitionKey); - else this.highWatermarkToPartitionsMap.Add(value.SyncTime, new HashSet { value.PartitionKey }); + else this.highWatermarkToPartitionsMap.Add(value.SyncTime, [value.PartitionKey]); moveTo = value.SyncTime - this.reorderLatency; if (moveTo < StreamEvent.MinSyncTime) moveTo = StreamEvent.MinSyncTime; @@ -6577,7 +6577,7 @@ public override void OnNext(TPayload inputValue) while ((!this.priorityQueueSorter.IsEmpty()) && this.priorityQueueSorter.Peek().SyncTime <= moveTo) { resultEvent = this.priorityQueueSorter.Dequeue(); - Process(ref resultEvent); + this.Process(ref resultEvent); } } else @@ -6591,7 +6591,7 @@ public override void OnNext(TPayload inputValue) while ((streamEvents.Count > 0) && ((!recheck) || (streamEvents.PeekFirst().SyncTime <= moveTo))) { resultEvent = streamEvents.Dequeue(); - Process(ref resultEvent); + this.Process(ref resultEvent); } } @@ -6602,7 +6602,7 @@ public override void OnNext(TPayload inputValue) if (value.SyncTime == moveTo) { - Process(ref value); + this.Process(ref value); return; } @@ -6610,7 +6610,7 @@ public override void OnNext(TPayload inputValue) if (this.priorityQueueSorter != null) this.priorityQueueSorter.Enqueue(value); else this.impatienceSorter.Enqueue(ref value); - UpdateCurrentTime(value.PartitionKey, moveTo, fromEvent: false); + this.UpdateCurrentTime(value.PartitionKey, moveTo, fromEvent: false); } [System.Diagnostics.CodeAnalysis.SuppressMessage( @@ -6623,7 +6623,7 @@ private void Process(ref PartitionedStreamEvent value) this.highWatermark = Math.Max(this.highWatermark, value.SyncTime); if (this.punctuationPolicyType == PeriodicPunctuationPolicyType.Time && !this.lastPunctuationTime.ContainsKey(value.PartitionKey)) - UpdatePunctuation(value.PartitionKey, this.lowWatermark.rawValue, this.lowWatermark.quantizedForPunctuationGeneration); + this.UpdatePunctuation(value.PartitionKey, this.lowWatermark.rawValue, this.lowWatermark.quantizedForPunctuationGeneration); // Retrieve current time for this partition, updating currentTime if necessary if (!this.currentTime.TryGetValue(value.PartitionKey, out long current)) @@ -6633,7 +6633,7 @@ private void Process(ref PartitionedStreamEvent value) else if (current < this.lowWatermark.rawValue) { current = this.lowWatermark.rawValue; - UpdateCurrentTime(value.PartitionKey, this.lowWatermark.rawValue); + this.UpdateCurrentTime(value.PartitionKey, this.lowWatermark.rawValue); } var outOfOrder = value.SyncTime < current; @@ -6681,16 +6681,16 @@ private void Process(ref PartitionedStreamEvent value) // SyncTime is sufficiently high to generate a new punctuation, but first snap it to the nearest generationPeriod boundary var punctuationTimeQuantized = value.SyncTime.SnapToLeftBoundary((long)this.punctuationGenerationPeriod); #if DEBUG - Debug.Assert(punctuationTimeQuantized >= LastEventTime(value.PartitionKey), "Bug in punctuation quantization logic"); + Debug.Assert(punctuationTimeQuantized >= this.LastEventTime(value.PartitionKey), "Bug in punctuation quantization logic"); #endif - OnPunctuation(value.CreatePunctuation(punctuationTimeQuantized)); + this.OnPunctuation(value.CreatePunctuation(punctuationTimeQuantized)); } } } this.action(value.SyncTime, value.OtherTime, value.Payload, new PartitionKey(value.PartitionKey)); - UpdateCurrentTime(value.PartitionKey, value.SyncTime); + this.UpdateCurrentTime(value.PartitionKey, value.SyncTime); } [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -6723,7 +6723,7 @@ private void GenerateAndProcessLowWatermark(long syncTime) while ((!this.priorityQueueSorter.IsEmpty()) && this.priorityQueueSorter.Peek().SyncTime <= syncTime) { resultEvent = this.priorityQueueSorter.Dequeue(); - Process(ref resultEvent); + this.Process(ref resultEvent); } } else @@ -6743,7 +6743,7 @@ private void GenerateAndProcessLowWatermark(long syncTime) while ((streamEvents.Count > 0) && ((!recheck) || (streamEvents.PeekFirst().SyncTime <= syncTime))) { resultEvent = streamEvents.Dequeue(); - Process(ref resultEvent); + this.Process(ref resultEvent); } if (!recheck) this.impatienceSorter.Return(entry.key, streamEvents); } @@ -6754,7 +6754,7 @@ private void GenerateAndProcessLowWatermark(long syncTime) this.highWatermark = Math.Max(syncTime, this.highWatermark); if (this.lowWatermark.rawValue < syncTime) { - UpdateLowWatermark(syncTime); + this.UpdateLowWatermark(syncTime); // Gather keys whose high watermarks are before the new low watermark var expiredWatermarkKVPs = new List>>(); @@ -6799,11 +6799,11 @@ private void GenerateAndProcessLowWatermark(long syncTime) if (this.flushPolicy == PartitionedFlushPolicy.FlushOnLowWatermark || (this.flushPolicy == PartitionedFlushPolicy.FlushOnBatchBoundary && this.currentBatch.Count == Config.DataBatchSize)) { - OnFlush(); + this.OnFlush(); } else if (this.currentBatch.Count == Config.DataBatchSize) { - FlushContents(); + this.FlushContents(); } } @@ -6814,17 +6814,17 @@ protected override void UpdatePointers() if (this.highWatermarkToPartitionsMap.TryGetValue(kvp.Value, out HashSet set)) set.Add(kvp.Key); else - this.highWatermarkToPartitionsMap.Add(kvp.Value, new HashSet { kvp.Key }); + this.highWatermarkToPartitionsMap.Add(kvp.Value, [kvp.Key]); } } protected override void OnCompleted(long punctuationTime) { - GenerateAndProcessLowWatermark(punctuationTime); + this.GenerateAndProcessLowWatermark(punctuationTime); // Flush, but if we just flushed due to the punctuation generated above if (this.flushPolicy != PartitionedFlushPolicy.FlushOnLowWatermark) - OnFlush(); + this.OnFlush(); } } @@ -6873,7 +6873,7 @@ public DisorderedPartitionedIntervalSubscriptionWithLatency( diagnosticOutput) { this.fuseModule = fuseModule; - Expression>> statement = (s, e, p, k) => Action(s, e, p, k); + Expression>> statement = (s, e, p, k) => this.Action(s, e, p, k); var actionExp = fuseModule.Coalesce>(statement); this.action = actionExp.Compile(); this.partitionExtractor = partitionExtractor; @@ -6910,7 +6910,7 @@ private void Action(long start, long end, TResult payload, PartitionKey ac if (value.IsLowWatermark) { - GenerateAndProcessLowWatermark(value.SyncTime); + this.GenerateAndProcessLowWatermark(value.SyncTime); return; } @@ -6923,7 +6923,7 @@ private void Action(long start, long end, TResult payload, PartitionKey ac { // SyncTime is sufficiently high to generate a new watermark, but first snap it to the nearest generationPeriod boundary var newLowWatermarkSnapped = newLowWatermark.SnapToLeftBoundary((long)this.lowWatermarkGenerationPeriod); - GenerateAndProcessLowWatermark(newLowWatermarkSnapped); + this.GenerateAndProcessLowWatermark(newLowWatermarkSnapped); } } @@ -6937,14 +6937,14 @@ private void Action(long start, long end, TResult payload, PartitionKey ac this.partitionHighWatermarks.Add(value.PartitionKey, this.lowWatermark.rawValue); if (this.highWatermarkToPartitionsMap.TryGetValue(this.lowWatermark.rawValue, out HashSet keySet)) keySet.Add(value.PartitionKey); - else this.highWatermarkToPartitionsMap.Add(this.lowWatermark.rawValue, new HashSet { value.PartitionKey }); + else this.highWatermarkToPartitionsMap.Add(this.lowWatermark.rawValue, [value.PartitionKey]); } long moveTo = moveFrom; // Events at the reorder boundary or earlier - are handled using default processing policies if (value.SyncTime <= moveFrom) { - Process(ref value); + this.Process(ref value); return; } @@ -6958,7 +6958,7 @@ private void Action(long start, long end, TResult payload, PartitionKey ac else oldSet.Remove(value.PartitionKey); if (this.highWatermarkToPartitionsMap.TryGetValue(value.SyncTime, out HashSet set)) set.Add(value.PartitionKey); - else this.highWatermarkToPartitionsMap.Add(value.SyncTime, new HashSet { value.PartitionKey }); + else this.highWatermarkToPartitionsMap.Add(value.SyncTime, [value.PartitionKey]); moveTo = value.SyncTime - this.reorderLatency; if (moveTo < StreamEvent.MinSyncTime) moveTo = StreamEvent.MinSyncTime; @@ -6974,7 +6974,7 @@ private void Action(long start, long end, TResult payload, PartitionKey ac while ((!this.priorityQueueSorter.IsEmpty()) && this.priorityQueueSorter.Peek().SyncTime <= moveTo) { resultEvent = this.priorityQueueSorter.Dequeue(); - Process(ref resultEvent); + this.Process(ref resultEvent); } } else @@ -6988,7 +6988,7 @@ private void Action(long start, long end, TResult payload, PartitionKey ac while ((streamEvents.Count > 0) && ((!recheck) || (streamEvents.PeekFirst().SyncTime <= moveTo))) { resultEvent = streamEvents.Dequeue(); - Process(ref resultEvent); + this.Process(ref resultEvent); } } @@ -6999,7 +6999,7 @@ private void Action(long start, long end, TResult payload, PartitionKey ac if (value.SyncTime == moveTo) { - Process(ref value); + this.Process(ref value); return; } @@ -7007,7 +7007,7 @@ private void Action(long start, long end, TResult payload, PartitionKey ac if (this.priorityQueueSorter != null) this.priorityQueueSorter.Enqueue(value); else this.impatienceSorter.Enqueue(ref value); - UpdateCurrentTime(value.PartitionKey, moveTo, fromEvent: false); + this.UpdateCurrentTime(value.PartitionKey, moveTo, fromEvent: false); } [System.Diagnostics.CodeAnalysis.SuppressMessage( @@ -7020,7 +7020,7 @@ private void Process(ref PartitionedStreamEvent value) this.highWatermark = Math.Max(this.highWatermark, value.SyncTime); if (this.punctuationPolicyType == PeriodicPunctuationPolicyType.Time && !this.lastPunctuationTime.ContainsKey(value.PartitionKey)) - UpdatePunctuation(value.PartitionKey, this.lowWatermark.rawValue, this.lowWatermark.quantizedForPunctuationGeneration); + this.UpdatePunctuation(value.PartitionKey, this.lowWatermark.rawValue, this.lowWatermark.quantizedForPunctuationGeneration); // Retrieve current time for this partition, updating currentTime if necessary if (!this.currentTime.TryGetValue(value.PartitionKey, out long current)) @@ -7030,7 +7030,7 @@ private void Process(ref PartitionedStreamEvent value) else if (current < this.lowWatermark.rawValue) { current = this.lowWatermark.rawValue; - UpdateCurrentTime(value.PartitionKey, this.lowWatermark.rawValue); + this.UpdateCurrentTime(value.PartitionKey, this.lowWatermark.rawValue); } var outOfOrder = value.SyncTime < current; @@ -7078,9 +7078,9 @@ private void Process(ref PartitionedStreamEvent value) // SyncTime is sufficiently high to generate a new punctuation, but first snap it to the nearest generationPeriod boundary var punctuationTimeQuantized = value.SyncTime.SnapToLeftBoundary((long)this.punctuationGenerationPeriod); #if DEBUG - Debug.Assert(punctuationTimeQuantized >= LastEventTime(value.PartitionKey), "Bug in punctuation quantization logic"); + Debug.Assert(punctuationTimeQuantized >= this.LastEventTime(value.PartitionKey), "Bug in punctuation quantization logic"); #endif - OnPunctuation(value.CreatePunctuation(punctuationTimeQuantized)); + this.OnPunctuation(value.CreatePunctuation(punctuationTimeQuantized)); } } } @@ -7088,11 +7088,11 @@ private void Process(ref PartitionedStreamEvent value) this.currentBatch.Add(value.SyncTime, value.OtherTime, new PartitionKey(value.PartitionKey), value.Payload); if (this.currentBatch.Count == Config.DataBatchSize) { - if (this.flushPolicy == PartitionedFlushPolicy.FlushOnBatchBoundary) OnFlush(); - else FlushContents(); + if (this.flushPolicy == PartitionedFlushPolicy.FlushOnBatchBoundary) this.OnFlush(); + else this.FlushContents(); } - UpdateCurrentTime(value.PartitionKey, value.SyncTime); + this.UpdateCurrentTime(value.PartitionKey, value.SyncTime); } [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -7125,7 +7125,7 @@ private void GenerateAndProcessLowWatermark(long syncTime) while ((!this.priorityQueueSorter.IsEmpty()) && this.priorityQueueSorter.Peek().SyncTime <= syncTime) { resultEvent = this.priorityQueueSorter.Dequeue(); - Process(ref resultEvent); + this.Process(ref resultEvent); } } else @@ -7145,7 +7145,7 @@ private void GenerateAndProcessLowWatermark(long syncTime) while ((streamEvents.Count > 0) && ((!recheck) || (streamEvents.PeekFirst().SyncTime <= syncTime))) { resultEvent = streamEvents.Dequeue(); - Process(ref resultEvent); + this.Process(ref resultEvent); } if (!recheck) this.impatienceSorter.Return(entry.key, streamEvents); } @@ -7156,7 +7156,7 @@ private void GenerateAndProcessLowWatermark(long syncTime) this.highWatermark = Math.Max(syncTime, this.highWatermark); if (this.lowWatermark.rawValue < syncTime) { - UpdateLowWatermark(syncTime); + this.UpdateLowWatermark(syncTime); // Gather keys whose high watermarks are before the new low watermark var expiredWatermarkKVPs = new List>>(); @@ -7201,11 +7201,11 @@ private void GenerateAndProcessLowWatermark(long syncTime) if (this.flushPolicy == PartitionedFlushPolicy.FlushOnLowWatermark || (this.flushPolicy == PartitionedFlushPolicy.FlushOnBatchBoundary && this.currentBatch.Count == Config.DataBatchSize)) { - OnFlush(); + this.OnFlush(); } else if (this.currentBatch.Count == Config.DataBatchSize) { - FlushContents(); + this.FlushContents(); } } @@ -7216,17 +7216,17 @@ protected override void UpdatePointers() if (this.highWatermarkToPartitionsMap.TryGetValue(kvp.Value, out HashSet set)) set.Add(kvp.Key); else - this.highWatermarkToPartitionsMap.Add(kvp.Value, new HashSet { kvp.Key }); + this.highWatermarkToPartitionsMap.Add(kvp.Value, [kvp.Key]); } } protected override void OnCompleted(long punctuationTime) { - GenerateAndProcessLowWatermark(punctuationTime); + this.GenerateAndProcessLowWatermark(punctuationTime); // Flush, but if we just flushed due to the punctuation generated above if (this.flushPolicy != PartitionedFlushPolicy.FlushOnLowWatermark) - OnFlush(); + this.OnFlush(); } } @@ -7295,7 +7295,7 @@ public override void OnNext(TPayload inputValue) if (value.IsLowWatermark) { - GenerateAndProcessLowWatermark(value.SyncTime); + this.GenerateAndProcessLowWatermark(value.SyncTime); return; } @@ -7308,7 +7308,7 @@ public override void OnNext(TPayload inputValue) { // SyncTime is sufficiently high to generate a new watermark, but first snap it to the nearest generationPeriod boundary var newLowWatermarkSnapped = newLowWatermark.SnapToLeftBoundary((long)this.lowWatermarkGenerationPeriod); - GenerateAndProcessLowWatermark(newLowWatermarkSnapped); + this.GenerateAndProcessLowWatermark(newLowWatermarkSnapped); } } @@ -7316,7 +7316,7 @@ public override void OnNext(TPayload inputValue) this.highWatermark = Math.Max(this.highWatermark, value.SyncTime); if (this.punctuationPolicyType == PeriodicPunctuationPolicyType.Time && !this.lastPunctuationTime.ContainsKey(value.PartitionKey)) - UpdatePunctuation(value.PartitionKey, this.lowWatermark.rawValue, this.lowWatermark.quantizedForPunctuationGeneration); + this.UpdatePunctuation(value.PartitionKey, this.lowWatermark.rawValue, this.lowWatermark.quantizedForPunctuationGeneration); // Retrieve current time for this partition, updating currentTime if necessary if (!this.currentTime.TryGetValue(value.PartitionKey, out long current)) @@ -7326,7 +7326,7 @@ public override void OnNext(TPayload inputValue) else if (current < this.lowWatermark.rawValue) { current = this.lowWatermark.rawValue; - UpdateCurrentTime(value.PartitionKey, this.lowWatermark.rawValue); + this.UpdateCurrentTime(value.PartitionKey, this.lowWatermark.rawValue); } var outOfOrder = value.SyncTime < current; @@ -7374,9 +7374,9 @@ public override void OnNext(TPayload inputValue) // SyncTime is sufficiently high to generate a new punctuation, but first snap it to the nearest generationPeriod boundary var punctuationTimeQuantized = value.SyncTime.SnapToLeftBoundary((long)this.punctuationGenerationPeriod); #if DEBUG - Debug.Assert(punctuationTimeQuantized >= LastEventTime(value.PartitionKey), "Bug in punctuation quantization logic"); + Debug.Assert(punctuationTimeQuantized >= this.LastEventTime(value.PartitionKey), "Bug in punctuation quantization logic"); #endif - OnPunctuation(value.CreatePunctuation(punctuationTimeQuantized)); + this.OnPunctuation(value.CreatePunctuation(punctuationTimeQuantized)); } } } @@ -7384,11 +7384,11 @@ public override void OnNext(TPayload inputValue) this.currentBatch.Add(value.SyncTime, value.OtherTime, new PartitionKey(value.PartitionKey), value.Payload); if (this.currentBatch.Count == Config.DataBatchSize) { - if (this.flushPolicy == PartitionedFlushPolicy.FlushOnBatchBoundary) OnFlush(); - else FlushContents(); + if (this.flushPolicy == PartitionedFlushPolicy.FlushOnBatchBoundary) this.OnFlush(); + else this.FlushContents(); } - UpdateCurrentTime(value.PartitionKey, value.SyncTime); + this.UpdateCurrentTime(value.PartitionKey, value.SyncTime); } [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -7418,7 +7418,7 @@ private void GenerateAndProcessLowWatermark(long syncTime) this.highWatermark = Math.Max(syncTime, this.highWatermark); if (this.lowWatermark.rawValue < syncTime) { - UpdateLowWatermark(syncTime); + this.UpdateLowWatermark(syncTime); } // Add LowWatermark to batch @@ -7435,21 +7435,21 @@ private void GenerateAndProcessLowWatermark(long syncTime) if (this.flushPolicy == PartitionedFlushPolicy.FlushOnLowWatermark || (this.flushPolicy == PartitionedFlushPolicy.FlushOnBatchBoundary && this.currentBatch.Count == Config.DataBatchSize)) { - OnFlush(); + this.OnFlush(); } else if (this.currentBatch.Count == Config.DataBatchSize) { - FlushContents(); + this.FlushContents(); } } protected override void OnCompleted(long punctuationTime) { - GenerateAndProcessLowWatermark(punctuationTime); + this.GenerateAndProcessLowWatermark(punctuationTime); // Flush, but if we just flushed due to the punctuation generated above if (this.flushPolicy != PartitionedFlushPolicy.FlushOnLowWatermark) - OnFlush(); + this.OnFlush(); } } @@ -7499,7 +7499,7 @@ public FusedPartitionedIntervalSubscription( { this.fuseModule = fuseModule; Expression>> statement = (s, e, p, k) => this.currentBatch.Add(s, e, k, p); - Expression flush = () => FlushContents(); + Expression flush = () => this.FlushContents(); Expression> test = () => this.currentBatch.Count == Config.DataBatchSize; var full = Expression.Lambda>>( Expression.Block( @@ -7533,7 +7533,7 @@ public override void OnNext(TPayload inputValue) if (value.IsLowWatermark) { - GenerateAndProcessLowWatermark(value.SyncTime); + this.GenerateAndProcessLowWatermark(value.SyncTime); return; } @@ -7546,7 +7546,7 @@ public override void OnNext(TPayload inputValue) { // SyncTime is sufficiently high to generate a new watermark, but first snap it to the nearest generationPeriod boundary var newLowWatermarkSnapped = newLowWatermark.SnapToLeftBoundary((long)this.lowWatermarkGenerationPeriod); - GenerateAndProcessLowWatermark(newLowWatermarkSnapped); + this.GenerateAndProcessLowWatermark(newLowWatermarkSnapped); } } @@ -7554,7 +7554,7 @@ public override void OnNext(TPayload inputValue) this.highWatermark = Math.Max(this.highWatermark, value.SyncTime); if (this.punctuationPolicyType == PeriodicPunctuationPolicyType.Time && !this.lastPunctuationTime.ContainsKey(value.PartitionKey)) - UpdatePunctuation(value.PartitionKey, this.lowWatermark.rawValue, this.lowWatermark.quantizedForPunctuationGeneration); + this.UpdatePunctuation(value.PartitionKey, this.lowWatermark.rawValue, this.lowWatermark.quantizedForPunctuationGeneration); // Retrieve current time for this partition, updating currentTime if necessary if (!this.currentTime.TryGetValue(value.PartitionKey, out long current)) @@ -7564,7 +7564,7 @@ public override void OnNext(TPayload inputValue) else if (current < this.lowWatermark.rawValue) { current = this.lowWatermark.rawValue; - UpdateCurrentTime(value.PartitionKey, this.lowWatermark.rawValue); + this.UpdateCurrentTime(value.PartitionKey, this.lowWatermark.rawValue); } var outOfOrder = value.SyncTime < current; @@ -7612,16 +7612,16 @@ public override void OnNext(TPayload inputValue) // SyncTime is sufficiently high to generate a new punctuation, but first snap it to the nearest generationPeriod boundary var punctuationTimeQuantized = value.SyncTime.SnapToLeftBoundary((long)this.punctuationGenerationPeriod); #if DEBUG - Debug.Assert(punctuationTimeQuantized >= LastEventTime(value.PartitionKey), "Bug in punctuation quantization logic"); + Debug.Assert(punctuationTimeQuantized >= this.LastEventTime(value.PartitionKey), "Bug in punctuation quantization logic"); #endif - OnPunctuation(value.CreatePunctuation(punctuationTimeQuantized)); + this.OnPunctuation(value.CreatePunctuation(punctuationTimeQuantized)); } } } this.action(value.SyncTime, value.OtherTime, value.Payload, new PartitionKey(value.PartitionKey)); - UpdateCurrentTime(value.PartitionKey, value.SyncTime); + this.UpdateCurrentTime(value.PartitionKey, value.SyncTime); } [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -7651,7 +7651,7 @@ private void GenerateAndProcessLowWatermark(long syncTime) this.highWatermark = Math.Max(syncTime, this.highWatermark); if (this.lowWatermark.rawValue < syncTime) { - UpdateLowWatermark(syncTime); + this.UpdateLowWatermark(syncTime); } // Add LowWatermark to batch @@ -7668,21 +7668,21 @@ private void GenerateAndProcessLowWatermark(long syncTime) if (this.flushPolicy == PartitionedFlushPolicy.FlushOnLowWatermark || (this.flushPolicy == PartitionedFlushPolicy.FlushOnBatchBoundary && this.currentBatch.Count == Config.DataBatchSize)) { - OnFlush(); + this.OnFlush(); } else if (this.currentBatch.Count == Config.DataBatchSize) { - FlushContents(); + this.FlushContents(); } } protected override void OnCompleted(long punctuationTime) { - GenerateAndProcessLowWatermark(punctuationTime); + this.GenerateAndProcessLowWatermark(punctuationTime); // Flush, but if we just flushed due to the punctuation generated above if (this.flushPolicy != PartitionedFlushPolicy.FlushOnLowWatermark) - OnFlush(); + this.OnFlush(); } } @@ -7731,7 +7731,7 @@ public DisorderedPartitionedIntervalSubscription( diagnosticOutput) { this.fuseModule = fuseModule; - Expression>> statement = (s, e, p, k) => Action(s, e, p, k); + Expression>> statement = (s, e, p, k) => this.Action(s, e, p, k); var actionExp = fuseModule.Coalesce>(statement); this.action = actionExp.Compile(); this.partitionExtractor = partitionExtractor; @@ -7768,7 +7768,7 @@ private void Action(long start, long end, TResult payload, PartitionKey ac if (value.IsLowWatermark) { - GenerateAndProcessLowWatermark(value.SyncTime); + this.GenerateAndProcessLowWatermark(value.SyncTime); return; } @@ -7781,7 +7781,7 @@ private void Action(long start, long end, TResult payload, PartitionKey ac { // SyncTime is sufficiently high to generate a new watermark, but first snap it to the nearest generationPeriod boundary var newLowWatermarkSnapped = newLowWatermark.SnapToLeftBoundary((long)this.lowWatermarkGenerationPeriod); - GenerateAndProcessLowWatermark(newLowWatermarkSnapped); + this.GenerateAndProcessLowWatermark(newLowWatermarkSnapped); } } @@ -7789,7 +7789,7 @@ private void Action(long start, long end, TResult payload, PartitionKey ac this.highWatermark = Math.Max(this.highWatermark, value.SyncTime); if (this.punctuationPolicyType == PeriodicPunctuationPolicyType.Time && !this.lastPunctuationTime.ContainsKey(value.PartitionKey)) - UpdatePunctuation(value.PartitionKey, this.lowWatermark.rawValue, this.lowWatermark.quantizedForPunctuationGeneration); + this.UpdatePunctuation(value.PartitionKey, this.lowWatermark.rawValue, this.lowWatermark.quantizedForPunctuationGeneration); // Retrieve current time for this partition, updating currentTime if necessary if (!this.currentTime.TryGetValue(value.PartitionKey, out long current)) @@ -7799,7 +7799,7 @@ private void Action(long start, long end, TResult payload, PartitionKey ac else if (current < this.lowWatermark.rawValue) { current = this.lowWatermark.rawValue; - UpdateCurrentTime(value.PartitionKey, this.lowWatermark.rawValue); + this.UpdateCurrentTime(value.PartitionKey, this.lowWatermark.rawValue); } var outOfOrder = value.SyncTime < current; @@ -7847,9 +7847,9 @@ private void Action(long start, long end, TResult payload, PartitionKey ac // SyncTime is sufficiently high to generate a new punctuation, but first snap it to the nearest generationPeriod boundary var punctuationTimeQuantized = value.SyncTime.SnapToLeftBoundary((long)this.punctuationGenerationPeriod); #if DEBUG - Debug.Assert(punctuationTimeQuantized >= LastEventTime(value.PartitionKey), "Bug in punctuation quantization logic"); + Debug.Assert(punctuationTimeQuantized >= this.LastEventTime(value.PartitionKey), "Bug in punctuation quantization logic"); #endif - OnPunctuation(value.CreatePunctuation(punctuationTimeQuantized)); + this.OnPunctuation(value.CreatePunctuation(punctuationTimeQuantized)); } } } @@ -7857,11 +7857,11 @@ private void Action(long start, long end, TResult payload, PartitionKey ac this.currentBatch.Add(value.SyncTime, value.OtherTime, new PartitionKey(value.PartitionKey), value.Payload); if (this.currentBatch.Count == Config.DataBatchSize) { - if (this.flushPolicy == PartitionedFlushPolicy.FlushOnBatchBoundary) OnFlush(); - else FlushContents(); + if (this.flushPolicy == PartitionedFlushPolicy.FlushOnBatchBoundary) this.OnFlush(); + else this.FlushContents(); } - UpdateCurrentTime(value.PartitionKey, value.SyncTime); + this.UpdateCurrentTime(value.PartitionKey, value.SyncTime); } [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -7891,7 +7891,7 @@ private void GenerateAndProcessLowWatermark(long syncTime) this.highWatermark = Math.Max(syncTime, this.highWatermark); if (this.lowWatermark.rawValue < syncTime) { - UpdateLowWatermark(syncTime); + this.UpdateLowWatermark(syncTime); } // Add LowWatermark to batch @@ -7908,21 +7908,21 @@ private void GenerateAndProcessLowWatermark(long syncTime) if (this.flushPolicy == PartitionedFlushPolicy.FlushOnLowWatermark || (this.flushPolicy == PartitionedFlushPolicy.FlushOnBatchBoundary && this.currentBatch.Count == Config.DataBatchSize)) { - OnFlush(); + this.OnFlush(); } else if (this.currentBatch.Count == Config.DataBatchSize) { - FlushContents(); + this.FlushContents(); } } protected override void OnCompleted(long punctuationTime) { - GenerateAndProcessLowWatermark(punctuationTime); + this.GenerateAndProcessLowWatermark(punctuationTime); // Flush, but if we just flushed due to the punctuation generated above if (this.flushPolicy != PartitionedFlushPolicy.FlushOnLowWatermark) - OnFlush(); + this.OnFlush(); } } diff --git a/Sources/Core/Microsoft.StreamProcessing/Ingress/Temporal/TemporalIngressTransformer.cs b/Sources/Core/Microsoft.StreamProcessing/Ingress/Temporal/TemporalIngressTransformer.cs index 2990c7285..28828960c 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Ingress/Temporal/TemporalIngressTransformer.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Ingress/Temporal/TemporalIngressTransformer.cs @@ -180,7 +180,7 @@ private static Tuple Generate( expressions = fuseModule.GetCodeGenExpressions(); } - return template.Generate(new Type[] { typeof(IStreamable<,>) }, expressions); + return template.Generate([typeof(IStreamable<,>)], expressions); } } } \ No newline at end of file diff --git a/Sources/Core/Microsoft.StreamProcessing/Ingress/TemporalArray/TemporalArrayIngressStreamable.cs b/Sources/Core/Microsoft.StreamProcessing/Ingress/TemporalArray/TemporalArrayIngressStreamable.cs index 5aa05f573..e6e04123c 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Ingress/TemporalArray/TemporalArrayIngressStreamable.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Ingress/TemporalArray/TemporalArrayIngressStreamable.cs @@ -26,8 +26,8 @@ public StreamEventArrayIngressStreamable( ? StreamProperties.Default.ToRowBased() : StreamProperties.Default).SetQueryContainer(container)) { - Contract.Requires(observable != null); - Contract.Requires(identifier != null); + ArgumentNullException.ThrowIfNull(observable); + ArgumentNullException.ThrowIfNull(identifier); this.IngressSiteIdentifier = identifier; this.observable = observable; @@ -35,12 +35,12 @@ public StreamEventArrayIngressStreamable( this.container = container; this.delayed = container != null; - if (delayed) container.RegisterIngressSite(identifier); + if (this.delayed) container.RegisterIngressSite(identifier); } public void Dispose() { - if (diagnosticOutput != null) diagnosticOutput.Dispose(); + if (this.diagnosticOutput != null) this.diagnosticOutput.Dispose(); } [ContractInvariantMethod] @@ -52,8 +52,8 @@ private void ObjectInvariant() public IObservable> GetDroppedAdjustedEventsDiagnostic() { - if (diagnosticOutput == null) diagnosticOutput = new DiagnosticObservable(); - return diagnosticOutput; + if (this.diagnosticOutput == null) this.diagnosticOutput = new DiagnosticObservable(); + return this.diagnosticOutput; } public override IDisposable Subscribe(IStreamObserver observer) @@ -64,12 +64,12 @@ public override IDisposable Subscribe(IStreamObserver observer) this.IngressSiteIdentifier, this, observer, - onCompletedPolicy, - diagnosticOutput); + this.onCompletedPolicy, + this.diagnosticOutput); - if (delayed) + if (this.delayed) { - container.RegisterIngressPipe(this.IngressSiteIdentifier, subscription); + this.container.RegisterIngressPipe(this.IngressSiteIdentifier, subscription); return subscription.DelayedDisposable; } else @@ -104,8 +104,8 @@ public IntervalArrayIngressStreamable( ? StreamProperties.DefaultIngress(startEdgeExtractor, endEdgeExtractor).ToRowBased() : StreamProperties.DefaultIngress(startEdgeExtractor, endEdgeExtractor)).SetQueryContainer(container)) { - Contract.Requires(observable != null); - Contract.Requires(identifier != null); + ArgumentNullException.ThrowIfNull(observable); + ArgumentNullException.ThrowIfNull(identifier); this.IngressSiteIdentifier = identifier; this.observable = observable; @@ -115,12 +115,12 @@ public IntervalArrayIngressStreamable( this.container = container; this.delayed = container != null; - if (delayed) container.RegisterIngressSite(identifier); + if (this.delayed) container.RegisterIngressSite(identifier); } public void Dispose() { - if (diagnosticOutput != null) diagnosticOutput.Dispose(); + if (this.diagnosticOutput != null) this.diagnosticOutput.Dispose(); } [ContractInvariantMethod] @@ -132,8 +132,8 @@ private void ObjectInvariant() public IObservable> GetDroppedAdjustedEventsDiagnostic() { - if (diagnosticOutput == null) diagnosticOutput = new DiagnosticObservable(); - return diagnosticOutput; + if (this.diagnosticOutput == null) this.diagnosticOutput = new DiagnosticObservable(); + return this.diagnosticOutput; } public override IDisposable Subscribe(IStreamObserver observer) @@ -146,12 +146,12 @@ public override IDisposable Subscribe(IStreamObserver observer) this.IngressSiteIdentifier, this, observer, - onCompletedPolicy, - diagnosticOutput); + this.onCompletedPolicy, + this.diagnosticOutput); - if (delayed) + if (this.delayed) { - container.RegisterIngressPipe(this.IngressSiteIdentifier, subscription); + this.container.RegisterIngressPipe(this.IngressSiteIdentifier, subscription); return subscription.DelayedDisposable; } else @@ -182,8 +182,8 @@ public PartitionedStreamEventArrayIngressStreamable( ? StreamProperties, TPayload>.Default.ToRowBased() : StreamProperties, TPayload>.Default).SetQueryContainer(container)) { - Contract.Requires(observable != null); - Contract.Requires(identifier != null); + ArgumentNullException.ThrowIfNull(observable); + ArgumentNullException.ThrowIfNull(identifier); this.IngressSiteIdentifier = identifier; this.observable = observable; @@ -191,12 +191,12 @@ public PartitionedStreamEventArrayIngressStreamable( this.container = container; this.delayed = container != null; - if (delayed) container.RegisterIngressSite(identifier); + if (this.delayed) container.RegisterIngressSite(identifier); } public void Dispose() { - if (diagnosticOutput != null) diagnosticOutput.Dispose(); + if (this.diagnosticOutput != null) this.diagnosticOutput.Dispose(); } [ContractInvariantMethod] @@ -208,8 +208,8 @@ private void ObjectInvariant() public IObservable> GetDroppedAdjustedEventsDiagnostic() { - if (diagnosticOutput == null) diagnosticOutput = new PartitionedDiagnosticObservable(); - return diagnosticOutput; + if (this.diagnosticOutput == null) this.diagnosticOutput = new PartitionedDiagnosticObservable(); + return this.diagnosticOutput; } public override IDisposable Subscribe(IStreamObserver, TPayload> observer) @@ -220,12 +220,12 @@ public override IDisposable Subscribe(IStreamObserver, TPayload>.DefaultIngress(startEdgeExtractor, endEdgeExtractor).ToRowBased() : StreamProperties, TPayload>.DefaultIngress(startEdgeExtractor, endEdgeExtractor)).SetQueryContainer(container)) { - Contract.Requires(observable != null); - Contract.Requires(identifier != null); + ArgumentNullException.ThrowIfNull(observable); + ArgumentNullException.ThrowIfNull(identifier); this.IngressSiteIdentifier = identifier; this.observable = observable; @@ -274,12 +274,12 @@ public PartitionedIntervalArrayIngressStreamable( this.container = container; this.delayed = container != null; - if (delayed) container.RegisterIngressSite(identifier); + if (this.delayed) container.RegisterIngressSite(identifier); } public void Dispose() { - if (diagnosticOutput != null) diagnosticOutput.Dispose(); + if (this.diagnosticOutput != null) this.diagnosticOutput.Dispose(); } [ContractInvariantMethod] @@ -291,8 +291,8 @@ private void ObjectInvariant() public IObservable> GetDroppedAdjustedEventsDiagnostic() { - if (diagnosticOutput == null) diagnosticOutput = new PartitionedDiagnosticObservable(); - return diagnosticOutput; + if (this.diagnosticOutput == null) this.diagnosticOutput = new PartitionedDiagnosticObservable(); + return this.diagnosticOutput; } public override IDisposable Subscribe(IStreamObserver, TPayload> observer) @@ -306,12 +306,12 @@ public override IDisposable Subscribe(IStreamObserver, TPayload>.Default<#= (m == "Interval") ? "Ingress(startEdgeExtractor, endEdgeExtractor)" : string.Empty #>.ToRowBased() : StreamProperties<<#= keyType #>, TPayload>.Default<#= (m == "Interval") ? "Ingress(startEdgeExtractor, endEdgeExtractor)" : string.Empty #>).SetQueryContainer(container)) { - Contract.Requires(observable != null); - Contract.Requires(identifier != null); + ArgumentNullException.ThrowIfNull(observable); + ArgumentNullException.ThrowIfNull(identifier); this.IngressSiteIdentifier = identifier; this.observable = observable; diff --git a/Sources/Core/Microsoft.StreamProcessing/Ingress/TemporalArray/TemporalArrayIngressSubscription.cs b/Sources/Core/Microsoft.StreamProcessing/Ingress/TemporalArray/TemporalArrayIngressSubscription.cs index 0a77ef582..5088518a3 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Ingress/TemporalArray/TemporalArrayIngressSubscription.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Ingress/TemporalArray/TemporalArrayIngressSubscription.cs @@ -164,20 +164,20 @@ public override void OnNext(ArraySegment> value) var current = value.Array[offset]; if (current.SyncTime < this.currentTime) current = StreamEvent.CreatePunctuation(this.currentTime); Array.Clear(this.currentBatch.hash.col, 0, this.currentBatch.hash.col.Length); - OnPunctuation(current); + this.OnPunctuation(current); offset++; } else if (full) { Array.Clear(this.currentBatch.hash.col, 0, this.currentBatch.hash.col.Length); - FlushContents(); + this.FlushContents(); } } } protected override void OnCompleted(long punctuationTime) { - OnNext(new ArraySegment>(new[] { StreamEvent.CreatePunctuation(punctuationTime) })); + this.OnNext(new ArraySegment>([StreamEvent.CreatePunctuation(punctuationTime)])); } } @@ -251,7 +251,7 @@ public override void OnNext(ArraySegment value) if (full) { Array.Clear(this.currentBatch.hash.col, 0, this.currentBatch.hash.col.Length); - FlushContents(); + this.FlushContents(); } } } @@ -259,7 +259,7 @@ public override void OnNext(ArraySegment value) protected override void OnCompleted(long punctuationTime) { this.currentBatch.AddPunctuation(punctuationTime); - OnFlush(); + this.OnFlush(); } } @@ -320,14 +320,14 @@ public override void OnNext(ArraySegment> if (full) { Array.Clear(this.currentBatch.hash.col, 0, this.currentBatch.hash.col.Length); - FlushContents(); + this.FlushContents(); } } } protected override void OnCompleted(long punctuationTime) { - OnNext(new ArraySegment>(new[] { PartitionedStreamEvent.CreateLowWatermark(punctuationTime) })); + this.OnNext(new ArraySegment>([PartitionedStreamEvent.CreateLowWatermark(punctuationTime)])); } } @@ -409,7 +409,7 @@ public override void OnNext(ArraySegment value) if (full) { Array.Clear(this.currentBatch.hash.col, 0, this.currentBatch.hash.col.Length); - FlushContents(); + this.FlushContents(); } } } @@ -417,7 +417,7 @@ public override void OnNext(ArraySegment value) protected override void OnCompleted(long punctuationTime) { this.currentBatch.AddLowWatermark(punctuationTime); - OnFlush(); + this.OnFlush(); } } diff --git a/Sources/Core/Microsoft.StreamProcessing/Microsoft.StreamProcessing.csproj b/Sources/Core/Microsoft.StreamProcessing/Microsoft.StreamProcessing.csproj index b96b07891..bdcd96f83 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Microsoft.StreamProcessing.csproj +++ b/Sources/Core/Microsoft.StreamProcessing/Microsoft.StreamProcessing.csproj @@ -1,7 +1,7 @@  - netstandard2.0 + net10.0 x64;AnyCPU @@ -10,15 +10,28 @@ Microsoft.StreamProcessing + + True + 1701;1702;0009 + + + + True + 1701;1702;0009 + + + + True + 1701;1702;0009 + + + + True + 1701;1702;0009 + + - - - - - - - - + diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/Afa/AfaDescriptor.cs b/Sources/Core/Microsoft.StreamProcessing/Operators/Afa/AfaDescriptor.cs index b701e11b1..5ff8fefb7 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/Afa/AfaDescriptor.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/Afa/AfaDescriptor.cs @@ -23,7 +23,7 @@ public static class Afa /// /// public static Afa Create(TRegister defaultRegister = default, TAccumulator defaultAccumulator = default) - => new Afa(defaultRegister, defaultAccumulator); + => new(defaultRegister, defaultAccumulator); /// /// @@ -33,7 +33,7 @@ public static Afa Create /// public static Afa Create(TRegister defaultRegister = default) - => new Afa(defaultRegister); + => new(defaultRegister); /// /// @@ -41,7 +41,7 @@ public static Afa Create(TRegister d /// /// public static Afa Create() - => new Afa(); + => new(); } /// @@ -71,12 +71,12 @@ public Afa(TRegister defaultRegister = default, TAccumulator defaultAccumulator /// /// The set of final states in the AFA. /// - internal List finalStates = new List(); + internal List finalStates = []; /// /// The arcs present in the AFA. /// - internal Dictionary>> transitionInfo = new Dictionary>>(); + internal Dictionary>> transitionInfo = []; /// /// Start state of the AFA. @@ -117,7 +117,7 @@ public Afa(TRegister defaultRegister = default, TAccumulator defaultAccumulator /// An added condition that must be met for the transition to occur /// An expression to mutate the register value when the transition occurs public void AddSingleElementArc(int fromState, int toState, Expression> fence, Expression> transfer = null) - => AddArc(fromState, toState, new SingleElementArc { Fence = fence, Transfer = transfer }); + => this.AddArc(fromState, toState, new SingleElementArc { Fence = fence, Transfer = transfer }); /// /// Adds a transition to the AFA triggered by a list of concurrent elements @@ -127,7 +127,7 @@ public void AddSingleElementArc(int fromState, int toState, ExpressionAn added condition that must be met for the transition to occur /// An expression to mutate the register value when the transition occurs public void AddListElementArc(int fromState, int toState, Expression, TRegister, bool>> fence, Expression, TRegister, TRegister>> transfer = null) - => AddArc(fromState, toState, new ListElementArc { Fence = fence, Transfer = transfer }); + => this.AddArc(fromState, toState, new ListElementArc { Fence = fence, Transfer = transfer }); /// /// Adds an epsilon (no action) arc to the AFA @@ -135,7 +135,7 @@ public void AddListElementArc(int fromState, int toState, ExpressionStarting state of the transition /// Ending state of the transition public void AddEpsilonElementArc(int fromState, int toState) - => AddArc(fromState, toState, new EpsilonArc()); + => this.AddArc(fromState, toState, new EpsilonArc()); /// /// Adds a transition that handles multiple elements (events) at a given timestamp @@ -155,7 +155,7 @@ public void AddMultiElementArc(int fromState, int toState, Expression> fence = null, Expression> transfer = null, Expression> dispose = null) - => AddArc(fromState, toState, new MultiElementArc + => this.AddArc(fromState, toState, new MultiElementArc { Initialize = initialize, Accumulate = accumulate, @@ -180,7 +180,7 @@ internal void AddArc(int fromState, int toState, Arc arc) if (!this.transitionInfo.ContainsKey(fromState)) { - this.transitionInfo.Add(fromState, new Dictionary>()); + this.transitionInfo.Add(fromState, []); } if (!this.transitionInfo[fromState].ContainsKey(toState)) @@ -258,7 +258,7 @@ public void RemoveFinalState(int state) /// public void SetDefaultRegister(TRegister register) => this.DefaultRegister = register; - internal CompiledAfa Compile() => new CompiledAfa(this); + internal CompiledAfa Compile() => new(this); /// /// Returns a string representation of the AFA diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/Afa/AfaMultiEventListTransformer.cs b/Sources/Core/Microsoft.StreamProcessing/Operators/Afa/AfaMultiEventListTransformer.cs index 1d2030c91..00f0e9d7c 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/Afa/AfaMultiEventListTransformer.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/Afa/AfaMultiEventListTransformer.cs @@ -13,8 +13,8 @@ namespace Microsoft.StreamProcessing internal partial class AfaMultiEventListTemplate : AfaTemplate { private Func keyEqualityComparer; - protected readonly List>> edgeInfos = new List>>(); - protected readonly List>> startEdgeInfos = new List>>(); + protected readonly List>> edgeInfos = []; + protected readonly List>> startEdgeInfos = []; private bool payloadIsAnon; private bool payloadHasNoFields; @@ -38,8 +38,8 @@ private AfaMultiEventListTemplate(string className, Type keyType, Type payloadTy internal static Tuple GenerateAFA( AfaStreamable stream) { - Contract.Requires(stream != null); - Contract.Ensures(Contract.Result>() == null || typeof(UnaryPipe).GetTypeInfo().IsAssignableFrom(Contract.Result>().Item1)); + ArgumentNullException.ThrowIfNull(stream); + Contract.Ensures(Contract.Result>() == null || typeof(UnaryPipe).IsAssignableFrom(Contract.Result>().Item1)); var className = string.Format("Generated{1}AfaMultiEventList_{0}", AFASequenceNumber++, typeof(TKey).Equals(typeof(Empty)) ? string.Empty : "Grouped"); var template = new AfaMultiEventListTemplate(className, typeof(TKey), typeof(TPayload), typeof(TRegister), typeof(TAccumulator)) diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/Afa/AfaStreamable.cs b/Sources/Core/Microsoft.StreamProcessing/Operators/Afa/AfaStreamable.cs index 41e1c9aac..4700bcd65 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/Afa/AfaStreamable.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/Afa/AfaStreamable.cs @@ -11,7 +11,7 @@ namespace Microsoft.StreamProcessing internal sealed class AfaStreamable : UnaryStreamable { private static readonly SafeConcurrentDictionary> cachedPipes - = new SafeConcurrentDictionary>(); + = new(); internal CompiledAfa afa; internal long MaxDuration; @@ -19,13 +19,13 @@ private static readonly SafeConcurrentDictionary> cachedPipe public AfaStreamable(IStreamable source, Afa afa, long maxDuration) : base(source, source.Properties.Afa()) { - Contract.Requires(source != null); + ArgumentNullException.ThrowIfNull(source); afa.Seal(); this.afa = afa.Compile(); this.MaxDuration = maxDuration; - Initialize(); + this.Initialize(); } internal override IStreamObserver CreatePipe(IStreamObserver observer) @@ -33,7 +33,7 @@ internal override IStreamObserver CreatePipe(IStreamObserver; @@ -61,7 +61,7 @@ internal override IStreamObserver CreatePipe(IStreamObserver CreatePipe(IStreamObserver + ? this.GetUngroupedDAfaPipe(emptyObserver) as IStreamObserver : new CompiledUngroupedDAfaPipe(downcast, observer as IStreamObserver, this.afa, this.MaxDuration) as IStreamObserver; } else { return this.Source.Properties.IsColumnar - ? GetUngroupedAFAPipe(emptyObserver) as IStreamObserver + ? this.GetUngroupedAFAPipe(emptyObserver) as IStreamObserver : new CompiledUngroupedAfaPipe(downcast, observer as IStreamObserver, this.afa, this.MaxDuration) as IStreamObserver; } } else { if (this.Source.Properties.IsColumnar) - return GetGroupedAFAPipe(observer); + return this.GetGroupedAFAPipe(observer); else { var partitionType = typeof(TKey).GetPartitionType(); @@ -123,7 +123,7 @@ internal override IStreamObserver CreatePipe(IStreamObserver; @@ -151,21 +151,21 @@ internal override IStreamObserver CreatePipe(IStreamObserver>> currentlyActiveInfo = new List>>(); - protected readonly List>> newActivationInfo = new List>>(); + protected readonly List>> currentlyActiveInfo = []; + protected readonly List>> newActivationInfo = []; protected string TKey; protected string TPayload; protected string TRegister; @@ -48,7 +48,7 @@ internal AfaTemplate(string className, Type keyType, Type payloadType, Type regi if (Config.ForceRowBasedExecution) { // then need to use the field "payload" that is defined on the generic StreamMessage - this.sourceFields = new MyFieldInfo[] { new MyFieldInfo(payloadType, "payload") }; + this.sourceFields = [new(payloadType, "payload")]; } else { @@ -64,7 +64,7 @@ protected Tuple Generate( string errorMessages = null; try { - var expandedCode = TransformText(); + var expandedCode = this.TransformText(); var assemblyReferences = Transformer.AssemblyReferencesNeededFor( typeof(TKey), typeof(TPayload), typeof(TRegister), typeof(Stack<>), typeof(IStreamable<,>)); @@ -72,14 +72,13 @@ protected Tuple Generate( assemblyReferences.Add(Transformer.GeneratedStreamMessageAssembly()); assemblyReferences.Add(Transformer.GeneratedMemoryPoolAssembly()); - var a = Transformer.CompileSourceCode(expandedCode, assemblyReferences, out errorMessages); - var t = a.GetType(this.className); - if (t.GetTypeInfo().IsGenericType) + var t = Transformer.CompileSourceCode(expandedCode, assemblyReferences, a => a.GetType(this.className), out errorMessages); + if (t.IsGenericType) { var list = typeof(TKey).GetAnonymousTypes(); list.AddRange(this.payloadType.GetAnonymousTypes()); list.AddRange(this.registerType.GetAnonymousTypes()); - t = t.MakeGenericType(list.ToArray()); + t = t.MakeGenericType([.. list]); } return Tuple.Create(t, errorMessages); } @@ -159,7 +158,7 @@ protected void UpdateRegisterValue(EdgeInfo e, string defaultRegisterValue, stri var newRegisterValue = !this.hasRegister || e.Transfer == null ? defaultRegisterValue : e.Transfer(ts, payloadList, reg); - WriteLine("{0}var newReg = {1};", this.CurrentIndent, newRegisterValue); + this.WriteLine("{0}var newReg = {1};", this.CurrentIndent, newRegisterValue); return; } @@ -168,7 +167,7 @@ protected void UpdateRegisterValue(MultiEdgeInfo e, string defaultRegisterValue, var newRegisterValue = e.Transfer == null ? defaultRegisterValue : e.Transfer(ts, acc, reg); - WriteLine("{0}var newReg = {1};", this.CurrentIndent, newRegisterValue); + this.WriteLine("{0}var newReg = {1};", this.CurrentIndent, newRegisterValue); return; } diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/Afa/CompiledAfa.cs b/Sources/Core/Microsoft.StreamProcessing/Operators/Afa/CompiledAfa.cs index 13b9ccf00..5946751b0 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/Afa/CompiledAfa.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/Afa/CompiledAfa.cs @@ -30,7 +30,7 @@ public CompiledAfa(Afa afa) this.uncompiledAfa = afa; this.defaultRegister = afa.DefaultRegister; this.defaultAccumulator = afa.DefaultAccumulator; - CompileAfa(afa); + this.CompileAfa(afa); } private void CompileAfa(Afa afa) diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/Afa/CompiledAfaPipeBase.cs b/Sources/Core/Microsoft.StreamProcessing/Operators/Afa/CompiledAfaPipeBase.cs index cfa8eba4f..c71251c02 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/Afa/CompiledAfaPipeBase.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/Afa/CompiledAfaPipeBase.cs @@ -205,7 +205,7 @@ protected void OnPunctuation(long timestamp) if (this.batch.key != null) this.batch.key.col[this.iter] = default; this.batch.hash.col[this.iter] = 0; this.iter++; - if (this.iter == Config.DataBatchSize) FlushContents(); + if (this.iter == Config.DataBatchSize) this.FlushContents(); } /// @@ -223,7 +223,7 @@ protected void OnLowWatermark(long timestamp) if (this.batch.key != null) this.batch.key.col[this.iter] = default; this.batch.hash.col[this.iter] = 0; this.iter++; - if (this.iter == Config.DataBatchSize) FlushContents(); + if (this.iter == Config.DataBatchSize) this.FlushContents(); } /// diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/Afa/CompiledGroupedAfaPipe_EventList.cs b/Sources/Core/Microsoft.StreamProcessing/Operators/Afa/CompiledGroupedAfaPipe_EventList.cs index 074dd76fd..160574597 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/Afa/CompiledGroupedAfaPipe_EventList.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/Afa/CompiledGroupedAfaPipe_EventList.cs @@ -28,7 +28,7 @@ internal sealed class CompiledGroupedAfaPipe_EventList stack = new Stack(); + private readonly Stack stack = new(); [Obsolete("Used only by serialization. Do not call directly.")] public CompiledGroupedAfaPipe_EventList() { } @@ -104,7 +104,7 @@ private void ProcessCurrentTimestamp() this.batch.hash.col[this.iter] = el_hash; this.iter++; - if (this.iter == Config.DataBatchSize) FlushContents(); + if (this.iter == Config.DataBatchSize) this.FlushContents(); } if (this.hasOutgoingArcs[ns]) @@ -179,7 +179,7 @@ private void ProcessCurrentTimestamp() this.batch.hash.col[this.iter] = el_hash; this.iter++; - if (this.iter == Config.DataBatchSize) FlushContents(); + if (this.iter == Config.DataBatchSize) this.FlushContents(); } if (this.hasOutgoingArcs[ns]) @@ -271,7 +271,7 @@ private void ProcessCurrentTimestamp() this.batch.hash.col[this.iter] = el_hash; this.iter++; - if (this.iter == Config.DataBatchSize) FlushContents(); + if (this.iter == Config.DataBatchSize) this.FlushContents(); } if (this.hasOutgoingArcs[ns]) { @@ -325,7 +325,7 @@ private void ProcessCurrentTimestamp() this.batch.hash.col[this.iter] = el_hash; this.iter++; - if (this.iter == Config.DataBatchSize) FlushContents(); + if (this.iter == Config.DataBatchSize) this.FlushContents(); } if (this.hasOutgoingArcs[ns]) { @@ -376,13 +376,13 @@ public override unsafe void OnNext(StreamMessage batch) if (synctime > this.lastSyncTime) // move time forward { - ProcessCurrentTimestamp(); + this.ProcessCurrentTimestamp(); this.lastSyncTime = synctime; } if (batch.vother.col[i] < 0) { - OnPunctuation(synctime); + this.OnPunctuation(synctime); continue; } diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/Afa/CompiledGroupedAfaPipe_MultiEvent.cs b/Sources/Core/Microsoft.StreamProcessing/Operators/Afa/CompiledGroupedAfaPipe_MultiEvent.cs index 6f640d1d0..5442f5294 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/Afa/CompiledGroupedAfaPipe_MultiEvent.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/Afa/CompiledGroupedAfaPipe_MultiEvent.cs @@ -82,7 +82,7 @@ private void ProcessCurrentTimestamp() this.iter++; if (this.iter == Config.DataBatchSize) - FlushContents(); + this.FlushContents(); } if (this.hasOutgoingArcs[state2.toState]) @@ -120,13 +120,13 @@ public override unsafe void OnNext(StreamMessage batch) if (synctime > this.lastSyncTime) // move time forward { - ProcessCurrentTimestamp(); + this.ProcessCurrentTimestamp(); this.lastSyncTime = synctime; } if (batch.vother.col[i] < 0) { - OnPunctuation(synctime); + this.OnPunctuation(synctime); continue; } diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/Afa/CompiledGroupedAfaPipe_MultiEventList.cs b/Sources/Core/Microsoft.StreamProcessing/Operators/Afa/CompiledGroupedAfaPipe_MultiEventList.cs index 438956eed..b7edd19b5 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/Afa/CompiledGroupedAfaPipe_MultiEventList.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/Afa/CompiledGroupedAfaPipe_MultiEventList.cs @@ -28,7 +28,7 @@ internal sealed class CompiledGroupedAfaPipe_MultiEventList stack = new Stack(); + private readonly Stack stack = new(); [Obsolete("Used only by serialization. Do not call directly.")] public CompiledGroupedAfaPipe_MultiEventList() { } @@ -113,7 +113,7 @@ private void ProcessCurrentTimestamp() this.batch.hash.col[this.iter] = el_hash; this.iter++; - if (this.iter == Config.DataBatchSize) FlushContents(); + if (this.iter == Config.DataBatchSize) this.FlushContents(); } if (this.hasOutgoingArcs[ns]) @@ -190,7 +190,7 @@ private void ProcessCurrentTimestamp() this.batch.hash.col[this.iter] = el_hash; this.iter++; - if (this.iter == Config.DataBatchSize) FlushContents(); + if (this.iter == Config.DataBatchSize) this.FlushContents(); } if (this.hasOutgoingArcs[ns]) @@ -276,7 +276,7 @@ private void ProcessCurrentTimestamp() this.batch.hash.col[this.iter] = el_hash; this.iter++; - if (this.iter == Config.DataBatchSize) FlushContents(); + if (this.iter == Config.DataBatchSize) this.FlushContents(); } if (this.hasOutgoingArcs[ns]) @@ -377,7 +377,7 @@ private void ProcessCurrentTimestamp() this.batch.hash.col[this.iter] = el_hash; this.iter++; - if (this.iter == Config.DataBatchSize) FlushContents(); + if (this.iter == Config.DataBatchSize) this.FlushContents(); } if (this.hasOutgoingArcs[ns]) { @@ -435,7 +435,7 @@ private void ProcessCurrentTimestamp() this.batch.hash.col[this.iter] = el_hash; this.iter++; - if (this.iter == Config.DataBatchSize) FlushContents(); + if (this.iter == Config.DataBatchSize) this.FlushContents(); } if (this.hasOutgoingArcs[ns]) { @@ -500,7 +500,7 @@ private void ProcessCurrentTimestamp() this.batch.hash.col[this.iter] = el_hash; this.iter++; - if (this.iter == Config.DataBatchSize) FlushContents(); + if (this.iter == Config.DataBatchSize) this.FlushContents(); } if (this.hasOutgoingArcs[ns]) { @@ -558,13 +558,13 @@ public override unsafe void OnNext(StreamMessage batch) if (synctime > this.lastSyncTime) // move time forward { - ProcessCurrentTimestamp(); + this.ProcessCurrentTimestamp(); this.lastSyncTime = synctime; } if (batch.vother.col[i] < 0) { - OnPunctuation(synctime); + this.OnPunctuation(synctime); continue; } diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/Afa/CompiledGroupedAfaPipe_SingleEvent.cs b/Sources/Core/Microsoft.StreamProcessing/Operators/Afa/CompiledGroupedAfaPipe_SingleEvent.cs index 719de2567..e15437e88 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/Afa/CompiledGroupedAfaPipe_SingleEvent.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/Afa/CompiledGroupedAfaPipe_SingleEvent.cs @@ -93,7 +93,7 @@ public override unsafe void OnNext(StreamMessage batch) if (this.iter == Config.DataBatchSize) { - FlushContents(); + this.FlushContents(); dest_vsync = this.batch.vsync.col; dest_vother = this.batch.vother.col; destkey = this.batch.key.col; @@ -202,7 +202,7 @@ public override unsafe void OnNext(StreamMessage batch) if (this.iter == Config.DataBatchSize) { - FlushContents(); + this.FlushContents(); dest_vsync = this.batch.vsync.col; dest_vother = this.batch.vother.col; destkey = this.batch.key.col; @@ -308,7 +308,7 @@ public override unsafe void OnNext(StreamMessage batch) if (this.iter == Config.DataBatchSize) { - FlushContents(); + this.FlushContents(); dest_vsync = this.batch.vsync.col; dest_vother = this.batch.vother.col; destkey = this.batch.key.col; @@ -367,7 +367,7 @@ public override unsafe void OnNext(StreamMessage batch) if (this.iter == Config.DataBatchSize) { - FlushContents(); + this.FlushContents(); dest_vsync = this.batch.vsync.col; dest_vother = this.batch.vother.col; destkey = this.batch.key.col; @@ -382,7 +382,7 @@ public override unsafe void OnNext(StreamMessage batch) } // Update dest_* on punctuation in case this event will hit the batch boundary and allocate a new batch - OnPunctuation(synctime); + this.OnPunctuation(synctime); dest_vsync = this.batch.vsync.col; dest_vother = this.batch.vother.col; @@ -394,5 +394,11 @@ public override unsafe void OnNext(StreamMessage batch) } batch.Free(); } + + protected override void DisposeState() + { + this.seenEvent?.Dispose(); + base.DisposeState(); + } } } \ No newline at end of file diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/Afa/CompiledPartitionedAfaPipe_EventList.cs b/Sources/Core/Microsoft.StreamProcessing/Operators/Afa/CompiledPartitionedAfaPipe_EventList.cs index 496061fc2..97f73c741 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/Afa/CompiledPartitionedAfaPipe_EventList.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/Afa/CompiledPartitionedAfaPipe_EventList.cs @@ -22,12 +22,12 @@ internal sealed class CompiledPartitionedAfaPipe_EventList>> currentTimestampEventList = new FastDictionary2>>(); + private FastDictionary2>> currentTimestampEventList = new(); [DataMember] - private FastDictionary2 lastSyncTime = new FastDictionary2(); + private FastDictionary2 lastSyncTime = new(); // Field instead of local variable to avoid re-initializing it - private readonly Stack stack = new Stack(); + private readonly Stack stack = new(); [Obsolete("Used only by serialization. Do not call directly.")] public CompiledPartitionedAfaPipe_EventList() { } @@ -101,7 +101,7 @@ private void ProcessCurrentTimestamp(int partitionIndex) this.batch.hash.col[this.iter] = el_hash; this.iter++; - if (this.iter == Config.DataBatchSize) FlushContents(); + if (this.iter == Config.DataBatchSize) this.FlushContents(); } if (this.hasOutgoingArcs[ns]) @@ -176,7 +176,7 @@ private void ProcessCurrentTimestamp(int partitionIndex) this.batch.hash.col[this.iter] = el_hash; this.iter++; - if (this.iter == Config.DataBatchSize) FlushContents(); + if (this.iter == Config.DataBatchSize) this.FlushContents(); } if (this.hasOutgoingArcs[ns]) @@ -268,7 +268,7 @@ private void ProcessCurrentTimestamp(int partitionIndex) this.batch.hash.col[this.iter] = el_hash; this.iter++; - if (this.iter == Config.DataBatchSize) FlushContents(); + if (this.iter == Config.DataBatchSize) this.FlushContents(); } if (this.hasOutgoingArcs[ns]) { @@ -323,7 +323,7 @@ private void ProcessCurrentTimestamp(int partitionIndex) this.batch.hash.col[this.iter] = el_hash; this.iter++; - if (this.iter == Config.DataBatchSize) FlushContents(); + if (this.iter == Config.DataBatchSize) this.FlushContents(); } if (this.hasOutgoingArcs[ns]) { @@ -372,7 +372,7 @@ public override unsafe void OnNext(StreamMessage batch) if ((src_bv[i >> 6] & (1L << (i & 0x3f))) == 0) { var partitionKey = this.getPartitionKey(srckey[i]); - int partitionIndex = EnsurePartition(partitionKey); + int partitionIndex = this.EnsurePartition(partitionKey); long synctime = src_vsync[i]; @@ -380,7 +380,7 @@ public override unsafe void OnNext(StreamMessage batch) if (synctime > this.lastSyncTime.entries[partitionIndex].value) // move time forward { - ProcessCurrentTimestamp(partitionIndex); + this.ProcessCurrentTimestamp(partitionIndex); this.lastSyncTime.entries[partitionIndex].value = synctime; } @@ -420,23 +420,23 @@ public override unsafe void OnNext(StreamMessage batch) { if (synctime > this.lastSyncTime.entries[partitionIndex].value) // move time forward { - ProcessCurrentTimestamp(partitionIndex); + this.ProcessCurrentTimestamp(partitionIndex); this.lastSyncTime.entries[partitionIndex].value = synctime; } } - OnLowWatermark(synctime); + this.OnLowWatermark(synctime); } else if (src_vother[i] == PartitionedStreamEvent.PunctuationOtherTime) { var partitionKey = this.getPartitionKey(srckey[i]); - int partitionIndex = EnsurePartition(partitionKey); + int partitionIndex = this.EnsurePartition(partitionKey); long synctime = src_vsync[i]; if (synctime > this.lastSyncTime.entries[partitionIndex].value) // move time forward { - ProcessCurrentTimestamp(partitionIndex); + this.ProcessCurrentTimestamp(partitionIndex); this.lastSyncTime.entries[partitionIndex].value = synctime; } } diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/Afa/CompiledPartitionedAfaPipe_MultiEvent.cs b/Sources/Core/Microsoft.StreamProcessing/Operators/Afa/CompiledPartitionedAfaPipe_MultiEvent.cs index 104f6e8ea..a1e359c95 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/Afa/CompiledPartitionedAfaPipe_MultiEvent.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/Afa/CompiledPartitionedAfaPipe_MultiEvent.cs @@ -21,9 +21,9 @@ internal sealed class CompiledPartitionedAfaPipe_MultiEvent> keyHeads = new FastDictionary2>(); + private FastDictionary2> keyHeads = new(); [DataMember] - private FastDictionary2 lastSyncTime = new FastDictionary2(); + private FastDictionary2 lastSyncTime = new(); [Obsolete("Used only by serialization. Do not call directly.")] public CompiledPartitionedAfaPipe_MultiEvent() { } @@ -75,7 +75,7 @@ private void ProcessCurrentTimestamp(int partitionIndex) this.iter++; if (this.iter == Config.DataBatchSize) - FlushContents(); + this.FlushContents(); } if (this.hasOutgoingArcs[state2.toState]) @@ -111,13 +111,13 @@ public override unsafe void OnNext(StreamMessage batch) if ((src_bv[i >> 6] & (1L << (i & 0x3f))) == 0) { var partitionKey = this.getPartitionKey(srckey[i]); - int partitionIndex = EnsurePartition(partitionKey); + int partitionIndex = this.EnsurePartition(partitionKey); long synctime = src_vsync[i]; if (synctime > this.lastSyncTime.entries[partitionIndex].value) // move time forward { - ProcessCurrentTimestamp(partitionIndex); + this.ProcessCurrentTimestamp(partitionIndex); this.lastSyncTime.entries[partitionIndex].value = synctime; } @@ -255,23 +255,23 @@ public override unsafe void OnNext(StreamMessage batch) { if (synctime > this.lastSyncTime.entries[partitionIndex].value) // move time forward { - ProcessCurrentTimestamp(partitionIndex); + this.ProcessCurrentTimestamp(partitionIndex); this.lastSyncTime.entries[partitionIndex].value = synctime; } } - OnLowWatermark(synctime); + this.OnLowWatermark(synctime); } else if (src_vother[i] == PartitionedStreamEvent.PunctuationOtherTime) { var partitionKey = this.getPartitionKey(srckey[i]); - int partitionIndex = EnsurePartition(partitionKey); + int partitionIndex = this.EnsurePartition(partitionKey); long synctime = src_vsync[i]; if (synctime > this.lastSyncTime.entries[partitionIndex].value) // move time forward { - ProcessCurrentTimestamp(partitionIndex); + this.ProcessCurrentTimestamp(partitionIndex); this.lastSyncTime.entries[partitionIndex].value = synctime; } } diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/Afa/CompiledPartitionedAfaPipe_MultiEventList.cs b/Sources/Core/Microsoft.StreamProcessing/Operators/Afa/CompiledPartitionedAfaPipe_MultiEventList.cs index 6ac7977da..e7147c5be 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/Afa/CompiledPartitionedAfaPipe_MultiEventList.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/Afa/CompiledPartitionedAfaPipe_MultiEventList.cs @@ -20,14 +20,14 @@ internal sealed class CompiledPartitionedAfaPipe_MultiEventList lastSyncTime = new FastDictionary2(); + private FastDictionary2 lastSyncTime = new(); [DataMember] - private FastDictionary2>> currentTimestampEventList = new FastDictionary2>>(); + private FastDictionary2>> currentTimestampEventList = new(); private FastMap>.FindTraverser activeFindTraverser; // Field instead of local variable to avoid re-initializing it - private readonly Stack stack = new Stack(); + private readonly Stack stack = new(); [Obsolete("Used only by serialization. Do not call directly.")] public CompiledPartitionedAfaPipe_MultiEventList() { } @@ -110,7 +110,7 @@ private void ProcessCurrentTimestamp(int partitionIndex) this.batch.hash.col[this.iter] = el_hash; this.iter++; - if (this.iter == Config.DataBatchSize) FlushContents(); + if (this.iter == Config.DataBatchSize) this.FlushContents(); } if (this.hasOutgoingArcs[ns]) @@ -187,7 +187,7 @@ private void ProcessCurrentTimestamp(int partitionIndex) this.batch.hash.col[this.iter] = el_hash; this.iter++; - if (this.iter == Config.DataBatchSize) FlushContents(); + if (this.iter == Config.DataBatchSize) this.FlushContents(); } if (this.hasOutgoingArcs[ns]) @@ -272,7 +272,7 @@ private void ProcessCurrentTimestamp(int partitionIndex) this.batch.hash.col[this.iter] = el_hash; this.iter++; - if (this.iter == Config.DataBatchSize) FlushContents(); + if (this.iter == Config.DataBatchSize) this.FlushContents(); } if (this.hasOutgoingArcs[ns]) @@ -373,7 +373,7 @@ private void ProcessCurrentTimestamp(int partitionIndex) this.batch.hash.col[this.iter] = el_hash; this.iter++; - if (this.iter == Config.DataBatchSize) FlushContents(); + if (this.iter == Config.DataBatchSize) this.FlushContents(); } if (this.hasOutgoingArcs[ns]) { @@ -431,7 +431,7 @@ private void ProcessCurrentTimestamp(int partitionIndex) this.batch.hash.col[this.iter] = el_hash; this.iter++; - if (this.iter == Config.DataBatchSize) FlushContents(); + if (this.iter == Config.DataBatchSize) this.FlushContents(); } if (this.hasOutgoingArcs[ns]) { @@ -496,7 +496,7 @@ private void ProcessCurrentTimestamp(int partitionIndex) this.batch.hash.col[this.iter] = el_hash; this.iter++; - if (this.iter == Config.DataBatchSize) FlushContents(); + if (this.iter == Config.DataBatchSize) this.FlushContents(); } if (this.hasOutgoingArcs[ns]) { @@ -549,7 +549,7 @@ public override unsafe void OnNext(StreamMessage batch) if ((src_bv[i >> 6] & (1L << (i & 0x3f))) == 0) { var partitionKey = this.getPartitionKey(srckey[i]); - int partitionIndex = EnsurePartition(partitionKey); + int partitionIndex = this.EnsurePartition(partitionKey); long synctime = src_vsync[i]; @@ -557,7 +557,7 @@ public override unsafe void OnNext(StreamMessage batch) if (synctime > this.lastSyncTime.entries[partitionIndex].value) // move time forward { - ProcessCurrentTimestamp(partitionIndex); + this.ProcessCurrentTimestamp(partitionIndex); this.lastSyncTime.entries[partitionIndex].value = synctime; } @@ -600,23 +600,23 @@ public override unsafe void OnNext(StreamMessage batch) { if (synctime > this.lastSyncTime.entries[partitionIndex].value) // move time forward { - ProcessCurrentTimestamp(partitionIndex); + this.ProcessCurrentTimestamp(partitionIndex); this.lastSyncTime.entries[partitionIndex].value = synctime; } } - OnLowWatermark(synctime); + this.OnLowWatermark(synctime); } else if (src_vother[i] == PartitionedStreamEvent.PunctuationOtherTime) { var partitionKey = this.getPartitionKey(srckey[i]); - int partitionIndex = EnsurePartition(partitionKey); + int partitionIndex = this.EnsurePartition(partitionKey); long synctime = src_vsync[i]; if (synctime > this.lastSyncTime.entries[partitionIndex].value) // move time forward { - ProcessCurrentTimestamp(partitionIndex); + this.ProcessCurrentTimestamp(partitionIndex); this.lastSyncTime.entries[partitionIndex].value = synctime; } } diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/Afa/CompiledPartitionedAfaPipe_SingleEvent.cs b/Sources/Core/Microsoft.StreamProcessing/Operators/Afa/CompiledPartitionedAfaPipe_SingleEvent.cs index 14d721791..9f3473884 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/Afa/CompiledPartitionedAfaPipe_SingleEvent.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/Afa/CompiledPartitionedAfaPipe_SingleEvent.cs @@ -16,7 +16,7 @@ internal sealed class CompiledPartitionedAfaPipe_SingleEvent getPartitionKey = GetPartitionExtractor(); [DataMember] - private FastMap> activeStates = new FastMap>(); + private FastMap> activeStates = new(); [DataMember] private FastDictionary2 seenEvent; @@ -24,7 +24,7 @@ internal sealed class CompiledPartitionedAfaPipe_SingleEvent>> tentativeOutput; [DataMember] - private FastDictionary2 lastSyncTime = new FastDictionary2(); + private FastDictionary2 lastSyncTime = new(); [Obsolete("Used only by serialization. Do not call directly.")] public CompiledPartitionedAfaPipe_SingleEvent() { } @@ -69,7 +69,7 @@ public override unsafe void OnNext(StreamMessage batch) { var key = srckey[i]; var partitionKey = this.getPartitionKey(key); - int partitionIndex = EnsurePartition(partitionKey); + int partitionIndex = this.EnsurePartition(partitionKey); long synctime = src_vsync[i]; if (!this.IsSyncTimeSimultaneityFree) @@ -98,7 +98,7 @@ public override unsafe void OnNext(StreamMessage batch) if (this.iter == Config.DataBatchSize) { - FlushContents(); + this.FlushContents(); dest_vsync = this.batch.vsync.col; dest_vother = this.batch.vother.col; destkey = this.batch.key.col; @@ -210,7 +210,7 @@ public override unsafe void OnNext(StreamMessage batch) if (this.iter == Config.DataBatchSize) { - FlushContents(); + this.FlushContents(); dest_vsync = this.batch.vsync.col; dest_vother = this.batch.vother.col; destkey = this.batch.key.col; @@ -318,7 +318,7 @@ public override unsafe void OnNext(StreamMessage batch) if (this.iter == Config.DataBatchSize) { - FlushContents(); + this.FlushContents(); dest_vsync = this.batch.vsync.col; dest_vother = this.batch.vother.col; destkey = this.batch.key.col; @@ -411,7 +411,7 @@ public override unsafe void OnNext(StreamMessage batch) if (this.iter == Config.DataBatchSize) { - FlushContents(); + this.FlushContents(); dest_vsync = this.batch.vsync.col; dest_vother = this.batch.vother.col; destkey = this.batch.key.col; @@ -428,7 +428,7 @@ public override unsafe void OnNext(StreamMessage batch) } // Update dest_* on low watermark in case this event will hit the batch boundary and allocate a new batch - OnLowWatermark(synctime); + this.OnLowWatermark(synctime); dest_vsync = this.batch.vsync.col; dest_vother = this.batch.vother.col; @@ -443,7 +443,7 @@ public override unsafe void OnNext(StreamMessage batch) if (!this.IsSyncTimeSimultaneityFree) { var partitionKey = this.getPartitionKey(key); - int partitionIndex = EnsurePartition(partitionKey); + int partitionIndex = this.EnsurePartition(partitionKey); if (synctime > this.lastSyncTime.entries[partitionIndex].value) // move time forward { @@ -467,7 +467,7 @@ public override unsafe void OnNext(StreamMessage batch) if (this.iter == Config.DataBatchSize) { - FlushContents(); + this.FlushContents(); dest_vsync = this.batch.vsync.col; dest_vother = this.batch.vother.col; destkey = this.batch.key.col; @@ -492,7 +492,7 @@ public override unsafe void OnNext(StreamMessage batch) if (this.iter == Config.DataBatchSize) { - FlushContents(); + this.FlushContents(); dest_vsync = this.batch.vsync.col; dest_vother = this.batch.vother.col; destkey = this.batch.key.col; diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/Afa/CompiledUngroupedAfaPipe_EventList.cs b/Sources/Core/Microsoft.StreamProcessing/Operators/Afa/CompiledUngroupedAfaPipe_EventList.cs index 27c6af00c..972df48d5 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/Afa/CompiledUngroupedAfaPipe_EventList.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/Afa/CompiledUngroupedAfaPipe_EventList.cs @@ -25,7 +25,7 @@ internal sealed class CompiledUngroupedAfaPipe_EventList stack = new Stack(); + private readonly Stack stack = new(); [Obsolete("Used only by serialization. Do not call directly.")] public CompiledUngroupedAfaPipe_EventList() { } @@ -36,7 +36,7 @@ public CompiledUngroupedAfaPipe_EventList(Streamable stream, I this.activeStates = new FastLinkedList>(); this.activeStatesTraverser = new FastLinkedList>.ListTraverser(this.activeStates); - this.currentList = new List(); + this.currentList = []; this.lastSyncTime = -1; } @@ -89,7 +89,7 @@ private void ProcessCurrentTimestamp() this.batch.hash.col[this.iter] = 0; this.iter++; - if (this.iter == Config.DataBatchSize) FlushContents(); + if (this.iter == Config.DataBatchSize) this.FlushContents(); } if (this.hasOutgoingArcs[ns]) @@ -147,7 +147,7 @@ private void ProcessCurrentTimestamp() this.batch.hash.col[this.iter] = 0; this.iter++; - if (this.iter == Config.DataBatchSize) FlushContents(); + if (this.iter == Config.DataBatchSize) this.FlushContents(); } if (this.hasOutgoingArcs[ns]) @@ -218,7 +218,7 @@ private void ProcessCurrentTimestamp() this.batch.hash.col[this.iter] = 0; this.iter++; - if (this.iter == Config.DataBatchSize) FlushContents(); + if (this.iter == Config.DataBatchSize) this.FlushContents(); } if (this.hasOutgoingArcs[ns]) { @@ -271,7 +271,7 @@ private void ProcessCurrentTimestamp() this.batch.hash.col[this.iter] = 0; this.iter++; - if (this.iter == Config.DataBatchSize) FlushContents(); + if (this.iter == Config.DataBatchSize) this.FlushContents(); } if (this.hasOutgoingArcs[ns]) { @@ -318,9 +318,9 @@ public override unsafe void OnNext(StreamMessage batch) if (synctime > this.lastSyncTime) // move time forward { - ProcessCurrentTimestamp(); + this.ProcessCurrentTimestamp(); this.lastSyncTime = synctime; - this.currentList = new List(); + this.currentList = []; } this.currentList.Add(batch.payload.col[i]); @@ -330,11 +330,11 @@ public override unsafe void OnNext(StreamMessage batch) long synctime = src_vsync[i]; if (synctime > this.lastSyncTime) // move time forward { - ProcessCurrentTimestamp(); + this.ProcessCurrentTimestamp(); this.lastSyncTime = synctime; } - OnPunctuation(synctime); + this.OnPunctuation(synctime); } } } diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/Afa/CompiledUngroupedAfaPipe_MultiEventList.cs b/Sources/Core/Microsoft.StreamProcessing/Operators/Afa/CompiledUngroupedAfaPipe_MultiEventList.cs index 1cff60c47..990df72a0 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/Afa/CompiledUngroupedAfaPipe_MultiEventList.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/Afa/CompiledUngroupedAfaPipe_MultiEventList.cs @@ -17,13 +17,13 @@ internal sealed class CompiledUngroupedAfaPipe_MultiEventList> activeStates; [DataMember] - private List currentTimestampEventList = new List(); + private List currentTimestampEventList = []; [DataMember] private long lastSyncTime; // Field instead of local variable to avoid re-initializing it - private readonly Stack stack = new Stack(); + private readonly Stack stack = new(); private FastLinkedList>.ListTraverser activeStatesTraverser; @@ -98,7 +98,7 @@ private void ProcessCurrentTimestamp() this.batch.hash.col[this.iter] = 0; this.iter++; - if (this.iter == Config.DataBatchSize) FlushContents(); + if (this.iter == Config.DataBatchSize) this.FlushContents(); } if (this.hasOutgoingArcs[ns]) @@ -158,7 +158,7 @@ private void ProcessCurrentTimestamp() this.batch.hash.col[this.iter] = 0; this.iter++; - if (this.iter == Config.DataBatchSize) FlushContents(); + if (this.iter == Config.DataBatchSize) this.FlushContents(); } if (this.hasOutgoingArcs[ns]) @@ -226,7 +226,7 @@ private void ProcessCurrentTimestamp() this.batch.hash.col[this.iter] = 0; this.iter++; - if (this.iter == Config.DataBatchSize) FlushContents(); + if (this.iter == Config.DataBatchSize) this.FlushContents(); } if (this.hasOutgoingArcs[ns]) @@ -305,7 +305,7 @@ private void ProcessCurrentTimestamp() this.batch.hash.col[this.iter] = 0; this.iter++; - if (this.iter == Config.DataBatchSize) FlushContents(); + if (this.iter == Config.DataBatchSize) this.FlushContents(); } if (this.hasOutgoingArcs[ns]) { @@ -361,7 +361,7 @@ private void ProcessCurrentTimestamp() this.batch.hash.col[this.iter] = 0; this.iter++; - if (this.iter == Config.DataBatchSize) FlushContents(); + if (this.iter == Config.DataBatchSize) this.FlushContents(); } if (this.hasOutgoingArcs[ns]) { @@ -424,7 +424,7 @@ private void ProcessCurrentTimestamp() this.batch.hash.col[this.iter] = 0; this.iter++; - if (this.iter == Config.DataBatchSize) FlushContents(); + if (this.iter == Config.DataBatchSize) this.FlushContents(); } if (this.hasOutgoingArcs[ns]) { @@ -473,11 +473,11 @@ public override unsafe void OnNext(StreamMessage batch) if (synctime > this.lastSyncTime) // move time forward { - ProcessCurrentTimestamp(); + this.ProcessCurrentTimestamp(); this.lastSyncTime = synctime; } - if (batch.vother.col[i] < 0) OnPunctuation(synctime); + if (batch.vother.col[i] < 0) this.OnPunctuation(synctime); else this.currentTimestampEventList.Add(batch.payload.col[i]); } diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/Afa/CompiledUngroupedAfaPipe_SingleEvent.cs b/Sources/Core/Microsoft.StreamProcessing/Operators/Afa/CompiledUngroupedAfaPipe_SingleEvent.cs index 29dfe5a66..18b3837bb 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/Afa/CompiledUngroupedAfaPipe_SingleEvent.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/Afa/CompiledUngroupedAfaPipe_SingleEvent.cs @@ -88,7 +88,7 @@ public override unsafe void OnNext(StreamMessage batch) if (this.iter == Config.DataBatchSize) { - FlushContents(); + this.FlushContents(); dest_vsync = this.batch.vsync.col; dest_vother = this.batch.vother.col; destkey = this.batch.key.col; @@ -176,7 +176,7 @@ public override unsafe void OnNext(StreamMessage batch) if (this.iter == Config.DataBatchSize) { - FlushContents(); + this.FlushContents(); dest_vsync = this.batch.vsync.col; dest_vother = this.batch.vother.col; destkey = this.batch.key.col; @@ -257,7 +257,7 @@ public override unsafe void OnNext(StreamMessage batch) if (this.iter == Config.DataBatchSize) { - FlushContents(); + this.FlushContents(); dest_vsync = this.batch.vsync.col; dest_vother = this.batch.vother.col; destkey = this.batch.key.col; @@ -316,7 +316,7 @@ public override unsafe void OnNext(StreamMessage batch) if (this.iter == Config.DataBatchSize) { - FlushContents(); + this.FlushContents(); dest_vsync = this.batch.vsync.col; dest_vother = this.batch.vother.col; destkey = this.batch.key.col; @@ -332,7 +332,7 @@ public override unsafe void OnNext(StreamMessage batch) } // Update dest_* on punctuation in case this event will hit the batch boundary and allocate a new batch - OnPunctuation(synctime); + this.OnPunctuation(synctime); dest_vsync = this.batch.vsync.col; dest_vother = this.batch.vother.col; diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/Afa/CompiledUngroupedDAfaPipe_SingleEvent.cs b/Sources/Core/Microsoft.StreamProcessing/Operators/Afa/CompiledUngroupedDAfaPipe_SingleEvent.cs index 7aee9386a..0b43eac43 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/Afa/CompiledUngroupedDAfaPipe_SingleEvent.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/Afa/CompiledUngroupedDAfaPipe_SingleEvent.cs @@ -93,7 +93,7 @@ public override unsafe void OnNext(StreamMessage batch) if (this.iter == Config.DataBatchSize) { - FlushContents(); + this.FlushContents(); dest_vsync = this.batch.vsync.col; dest_vother = this.batch.vother.col; destkey = this.batch.key.col; @@ -171,7 +171,7 @@ public override unsafe void OnNext(StreamMessage batch) if (this.iter == Config.DataBatchSize) { - FlushContents(); + this.FlushContents(); dest_vsync = this.batch.vsync.col; dest_vother = this.batch.vother.col; destkey = this.batch.key.col; @@ -234,7 +234,7 @@ public override unsafe void OnNext(StreamMessage batch) if (this.iter == Config.DataBatchSize) { - FlushContents(); + this.FlushContents(); dest_vsync = this.batch.vsync.col; dest_vother = this.batch.vother.col; destkey = this.batch.key.col; @@ -281,7 +281,7 @@ public override unsafe void OnNext(StreamMessage batch) if (this.iter == Config.DataBatchSize) { - FlushContents(); + this.FlushContents(); dest_vsync = this.batch.vsync.col; dest_vother = this.batch.vother.col; destkey = this.batch.key.col; @@ -297,7 +297,7 @@ public override unsafe void OnNext(StreamMessage batch) } // Update dest_* on punctuation in case this event will hit the batch boundary and allocate a new batch - OnPunctuation(synctime); + this.OnPunctuation(synctime); dest_vsync = this.batch.vsync.col; dest_vother = this.batch.vother.col; diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/Afa/GroupedAfaEventListTransformer.cs b/Sources/Core/Microsoft.StreamProcessing/Operators/Afa/GroupedAfaEventListTransformer.cs index a3856188d..2abc59fb3 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/Afa/GroupedAfaEventListTransformer.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/Afa/GroupedAfaEventListTransformer.cs @@ -32,8 +32,8 @@ private GroupedAfaEventListTemplate(string className, Type keyType, Type payload internal static Tuple GenerateAFA( AfaStreamable stream) { - Contract.Requires(stream != null); - Contract.Ensures(Contract.Result>() == null || typeof(UnaryPipe).GetTypeInfo().IsAssignableFrom(Contract.Result>().Item1)); + ArgumentNullException.ThrowIfNull(stream); + Contract.Ensures(Contract.Result>() == null || typeof(UnaryPipe).IsAssignableFrom(Contract.Result>().Item1)); var className = $"GeneratedGroupedAfaEventList_{AFASequenceNumber++}"; var template = new GroupedAfaEventListTemplate(className, typeof(TKey), typeof(TPayload), typeof(TRegister), typeof(TAccumulator)) diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/Afa/GroupedAfaMultiEventTransformer.cs b/Sources/Core/Microsoft.StreamProcessing/Operators/Afa/GroupedAfaMultiEventTransformer.cs index d7c440689..11f0a6991 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/Afa/GroupedAfaMultiEventTransformer.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/Afa/GroupedAfaMultiEventTransformer.cs @@ -13,8 +13,8 @@ namespace Microsoft.StreamProcessing internal partial class GroupedAfaMultiEventTemplate : AfaTemplate { private Func keyEqualityComparer; - protected readonly List>> edgeInfos = new List>>(); - protected readonly List>> startEdgeInfos = new List>>(); + protected readonly List>> edgeInfos = []; + protected readonly List>> startEdgeInfos = []; private GroupedAfaMultiEventTemplate(string className, Type keyType, Type payloadType, Type registerType, Type accumulatorType) : base(className, keyType, payloadType, registerType, accumulatorType) @@ -36,8 +36,8 @@ private GroupedAfaMultiEventTemplate(string className, Type keyType, Type payloa internal static Tuple GenerateAFA( AfaStreamable stream) { - Contract.Requires(stream != null); - Contract.Ensures(Contract.Result>() == null || typeof(UnaryPipe).GetTypeInfo().IsAssignableFrom(Contract.Result>().Item1)); + ArgumentNullException.ThrowIfNull(stream); + Contract.Ensures(Contract.Result>() == null || typeof(UnaryPipe).IsAssignableFrom(Contract.Result>().Item1)); var className = $"GeneratedGroupedAfaMultiEvent_{AFASequenceNumber++}"; var template = new GroupedAfaMultiEventTemplate(className, typeof(TKey), typeof(TPayload), typeof(TRegister), typeof(TAccumulator)) diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/Afa/GroupedAfaTransformer.cs b/Sources/Core/Microsoft.StreamProcessing/Operators/Afa/GroupedAfaTransformer.cs index fbb0c4f9b..f03961bcb 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/Afa/GroupedAfaTransformer.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/Afa/GroupedAfaTransformer.cs @@ -32,8 +32,8 @@ private GroupedAfaTemplate(string className, Type keyType, Type payloadType, Typ internal static Tuple GenerateAFA( AfaStreamable stream) { - Contract.Requires(stream != null); - Contract.Ensures(Contract.Result>() == null || typeof(UnaryPipe).GetTypeInfo().IsAssignableFrom(Contract.Result>().Item1)); + ArgumentNullException.ThrowIfNull(stream); + Contract.Ensures(Contract.Result>() == null || typeof(UnaryPipe).IsAssignableFrom(Contract.Result>().Item1)); var className = $"GeneratedGroupedAfa_{AFASequenceNumber++}"; var template = new GroupedAfaTemplate(className, typeof(TKey), typeof(TPayload), typeof(TRegister), typeof(TAccumulator)) diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/Afa/PatternMatcher.cs b/Sources/Core/Microsoft.StreamProcessing/Operators/Afa/PatternMatcher.cs index d51811853..3cb03ae13 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/Afa/PatternMatcher.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/Afa/PatternMatcher.cs @@ -35,59 +35,59 @@ public IPattern SingleElement(Expressio afa.AddArc(0, 1, new SingleElementArc { Fence = condition, Transfer = aggregator }); afa.Seal(); - return Concat(x => new PatternMatcher(this.source, afa)); + return this.Concat(x => new PatternMatcher(this.source, afa)); } public IPattern SingleElement(Expression> condition, Expression> aggregator) { Expression> aggregatorTemplate = (ts, ev, r) => CallInliner.Call(aggregator, ev, r); - return SingleElement(condition, aggregatorTemplate.InlineCalls()); + return this.SingleElement(condition, aggregatorTemplate.InlineCalls()); } public IPattern SingleElement(Expression> condition, Expression> aggregator) { Expression> aggregatorTemplate = (ts, ev, r) => CallInliner.Call(aggregator, ev); - return SingleElement(condition, aggregatorTemplate.InlineCalls()); + return this.SingleElement(condition, aggregatorTemplate.InlineCalls()); } public IPattern SingleElement(Expression> condition, Expression> aggregator = null) { Expression> conditionTemplate = (ts, ev, r) => CallInliner.Call(condition, ev, r); - return SingleElement(conditionTemplate.InlineCalls(), aggregator); + return this.SingleElement(conditionTemplate.InlineCalls(), aggregator); } public IPattern SingleElement(Expression> condition, Expression> aggregator) { Expression> conditionTemplate = (ts, ev, r) => CallInliner.Call(condition, ev, r); Expression> aggregatorTemplate = (ts, ev, r) => CallInliner.Call(aggregator, ev, r); - return SingleElement(conditionTemplate.InlineCalls(), aggregatorTemplate.InlineCalls()); + return this.SingleElement(conditionTemplate.InlineCalls(), aggregatorTemplate.InlineCalls()); } public IPattern SingleElement(Expression> condition, Expression> aggregator) { Expression> conditionTemplate = (ts, ev, r) => CallInliner.Call(condition, ev, r); Expression> aggregatorTemplate = (ts, ev, r) => CallInliner.Call(aggregator, ev); - return SingleElement(conditionTemplate.InlineCalls(), aggregatorTemplate.InlineCalls()); + return this.SingleElement(conditionTemplate.InlineCalls(), aggregatorTemplate.InlineCalls()); } public IPattern SingleElement(Expression> condition, Expression> aggregator = null) { Expression> conditionTemplate = (ts, ev, r) => CallInliner.Call(condition, ev); - return SingleElement(conditionTemplate.InlineCalls(), aggregator); + return this.SingleElement(conditionTemplate.InlineCalls(), aggregator); } public IPattern SingleElement(Expression> condition, Expression> aggregator) { Expression> conditionTemplate = (ts, ev, r) => CallInliner.Call(condition, ev); Expression> aggregatorTemplate = (ts, ev, r) => CallInliner.Call(aggregator, ev, r); - return SingleElement(conditionTemplate.InlineCalls(), aggregatorTemplate.InlineCalls()); + return this.SingleElement(conditionTemplate.InlineCalls(), aggregatorTemplate.InlineCalls()); } public IPattern SingleElement(Expression> condition, Expression> aggregator) { Expression> conditionTemplate = (ts, ev, r) => CallInliner.Call(condition, ev); Expression> aggregatorTemplate = (ts, ev, r) => CallInliner.Call(aggregator, ev); - return SingleElement(conditionTemplate.InlineCalls(), aggregatorTemplate.InlineCalls()); + return this.SingleElement(conditionTemplate.InlineCalls(), aggregatorTemplate.InlineCalls()); } #endregion @@ -98,59 +98,59 @@ public IPattern ListElement(Expression< afa.AddArc(0, 1, new ListElementArc { Fence = condition, Transfer = aggregator }); afa.Seal(); - return Concat(x => new PatternMatcher(this.source, afa)); + return this.Concat(x => new PatternMatcher(this.source, afa)); } public IPattern ListElement(Expression, TRegister, bool>> condition, Expression, TRegister, TRegister>> aggregator) { Expression, TRegister, TRegister>> aggregatorTemplate = (ts, ev, r) => CallInliner.Call(aggregator, ev, r); - return ListElement(condition, aggregatorTemplate.InlineCalls()); + return this.ListElement(condition, aggregatorTemplate.InlineCalls()); } public IPattern ListElement(Expression, TRegister, bool>> condition, Expression, TRegister>> aggregator) { Expression, TRegister, TRegister>> aggregatorTemplate = (ts, ev, r) => CallInliner.Call(aggregator, ev); - return ListElement(condition, aggregatorTemplate.InlineCalls()); + return this.ListElement(condition, aggregatorTemplate.InlineCalls()); } public IPattern ListElement(Expression, TRegister, bool>> condition, Expression, TRegister, TRegister>> aggregator = null) { Expression, TRegister, bool>> conditionTemplate = (ts, ev, r) => CallInliner.Call(condition, ev, r); - return ListElement(conditionTemplate.InlineCalls(), aggregator); + return this.ListElement(conditionTemplate.InlineCalls(), aggregator); } public IPattern ListElement(Expression, TRegister, bool>> condition, Expression, TRegister, TRegister>> aggregator) { Expression, TRegister, bool>> conditionTemplate = (ts, ev, r) => CallInliner.Call(condition, ev, r); Expression, TRegister, TRegister>> aggregatorTemplate = (ts, ev, r) => CallInliner.Call(aggregator, ev, r); - return ListElement(conditionTemplate.InlineCalls(), aggregatorTemplate.InlineCalls()); + return this.ListElement(conditionTemplate.InlineCalls(), aggregatorTemplate.InlineCalls()); } public IPattern ListElement(Expression, TRegister, bool>> condition, Expression, TRegister>> aggregator) { Expression, TRegister, bool>> conditionTemplate = (ts, ev, r) => CallInliner.Call(condition, ev, r); Expression, TRegister, TRegister>> aggregatorTemplate = (ts, ev, r) => CallInliner.Call(aggregator, ev); - return ListElement(conditionTemplate.InlineCalls(), aggregatorTemplate.InlineCalls()); + return this.ListElement(conditionTemplate.InlineCalls(), aggregatorTemplate.InlineCalls()); } public IPattern ListElement(Expression, bool>> condition, Expression, TRegister, TRegister>> aggregator = null) { Expression, TRegister, bool>> conditionTemplate = (ts, ev, r) => CallInliner.Call(condition, ev); - return ListElement(conditionTemplate.InlineCalls(), aggregator); + return this.ListElement(conditionTemplate.InlineCalls(), aggregator); } public IPattern ListElement(Expression, bool>> condition, Expression, TRegister, TRegister>> aggregator) { Expression, TRegister, bool>> conditionTemplate = (ts, ev, r) => CallInliner.Call(condition, ev); Expression, TRegister, TRegister>> aggregatorTemplate = (ts, ev, r) => CallInliner.Call(aggregator, ev, r); - return ListElement(conditionTemplate.InlineCalls(), aggregatorTemplate.InlineCalls()); + return this.ListElement(conditionTemplate.InlineCalls(), aggregatorTemplate.InlineCalls()); } public IPattern ListElement(Expression, bool>> condition, Expression, TRegister>> aggregator) { Expression, TRegister, bool>> conditionTemplate = (ts, ev, r) => CallInliner.Call(condition, ev); Expression, TRegister, TRegister>> aggregatorTemplate = (ts, ev, r) => CallInliner.Call(aggregator, ev); - return ListElement(conditionTemplate.InlineCalls(), aggregatorTemplate.InlineCalls()); + return this.ListElement(conditionTemplate.InlineCalls(), aggregatorTemplate.InlineCalls()); } #endregion @@ -161,7 +161,7 @@ public IPattern Epsilon() afa.AddArc(0, 1, new EpsilonArc { }); afa.Seal(); - return Concat(x => new PatternMatcher(this.source, afa)); + return this.Concat(x => new PatternMatcher(this.source, afa)); } #endregion @@ -180,7 +180,7 @@ public IPattern MultiElement(Expression }); afa.Seal(); - return Concat(x => new PatternMatcher(this.source, afa)); + return this.Concat(x => new PatternMatcher(this.source, afa)); } #endregion @@ -212,11 +212,11 @@ public IPattern KleeneStar( result.finalStates.Add(pattern_.StartState); result.StartState = pattern_.StartState; - return Concat(x => new PatternMatcher(this.source, result)); + return this.Concat(x => new PatternMatcher(this.source, result)); } public IPattern KleenePlus(Func, IPattern> pattern) - => Concat(pattern, x => x.KleeneStar(pattern)); + => this.Concat(pattern, x => x.KleeneStar(pattern)); public IPattern Concat( Func, IPattern> pattern, @@ -248,7 +248,7 @@ public IPattern OrConcat( var result = ConcatWorker(true, afa1, afa2, afa); - return Concat(x => new PatternMatcher(this.source, result)); + return this.Concat(x => new PatternMatcher(this.source, result)); } public IPattern Or( @@ -301,7 +301,7 @@ public IPattern Or( } result.StartState = 0; - return Concat(x => new PatternMatcher(this.source, result)); + return this.Concat(x => new PatternMatcher(this.source, result)); } #endregion diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/Afa/UngroupedAfaTransformer.cs b/Sources/Core/Microsoft.StreamProcessing/Operators/Afa/UngroupedAfaTransformer.cs index 367120014..b44173902 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/Afa/UngroupedAfaTransformer.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/Afa/UngroupedAfaTransformer.cs @@ -30,8 +30,8 @@ private UngroupedAfaTemplate(string className, Type payloadType, Type registerTy internal static Tuple GenerateAFA( AfaStreamable stream) { - Contract.Requires(stream != null); - Contract.Ensures(Contract.Result>() == null || typeof(UnaryPipe).GetTypeInfo().IsAssignableFrom(Contract.Result>().Item1)); + ArgumentNullException.ThrowIfNull(stream); + Contract.Ensures(Contract.Result>() == null || typeof(UnaryPipe).IsAssignableFrom(Contract.Result>().Item1)); var className = $"GeneratedUngroupedAfa_{AFASequenceNumber++}"; var template = new UngroupedAfaTemplate(className, typeof(TPayload), typeof(TRegister), typeof(TAccumulator)) diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/Afa/UngroupedDAfaTransformer.cs b/Sources/Core/Microsoft.StreamProcessing/Operators/Afa/UngroupedDAfaTransformer.cs index 15be7528e..b6656f55e 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/Afa/UngroupedDAfaTransformer.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/Afa/UngroupedDAfaTransformer.cs @@ -30,8 +30,8 @@ private UngroupedDAfaTemplate(string className, Type payloadType, Type registerT internal static Tuple GenerateAFA( AfaStreamable stream) { - Contract.Requires(stream != null); - Contract.Ensures(Contract.Result>() == null || typeof(UnaryPipe).GetTypeInfo().IsAssignableFrom(Contract.Result>().Item1)); + ArgumentNullException.ThrowIfNull(stream); + Contract.Ensures(Contract.Result>() == null || typeof(UnaryPipe).IsAssignableFrom(Contract.Result>().Item1)); var className = $"GeneratedUngroupedDAfa_{AFASequenceNumber++}"; var template = new UngroupedDAfaTemplate(className, typeof(TPayload), typeof(TRegister), typeof(TAccumulator)) diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/AlterLifetime/AlterLifetimeConstantDurationPipe.cs b/Sources/Core/Microsoft.StreamProcessing/Operators/AlterLifetime/AlterLifetimeConstantDurationPipe.cs index 4e7ab31f9..4bc8cc478 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/AlterLifetime/AlterLifetimeConstantDurationPipe.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/AlterLifetime/AlterLifetimeConstantDurationPipe.cs @@ -33,7 +33,7 @@ public AlterLifetimeConstantDurationPipe() { } public AlterLifetimeConstantDurationPipe(AlterLifetimeStreamable stream, IStreamObserver observer) : base(stream, observer) { - Contract.Requires(stream != null); + ArgumentNullException.ThrowIfNull(stream); this.constantDurationSelector = (long)((ConstantExpression)stream.DurationSelector.Body).Value; this.startTimeSelector = (Expression>)stream.StartTimeSelector; diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/AlterLifetime/AlterLifetimeConstantDurationStatelessPipe.cs b/Sources/Core/Microsoft.StreamProcessing/Operators/AlterLifetime/AlterLifetimeConstantDurationStatelessPipe.cs index f36831f80..e3ffaef0c 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/AlterLifetime/AlterLifetimeConstantDurationStatelessPipe.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/AlterLifetime/AlterLifetimeConstantDurationStatelessPipe.cs @@ -26,7 +26,7 @@ public AlterLifetimeConstantDurationStatelessPipe() { } public AlterLifetimeConstantDurationStatelessPipe(AlterLifetimeStreamable stream, IStreamObserver observer) : base(stream, observer) { - Contract.Requires(stream != null); + ArgumentNullException.ThrowIfNull(stream); this.constantDurationSelector = (long)((ConstantExpression)stream.DurationSelector.Body).Value; this.pool = MemoryManager.GetMemoryPool(stream.Properties.IsColumnar); diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/AlterLifetime/AlterLifetimeStartDependentDurationPipe.cs b/Sources/Core/Microsoft.StreamProcessing/Operators/AlterLifetime/AlterLifetimeStartDependentDurationPipe.cs index 3c292b622..fa03c80a9 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/AlterLifetime/AlterLifetimeStartDependentDurationPipe.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/AlterLifetime/AlterLifetimeStartDependentDurationPipe.cs @@ -34,7 +34,7 @@ public AlterLifetimeStartDependentDurationPipe() { } public AlterLifetimeStartDependentDurationPipe(AlterLifetimeStreamable stream, IStreamObserver observer) : base(stream, observer) { - Contract.Requires(stream != null); + ArgumentNullException.ThrowIfNull(stream); this.startTimeDurationSelector = (Expression>)stream.DurationSelector; this.startTimeDurationSelectorCompiled = this.startTimeDurationSelector.Compile(); diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/AlterLifetime/AlterLifetimeStartDependentDurationStatelessPipe.cs b/Sources/Core/Microsoft.StreamProcessing/Operators/AlterLifetime/AlterLifetimeStartDependentDurationStatelessPipe.cs index a6246d6f3..c7f9f4cc7 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/AlterLifetime/AlterLifetimeStartDependentDurationStatelessPipe.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/AlterLifetime/AlterLifetimeStartDependentDurationStatelessPipe.cs @@ -27,7 +27,7 @@ public AlterLifetimeStartDependentDurationStatelessPipe() { } public AlterLifetimeStartDependentDurationStatelessPipe(AlterLifetimeStreamable stream, IStreamObserver observer) : base(stream, observer) { - Contract.Requires(stream != null); + ArgumentNullException.ThrowIfNull(stream); this.startTimeDurationSelector = (Expression>)stream.DurationSelector; this.startTimeDurationSelectorCompiled = this.startTimeDurationSelector.Compile(); diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/AlterLifetime/AlterLifetimeStreamable.cs b/Sources/Core/Microsoft.StreamProcessing/Operators/AlterLifetime/AlterLifetimeStreamable.cs index 6025b53ba..34ee7e905 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/AlterLifetime/AlterLifetimeStreamable.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/AlterLifetime/AlterLifetimeStreamable.cs @@ -19,7 +19,7 @@ public AlterLifetimeStreamable( LambdaExpression durationSelector) : base(source, source.Properties.AlterLifetime(durationSelector)) { - Contract.Requires(source != null); + ArgumentNullException.ThrowIfNull(source); this.StartTimeSelector = startTimeSelector; this.DurationSelector = durationSelector; diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/AlterLifetime/AlterLifetimeVariableDurationPipe.cs b/Sources/Core/Microsoft.StreamProcessing/Operators/AlterLifetime/AlterLifetimeVariableDurationPipe.cs index 67bd6d294..68a910fbc 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/AlterLifetime/AlterLifetimeVariableDurationPipe.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/AlterLifetime/AlterLifetimeVariableDurationPipe.cs @@ -34,7 +34,7 @@ public AlterLifetimeVariableDurationPipe() { } public AlterLifetimeVariableDurationPipe(AlterLifetimeStreamable stream, IStreamObserver observer) : base(stream, observer) { - Contract.Requires(stream != null); + ArgumentNullException.ThrowIfNull(stream); this.durationSelector = (Expression>)stream.DurationSelector; this.startTimeSelector = (Expression>)stream.StartTimeSelector; diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/AlterLifetime/PartitionedAlterLifetimeConstantDurationPipe.cs b/Sources/Core/Microsoft.StreamProcessing/Operators/AlterLifetime/PartitionedAlterLifetimeConstantDurationPipe.cs index e0afe8ae5..1a75683d9 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/AlterLifetime/PartitionedAlterLifetimeConstantDurationPipe.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/AlterLifetime/PartitionedAlterLifetimeConstantDurationPipe.cs @@ -25,7 +25,7 @@ internal sealed class PartitionedAlterLifetimeConstantDurationPipe startTimeSelectorCompiled; [DataMember] - private FastDictionary lastSync = new FastDictionary(); + private FastDictionary lastSync = new(); private readonly Func getPartitionKey = GetPartitionExtractor(); @@ -35,7 +35,7 @@ public PartitionedAlterLifetimeConstantDurationPipe() { } public PartitionedAlterLifetimeConstantDurationPipe(AlterLifetimeStreamable stream, IStreamObserver observer) : base(stream, observer) { - Contract.Requires(stream != null); + ArgumentNullException.ThrowIfNull(stream); this.constantDurationSelector = (long)((ConstantExpression)stream.DurationSelector.Body).Value; this.startTimeSelector = (Expression>)stream.StartTimeSelector; @@ -144,6 +144,11 @@ public unsafe override void OnNext(StreamMessage batch) this.Observer.OnNext(batch); } + protected override void DisposeState() + { + this.lastSync.Dispose(); + } + public override int CurrentlyBufferedOutputCount => 0; public override int CurrentlyBufferedInputCount => 0; diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/AlterLifetime/PartitionedAlterLifetimeStartDependentDurationPipe.cs b/Sources/Core/Microsoft.StreamProcessing/Operators/AlterLifetime/PartitionedAlterLifetimeStartDependentDurationPipe.cs index b4da482ae..5e751b094 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/AlterLifetime/PartitionedAlterLifetimeStartDependentDurationPipe.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/AlterLifetime/PartitionedAlterLifetimeStartDependentDurationPipe.cs @@ -26,7 +26,7 @@ internal sealed class PartitionedAlterLifetimeStartDependentDurationPipe startTimeSelectorCompiled; [DataMember] - private FastDictionary lastSync = new FastDictionary(); + private FastDictionary lastSync = new(); private readonly Func getPartitionKey = GetPartitionExtractor(); @@ -36,7 +36,7 @@ public PartitionedAlterLifetimeStartDependentDurationPipe() { } public PartitionedAlterLifetimeStartDependentDurationPipe(AlterLifetimeStreamable stream, IStreamObserver observer) : base(stream, observer) { - Contract.Requires(stream != null); + ArgumentNullException.ThrowIfNull(stream); this.startTimeDurationSelector = (Expression>)stream.DurationSelector; this.startTimeDurationSelectorCompiled = this.startTimeDurationSelector.Compile(); @@ -144,6 +144,11 @@ public unsafe override void OnNext(StreamMessage batch) this.Observer.OnNext(batch); } + protected override void DisposeState() + { + this.lastSync.Dispose(); + } + public override int CurrentlyBufferedOutputCount => 0; public override int CurrentlyBufferedInputCount => 0; diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/AlterLifetime/PartitionedAlterLifetimeVariableDurationByKeyPipe.cs b/Sources/Core/Microsoft.StreamProcessing/Operators/AlterLifetime/PartitionedAlterLifetimeVariableDurationByKeyPipe.cs index 0aa0204d4..e7a07ae74 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/AlterLifetime/PartitionedAlterLifetimeVariableDurationByKeyPipe.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/AlterLifetime/PartitionedAlterLifetimeVariableDurationByKeyPipe.cs @@ -26,7 +26,7 @@ internal sealed class PartitionedAlterLifetimeVariableDurationByKeyPipe startTimeSelectorCompiled; [DataMember] - private FastDictionary lastSync = new FastDictionary(); + private FastDictionary lastSync = new(); [Obsolete("Used only by serialization. Do not call directly.")] public PartitionedAlterLifetimeVariableDurationByKeyPipe() { } @@ -34,7 +34,7 @@ public PartitionedAlterLifetimeVariableDurationByKeyPipe() { } public PartitionedAlterLifetimeVariableDurationByKeyPipe(AlterLifetimeStreamable, TPayload> stream, IStreamObserver, TPayload> observer) : base(stream, observer) { - Contract.Requires(stream != null); + ArgumentNullException.ThrowIfNull(stream); this.durationSelector = (Expression>)stream.DurationSelector; this.startTimeSelector = (Expression>)stream.StartTimeSelector; @@ -152,6 +152,11 @@ public unsafe override void OnNext(StreamMessage, TP this.Observer.OnNext(batch); } + protected override void DisposeState() + { + this.lastSync.Dispose(); + } + public override int CurrentlyBufferedOutputCount => 0; public override int CurrentlyBufferedInputCount => 0; diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/AlterLifetime/PartitionedAlterLifetimeVariableDurationPipe.cs b/Sources/Core/Microsoft.StreamProcessing/Operators/AlterLifetime/PartitionedAlterLifetimeVariableDurationPipe.cs index 60d436086..191edc624 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/AlterLifetime/PartitionedAlterLifetimeVariableDurationPipe.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/AlterLifetime/PartitionedAlterLifetimeVariableDurationPipe.cs @@ -28,7 +28,7 @@ internal sealed class PartitionedAlterLifetimeVariableDurationPipe getPartitionKey = GetPartitionExtractor(); [DataMember] - private FastDictionary lastSync = new FastDictionary(); + private FastDictionary lastSync = new(); [Obsolete("Used only by serialization. Do not call directly.")] public PartitionedAlterLifetimeVariableDurationPipe() { } @@ -36,7 +36,7 @@ public PartitionedAlterLifetimeVariableDurationPipe() { } public PartitionedAlterLifetimeVariableDurationPipe(AlterLifetimeStreamable stream, IStreamObserver observer) : base(stream, observer) { - Contract.Requires(stream != null); + ArgumentNullException.ThrowIfNull(stream); this.durationSelector = (Expression>)stream.DurationSelector; this.startTimeSelector = (Expression>)stream.StartTimeSelector; @@ -152,6 +152,11 @@ public unsafe override void OnNext(StreamMessage batch) this.Observer.OnNext(batch); } + protected override void DisposeState() + { + this.lastSync.Dispose(); + } + public override int CurrentlyBufferedOutputCount => 0; public override int CurrentlyBufferedInputCount => 0; diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/Beat/BeatPipe.cs b/Sources/Core/Microsoft.StreamProcessing/Operators/Beat/BeatPipe.cs index 32695b632..29a16fa0a 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/Beat/BeatPipe.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/Beat/BeatPipe.cs @@ -32,9 +32,9 @@ internal sealed class BeatPipe : UnaryPipe output; [DataMember] - private FastMap intervals = new FastMap(); + private FastMap intervals = new(); [DataMember] - private FastMap edges = new FastMap(); + private FastMap edges = new(); [DataMember] private long currBeatTime = long.MinValue; [DataMember] @@ -85,7 +85,7 @@ public override unsafe void OnNext(StreamMessage batch) long endTime = *sourceVOtherPtr; int hash = *sourceHashPtr; - AdvanceTime(startTime); + this.AdvanceTime(startTime); bool isPunctuation = endTime == long.MinValue; bool isInsert = startTime < endTime; @@ -93,12 +93,12 @@ public override unsafe void OnNext(StreamMessage batch) bool isEndEdge = !isInsert; if (isPunctuation) { - AddToBatch(startTime, long.MinValue, ref sourceKey[row], ref sourcePayload[row], hash); + this.AddToBatch(startTime, long.MinValue, ref sourceKey[row], ref sourcePayload[row], hash); } else if (isStartEdge) { // Add starting edge { vSync = startTime, vOther = StreamEvent.InfinitySyncTime }. - AddToBatch( + this.AddToBatch( startTime, StreamEvent.InfinitySyncTime, ref sourceKey[row], @@ -127,7 +127,7 @@ public override unsafe void OnNext(StreamMessage batch) if (edgeStartedBeforeLastBeat) { // Add closing edge { vSync = edgeEndTime, vOther = lastBeatTime }. - AddToBatch( + this.AddToBatch( edgeEndTime, lastBeatTime, ref sourceKey[row], @@ -137,7 +137,7 @@ public override unsafe void OnNext(StreamMessage batch) else { // Add closing edge { vSync = edgeEndTime, vOther = edgeStartTime }. - AddToBatch( + this.AddToBatch( edgeEndTime, edgeStartTime, ref sourceKey[row], @@ -151,7 +151,7 @@ public override unsafe void OnNext(StreamMessage batch) while (edgesTraversal.Next(out int index)) { var temp = this.edges.Values[index]; - if (AreSame(edgeStartTime, ref sourceKey[row], ref sourcePayload[row], ref temp)) + if (this.AreSame(edgeStartTime, ref sourceKey[row], ref sourcePayload[row], ref temp)) { edgesTraversal.Remove(); @@ -167,14 +167,14 @@ public override unsafe void OnNext(StreamMessage batch) if (isLastBeatForInterval) { // Add interval { vSync = startTime, vOther = endTime }. - AddToBatch(startTime, endTime, ref sourceKey[row], ref sourcePayload[row], hash); + this.AddToBatch(startTime, endTime, ref sourceKey[row], ref sourcePayload[row], hash); // No need to add to active list as interval ends <= nextBeatTime. } else { // Add interval { vSync = startTime, vOther = nextBeatTime }. - AddToBatch(startTime, nextBeatTime, ref sourceKey[row], ref sourcePayload[row], hash); + this.AddToBatch(startTime, nextBeatTime, ref sourceKey[row], ref sourcePayload[row], hash); // Add to active list to handle repeat at beats. int index = this.intervals.Insert(hash); @@ -218,7 +218,7 @@ private void AdvanceTime(long time) if (this.edges.IsEmpty && this.intervals.IsEmpty) { // No elements to track, so just advance time to next beat. - this.currBeatTime = FindNextBeatGreaterThanOrEqualTo(time); + this.currBeatTime = this.FindNextBeatGreaterThanOrEqualTo(time); this.lastTime = time; return; } @@ -228,12 +228,12 @@ private void AdvanceTime(long time) if (this.lastTime < this.currBeatTime) { // This is the first time reaching the time currBeatTime, so handle reaching a beat. - ReachBeat(this.currBeatTime); + this.ReachBeat(this.currBeatTime); if (this.edges.IsEmpty && this.intervals.IsEmpty) { // No elements to track, so just advance time to next beat. - this.currBeatTime = FindNextBeatGreaterThanOrEqualTo(time); + this.currBeatTime = this.FindNextBeatGreaterThanOrEqualTo(time); this.lastTime = time; return; } @@ -247,14 +247,14 @@ private void AdvanceTime(long time) // been edges at currBeatTime or edges to still come at currBeatTime + period, however. // Regardless, we can optimize edges to output as intervals for (currBeatTime, currBeatTime + period). - LeaveBeatContinuousToNext(this.currBeatTime); + this.LeaveBeatContinuousToNext(this.currBeatTime); this.currBeatTime += this.period; - ReachBeatContinuousFromLast(this.currBeatTime); + this.ReachBeatContinuousFromLast(this.currBeatTime); if (this.edges.IsEmpty && this.intervals.IsEmpty) { // No elements to track, so just advance time to next beat. - this.currBeatTime = FindNextBeatGreaterThanOrEqualTo(time); + this.currBeatTime = this.FindNextBeatGreaterThanOrEqualTo(time); this.lastTime = time; return; } @@ -264,7 +264,7 @@ private void AdvanceTime(long time) if (time > this.currBeatTime) { // time has passed the beat at currBeatTime, so handle the beat. - LeaveBeat(this.currBeatTime); + this.LeaveBeat(this.currBeatTime); this.currBeatTime += this.period; } @@ -292,12 +292,12 @@ private void ReachBeat(long beatTime) if (edgeStartedBeforeLastBeat) { // Add closing edge { vSync = beatTime, vOther = lastBeatTime }. - AddToBatch(beatTime, lastBeatTime, ref activeEdge.Key, ref activeEdge.Payload, hash); + this.AddToBatch(beatTime, lastBeatTime, ref activeEdge.Key, ref activeEdge.Payload, hash); } else { // Add closing edge { vSync = beatTime, vOther = edge.Start }. - AddToBatch(beatTime, activeEdge.Start, ref activeEdge.Key, ref activeEdge.Payload, hash); + this.AddToBatch(beatTime, activeEdge.Start, ref activeEdge.Key, ref activeEdge.Payload, hash); } } @@ -311,7 +311,7 @@ private void ReachBeat(long beatTime) if (isLastBeatForInterval) { // Add interval { vSync = beatTime, vOther = interval.End }. - AddToBatch(beatTime, activeInterval.End, ref activeInterval.Key, ref activeInterval.Payload, hash); + this.AddToBatch(beatTime, activeInterval.End, ref activeInterval.Key, ref activeInterval.Payload, hash); // Remove from active list as no longer need to output. intervalTraverser.Remove(); @@ -320,7 +320,7 @@ private void ReachBeat(long beatTime) else { // Add interval { vSync = beatTime, vOther = nextBeatTime }. - AddToBatch(beatTime, nextBeatTime, ref activeInterval.Key, ref activeInterval.Payload, hash); + this.AddToBatch(beatTime, nextBeatTime, ref activeInterval.Key, ref activeInterval.Payload, hash); } } } @@ -338,7 +338,7 @@ private void LeaveBeat(long beatTime) if (edgeWasAddedPriorToBeat) { // Add starting edge { vSync = beatTime, vOther = StreamEvent.InfinitySyncTime }. - AddToBatch(beatTime, StreamEvent.InfinitySyncTime, ref activeEdge.Key, ref activeEdge.Payload, hash); + this.AddToBatch(beatTime, StreamEvent.InfinitySyncTime, ref activeEdge.Key, ref activeEdge.Payload, hash); } } } @@ -358,7 +358,7 @@ private void LeaveBeatContinuousToNext(long beatTime) if (edgeWasAddedPriorToBeat) { // Add interval for edge { vSync = beatTime, vOther = nextBeatTime }. - AddToBatch(beatTime, nextBeatTime, ref activeEdge.Key, ref activeEdge.Payload, hash); + this.AddToBatch(beatTime, nextBeatTime, ref activeEdge.Key, ref activeEdge.Payload, hash); } else { @@ -375,7 +375,7 @@ private void LeaveBeatContinuousToNext(long beatTime) // Add closing edge { vSync = nextBeatTime, vOther = beatTime }. var activeEdge = this.edges.Values[index]; - AddToBatch(nextBeatTime, beatTime, ref activeEdge.Key, ref activeEdge.Payload, hash); + this.AddToBatch(nextBeatTime, beatTime, ref activeEdge.Key, ref activeEdge.Payload, hash); invisibleTraverser.MakeVisible(); } } @@ -395,7 +395,7 @@ private void ReachBeatContinuousFromLast(long beatTime) if (isLastBeatForInterval) { // Add interval { vSync = beatTime, vOther = interval.End }. - AddToBatch(beatTime, activeInterval.End, ref activeInterval.Key, ref activeInterval.Payload, hash); + this.AddToBatch(beatTime, activeInterval.End, ref activeInterval.Key, ref activeInterval.Payload, hash); // Remove from active list as no longer need to output. intervalTraverser.Remove(); @@ -403,7 +403,7 @@ private void ReachBeatContinuousFromLast(long beatTime) else { // Add interval { vSync = beatTime, vOther = nextBeatTime }. - AddToBatch(beatTime, nextBeatTime, ref activeInterval.Key, ref activeInterval.Payload, hash); + this.AddToBatch(beatTime, nextBeatTime, ref activeInterval.Key, ref activeInterval.Payload, hash); } } } @@ -426,7 +426,7 @@ private void AddToBatch(long start, long end, ref TKey key, ref TPayload payload this.output.hash.col[index] = hash; if (end == StreamEvent.PunctuationOtherTime) this.output.bitvector.col[index >> 6] |= (1L << (index & 0x3f)); - if (this.output.Count == Config.DataBatchSize) FlushContents(); + if (this.output.Count == Config.DataBatchSize) this.FlushContents(); } [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -466,7 +466,7 @@ public void Populate(long end, ref TKey key, ref TPayload payload) this.Payload = payload; } - public override string ToString() + public override readonly string ToString() => "[End=" + this.End + ", Key='" + this.Key + "', Payload='" + this.Payload + "']"; } @@ -488,7 +488,7 @@ public void Populate(long start, ref TKey key, ref TPayload payload) this.Payload = payload; } - public override string ToString() => "[Start=" + this.Start + ", Key='" + this.Key + "', Payload='" + this.Payload + "']"; + public override readonly string ToString() => "[Start=" + this.Start + ", Key='" + this.Key + "', Payload='" + this.Payload + "']"; } } } diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/Beat/BeatStreamable.cs b/Sources/Core/Microsoft.StreamProcessing/Operators/Beat/BeatStreamable.cs index 9a68afbe4..45fd66e83 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/Beat/BeatStreamable.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/Beat/BeatStreamable.cs @@ -11,7 +11,7 @@ namespace Microsoft.StreamProcessing internal sealed class BeatStreamable : UnaryStreamable { private static readonly SafeConcurrentDictionary> cachedPipes - = new SafeConcurrentDictionary>(); + = new(); public readonly long Offset; public readonly long Period; @@ -19,7 +19,7 @@ private static readonly SafeConcurrentDictionary> cachedPipe public BeatStreamable(IStreamable source, long offset, long period) : base(source, source.Properties) { - Contract.Requires(source != null); + ArgumentNullException.ThrowIfNull(source); Contract.Requires(period > 0); // This operator uses the equality method on payloads @@ -31,7 +31,7 @@ public BeatStreamable(IStreamable source, long offset, long peri this.Offset = offset; this.Period = period; - Initialize(); + this.Initialize(); } internal override IStreamObserver CreatePipe(IStreamObserver observer) @@ -40,7 +40,7 @@ internal override IStreamObserver CreatePipe(IStreamObserver(this, observer); } diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/Beat/BeatTemplate.cs b/Sources/Core/Microsoft.StreamProcessing/Operators/Beat/BeatTemplate.cs index 34354a062..c6db9ed2f 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/Beat/BeatTemplate.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/Beat/BeatTemplate.cs @@ -439,7 +439,7 @@ public override string TransformText() this.Write(";\r\n }\r\n\r\n protected override void FlushContents()\r\n {\r\n if (outpu" + "t.Count == 0) return;\r\n this.Observer.OnNext(output);\r\n GetOutputB" + "atch();\r\n }\r\n\r\n"); - if (!noFields && !this.payloadType.GetTypeInfo().IsValueType) { + if (!noFields && !this.payloadType.IsValueType) { this.Write(" [DataContract]\r\n private struct "); this.Write(this.ToStringHelper.ToStringWithCulture(ActiveEventType)); this.Write("\r\n {\r\n "); diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/Beat/BeatTemplate.tt b/Sources/Core/Microsoft.StreamProcessing/Operators/Beat/BeatTemplate.tt index 09c63c49e..6fdd881e0 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/Beat/BeatTemplate.tt +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/Beat/BeatTemplate.tt @@ -539,7 +539,7 @@ internal sealed class <#= className #><#= TKeyTPayloadGenericParameters #> : Una GetOutputBatch(); } -<# if (!noFields && !this.payloadType.GetTypeInfo().IsValueType) { #> +<# if (!noFields && !this.payloadType.IsValueType) { #> [DataContract] private struct <#= ActiveEventType #> { diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/Beat/BeatTransformer.cs b/Sources/Core/Microsoft.StreamProcessing/Operators/Beat/BeatTransformer.cs index bb07af249..3c3e6ee2a 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/Beat/BeatTransformer.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/Beat/BeatTransformer.cs @@ -3,6 +3,9 @@ // Licensed under the MIT License // ********************************************************************* using System; +#if CODEGEN_TIMING +using System.Diagnostics; +#endif using System.Diagnostics.Contracts; using System.Reflection; @@ -30,8 +33,8 @@ private BeatTemplate(string className, Type keyType, Type payloadType) /// internal static Tuple Generate(BeatStreamable stream) { - Contract.Requires(stream != null); - Contract.Ensures(Contract.Result>() == null || typeof(UnaryPipe).GetTypeInfo().IsAssignableFrom(Contract.Result>().Item1)); + ArgumentNullException.ThrowIfNull(stream); + Contract.Ensures(Contract.Result>() == null || typeof(UnaryPipe).IsAssignableFrom(Contract.Result>().Item1)); #if CODEGEN_TIMING Stopwatch sw = new Stopwatch(); @@ -41,7 +44,7 @@ internal static Tuple Generate(BeatStreamable : Unary private StreamMessage output; [DataMember] - private FastDictionary> intervals = new FastDictionary>(); + private FastDictionary> intervals = new(); [DataMember] - private FastDictionary> edges = new FastDictionary>(); + private FastDictionary> edges = new(); [DataMember] private int intervalIndex; [DataMember] private int edgeIndex; [DataMember] - private FastDictionary currBeatTime = new FastDictionary(); + private FastDictionary currBeatTime = new(); [DataMember] - private FastDictionary lastTime = new FastDictionary(); + private FastDictionary lastTime = new(); [DataMember] private int currBeatIndex; [DataMember] @@ -105,17 +105,17 @@ public override unsafe void OnNext(StreamMessage batch) bool isStartEdge = isInsert && endTime == StreamEvent.InfinitySyncTime; bool isEndEdge = !isInsert; - if (isLowWatermark) AdvanceGlobalTime(startTime); - else AdvanceTime(startTime); + if (isLowWatermark) this.AdvanceGlobalTime(startTime); + else this.AdvanceTime(startTime); if (isPunctuation || isLowWatermark) { - AddToBatch(startTime, endTime, ref sourceKey[row], ref sourcePayload[row], hash); + this.AddToBatch(startTime, endTime, ref sourceKey[row], ref sourcePayload[row], hash); } else if (isStartEdge) { // Add starting edge { vSync = startTime, vOther = StreamEvent.InfinitySyncTime }. - AddToBatch(startTime, StreamEvent.InfinitySyncTime, ref sourceKey[row], ref sourcePayload[row], hash); + this.AddToBatch(startTime, StreamEvent.InfinitySyncTime, ref sourceKey[row], ref sourcePayload[row], hash); // Add to active edges list to handle repeat at beats (and waiting for closing edge). int index = this.edges.entries[this.edgeIndex].value.Insert(hash); @@ -138,12 +138,12 @@ public override unsafe void OnNext(StreamMessage batch) if (edgeStartedBeforeLastBeat) { // Add closing edge { vSync = edgeEndTime, vOther = lastBeatTime }. - AddToBatch(edgeEndTime, lastBeatTime, ref sourceKey[row], ref sourcePayload[row], hash); + this.AddToBatch(edgeEndTime, lastBeatTime, ref sourceKey[row], ref sourcePayload[row], hash); } else { // Add closing edge { vSync = edgeEndTime, vOther = edgeStartTime }. - AddToBatch(edgeEndTime, edgeStartTime, ref sourceKey[row], ref sourcePayload[row], hash); + this.AddToBatch(edgeEndTime, edgeStartTime, ref sourceKey[row], ref sourcePayload[row], hash); } } @@ -151,7 +151,7 @@ public override unsafe void OnNext(StreamMessage batch) var edgesTraversal = this.edges.entries[this.edgeIndex].value.Find(hash); while (edgesTraversal.Next(out int index)) { - if (AreSame(edgeStartTime, ref sourceKey[row], ref sourcePayload[row], ref this.edges.entries[this.edgeIndex].value.Values[index])) + if (this.AreSame(edgeStartTime, ref sourceKey[row], ref sourcePayload[row], ref this.edges.entries[this.edgeIndex].value.Values[index])) { edgesTraversal.Remove(); break; @@ -166,14 +166,14 @@ public override unsafe void OnNext(StreamMessage batch) if (isLastBeatForInterval) { // Add interval { vSync = startTime, vOther = endTime }. - AddToBatch(startTime, endTime, ref sourceKey[row], ref sourcePayload[row], hash); + this.AddToBatch(startTime, endTime, ref sourceKey[row], ref sourcePayload[row], hash); // No need to add to active list as interval ends <= nextBeatTime. } else { // Add interval { vSync = startTime, vOther = nextBeatTime }. - AddToBatch(startTime, nextBeatTime, ref sourceKey[row], ref sourcePayload[row], hash); + this.AddToBatch(startTime, nextBeatTime, ref sourceKey[row], ref sourcePayload[row], hash); // Add to active list to handle repeat at beats. int index = this.intervals.entries[this.intervalIndex].value.Insert(hash); @@ -206,7 +206,7 @@ private void AdvanceGlobalTime(long time) this.edges.Lookup(partitionKey, out this.edgeIndex); this.currBeatTime.Lookup(partitionKey, out this.currBeatIndex); this.lastTime.Lookup(partitionKey, out this.lastIndex); - AdvanceTime(time); + this.AdvanceTime(time); } } @@ -231,7 +231,7 @@ private void AdvanceTime(long time) if (this.edges.entries[this.edgeIndex].value.IsEmpty && this.intervals.entries[this.intervalIndex].value.IsEmpty) { // No elements to track, so just advance time to next beat. - this.currBeatTime.entries[this.currBeatIndex].value = FindNextBeatGreaterThanOrEqualTo(time); + this.currBeatTime.entries[this.currBeatIndex].value = this.FindNextBeatGreaterThanOrEqualTo(time); this.lastTime.entries[this.lastIndex].value = time; return; } @@ -241,12 +241,12 @@ private void AdvanceTime(long time) if (this.lastTime.entries[this.lastIndex].value < this.currBeatTime.entries[this.currBeatIndex].value) { // This is the first time reaching the time currBeatTime, so handle reaching a beat. - ReachBeat(this.currBeatTime.entries[this.currBeatIndex].value); + this.ReachBeat(this.currBeatTime.entries[this.currBeatIndex].value); if (this.edges.entries[this.edgeIndex].value.IsEmpty && this.intervals.entries[this.intervalIndex].value.IsEmpty) { // No elements to track, so just advance time to next beat. - this.currBeatTime.entries[this.currBeatIndex].value = FindNextBeatGreaterThanOrEqualTo(time); + this.currBeatTime.entries[this.currBeatIndex].value = this.FindNextBeatGreaterThanOrEqualTo(time); this.lastTime.entries[this.currBeatIndex].value = time; return; } @@ -260,14 +260,14 @@ private void AdvanceTime(long time) // been edges at currBeatTime or edges to still come at currBeatTime + period, however. // Regardless, we can optimize edges to output as intervals for (currBeatTime, currBeatTime + period). - LeaveBeatContinuousToNext(this.currBeatTime.entries[this.currBeatIndex].value); + this.LeaveBeatContinuousToNext(this.currBeatTime.entries[this.currBeatIndex].value); this.currBeatTime.entries[this.currBeatIndex].value += this.period; - ReachBeatContinuousFromLast(this.currBeatTime.entries[this.currBeatIndex].value); + this.ReachBeatContinuousFromLast(this.currBeatTime.entries[this.currBeatIndex].value); if (this.edges.entries[this.edgeIndex].value.IsEmpty && this.intervals.entries[this.intervalIndex].value.IsEmpty) { // No elements to track, so just advance time to next beat. - this.currBeatTime.entries[this.currBeatIndex].value = FindNextBeatGreaterThanOrEqualTo(time); + this.currBeatTime.entries[this.currBeatIndex].value = this.FindNextBeatGreaterThanOrEqualTo(time); this.lastTime.entries[this.lastIndex].value = time; return; } @@ -277,7 +277,7 @@ private void AdvanceTime(long time) if (time > this.currBeatTime.entries[this.currBeatIndex].value) { // time has passed the beat at currBeatTime, so handle the beat. - LeaveBeat(this.currBeatTime.entries[this.currBeatIndex].value); + this.LeaveBeat(this.currBeatTime.entries[this.currBeatIndex].value); this.currBeatTime.entries[this.currBeatIndex].value += this.period; } @@ -303,12 +303,12 @@ private void ReachBeat(long beatTime) if (edgeStartedBeforeLastBeat) { // Add closing edge { vSync = beatTime, vOther = lastBeatTime }. - AddToBatch(beatTime, lastBeatTime, ref this.edges.entries[this.edgeIndex].value.Values[index].Key, ref this.edges.entries[this.edgeIndex].value.Values[index].Payload, hash); + this.AddToBatch(beatTime, lastBeatTime, ref this.edges.entries[this.edgeIndex].value.Values[index].Key, ref this.edges.entries[this.edgeIndex].value.Values[index].Payload, hash); } else { // Add closing edge { vSync = beatTime, vOther = edge.Start }. - AddToBatch(beatTime, edgeStartTime, ref this.edges.entries[this.edgeIndex].value.Values[index].Key, ref this.edges.entries[this.edgeIndex].value.Values[index].Payload, hash); + this.AddToBatch(beatTime, edgeStartTime, ref this.edges.entries[this.edgeIndex].value.Values[index].Key, ref this.edges.entries[this.edgeIndex].value.Values[index].Payload, hash); } } @@ -322,7 +322,7 @@ private void ReachBeat(long beatTime) if (isLastBeatForInterval) { // Add interval { vSync = beatTime, vOther = interval.End }. - AddToBatch(beatTime, intervalEndTime, ref this.intervals.entries[this.intervalIndex].value.Values[index].Key, ref this.intervals.entries[this.intervalIndex].value.Values[index].Payload, hash); + this.AddToBatch(beatTime, intervalEndTime, ref this.intervals.entries[this.intervalIndex].value.Values[index].Key, ref this.intervals.entries[this.intervalIndex].value.Values[index].Payload, hash); // Remove from active list as no longer need to output. intervalTraverser.Remove(); @@ -330,7 +330,7 @@ private void ReachBeat(long beatTime) else { // Add interval { vSync = beatTime, vOther = nextBeatTime }. - AddToBatch(beatTime, nextBeatTime, ref this.intervals.entries[this.intervalIndex].value.Values[index].Key, ref this.intervals.entries[this.intervalIndex].value.Values[index].Payload, hash); + this.AddToBatch(beatTime, nextBeatTime, ref this.intervals.entries[this.intervalIndex].value.Values[index].Key, ref this.intervals.entries[this.intervalIndex].value.Values[index].Payload, hash); } } } @@ -347,7 +347,7 @@ private void LeaveBeat(long beatTime) if (edgeWasAddedPriorToBeat) { // Add starting edge { vSync = beatTime, vOther = StreamEvent.InfinitySyncTime }. - AddToBatch(beatTime, StreamEvent.InfinitySyncTime, ref this.edges.entries[this.edgeIndex].value.Values[index].Key, ref this.edges.entries[this.edgeIndex].value.Values[index].Payload, hash); + this.AddToBatch(beatTime, StreamEvent.InfinitySyncTime, ref this.edges.entries[this.edgeIndex].value.Values[index].Key, ref this.edges.entries[this.edgeIndex].value.Values[index].Payload, hash); } } } @@ -368,7 +368,7 @@ private void LeaveBeatContinuousToNext(long beatTime) if (edgeWasAddedPriorToBeat) { // Add interval for edge { vSync = beatTime, vOther = nextBeatTime }. - AddToBatch(beatTime, nextBeatTime, ref this.edges.entries[this.edgeIndex].value.Values[index].Key, ref this.edges.entries[this.edgeIndex].value.Values[index].Payload, hash); + this.AddToBatch(beatTime, nextBeatTime, ref this.edges.entries[this.edgeIndex].value.Values[index].Key, ref this.edges.entries[this.edgeIndex].value.Values[index].Payload, hash); } else { @@ -382,7 +382,7 @@ private void LeaveBeatContinuousToNext(long beatTime) while (invisibleTraverser.Next(out index, out hash)) { // Add closing edge { vSync = nextBeatTime, vOther = beatTime }. - AddToBatch(nextBeatTime, beatTime, ref this.edges.entries[this.edgeIndex].value.Values[index].Key, ref this.edges.entries[this.edgeIndex].value.Values[index].Payload, hash); + this.AddToBatch(nextBeatTime, beatTime, ref this.edges.entries[this.edgeIndex].value.Values[index].Key, ref this.edges.entries[this.edgeIndex].value.Values[index].Payload, hash); invisibleTraverser.MakeVisible(); } } @@ -402,7 +402,7 @@ private void ReachBeatContinuousFromLast(long beatTime) if (isLastBeatForInterval) { // Add interval { vSync = beatTime, vOther = interval.End }. - AddToBatch(beatTime, intervalEndTime, ref this.intervals.entries[this.intervalIndex].value.Values[index].Key, ref this.intervals.entries[this.intervalIndex].value.Values[index].Payload, hash); + this.AddToBatch(beatTime, intervalEndTime, ref this.intervals.entries[this.intervalIndex].value.Values[index].Key, ref this.intervals.entries[this.intervalIndex].value.Values[index].Payload, hash); // Remove from active list as no longer need to output. intervalTraverser.Remove(); @@ -410,7 +410,7 @@ private void ReachBeatContinuousFromLast(long beatTime) else { // Add interval { vSync = beatTime, vOther = nextBeatTime }. - AddToBatch(beatTime, nextBeatTime, ref this.intervals.entries[this.intervalIndex].value.Values[index].Key, ref this.intervals.entries[this.intervalIndex].value.Values[index].Payload, hash); + this.AddToBatch(beatTime, nextBeatTime, ref this.intervals.entries[this.intervalIndex].value.Values[index].Key, ref this.intervals.entries[this.intervalIndex].value.Values[index].Payload, hash); } } } @@ -433,7 +433,7 @@ private void AddToBatch(long start, long end, ref TKey key, ref TPayload payload this.output.hash.col[index] = hash; if (end < 0) this.output.bitvector.col[index >> 6] |= (1L << (index & 0x3f)); - if (this.output.Count == Config.DataBatchSize) FlushContents(); + if (this.output.Count == Config.DataBatchSize) this.FlushContents(); } [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -449,7 +449,14 @@ protected override void FlushContents() this.output.Allocate(); } - protected override void DisposeState() => this.output.Free(); + protected override void DisposeState() + { + this.intervals.Dispose(); + this.edges.Dispose(); + this.currBeatTime.Dispose(); + this.lastTime.Dispose(); + this.output.Free(); + } public override int CurrentlyBufferedOutputCount => this.output.Count; @@ -484,7 +491,7 @@ public void Populate(long end, ref TKey key, ref TPayload payload) this.Payload = payload; } - public override string ToString() + public override readonly string ToString() => "[End=" + this.End + ", Key='" + this.Key + "', Payload='" + this.Payload + "']"; } @@ -506,7 +513,7 @@ public void Populate(long start, ref TKey key, ref TPayload payload) this.Payload = payload; } - public override string ToString() + public override readonly string ToString() => "[Start=" + this.Start + ", Key='" + this.Key + "', Payload='" + this.Payload + "']"; } } diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/Clip/ClipJoinPipe.cs b/Sources/Core/Microsoft.StreamProcessing/Operators/Clip/ClipJoinPipe.cs index 9b7f34450..eab299e85 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/Clip/ClipJoinPipe.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/Clip/ClipJoinPipe.cs @@ -30,13 +30,13 @@ internal sealed class ClipJoinPipe : BinaryPipe [DataMember] - private FastMap leftIntervalMap = new FastMap(); + private FastMap leftIntervalMap = new(); /// /// Stores left start edges at /// [DataMember] - private FastMap leftEdgeMap = new FastMap(); + private FastMap leftEdgeMap = new(); /// /// Stores left end edges at some point in the future, i.e. after . @@ -108,8 +108,8 @@ protected override void ProcessBothBatches(StreamMessage leftBatch, { if (this.nextLeftTime <= this.nextRightTime) { - UpdateTime(this.nextLeftTime); - ProcessLeftEvent( + this.UpdateTime(this.nextLeftTime); + this.ProcessLeftEvent( this.nextLeftTime, leftBatch.vother.col[leftBatch.iter], ref leftBatch.key.col[leftBatch.iter], @@ -129,8 +129,8 @@ protected override void ProcessBothBatches(StreamMessage leftBatch, } else { - UpdateTime(this.nextRightTime); - ProcessRightEvent( + this.UpdateTime(this.nextRightTime); + this.ProcessRightEvent( this.nextRightTime, rightBatch.vother.col[rightBatch.iter], ref rightBatch.key.col[rightBatch.iter], @@ -170,9 +170,9 @@ protected override void ProcessLeftBatch(StreamMessage batch, out b return; } - UpdateTime(this.nextLeftTime); + this.UpdateTime(this.nextLeftTime); - ProcessLeftEvent( + this.ProcessLeftEvent( this.nextLeftTime, batch.vother.col[batch.iter], ref batch.key.col[batch.iter], @@ -203,9 +203,9 @@ protected override void ProcessRightBatch(StreamMessage batch, out return; } - UpdateTime(this.nextRightTime); + this.UpdateTime(this.nextRightTime); - ProcessRightEvent( + this.ProcessRightEvent( this.nextRightTime, batch.vother.col[batch.iter], ref batch.key.col[batch.iter], @@ -230,7 +230,7 @@ private void UpdateTime(long time) if (time != this.currTime) { this.currTime = time; - ReachTime(); + this.ReachTime(); } } @@ -247,7 +247,7 @@ private void ProcessLeftEvent(long start, long end, ref TKey key, TLeft payload, if (isFullyOutputtable) { // Output full interval. - AddToBatch(start, end, ref key, ref payload, hash); + this.AddToBatch(start, end, ref key, ref payload, hash); } else { @@ -261,7 +261,7 @@ private void ProcessLeftEvent(long start, long end, ref TKey key, TLeft payload, this.leftIntervalMap.Values[mapIndex].Initialize(start, ref key, ref payload, heapIndex); // Output start edge. - AddToBatch(start, StreamEvent.InfinitySyncTime, ref key, ref payload, hash); + this.AddToBatch(start, StreamEvent.InfinitySyncTime, ref key, ref payload, hash); } } else @@ -270,12 +270,12 @@ private void ProcessLeftEvent(long start, long end, ref TKey key, TLeft payload, this.leftEdgeMap.Values[index].Populate(start, ref key, ref payload); // Output start edge. - AddToBatch(start, StreamEvent.InfinitySyncTime, ref key, ref payload, hash); + this.AddToBatch(start, StreamEvent.InfinitySyncTime, ref key, ref payload, hash); } } else if (end == StreamEvent.PunctuationOtherTime) { - AddPunctuationToBatch(start); + this.AddPunctuationToBatch(start); } else { @@ -283,10 +283,10 @@ private void ProcessLeftEvent(long start, long end, ref TKey key, TLeft payload, var leftEvents = this.leftEdgeMap.Find(hash); while (leftEvents.Next(out int index)) { - if (AreSame(end, ref key, ref payload, ref this.leftEdgeMap.Values[index])) + if (this.AreSame(end, ref key, ref payload, ref this.leftEdgeMap.Values[index])) { // Output end edge. - AddToBatch(start, end, ref key, ref payload, hash); + this.AddToBatch(start, end, ref key, ref payload, hash); // Remove from leftMap. leftEvents.Remove(); @@ -301,7 +301,7 @@ private void ProcessRightEvent(long start, long end, ref TKey key, int hash) { if (end == StreamEvent.PunctuationOtherTime) { - AddPunctuationToBatch(start); + this.AddPunctuationToBatch(start); return; } else if (start >= end) @@ -320,7 +320,7 @@ private void ProcessRightEvent(long start, long end, ref TKey key, int hash) if (leftStart < start && this.keyComparerEquals(key, this.leftIntervalMap.Values[index].Key)) { // Output end edge. - AddToBatch( + this.AddToBatch( start, leftStart, ref this.leftIntervalMap.Values[index].Key, @@ -341,7 +341,7 @@ private void ProcessRightEvent(long start, long end, ref TKey key, int hash) if (leftStart < start && this.keyComparerEquals(key, this.leftEdgeMap.Values[index].Key)) { // Output end edge. - AddToBatch( + this.AddToBatch( start, leftStart, ref this.leftEdgeMap.Values[index].Key, @@ -361,7 +361,7 @@ private void ReachTime() while (this.leftEndPointHeap.TryGetNextInclusive(this.currTime, out long endPointTime, out int index)) { // Output end edge. - AddToBatch( + this.AddToBatch( endPointTime, this.leftIntervalMap.Values[index].Start, ref this.leftIntervalMap.Values[index].Key, ref this.leftIntervalMap.Values[index].Payload, this.leftIntervalMap.GetHash(index)); @@ -386,7 +386,7 @@ private void AddPunctuationToBatch(long start) this.output.hash.col[index] = 0; this.output.bitvector.col[index >> 6] |= 1L << (index & 0x3f); - if (this.output.Count == Config.DataBatchSize) FlushContents(); + if (this.output.Count == Config.DataBatchSize) this.FlushContents(); } } @@ -405,7 +405,7 @@ private void AddToBatch(long start, long end, ref TKey key, ref TLeft payload, i this.output[index] = payload; this.output.hash.col[index] = hash; - if (this.output.Count == Config.DataBatchSize) FlushContents(); + if (this.output.Count == Config.DataBatchSize) this.FlushContents(); } [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -444,7 +444,7 @@ public void Initialize(long start, ref TKey key, ref TLeft payload, int heapInde this.HeapIndex = heapIndex; } - public override string ToString() + public override readonly string ToString() => "[Start=" + this.Start + ", Key='" + this.Key + "', Payload='" + this.Payload + "', HeapIndex=" + this.HeapIndex + "]"; } @@ -466,7 +466,7 @@ public void Populate(long start, ref TKey key, ref TLeft payload) this.Payload = payload; } - public override string ToString() + public override readonly string ToString() => "[Start=" + this.Start + ", Key='" + this.Key + "', Payload='" + this.Payload + "]"; } } diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/Clip/ClipJoinStreamable.cs b/Sources/Core/Microsoft.StreamProcessing/Operators/Clip/ClipJoinStreamable.cs index 068393349..f32e8b2d2 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/Clip/ClipJoinStreamable.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/Clip/ClipJoinStreamable.cs @@ -11,7 +11,7 @@ namespace Microsoft.StreamProcessing internal sealed class ClipJoinStreamable : BinaryStreamable { private static readonly SafeConcurrentDictionary> cachedPipes - = new SafeConcurrentDictionary>(); + = new(); [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes", Justification = "Expressions are immutable")] public readonly IEqualityComparerExpression LeftComparer; @@ -19,8 +19,8 @@ private static readonly SafeConcurrentDictionary> cachedPipe public ClipJoinStreamable(IStreamable left, IStreamable right) : base(left.Properties.Clip(right.Properties), left, right) { - Contract.Requires(left != null); - Contract.Requires(right != null); + ArgumentNullException.ThrowIfNull(left); + ArgumentNullException.ThrowIfNull(right); this.LeftComparer = left.Properties.PayloadEqualityComparer; @@ -30,12 +30,12 @@ public ClipJoinStreamable(IStreamable left, IStreamable CreatePipe(IStreamObserver observer) { - if (this.properties.IsColumnar) return GetPipe(observer); + if (this.properties.IsColumnar) return this.GetPipe(observer); else { var part = typeof(TKey).GetPartitionType(); diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/Clip/ClipJoinTemplate.cs b/Sources/Core/Microsoft.StreamProcessing/Operators/Clip/ClipJoinTemplate.cs index 0bdab9d80..ef9fb5f56 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/Clip/ClipJoinTemplate.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/Clip/ClipJoinTemplate.cs @@ -546,7 +546,7 @@ protected override void FlushContents() "); GetOutputBatch(); this.Write(" }\r\n"); - if (!noFields && !this.leftType.GetTypeInfo().IsValueType) { + if (!noFields && !this.leftType.IsValueType) { this.Write(" [DataContract]\r\n private struct "); this.Write(this.ToStringHelper.ToStringWithCulture(ActiveEventType)); this.Write("\r\n {\r\n"); diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/Clip/ClipJoinTemplate.tt b/Sources/Core/Microsoft.StreamProcessing/Operators/Clip/ClipJoinTemplate.tt index 5e4560296..41740b387 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/Clip/ClipJoinTemplate.tt +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/Clip/ClipJoinTemplate.tt @@ -473,7 +473,7 @@ internal sealed class <#= className #><#= genericParameters #> : BinaryPipe<<#= this.Observer.OnNext(output); <# GetOutputBatch(); #> } -<# if (!noFields && !this.leftType.GetTypeInfo().IsValueType) { #> +<# if (!noFields && !this.leftType.IsValueType) { #> [DataContract] private struct <#= ActiveEventType #> { diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/Clip/ClipJoinTransformer.cs b/Sources/Core/Microsoft.StreamProcessing/Operators/Clip/ClipJoinTransformer.cs index d28dfa747..7050516ec 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/Clip/ClipJoinTransformer.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/Clip/ClipJoinTransformer.cs @@ -39,8 +39,8 @@ private ClipJoinTemplate(string className, Type keyType, Type leftType, Type rig /// internal static Tuple Generate(ClipJoinStreamable stream) { - Contract.Requires(stream != null); - Contract.Ensures(Contract.Result>() == null || typeof(BinaryPipe).GetTypeInfo().IsAssignableFrom(Contract.Result>().Item1)); + ArgumentNullException.ThrowIfNull(stream); + Contract.Ensures(Contract.Result>() == null || typeof(BinaryPipe).IsAssignableFrom(Contract.Result>().Item1)); var template = new ClipJoinTemplate($"GeneratedClip_{ClipSequenceNumber++}", typeof(TKey), typeof(TLeft), typeof(TRight)); @@ -53,7 +53,7 @@ internal static Tuple Generate(ClipJoinStream var resultRepresentation = new ColumnarRepresentation(leftType); - template.ActiveEventType = leftType.GetTypeInfo().IsValueType ? template.TLeft : "Active_Event"; + template.ActiveEventType = leftType.IsValueType ? template.TLeft : "Active_Event"; #region Key Comparer var keyComparer = stream.Properties.KeyEqualityComparer.GetEqualsExpr(); diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/Clip/PartitionedClipJoinPipe.cs b/Sources/Core/Microsoft.StreamProcessing/Operators/Clip/PartitionedClipJoinPipe.cs index 8a551008a..4a86963e2 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/Clip/PartitionedClipJoinPipe.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/Clip/PartitionedClipJoinPipe.cs @@ -26,20 +26,20 @@ internal sealed class PartitionedClipJoinPipe leftComparerEquals; [DataMember] - private FastDictionary2> leftQueue = new FastDictionary2>(); + private FastDictionary2> leftQueue = new(); [DataMember] - private FastDictionary2> rightQueue = new FastDictionary2>(); + private FastDictionary2> rightQueue = new(); [DataMember] - private HashSet processQueue = new HashSet(); + private HashSet processQueue = []; [DataMember] - private HashSet seenKeys = new HashSet(); + private HashSet seenKeys = []; [DataMember] - private HashSet cleanKeys = new HashSet(); + private HashSet cleanKeys = []; [DataMember] private StreamMessage output; [DataMember] - private FastDictionary partitionData = new FastDictionary(); + private FastDictionary partitionData = new(); [DataMember] private long lastLeftCTI = long.MinValue; [DataMember] @@ -82,12 +82,16 @@ private void NewPartition(TPartitionKey pKey) if (!this.partitionData.Lookup(pKey, out int eph)) this.partitionData.Insert(ref eph, pKey, new PartitionEntry()); } - protected override void DisposeState() => this.output.Free(); + protected override void DisposeState() + { + this.partitionData.Dispose(); + this.output.Free(); + } protected override void ProcessBothBatches(StreamMessage leftBatch, StreamMessage rightBatch, out bool leftBatchDone, out bool rightBatchDone, out bool leftBatchFree, out bool rightBatchFree) { - ProcessLeftBatch(leftBatch, out leftBatchDone, out leftBatchFree); - ProcessRightBatch(rightBatch, out rightBatchDone, out rightBatchFree); + this.ProcessLeftBatch(leftBatch, out leftBatchDone, out leftBatchFree); + this.ProcessRightBatch(rightBatch, out rightBatchDone, out rightBatchFree); } protected override void ProcessLeftBatch(StreamMessage batch, out bool leftBatchDone, out bool leftBatchFree) @@ -116,7 +120,7 @@ protected override void ProcessLeftBatch(StreamMessage batch, out b var partitionKey = this.getPartitionKey(batch.key.col[i]); if (first || !partitionKey.Equals(previous)) { - if (this.seenKeys.Add(partitionKey)) NewPartition(partitionKey); + if (this.seenKeys.Add(partitionKey)) this.NewPartition(partitionKey); this.leftQueue.Lookup(partitionKey, out int index); queue = this.leftQueue.entries[index].value; this.processQueue.Add(partitionKey); @@ -133,7 +137,7 @@ protected override void ProcessLeftBatch(StreamMessage batch, out b first = false; previous = partitionKey; } - ProcessPendingEntries(); + this.ProcessPendingEntries(); } protected override void ProcessRightBatch(StreamMessage batch, out bool rightBatchDone, out bool rightBatchFree) @@ -161,7 +165,7 @@ protected override void ProcessRightBatch(StreamMessage batch, out var partitionKey = this.getPartitionKey(batch.key.col[i]); if (first || !partitionKey.Equals(previous)) { - if (this.seenKeys.Add(partitionKey)) NewPartition(partitionKey); + if (this.seenKeys.Add(partitionKey)) this.NewPartition(partitionKey); this.rightQueue.Lookup(partitionKey, out int index); queue = this.rightQueue.entries[index].value; this.processQueue.Add(partitionKey); @@ -177,7 +181,7 @@ protected override void ProcessRightBatch(StreamMessage batch, out first = false; previous = partitionKey; } - ProcessPendingEntries(); + this.ProcessPendingEntries(); } [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -213,11 +217,11 @@ private void ProcessPendingEntries() if (partition.nextLeftTime <= partition.nextRightTime) { - UpdateTime(partition, partition.nextLeftTime); + this.UpdateTime(partition, partition.nextLeftTime); if (leftEntry.Other != long.MinValue) { - ProcessLeftEvent( + this.ProcessLeftEvent( partition, partition.nextLeftTime, leftEntry.Other, @@ -228,7 +232,7 @@ private void ProcessPendingEntries() } else if (partition.currTime > old) { - AddToBatch( + this.AddToBatch( partition.currTime, long.MinValue, ref leftEntry.Key, @@ -240,11 +244,11 @@ private void ProcessPendingEntries() } else { - UpdateTime(partition, partition.nextRightTime); + this.UpdateTime(partition, partition.nextRightTime); if (rightEntry.Other != long.MinValue) { - ProcessRightEvent( + this.ProcessRightEvent( partition, partition.nextRightTime, rightEntry.Other, @@ -255,7 +259,7 @@ private void ProcessPendingEntries() else if (partition.currTime > old) { var l = default(TLeft); - AddToBatch( + this.AddToBatch( partition.currTime, long.MinValue, ref rightEntry.Key, @@ -276,15 +280,15 @@ private void ProcessPendingEntries() // If we have not yet reached the lesser of the two sides (in this case, right), and we don't // have input from that side, reach that time now. This can happen with low watermarks. if (partition.currTime < partition.nextRightTime) - UpdateTime(partition, partition.nextRightTime); + this.UpdateTime(partition, partition.nextRightTime); break; } - UpdateTime(partition, partition.nextLeftTime); + this.UpdateTime(partition, partition.nextLeftTime); if (leftEntry.Other != long.MinValue) { - ProcessLeftEvent( + this.ProcessLeftEvent( partition, partition.nextLeftTime, leftEntry.Other, @@ -294,7 +298,7 @@ private void ProcessPendingEntries() } else if (partition.currTime > old) { - AddToBatch( + this.AddToBatch( partition.currTime, long.MinValue, ref leftEntry.Key, @@ -314,15 +318,15 @@ private void ProcessPendingEntries() // If we have not yet reached the lesser of the two sides (in this case, left), and we don't // have input from that side, reach that time now. This can happen with low watermarks. if (partition.currTime < partition.nextLeftTime) - UpdateTime(partition, partition.nextLeftTime); + this.UpdateTime(partition, partition.nextLeftTime); break; } - UpdateTime(partition, partition.nextRightTime); + this.UpdateTime(partition, partition.nextRightTime); if (rightEntry.Other != long.MinValue) { - ProcessRightEvent( + this.ProcessRightEvent( partition, partition.nextRightTime, rightEntry.Other, @@ -332,7 +336,7 @@ private void ProcessPendingEntries() else if (partition.currTime > old) { var l = default(TLeft); - AddToBatch( + this.AddToBatch( partition.currTime, long.MinValue, ref rightEntry.Key, @@ -349,7 +353,7 @@ private void ProcessPendingEntries() if (partition.nextRightTime < this.lastRightCTI) partition.nextRightTime = this.lastRightCTI; - UpdateTime(partition, Math.Min(this.lastLeftCTI, this.lastRightCTI)); + this.UpdateTime(partition, Math.Min(this.lastLeftCTI, this.lastRightCTI)); if (partition.IsClean()) this.cleanKeys.Add(pKey); break; @@ -360,7 +364,7 @@ private void ProcessPendingEntries() if (this.emitCTI) { var earliest = Math.Min(this.lastLeftCTI, this.lastRightCTI); - AddLowWatermarkToBatch(earliest); + this.AddLowWatermarkToBatch(earliest); this.emitCTI = false; foreach (var p in this.cleanKeys) { @@ -381,7 +385,7 @@ private void UpdateTime(PartitionEntry partition, long time) if (time > partition.currTime) { partition.currTime = time; - ReachTime(partition); + this.ReachTime(partition); } } @@ -401,7 +405,7 @@ private void ProcessLeftEvent(PartitionEntry partition, long start, long end, re if (isFullyOutputtable) { // Output full interval. - AddToBatch(start, end, ref key, ref payload, hash); + this.AddToBatch(start, end, ref key, ref payload, hash); } else { @@ -415,7 +419,7 @@ private void ProcessLeftEvent(PartitionEntry partition, long start, long end, re lim.Values[mapIndex].Initialize(start, ref key, ref payload, heapIndex); // Output start edge. - AddToBatch(start, StreamEvent.InfinitySyncTime, ref key, ref payload, hash); + this.AddToBatch(start, StreamEvent.InfinitySyncTime, ref key, ref payload, hash); } } else @@ -424,7 +428,7 @@ private void ProcessLeftEvent(PartitionEntry partition, long start, long end, re lem.Values[index].Populate(start, ref key, ref payload); // Output start edge. - AddToBatch(start, StreamEvent.InfinitySyncTime, ref key, ref payload, hash); + this.AddToBatch(start, StreamEvent.InfinitySyncTime, ref key, ref payload, hash); } } else @@ -433,10 +437,10 @@ private void ProcessLeftEvent(PartitionEntry partition, long start, long end, re var leftEvents = lem.Find(hash); while (leftEvents.Next(out int index)) { - if (AreSame(end, ref key, ref payload, ref lem.Values[index])) + if (this.AreSame(end, ref key, ref payload, ref lem.Values[index])) { // Output end edge. - AddToBatch(start, end, ref key, ref payload, hash); + this.AddToBatch(start, end, ref key, ref payload, hash); // Remove from leftMap. leftEvents.Remove(); @@ -467,7 +471,7 @@ private void ProcessRightEvent(PartitionEntry partition, long start, long end, r if (leftStart < start && this.keyComparerEquals(key, lim.Values[index].Key)) { // Output end edge. - AddToBatch( + this.AddToBatch( start, leftStart, ref lim.Values[index].Key, @@ -488,7 +492,7 @@ private void ProcessRightEvent(PartitionEntry partition, long start, long end, r if (leftStart < start && this.keyComparerEquals(key, lem.Values[index].Key)) { // Output end edge. - AddToBatch( + this.AddToBatch( start, leftStart, ref lem.Values[index].Key, @@ -510,7 +514,7 @@ private void ReachTime(PartitionEntry partition) while (leph.TryGetNextInclusive(partition.currTime, out long endPointTime, out int index)) { // Output end edge. - AddToBatch( + this.AddToBatch( endPointTime, lim.Values[index].Start, ref lim.Values[index].Key, @@ -537,7 +541,7 @@ private void AddLowWatermarkToBatch(long start) this.output.hash.col[index] = 0; this.output.bitvector.col[index >> 6] |= 1L << (index & 0x3f); - if (this.output.Count == Config.DataBatchSize) FlushContents(); + if (this.output.Count == Config.DataBatchSize) this.FlushContents(); } } @@ -560,7 +564,7 @@ private void AddToBatch(long start, long end, ref TKey key, ref TLeft payload, i this.output.bitvector.col[index >> 6] |= (1L << (index & 0x3f)); } - if (this.output.Count == Config.DataBatchSize) FlushContents(); + if (this.output.Count == Config.DataBatchSize) this.FlushContents(); } [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -656,7 +660,7 @@ public void Initialize(long start, ref TKey key, ref TLeft payload, int heapInde this.HeapIndex = heapIndex; } - public override string ToString() + public override readonly string ToString() => "[Start=" + this.Start + ", Key='" + this.Key + "', Payload='" + this.Payload + "', HeapIndex=" + this.HeapIndex + "]"; } @@ -678,7 +682,7 @@ public void Populate(long start, ref TKey key, ref TLeft payload) this.Payload = payload; } - public override string ToString() + public override readonly string ToString() => "[Start=" + this.Start + ", Key='" + this.Key + "', Payload='" + this.Payload + "]"; } @@ -738,20 +742,20 @@ private sealed class PartitionEntry /// Stores intervals for active left events. /// [DataMember] - public FastMap leftIntervalMap = new FastMap(); + public FastMap leftIntervalMap = new(); /// /// Stores left start edges at /// [DataMember] - public FastMap leftEdgeMap = new FastMap(); + public FastMap leftEdgeMap = new(); /// /// Stores left end edges at some point in the future, i.e. after . /// These can originate from edge end events or interval events. /// [DataMember] - public RemovableEndPointHeap leftEndPointHeap = new RemovableEndPointHeap(); + public RemovableEndPointHeap leftEndPointHeap = new(); [DataMember] public long nextLeftTime = long.MinValue; diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/ClipByConstant/ClipByConstantPipe.cs b/Sources/Core/Microsoft.StreamProcessing/Operators/ClipByConstant/ClipByConstantPipe.cs index b602be6de..495108e98 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/ClipByConstant/ClipByConstantPipe.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/ClipByConstant/ClipByConstantPipe.cs @@ -24,7 +24,7 @@ internal sealed class ClipByConstantPipe : UnaryPipe output; [DataMember] - private SortedDictionary> syncTimeMap = new SortedDictionary>(); + private SortedDictionary> syncTimeMap = []; [Obsolete("Used only by serialization. Do not call directly.")] public ClipByConstantPipe() { } @@ -61,7 +61,7 @@ private void ReachTime(long timestamp) this.output[ind] = ae.Payload; this.output.hash.col[ind] = ae.Hash; - if (this.output.Count == Config.DataBatchSize) FlushContents(); + if (this.output.Count == Config.DataBatchSize) this.FlushContents(); } toDelete.Add(kvp.Key); @@ -80,7 +80,7 @@ public override unsafe void OnNext(StreamMessage batch) { if ((bv[i >> 6] & (1L << (i & 0x3f))) == 0) { - ReachTime(batch.vsync.col[i]); + this.ReachTime(batch.vsync.col[i]); if (batch.vother.col[i] == StreamEvent.InfinitySyncTime) { @@ -94,7 +94,7 @@ public override unsafe void OnNext(StreamMessage batch) this.output[ind] = batch[i]; this.output.hash.col[ind] = batch.hash.col[i]; - if (this.output.Count == Config.DataBatchSize) FlushContents(); + if (this.output.Count == Config.DataBatchSize) this.FlushContents(); if (!this.syncTimeMap.TryGetValue(sync, out var multiSet)) { @@ -113,7 +113,7 @@ public override unsafe void OnNext(StreamMessage batch) this.output[ind] = batch[i]; this.output.hash.col[ind] = batch.hash.col[i]; - if (this.output.Count == Config.DataBatchSize) FlushContents(); + if (this.output.Count == Config.DataBatchSize) this.FlushContents(); } else { @@ -132,7 +132,7 @@ public override unsafe void OnNext(StreamMessage batch) this.output[ind] = payload; this.output.hash.col[ind] = batch.hash.col[i]; - if (this.output.Count == Config.DataBatchSize) FlushContents(); + if (this.output.Count == Config.DataBatchSize) this.FlushContents(); // Remove the corresponding start edge from the waiting list this.syncTimeMap[other].Remove(new ActiveEvent { Payload = payload, Key = batch.key.col[i], Hash = batch.hash.col[i] }); @@ -141,7 +141,7 @@ public override unsafe void OnNext(StreamMessage batch) } else if (batch.vother.col[i] == StreamEvent.PunctuationOtherTime) { - ReachTime(batch.vsync.col[i]); + this.ReachTime(batch.vsync.col[i]); int ind = this.output.Count++; this.output.vsync.col[ind] = batch.vsync.col[i]; @@ -151,7 +151,7 @@ public override unsafe void OnNext(StreamMessage batch) this.output.hash.col[ind] = batch.hash.col[i]; this.output.bitvector.col[ind >> 6] |= 1L << (ind & 0x3f); - if (this.output.Count == Config.DataBatchSize) FlushContents(); + if (this.output.Count == Config.DataBatchSize) this.FlushContents(); } } } @@ -183,7 +183,7 @@ private struct ActiveEvent [DataMember] public int Hash; - public override string ToString() => "Key='" + this.Key + "', Payload='" + this.Payload; + public override readonly string ToString() => "Key='" + this.Key + "', Payload='" + this.Payload; } } diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/ClipByConstant/ClipByConstantStreamable.cs b/Sources/Core/Microsoft.StreamProcessing/Operators/ClipByConstant/ClipByConstantStreamable.cs index d34d5c7e7..552f4febf 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/ClipByConstant/ClipByConstantStreamable.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/ClipByConstant/ClipByConstantStreamable.cs @@ -11,7 +11,7 @@ namespace Microsoft.StreamProcessing internal sealed class ClipByConstantStreamable : UnaryStreamable { private static readonly SafeConcurrentDictionary> cachedPipes - = new SafeConcurrentDictionary>(); + = new(); private readonly long limit; @@ -28,7 +28,7 @@ internal override IStreamObserver CreatePipe(IStreamObserver(this, observer, this.limit); } var outputType = typeof(PartitionedClipByConstantPipe<,,>).MakeGenericType( diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/ClipByConstant/ClipByConstantTransformer.cs b/Sources/Core/Microsoft.StreamProcessing/Operators/ClipByConstant/ClipByConstantTransformer.cs index 1bbe0e42a..719ba572b 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/ClipByConstant/ClipByConstantTransformer.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/ClipByConstant/ClipByConstantTransformer.cs @@ -3,6 +3,9 @@ // Licensed under the MIT License // ********************************************************************* using System; +#if CODEGEN_TIMING +using System.Diagnostics; +#endif using System.Diagnostics.Contracts; using System.Reflection; @@ -27,8 +30,8 @@ private ClipByConstantTemplate(string className, Type keyType, Type payloadType) /// internal static Tuple Generate(ClipByConstantStreamable stream) { - Contract.Requires(stream != null); - Contract.Ensures(Contract.Result>() == null || typeof(UnaryPipe).GetTypeInfo().IsAssignableFrom(Contract.Result>().Item1)); + ArgumentNullException.ThrowIfNull(stream); + Contract.Ensures(Contract.Result>() == null || typeof(UnaryPipe).IsAssignableFrom(Contract.Result>().Item1)); #if CODEGEN_TIMING Stopwatch sw = new Stopwatch(); diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/ClipByConstant/PartitionedClipByConstantPipe.cs b/Sources/Core/Microsoft.StreamProcessing/Operators/ClipByConstant/PartitionedClipByConstantPipe.cs index f7e4dce49..dcfa8c704 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/ClipByConstant/PartitionedClipByConstantPipe.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/ClipByConstant/PartitionedClipByConstantPipe.cs @@ -25,9 +25,9 @@ internal sealed class PartitionedClipByConstantPipe output; [DataMember] - private FastDictionary lastSyncTimeDictionary = new FastDictionary(); + private FastDictionary lastSyncTimeDictionary = new(); [DataMember] - private FastDictionary>> syncTimeMapDictionary = new FastDictionary>>(); + private FastDictionary>> syncTimeMapDictionary = new(); [Obsolete("Used only by serialization. Do not call directly.")] public PartitionedClipByConstantPipe() { } @@ -51,7 +51,7 @@ public override void ProduceQueryPlan(PlanNode previous) private void ReachTime(long timestamp) { int partitionKey = FastDictionary.IteratorStart; - while (this.lastSyncTimeDictionary.Iterate(ref partitionKey)) ReachTime(this.lastSyncTimeDictionary.entries[partitionKey].key, timestamp); + while (this.lastSyncTimeDictionary.Iterate(ref partitionKey)) this.ReachTime(this.lastSyncTimeDictionary.entries[partitionKey].key, timestamp); } private void ReachTime(TPartitionKey pKey, long timestamp) @@ -75,7 +75,7 @@ private void ReachTime(TPartitionKey pKey, long timestamp) this.output[ind] = ae.Payload; this.output.hash.col[ind] = ae.Hash; - if (this.output.Count == Config.DataBatchSize) FlushContents(); + if (this.output.Count == Config.DataBatchSize) this.FlushContents(); } toDelete.Add(kvp.Key); @@ -88,7 +88,7 @@ private void ReachTime(TPartitionKey pKey, long timestamp) private void AllocatePartition(TPartitionKey pKey, long timestamp) { this.syncTimeMapDictionary.Lookup(pKey, out int mapIndex); - this.syncTimeMapDictionary.Insert(ref mapIndex, pKey, new SortedDictionary>()); + this.syncTimeMapDictionary.Insert(ref mapIndex, pKey, []); this.lastSyncTimeDictionary.Lookup(pKey, out int timeIndex); this.lastSyncTimeDictionary.Insert(ref timeIndex, pKey, timestamp); } @@ -106,9 +106,9 @@ public override unsafe void OnNext(StreamMessage batch) var partition = this.getPartitionKey(batch.key.col[i]); if (!this.lastSyncTimeDictionary.Lookup(partition, out int timeIndex)) { - AllocatePartition(partition, batch.vsync.col[i]); + this.AllocatePartition(partition, batch.vsync.col[i]); } - else ReachTime(partition, batch.vsync.col[i]); + else this.ReachTime(partition, batch.vsync.col[i]); if (batch.vother.col[i] == StreamEvent.InfinitySyncTime) { @@ -122,7 +122,7 @@ public override unsafe void OnNext(StreamMessage batch) this.output[ind] = batch[i]; this.output.hash.col[ind] = batch.hash.col[i]; - if (this.output.Count == Config.DataBatchSize) FlushContents(); + if (this.output.Count == Config.DataBatchSize) this.FlushContents(); this.syncTimeMapDictionary.Lookup(partition, out int mapIndex); var syncTimeMap = this.syncTimeMapDictionary.entries[mapIndex].value; @@ -143,7 +143,7 @@ public override unsafe void OnNext(StreamMessage batch) this.output[ind] = batch[i]; this.output.hash.col[ind] = batch.hash.col[i]; - if (this.output.Count == Config.DataBatchSize) FlushContents(); + if (this.output.Count == Config.DataBatchSize) this.FlushContents(); } else { @@ -162,7 +162,7 @@ public override unsafe void OnNext(StreamMessage batch) this.output[ind] = payload; this.output.hash.col[ind] = batch.hash.col[i]; - if (this.output.Count == Config.DataBatchSize) FlushContents(); + if (this.output.Count == Config.DataBatchSize) this.FlushContents(); // Remove the corresponding start edge from the waiting list this.syncTimeMapDictionary.Lookup(partition, out int mapIndex); @@ -173,7 +173,7 @@ public override unsafe void OnNext(StreamMessage batch) } else if (batch.vother.col[i] == PartitionedStreamEvent.LowWatermarkOtherTime) { - ReachTime(batch.vsync.col[i]); + this.ReachTime(batch.vsync.col[i]); int ind = this.output.Count++; this.output.vsync.col[ind] = batch.vsync.col[i]; @@ -183,12 +183,12 @@ public override unsafe void OnNext(StreamMessage batch) this.output.hash.col[ind] = 0; this.output.bitvector.col[ind >> 6] |= 1L << (ind & 0x3f); - if (this.output.Count == Config.DataBatchSize) FlushContents(); + if (this.output.Count == Config.DataBatchSize) this.FlushContents(); } else if (batch.vother.col[i] == PartitionedStreamEvent.PunctuationOtherTime) { var partition = this.getPartitionKey(batch.key.col[i]); - ReachTime(partition, batch.vsync.col[i]); + this.ReachTime(partition, batch.vsync.col[i]); int ind = this.output.Count++; this.output.vsync.col[ind] = batch.vsync.col[i]; @@ -198,7 +198,7 @@ public override unsafe void OnNext(StreamMessage batch) this.output.hash.col[ind] = batch.hash.col[i]; this.output.bitvector.col[ind >> 6] |= 1L << (ind & 0x3f); - if (this.output.Count == Config.DataBatchSize) FlushContents(); + if (this.output.Count == Config.DataBatchSize) this.FlushContents(); } } } @@ -214,7 +214,12 @@ protected override void FlushContents() this.output.Allocate(); } - protected override void DisposeState() => this.output.Free(); + protected override void DisposeState() + { + this.lastSyncTimeDictionary.Dispose(); + this.syncTimeMapDictionary.Dispose(); + this.output.Free(); + } public override int CurrentlyBufferedOutputCount => this.output.Count; @@ -239,7 +244,7 @@ private struct ActiveEvent [DataMember] public int Hash; - public override string ToString() => "Key='" + this.Key + "', Payload='" + this.Payload; + public override readonly string ToString() => "Key='" + this.Key + "', Payload='" + this.Payload; } } } \ No newline at end of file diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/ColumnToRow/ColumnToRowStreamable.cs b/Sources/Core/Microsoft.StreamProcessing/Operators/ColumnToRow/ColumnToRowStreamable.cs index d9ad7229d..4fef4c077 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/ColumnToRow/ColumnToRowStreamable.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/ColumnToRow/ColumnToRowStreamable.cs @@ -11,12 +11,12 @@ namespace Microsoft.StreamProcessing internal sealed class ColumnToRowStreamable : UnaryStreamable { private static readonly SafeConcurrentDictionary> cachedPipes - = new SafeConcurrentDictionary>(); + = new(); public ColumnToRowStreamable(IStreamable source) : base(source, source.Properties.ToRowBased()) { - Contract.Requires(source != null); + ArgumentNullException.ThrowIfNull(source); } internal override IStreamObserver CreatePipe(IStreamObserver observer) diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/ColumnToRow/ColumnToRowTemplate.cs b/Sources/Core/Microsoft.StreamProcessing/Operators/ColumnToRow/ColumnToRowTemplate.cs index 7adad1fb2..50723c888 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/ColumnToRow/ColumnToRowTemplate.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/ColumnToRow/ColumnToRowTemplate.cs @@ -189,7 +189,7 @@ public override void ProduceQueryPlan(PlanNode previous) this.Write(" );\r\n "); } else { this.Write(" "); - if (!payloadType.GetTypeInfo().IsValueType) { + if (!payloadType.IsValueType) { this.Write("\r\n destpayload[i] = new "); this.Write(this.ToStringHelper.ToStringWithCulture(TPayload)); this.Write("();\r\n "); diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/ColumnToRow/ColumnToRowTemplate.tt b/Sources/Core/Microsoft.StreamProcessing/Operators/ColumnToRow/ColumnToRowTemplate.tt index 437f369a1..ffb24f068 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/ColumnToRow/ColumnToRowTemplate.tt +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/ColumnToRow/ColumnToRowTemplate.tt @@ -118,7 +118,7 @@ internal sealed class <#= className #><#= genericParameters #> : UnaryPipe<<#= T destpayload[i] = (<#= TPayload #>)Activator.CreateInstance(typeof(<#= TPayload #>) <#= fieldArgs #> ); <# } else { #> - <# if (!payloadType.GetTypeInfo().IsValueType) { #> + <# if (!payloadType.IsValueType) { #> destpayload[i] = new <#= TPayload #>(); <# } #> diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/ColumnToRow/ColumnToRowTransformer.cs b/Sources/Core/Microsoft.StreamProcessing/Operators/ColumnToRow/ColumnToRowTransformer.cs index 88140d53c..7d49b14e8 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/ColumnToRow/ColumnToRowTransformer.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/ColumnToRow/ColumnToRowTransformer.cs @@ -10,19 +10,17 @@ namespace Microsoft.StreamProcessing { - internal partial class ColumnToRowTemplate + internal partial class ColumnToRowTemplate(string className, Type keyType, Type payloadType) + : CommonUnaryTemplate(className, keyType, payloadType, payloadType) { private static int ColumnToRowSequenceNumber = 0; private bool rowMajor = true; - public ColumnToRowTemplate(string className, Type keyType, Type payloadType) - : base(className, keyType, payloadType, payloadType) { } - internal static Tuple Generate(ColumnToRowStreamable stream) { - Contract.Requires(stream != null); + ArgumentNullException.ThrowIfNull(stream); Contract.Ensures(Contract.Result>() != null); - Contract.Ensures(typeof(UnaryPipe).GetTypeInfo().IsAssignableFrom(Contract.Result>().Item1)); + Contract.Ensures(typeof(UnaryPipe).IsAssignableFrom(Contract.Result>().Item1)); var keyType = typeof(TKey); var payloadType = typeof(TPayload); @@ -36,24 +34,22 @@ internal static Tuple Generate(ColumnToRowStreamab var expandedCode = template.TransformText(); - assemblyReferences.Add(typeof(IStreamable<,>).GetTypeInfo().Assembly); + assemblyReferences.Add(typeof(IStreamable<,>).Assembly); assemblyReferences.Add(Transformer.GeneratedStreamMessageAssembly()); generatedClassName = generatedClassName.AddNumberOfNecessaryGenericArguments(keyType, payloadType); - var a = Transformer.CompileSourceCode(expandedCode, assemblyReferences, out string errorMessages); + var t = Transformer.CompileSourceCode(expandedCode, assemblyReferences, a => a.GetType(generatedClassName), out var errorMessages); if (payloadType.IsAnonymousTypeName()) { - if (errorMessages == null) errorMessages = string.Empty; + errorMessages ??= string.Empty; errorMessages += "\nCodegen Warning: The payload type for ColumnToRow is anonymous, causing the use of Activator.CreateInstance in an inner loop. This will lead to poor performance.\n"; } - - var t = a.GetType(generatedClassName); - if (t.GetTypeInfo().IsGenericType) + if (t.IsGenericType) { var list = keyType.GetAnonymousTypes(); list.AddRange(payloadType.GetAnonymousTypes()); - return Tuple.Create(t.MakeGenericType(list.ToArray()), errorMessages); + return Tuple.Create(t.MakeGenericType([.. list]), errorMessages); } else { diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/DisjointUnion/DisjointUnionPipe.cs b/Sources/Core/Microsoft.StreamProcessing/Operators/DisjointUnion/DisjointUnionPipe.cs index 57aa24c1f..5b2ec1c8e 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/DisjointUnion/DisjointUnionPipe.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/DisjointUnion/DisjointUnionPipe.cs @@ -35,13 +35,13 @@ protected override void ProcessBothBatches(StreamMessage leftBat rightBatchDone = true; rightBatchFree = false; - var newLeftGlobalPunctuation = Math.Max(this.leftGlobalPunctuation, ExtractGlobalPunctuations(leftBatch)); - var newRightGlobalPunctuation = Math.Max(this.rightGlobalPunctuation, ExtractGlobalPunctuations(rightBatch)); + var newLeftGlobalPunctuation = Math.Max(this.leftGlobalPunctuation, this.ExtractGlobalPunctuations(leftBatch)); + var newRightGlobalPunctuation = Math.Max(this.rightGlobalPunctuation, this.ExtractGlobalPunctuations(rightBatch)); this.Observer.OnNext(leftBatch); this.Observer.OnNext(rightBatch); var newGlobalPunctuation = Math.Min(newLeftGlobalPunctuation, newRightGlobalPunctuation); - EmitGlobalPunctuationIfNecessary(newGlobalPunctuation); + this.EmitGlobalPunctuationIfNecessary(newGlobalPunctuation); this.leftGlobalPunctuation = newLeftGlobalPunctuation; this.rightGlobalPunctuation = newRightGlobalPunctuation; @@ -52,11 +52,11 @@ protected override void ProcessLeftBatch(StreamMessage leftBatch leftBatchDone = true; leftBatchFree = false; - var newLeftGlobalPunctuation = Math.Max(this.leftGlobalPunctuation, ExtractGlobalPunctuations(leftBatch)); + var newLeftGlobalPunctuation = Math.Max(this.leftGlobalPunctuation, this.ExtractGlobalPunctuations(leftBatch)); this.Observer.OnNext(leftBatch); var newGlobalPunctuation = Math.Min(newLeftGlobalPunctuation, this.rightGlobalPunctuation); - EmitGlobalPunctuationIfNecessary(newGlobalPunctuation); + this.EmitGlobalPunctuationIfNecessary(newGlobalPunctuation); this.leftGlobalPunctuation = newLeftGlobalPunctuation; } @@ -66,11 +66,11 @@ protected override void ProcessRightBatch(StreamMessage rightBat rightBatchDone = true; rightBatchFree = false; - var newRightGlobalPunctuation = Math.Max(this.rightGlobalPunctuation, ExtractGlobalPunctuations(rightBatch)); + var newRightGlobalPunctuation = Math.Max(this.rightGlobalPunctuation, this.ExtractGlobalPunctuations(rightBatch)); this.Observer.OnNext(rightBatch); var newGlobalPunctuation = Math.Min(this.leftGlobalPunctuation, newRightGlobalPunctuation); - EmitGlobalPunctuationIfNecessary(newGlobalPunctuation); + this.EmitGlobalPunctuationIfNecessary(newGlobalPunctuation); this.rightGlobalPunctuation = newRightGlobalPunctuation; } diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/EndEdgeFreeOutput/EndEdgeFreeOutputPipe.cs b/Sources/Core/Microsoft.StreamProcessing/Operators/EndEdgeFreeOutput/EndEdgeFreeOutputPipe.cs index d68c406b3..69a8106cd 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/EndEdgeFreeOutput/EndEdgeFreeOutputPipe.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/EndEdgeFreeOutput/EndEdgeFreeOutputPipe.cs @@ -43,12 +43,12 @@ public EndEdgeFreeOutputPipe(EndEdgeFreeOutputStreamable stream, var getHashCode = compoundEqualityExpr.GetGetHashCodeExpr().Compile(); var generator = compoundEqualityExpr.CreateFastDictionary2Generator(1, equals, getHashCode, stream.Properties.QueryContainer); - this.dictPool = new DataStructurePool>(() => generator.Invoke()); + this.dictPool = new DataStructurePool>(generator.Invoke); this.pool.Get(out this.output); this.output.Allocate(); - this.eventMap = new SortedDictionary>(); + this.eventMap = []; this.lastSyncTime = StreamEvent.MinSyncTime; this.lastCti = StreamEvent.MinSyncTime; } @@ -84,7 +84,7 @@ private void OutputCompletedIntervals() this.output[ind] = outevt.Payload; this.output.hash.col[ind] = outevt.Hash; - if (this.output.Count == Config.DataBatchSize) FlushContents(); + if (this.output.Count == Config.DataBatchSize) this.FlushContents(); } kvp.Value.Remove(outevt); } @@ -114,7 +114,7 @@ private void OutputAllEvents() this.output[ind] = outevt.Payload; this.output.hash.col[ind] = outevt.Hash; - if (this.output.Count == Config.DataBatchSize) FlushContents(); + if (this.output.Count == Config.DataBatchSize) this.FlushContents(); } } } @@ -136,13 +136,13 @@ public override unsafe void OnNext(StreamMessage batch) if (batch.vother.col[i] == long.MinValue) // Punctuation { if (vsync[i] == StreamEvent.InfinitySyncTime) - OutputAllEvents(); + this.OutputAllEvents(); else - OutputCompletedIntervals(); + this.OutputCompletedIntervals(); this.lastCti = Math.Max(vsync[i], this.lastCti); this.lastSyncTime = Math.Max(vsync[i], this.lastSyncTime); - AddPunctuationToBatch(batch.vsync.col[i]); + this.AddPunctuationToBatch(batch.vsync.col[i]); } else if (vsync[i] < vother[i]) // Start edge or interval { @@ -197,7 +197,7 @@ public override unsafe void OnNext(StreamMessage batch) entry.Insert(lookupevt, 1); else entry.entries[index].value++; - OutputCompletedIntervals(); // Can make this more efficient by trying only if the first event in index got completed + this.OutputCompletedIntervals(); // Can make this more efficient by trying only if the first event in index got completed } } } @@ -216,7 +216,7 @@ private void AddPunctuationToBatch(long start) this.output.hash.col[index] = 0; this.output.bitvector.col[index >> 6] |= (1L << (index & 0x3f)); - if (this.output.Count == Config.DataBatchSize) FlushContents(); + if (this.output.Count == Config.DataBatchSize) this.FlushContents(); } public override void ProduceQueryPlan(PlanNode previous) @@ -260,7 +260,7 @@ private struct ActiveEvent [DataMember] public int Hash; - public override string ToString() => "[End=" + this.End + ", Key='" + this.Key + "', Payload='" + this.Payload + "']"; + public override readonly string ToString() => "[End=" + this.End + ", Key='" + this.Key + "', Payload='" + this.Payload + "']"; } } } diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/EndEdgeFreeOutput/EndEdgeFreeOutputStreamable.cs b/Sources/Core/Microsoft.StreamProcessing/Operators/EndEdgeFreeOutput/EndEdgeFreeOutputStreamable.cs index c7e862fe4..23104dae2 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/EndEdgeFreeOutput/EndEdgeFreeOutputStreamable.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/EndEdgeFreeOutput/EndEdgeFreeOutputStreamable.cs @@ -12,11 +12,11 @@ namespace Microsoft.StreamProcessing internal sealed class EndEdgeFreeOutputStreamable : UnaryStreamable { private static readonly SafeConcurrentDictionary> cachedPipes - = new SafeConcurrentDictionary>(); + = new(); public EndEdgeFreeOutputStreamable(IStreamable source) : base(source, source.Properties.ToIntervalFree(false)) { - Contract.Requires(source != null); + ArgumentNullException.ThrowIfNull(source); // This operator uses the equality method on payloads if (this.Properties.IsColumnar && !this.Properties.PayloadEqualityComparer.CanUsePayloadEquality()) @@ -24,13 +24,13 @@ public EndEdgeFreeOutputStreamable(IStreamable source) throw new InvalidOperationException($"Type of payload, '{typeof(TPayload).FullName}', to EndEdgeFreeOutputStreamable does not have a valid equality operator for columnar mode."); } - Initialize(); + this.Initialize(); } public override sealed IDisposable Subscribe(IStreamObserver observer) => this.Source.Properties.IsConstantDuration ? this.Source.Subscribe(observer) - : this.Source.Subscribe(CreatePipe(observer)); + : this.Source.Subscribe(this.CreatePipe(observer)); internal override IStreamObserver CreatePipe(IStreamObserver observer) { @@ -38,7 +38,7 @@ internal override IStreamObserver CreatePipe(IStreamObserver(this, observer); } diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/EndEdgeFreeOutput/EndEdgeFreeOutputTemplate.cs b/Sources/Core/Microsoft.StreamProcessing/Operators/EndEdgeFreeOutput/EndEdgeFreeOutputTemplate.cs index ae7d31776..479bddf4d 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/EndEdgeFreeOutput/EndEdgeFreeOutputTemplate.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/EndEdgeFreeOutput/EndEdgeFreeOutputTemplate.cs @@ -267,7 +267,7 @@ private void GetOutputBatch() "\n while (tuple.Value.Iterate(ref iter)) count += tuple.Value.entr" + "ies[iter].value;\r\n }\r\n return count;\r\n }\r\n }\r\n\r\n" + ""); - if (!noFields && !this.payloadType.GetTypeInfo().IsValueType) { + if (!noFields && !this.payloadType.IsValueType) { this.Write(" [DataContract]\r\n public struct "); this.Write(this.ToStringHelper.ToStringWithCulture(ActiveEventType)); this.Write("\r\n {\r\n"); diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/EndEdgeFreeOutput/EndEdgeFreeOutputTemplate.tt b/Sources/Core/Microsoft.StreamProcessing/Operators/EndEdgeFreeOutput/EndEdgeFreeOutputTemplate.tt index 336f91034..0d3f94582 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/EndEdgeFreeOutput/EndEdgeFreeOutputTemplate.tt +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/EndEdgeFreeOutput/EndEdgeFreeOutputTemplate.tt @@ -305,7 +305,7 @@ internal sealed class <#= className #><#= TKeyTPayloadGenericParameters #> : Una } } -<# if (!noFields && !this.payloadType.GetTypeInfo().IsValueType) { #> +<# if (!noFields && !this.payloadType.IsValueType) { #> [DataContract] public struct <#= ActiveEventType #> { diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/EndEdgeFreeOutput/EndEdgeFreeOutputTransformer.cs b/Sources/Core/Microsoft.StreamProcessing/Operators/EndEdgeFreeOutput/EndEdgeFreeOutputTransformer.cs index cb3127c96..28bbefa68 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/EndEdgeFreeOutput/EndEdgeFreeOutputTransformer.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/EndEdgeFreeOutput/EndEdgeFreeOutputTransformer.cs @@ -34,14 +34,14 @@ private EndEdgeFreeOutputTemplate(string className, Type keyType, Type payloadTy internal static Tuple Generate( EndEdgeFreeOutputStreamable stream) { - Contract.Requires(stream != null); - Contract.Ensures(Contract.Result>() == null || typeof(UnaryPipe).GetTypeInfo().IsAssignableFrom(Contract.Result>().Item1)); + ArgumentNullException.ThrowIfNull(stream); + Contract.Ensures(Contract.Result>() == null || typeof(UnaryPipe).IsAssignableFrom(Contract.Result>().Item1)); var template = new EndEdgeFreeOutputTemplate( $"GeneratedEndEdgeFreeOutput_{EndEdgeFreeOutputTemplateSequenceNumber++}", typeof(TKey), typeof(TPayload)); - template.ActiveEventType = typeof(TPayload).GetTypeInfo().IsValueType ? template.TPayload : "Active_Event"; + template.ActiveEventType = typeof(TPayload).IsValueType ? template.TPayload : "Active_Event"; #region Key Equals var keyComparer = stream.Properties.KeyEqualityComparer.GetEqualsExpr(); diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/EndEdgeFreeOutput/PartitionedEndEdgeFreeOutputPipe.cs b/Sources/Core/Microsoft.StreamProcessing/Operators/EndEdgeFreeOutput/PartitionedEndEdgeFreeOutputPipe.cs index 345f2bd5a..386edeba5 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/EndEdgeFreeOutput/PartitionedEndEdgeFreeOutputPipe.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/EndEdgeFreeOutput/PartitionedEndEdgeFreeOutputPipe.cs @@ -21,7 +21,7 @@ internal sealed class PartitionedEndEdgeFreeOutputPipe output; [DataMember] - private FastDictionary partitionData = new FastDictionary(); + private FastDictionary partitionData = new(); private readonly DataStructurePool> dictPool; @@ -39,7 +39,7 @@ public PartitionedEndEdgeFreeOutputPipe(IStreamable stream, IStr var equals = compoundEqualityExpr.GetEqualsExpr().Compile(); var getHashCode = compoundEqualityExpr.GetGetHashCodeExpr().Compile(); var generator = compoundEqualityExpr.CreateFastDictionary2Generator(1, equals, getHashCode, stream.Properties.QueryContainer); - this.dictPool = new DataStructurePool>(() => generator.Invoke()); + this.dictPool = new DataStructurePool>(generator.Invoke); this.pool.Get(out this.output); this.output.Allocate(); } @@ -77,7 +77,7 @@ private void OutputCompletedIntervals(PartitionEntry partition) this.output.hash.col[ind] = outevt.Hash; partition.lastSyncTime = kvp.Key; - if (this.output.Count == Config.DataBatchSize) FlushContents(); + if (this.output.Count == Config.DataBatchSize) this.FlushContents(); } kvp.Value.Remove(outevt); } @@ -108,7 +108,7 @@ private void OutputAllEvents(PartitionEntry partition) this.output[ind] = outevt.Payload; this.output.hash.col[ind] = outevt.Hash; - if (this.output.Count == Config.DataBatchSize) FlushContents(); + if (this.output.Count == Config.DataBatchSize) this.FlushContents(); } } } @@ -132,15 +132,15 @@ public override unsafe void OnNext(StreamMessage batch) { var p = this.partitionData.entries[index].value; if (batch.vsync.col[i] == StreamEvent.InfinitySyncTime) - OutputAllEvents(p); + this.OutputAllEvents(p); else - OutputCompletedIntervals(p); + this.OutputCompletedIntervals(p); p.lastCti = Math.Max(batch.vsync.col[i], p.lastCti); p.lastSyncTime = Math.Max(batch.vsync.col[i], p.lastSyncTime); } - AddLowWatermarkToBatch(batch.vother.col[i]); + this.AddLowWatermarkToBatch(batch.vother.col[i]); continue; } @@ -216,7 +216,7 @@ public override unsafe void OnNext(StreamMessage batch) { entry.entries[index].value++; } - OutputCompletedIntervals(partition); // Can make this more efficient by trying only if the first event in index got completed + this.OutputCompletedIntervals(partition); // Can make this more efficient by trying only if the first event in index got completed } } } @@ -235,7 +235,7 @@ private void AddLowWatermarkToBatch(long start) this.output.hash.col[index] = 0; this.output.bitvector.col[index >> 6] |= (1L << (index & 0x3f)); - if (this.output.Count == Config.DataBatchSize) FlushContents(); + if (this.output.Count == Config.DataBatchSize) this.FlushContents(); } public override void ProduceQueryPlan(PlanNode previous) @@ -283,7 +283,7 @@ private struct ActiveEvent [DataMember] public int Hash; - public override string ToString() + public override readonly string ToString() => "[End=" + this.End + ", Key='" + this.Key + "', Payload='" + this.Payload + "']"; } @@ -291,7 +291,7 @@ public override string ToString() private sealed class PartitionEntry { [DataMember] - public SortedDictionary> eventMap = new SortedDictionary>(); + public SortedDictionary> eventMap = []; [DataMember] public long lastSyncTime = StreamEvent.MinSyncTime; [DataMember] diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/EquiJoin/Basic/EquiJoinPipe.cs b/Sources/Core/Microsoft.StreamProcessing/Operators/EquiJoin/Basic/EquiJoinPipe.cs index d8c6cf6e7..6abd8248c 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/EquiJoin/Basic/EquiJoinPipe.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/EquiJoin/Basic/EquiJoinPipe.cs @@ -38,7 +38,7 @@ internal sealed class EquiJoinPipe : BinaryPipe [DataMember] - private FastMap> leftIntervalMap = new FastMap>(); + private FastMap> leftIntervalMap = new(); /// /// Stores left start edges at @@ -46,7 +46,7 @@ internal sealed class EquiJoinPipe : BinaryPipe [DataMember] - private FastMap> leftEdgeMap = new FastMap>(); + private FastMap> leftEdgeMap = new(); /// /// Stores end edges for the current join at some point in the future, i.e. after . @@ -61,7 +61,7 @@ internal sealed class EquiJoinPipe : BinaryPipe [DataMember] - private FastMap> rightIntervalMap = new FastMap>(); + private FastMap> rightIntervalMap = new(); /// /// Stores right start edges at @@ -69,7 +69,7 @@ internal sealed class EquiJoinPipe : BinaryPipe [DataMember] - private FastMap> rightEdgeMap = new FastMap>(); + private FastMap> rightEdgeMap = new(); [DataMember] private long nextLeftTime = long.MinValue; @@ -150,7 +150,7 @@ protected override void ProcessBothBatches(StreamMessage leftBatch, return; } - UpdateNextLeftTime(leftBatch.vsync.col[leftBatch.iter]); + this.UpdateNextLeftTime(leftBatch.vsync.col[leftBatch.iter]); if (!GoToVisibleRow(rightBatch)) { leftBatchDone = false; @@ -158,14 +158,14 @@ protected override void ProcessBothBatches(StreamMessage leftBatch, return; } - UpdateNextRightTime(rightBatch.vsync.col[rightBatch.iter]); + this.UpdateNextRightTime(rightBatch.vsync.col[rightBatch.iter]); while (true) { if (this.nextLeftTime <= this.nextRightTime) { - UpdateTime(this.nextLeftTime); - ProcessLeftEvent( + this.UpdateTime(this.nextLeftTime); + this.ProcessLeftEvent( this.nextLeftTime, leftBatch.vother.col[leftBatch.iter], ref leftBatch.key.col[leftBatch.iter], @@ -181,12 +181,12 @@ protected override void ProcessBothBatches(StreamMessage leftBatch, return; } - UpdateNextLeftTime(leftBatch.vsync.col[leftBatch.iter]); + this.UpdateNextLeftTime(leftBatch.vsync.col[leftBatch.iter]); } else { - UpdateTime(this.nextRightTime); - ProcessRightEvent( + this.UpdateTime(this.nextRightTime); + this.ProcessRightEvent( this.nextRightTime, rightBatch.vother.col[rightBatch.iter], ref rightBatch.key.col[rightBatch.iter], @@ -202,7 +202,7 @@ protected override void ProcessBothBatches(StreamMessage leftBatch, return; } - UpdateNextRightTime(rightBatch.vsync.col[rightBatch.iter]); + this.UpdateNextRightTime(rightBatch.vsync.col[rightBatch.iter]); } } } @@ -219,7 +219,7 @@ protected override void ProcessLeftBatch(StreamMessage batch, out b return; } - UpdateNextLeftTime(batch.vsync.col[batch.iter]); + this.UpdateNextLeftTime(batch.vsync.col[batch.iter]); if (this.nextLeftTime > this.nextRightTime) { @@ -227,9 +227,9 @@ protected override void ProcessLeftBatch(StreamMessage batch, out b return; } - UpdateTime(this.nextLeftTime); + this.UpdateTime(this.nextLeftTime); - ProcessLeftEvent( + this.ProcessLeftEvent( this.nextLeftTime, batch.vother.col[batch.iter], ref batch.key.col[batch.iter], @@ -252,7 +252,7 @@ protected override void ProcessRightBatch(StreamMessage batch, out return; } - UpdateNextRightTime(batch.vsync.col[batch.iter]); + this.UpdateNextRightTime(batch.vsync.col[batch.iter]); if (this.nextRightTime > this.nextLeftTime) { @@ -260,9 +260,9 @@ protected override void ProcessRightBatch(StreamMessage batch, out return; } - UpdateTime(this.nextRightTime); + this.UpdateTime(this.nextRightTime); - ProcessRightEvent( + this.ProcessRightEvent( this.nextRightTime, batch.vother.col[batch.iter], ref batch.key.col[batch.iter], @@ -287,9 +287,9 @@ private void UpdateTime(long time) { if (time != this.currTime) { - LeaveTime(); + this.LeaveTime(); this.currTime = time; - ReachTime(); + this.ReachTime(); } } @@ -331,7 +331,7 @@ private void ProcessLeftEvent(long start, long end, ref TKey key, TLeft payload, this.leftEdgeMap.Values[index].Populate(start, ref key, ref payload); } - CreateOutputForStartEdge(start, ref key, ref payload, hash); + this.CreateOutputForStartEdge(start, ref key, ref payload, hash); } else { @@ -346,7 +346,7 @@ private void ProcessLeftEvent(long start, long end, ref TKey key, TLeft payload, { int index = this.leftIntervalMap.Insert(hash); this.leftIntervalMap.Values[index].Populate(start, end, ref key, ref payload); - CreateOutputForStartInterval(start, end, ref key, ref payload, hash); + this.CreateOutputForStartInterval(start, end, ref key, ref payload, hash); this.endPointHeap.Insert(end, index); } else @@ -358,7 +358,7 @@ private void ProcessLeftEvent(long start, long end, ref TKey key, TLeft payload, } else if (end == StreamEvent.PunctuationOtherTime) { - AddPunctuationToBatch(start); + this.AddPunctuationToBatch(start); } else { @@ -370,7 +370,7 @@ private void ProcessLeftEvent(long start, long end, ref TKey key, TLeft payload, while (edges.Next(out int index)) { var temp = this.leftEdgeMap.Values[index]; - if (AreSame(end, ref key, ref payload, ref temp)) + if (this.AreSame(end, ref key, ref payload, ref temp)) { edges.Remove(); break; @@ -379,7 +379,7 @@ private void ProcessLeftEvent(long start, long end, ref TKey key, TLeft payload, } // Output end edges. - CreateOutputForEndEdge(start, end, ref key, ref payload, hash); + this.CreateOutputForEndEdge(start, end, ref key, ref payload, hash); } } @@ -401,7 +401,7 @@ private void ProcessRightEvent(long start, long end, ref TKey key, TRight payloa this.rightEdgeMap.Values[index].Populate(start, ref key, ref payload); } - CreateOutputForStartEdge(start, ref key, ref payload, hash); + this.CreateOutputForStartEdge(start, ref key, ref payload, hash); } else { @@ -418,7 +418,7 @@ private void ProcessRightEvent(long start, long end, ref TKey key, TRight payloa int index = this.rightIntervalMap.Insert(hash); this.rightIntervalMap.Values[index].Populate(start, end, ref key, ref payload); - CreateOutputForStartInterval(start, end, ref key, ref payload, hash); + this.CreateOutputForStartInterval(start, end, ref key, ref payload, hash); this.endPointHeap.Insert(end, ~index); } else @@ -430,7 +430,7 @@ private void ProcessRightEvent(long start, long end, ref TKey key, TRight payloa } else if (end == StreamEvent.PunctuationOtherTime) { - AddPunctuationToBatch(start); + this.AddPunctuationToBatch(start); } else { @@ -443,7 +443,7 @@ private void ProcessRightEvent(long start, long end, ref TKey key, TRight payloa while (edges.Next(out int index)) { var temp = this.rightEdgeMap.Values[index]; - if (AreSame(end, ref key, ref payload, ref temp)) + if (this.AreSame(end, ref key, ref payload, ref temp)) { edges.Remove(); @@ -453,7 +453,7 @@ private void ProcessRightEvent(long start, long end, ref TKey key, TRight payloa } // Output end edges. - CreateOutputForEndEdge(start, end, ref key, ref payload, hash); + this.CreateOutputForEndEdge(start, end, ref key, ref payload, hash); } } @@ -468,7 +468,7 @@ private void LeaveTime() { var ed = this.leftEdgeMap.Values[index]; - CreateOutputForStartEdge( + this.CreateOutputForStartEdge( this.currTime, ref ed.Key, ref ed.Payload, @@ -483,7 +483,7 @@ private void LeaveTime() var intrvl = this.leftIntervalMap.Values[index]; long end = intrvl.End; - CreateOutputForStartInterval( + this.CreateOutputForStartInterval( this.currTime, end, ref intrvl.Key, @@ -498,7 +498,7 @@ private void LeaveTime() while (rightEdges.Next(out index, out hash)) { var ed = this.rightEdgeMap.Values[index]; - CreateOutputForStartEdge( + this.CreateOutputForStartEdge( this.currTime, ref ed.Key, ref ed.Payload, @@ -512,7 +512,7 @@ private void LeaveTime() { var intrvl = this.rightIntervalMap.Values[index]; long end = intrvl.End; - CreateOutputForStartInterval( + this.CreateOutputForStartInterval( this.currTime, end, ref intrvl.Key, @@ -543,7 +543,7 @@ private void ReachTime() { // Endpoint is left interval ending. var intrvl = this.leftIntervalMap.Values[index]; - CreateOutputForEndInterval( + this.CreateOutputForEndInterval( endPointTime, intrvl.Start, ref intrvl.Key, @@ -557,7 +557,7 @@ private void ReachTime() index = ~index; var intrvl = this.rightIntervalMap.Values[index]; - CreateOutputForEndInterval( + this.CreateOutputForEndInterval( endPointTime, intrvl.Start, ref intrvl.Key, @@ -579,7 +579,7 @@ private void CreateOutputForEndEdge(long currentTime, long start, ref TKey key, if (this.keyComparerEquals(key, ed.Key)) { long rightStart = ed.Start; - AddToBatch( + this.AddToBatch( currentTime, start > rightStart ? start : rightStart, ref key, @@ -597,7 +597,7 @@ private void CreateOutputForEndEdge(long currentTime, long start, ref TKey key, if (this.keyComparerEquals(key, ed.Key)) { long rightStart = ed.Start; - AddToBatch( + this.AddToBatch( currentTime, start > rightStart ? start : rightStart, ref key, @@ -620,7 +620,7 @@ private void CreateOutputForEndEdge(long currentTime, long start, ref TKey key, if (this.keyComparerEquals(key, ld.Key)) { long leftStart = ld.Start; - AddToBatch( + this.AddToBatch( currentTime, start > leftStart ? start : leftStart, ref key, @@ -638,7 +638,7 @@ private void CreateOutputForEndEdge(long currentTime, long start, ref TKey key, if (this.keyComparerEquals(key, li.Key)) { long leftStart = li.Start; - AddToBatch( + this.AddToBatch( currentTime, start > leftStart ? start : leftStart, ref key, @@ -660,7 +660,7 @@ private void CreateOutputForStartEdge(long currentTime, ref TKey key, ref TLeft var red = this.rightEdgeMap.Values[index]; if (this.keyComparerEquals(key, red.Key)) { - AddToBatch( + this.AddToBatch( currentTime, StreamEvent.InfinitySyncTime, ref key, @@ -677,7 +677,7 @@ private void CreateOutputForStartEdge(long currentTime, ref TKey key, ref TLeft var rin = this.rightIntervalMap.Values[index]; if (this.keyComparerEquals(key, rin.Key)) { - AddToBatch( + this.AddToBatch( currentTime, StreamEvent.InfinitySyncTime, ref key, @@ -699,7 +699,7 @@ private void CreateOutputForStartEdge(long currentTime, ref TKey key, ref TRight var led = this.leftEdgeMap.Values[index]; if (this.keyComparerEquals(key, led.Key)) { - AddToBatch( + this.AddToBatch( currentTime, StreamEvent.InfinitySyncTime, ref key, @@ -716,7 +716,7 @@ private void CreateOutputForStartEdge(long currentTime, ref TKey key, ref TRight var lin = this.leftIntervalMap.Values[index]; if (this.keyComparerEquals(key, lin.Key)) { - AddToBatch( + this.AddToBatch( currentTime, StreamEvent.InfinitySyncTime, ref key, @@ -738,7 +738,7 @@ private void CreateOutputForStartInterval(long currentTime, long end, ref TKey k var red = this.rightEdgeMap.Values[index]; if (this.keyComparerEquals(key, red.Key)) { - AddToBatch( + this.AddToBatch( currentTime, StreamEvent.InfinitySyncTime, ref key, @@ -756,7 +756,7 @@ private void CreateOutputForStartInterval(long currentTime, long end, ref TKey k if (this.keyComparerEquals(key, rin.Key)) { long rightEnd = rin.End; - AddToBatch( + this.AddToBatch( currentTime, end < rightEnd ? end : rightEnd, ref key, @@ -778,7 +778,7 @@ private void CreateOutputForStartInterval(long currentTime, long end, ref TKey k var led = this.leftEdgeMap.Values[index]; if (this.keyComparerEquals(key, led.Key)) { - AddToBatch( + this.AddToBatch( currentTime, StreamEvent.InfinitySyncTime, ref key, @@ -796,7 +796,7 @@ private void CreateOutputForStartInterval(long currentTime, long end, ref TKey k if (this.keyComparerEquals(key, lin.Key)) { long leftEnd = lin.End; - AddToBatch( + this.AddToBatch( currentTime, end < leftEnd ? end : leftEnd, ref key, @@ -818,7 +818,7 @@ private void CreateOutputForEndInterval(long currentTime, long start, ref TKey k if (this.keyComparerEquals(key, red.Key)) { long rightStart = red.Start; - AddToBatch( + this.AddToBatch( currentTime, start > rightStart ? start : rightStart, ref key, @@ -840,7 +840,7 @@ private void CreateOutputForEndInterval(long currentTime, long start, ref TKey k if (this.keyComparerEquals(key, led.Key)) { long leftStart = led.Start; - AddToBatch( + this.AddToBatch( currentTime, start > leftStart ? start : leftStart, ref key, @@ -866,7 +866,7 @@ private void AddPunctuationToBatch(long start) this.output.hash.col[index] = 0; this.output.bitvector.col[index >> 6] |= (1L << (index & 0x3f)); - if (this.output.Count == Config.DataBatchSize) FlushContents(); + if (this.output.Count == Config.DataBatchSize) this.FlushContents(); } } @@ -885,7 +885,7 @@ private void AddToBatch(long start, long end, ref TKey key, ref TLeft leftPayloa this.output[index] = this.selector(leftPayload, rightPayload); this.output.hash.col[index] = hash; - if (this.output.Count == Config.DataBatchSize) FlushContents(); + if (this.output.Count == Config.DataBatchSize) this.FlushContents(); } [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -930,7 +930,7 @@ public void Populate(long start, long end, ref TKey key, ref TPayload payload) this.Payload = payload; } - public override string ToString() => "[Start=" + this.Start + ", End=" + this.End + ", Key='" + this.Key + "', Payload='" + this.Payload + "']"; + public override readonly string ToString() => "[Start=" + this.Start + ", End=" + this.End + ", Key='" + this.Key + "', Payload='" + this.Payload + "']"; } [DataContract] @@ -951,7 +951,7 @@ public void Populate(long start, ref TKey key, ref TPayload payload) this.Payload = payload; } - public override string ToString() => "[Start=" + this.Start + ", Key='" + this.Key + "', Payload='" + this.Payload + "']"; + public override readonly string ToString() => "[Start=" + this.Start + ", Key='" + this.Key + "', Payload='" + this.Payload + "']"; } } } diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/EquiJoin/Basic/EquiJoinTemplate.cs b/Sources/Core/Microsoft.StreamProcessing/Operators/EquiJoin/Basic/EquiJoinTemplate.cs index df1b68020..2711d34e7 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/EquiJoin/Basic/EquiJoinTemplate.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/EquiJoin/Basic/EquiJoinTemplate.cs @@ -1060,7 +1060,7 @@ private void AddPunctuationToBatch(long start) this.Write(";\r\n }\r\n\r\n protected override void FlushContents()\r\n {\r\n if (outpu" + "t.Count == 0) return;\r\n output.Seal();\r\n this.Observer.OnNext(outp" + "ut);\r\n GetOutputBatch();\r\n }\r\n\r\n"); - if (!this.leftType.GetTypeInfo().IsValueType) { + if (!this.leftType.IsValueType) { this.Write(" [DataContract]\r\n private struct "); this.Write(this.ToStringHelper.ToStringWithCulture(ActiveEventTypeLeft)); this.Write("\r\n {\r\n "); @@ -1073,7 +1073,7 @@ private void AddPunctuationToBatch(long start) } this.Write(" }\r\n"); } - if (!this.rightType.GetTypeInfo().IsValueType) { + if (!this.rightType.IsValueType) { this.Write(" [DataContract]\r\n private struct "); this.Write(this.ToStringHelper.ToStringWithCulture(ActiveEventTypeRight)); this.Write("\r\n {\r\n "); diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/EquiJoin/Basic/EquiJoinTemplate.tt b/Sources/Core/Microsoft.StreamProcessing/Operators/EquiJoin/Basic/EquiJoinTemplate.tt index 7d9909ab9..f1abe865d 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/EquiJoin/Basic/EquiJoinTemplate.tt +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/EquiJoin/Basic/EquiJoinTemplate.tt @@ -1127,7 +1127,7 @@ internal sealed class <#= className #><#= genericParameters #> : BinaryPipe<<#= GetOutputBatch(); } -<# if (!this.leftType.GetTypeInfo().IsValueType) { #> +<# if (!this.leftType.IsValueType) { #> [DataContract] private struct <#= ActiveEventTypeLeft #> { @@ -1137,7 +1137,7 @@ internal sealed class <#= className #><#= genericParameters #> : BinaryPipe<<#= <# } #> } <# } #> -<# if (!this.rightType.GetTypeInfo().IsValueType) { #> +<# if (!this.rightType.IsValueType) { #> [DataContract] private struct <#= ActiveEventTypeRight #> { diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/EquiJoin/Basic/EquijoinTransformer.cs b/Sources/Core/Microsoft.StreamProcessing/Operators/EquiJoin/Basic/EquijoinTransformer.cs index a54b1081e..3d1731969 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/EquiJoin/Basic/EquijoinTransformer.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/EquiJoin/Basic/EquijoinTransformer.cs @@ -40,8 +40,8 @@ internal static Tuple Generate( BinaryStreamable stream, Expression> selector) { - Contract.Requires(stream != null); - Contract.Ensures(Contract.Result>() == null || typeof(BinaryPipe).GetTypeInfo().IsAssignableFrom(Contract.Result>().Item1)); + ArgumentNullException.ThrowIfNull(stream); + Contract.Ensures(Contract.Result>() == null || typeof(BinaryPipe).IsAssignableFrom(Contract.Result>().Item1)); string errorMessages = null; try @@ -68,8 +68,8 @@ internal static Tuple Generate( template.rightFields = template.rightMessageRepresentation.AllFields; template.resultFields = resultMessageRepresentation.AllFields; - template.ActiveEventTypeLeft = template.leftType.GetTypeInfo().IsValueType ? template.TLeft : "Active_Event_Left"; - template.ActiveEventTypeRight = template.rightType.GetTypeInfo().IsValueType ? template.TRight : "Active_Event_Right"; + template.ActiveEventTypeLeft = template.leftType.IsValueType ? template.TLeft : "Active_Event_Left"; + template.ActiveEventTypeRight = template.rightType.IsValueType ? template.TRight : "Active_Event_Right"; #region Key Equals var keyComparer = stream.Properties.KeyEqualityComparer.GetEqualsExpr(); diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/EquiJoin/Basic/PartitionedEquiJoinPipe.cs b/Sources/Core/Microsoft.StreamProcessing/Operators/EquiJoin/Basic/PartitionedEquiJoinPipe.cs index 901caebe8..f4ba3ecf1 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/EquiJoin/Basic/PartitionedEquiJoinPipe.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/EquiJoin/Basic/PartitionedEquiJoinPipe.cs @@ -33,21 +33,21 @@ internal sealed class PartitionedEquiJoinPipe rightComparerEquals; [DataMember] - private FastDictionary2> leftQueue = new FastDictionary2>(); + private FastDictionary2> leftQueue = new(); [DataMember] - private FastDictionary2> rightQueue = new FastDictionary2>(); + private FastDictionary2> rightQueue = new(); [DataMember] - private HashSet processQueue = new HashSet(); + private HashSet processQueue = []; [DataMember] - private HashSet seenKeys = new HashSet(); + private HashSet seenKeys = []; [DataMember] - private HashSet cleanKeys = new HashSet(); + private HashSet cleanKeys = []; [DataMember] private StreamMessage output; [DataMember] - private FastDictionary partitionData = new FastDictionary(); + private FastDictionary partitionData = new(); [DataMember] private long lastLeftCTI = long.MinValue; [DataMember] @@ -143,8 +143,8 @@ private void NewPartition(TPartitionKey pKey) protected override void ProcessBothBatches(StreamMessage leftBatch, StreamMessage rightBatch, out bool leftBatchDone, out bool rightBatchDone, out bool leftBatchFree, out bool rightBatchFree) { - ProcessLeftBatch(leftBatch, out leftBatchDone, out leftBatchFree); - ProcessRightBatch(rightBatch, out rightBatchDone, out rightBatchFree); + this.ProcessLeftBatch(leftBatch, out leftBatchDone, out leftBatchFree); + this.ProcessRightBatch(rightBatch, out rightBatchDone, out rightBatchFree); } protected override void ProcessLeftBatch(StreamMessage batch, out bool leftBatchDone, out bool leftBatchFree) @@ -173,7 +173,7 @@ protected override void ProcessLeftBatch(StreamMessage batch, out b var partitionKey = this.getPartitionKey(batch.key.col[i]); if (first || !partitionKey.Equals(previous)) { - if (this.seenKeys.Add(partitionKey)) NewPartition(partitionKey); + if (this.seenKeys.Add(partitionKey)) this.NewPartition(partitionKey); this.leftQueue.Lookup(partitionKey, out int index); queue = this.leftQueue.entries[index].value; this.processQueue.Add(partitionKey); @@ -191,7 +191,7 @@ protected override void ProcessLeftBatch(StreamMessage batch, out b previous = partitionKey; } - ProcessPendingEntries(); + this.ProcessPendingEntries(); } protected override void ProcessRightBatch(StreamMessage batch, out bool rightBatchDone, out bool rightBatchFree) @@ -219,7 +219,7 @@ protected override void ProcessRightBatch(StreamMessage batch, out var partitionKey = this.getPartitionKey(batch.key.col[i]); if (first || !partitionKey.Equals(previous)) { - if (this.seenKeys.Add(partitionKey)) NewPartition(partitionKey); + if (this.seenKeys.Add(partitionKey)) this.NewPartition(partitionKey); this.rightQueue.Lookup(partitionKey, out int index); queue = this.rightQueue.entries[index].value; this.processQueue.Add(partitionKey); @@ -237,11 +237,15 @@ protected override void ProcessRightBatch(StreamMessage batch, out previous = partitionKey; } - ProcessPendingEntries(); + this.ProcessPendingEntries(); } [MethodImpl(MethodImplOptions.AggressiveInlining)] - protected override void DisposeState() => this.output.Free(); + protected override void DisposeState() + { + this.partitionData.Dispose(); + this.output.Free(); + } [MethodImpl(MethodImplOptions.AggressiveInlining)] private void ProcessPendingEntries() @@ -276,11 +280,11 @@ private void ProcessPendingEntries() if (partition.nextLeftTime < partition.nextRightTime) { - UpdateTime(partition, partition.nextLeftTime); + this.UpdateTime(partition, partition.nextLeftTime); if (leftEntry.Other != long.MinValue) { - ProcessLeftEvent( + this.ProcessLeftEvent( partition, partition.nextLeftTime, leftEntry.Other, @@ -291,7 +295,7 @@ private void ProcessPendingEntries() else if (partition.currTime > old) { var r = default(TRight); - AddToBatch( + this.AddToBatch( partition.currTime, long.MinValue, ref leftEntry.Key, @@ -304,11 +308,11 @@ private void ProcessPendingEntries() } else { - UpdateTime(partition, partition.nextRightTime); + this.UpdateTime(partition, partition.nextRightTime); if (rightEntry.Other != long.MinValue) { - ProcessRightEvent( + this.ProcessRightEvent( partition, partition.nextRightTime, rightEntry.Other, @@ -319,7 +323,7 @@ private void ProcessPendingEntries() else if (partition.currTime > old) { var l = default(TLeft); - AddToBatch( + this.AddToBatch( partition.currTime, long.MinValue, ref rightEntry.Key, @@ -341,15 +345,15 @@ private void ProcessPendingEntries() // If we have not yet reached the lesser of the two sides (in this case, right), and we don't // have input from that side, reach that time now. This can happen with low watermarks. if (partition.currTime < partition.nextRightTime) - UpdateTime(partition, partition.nextRightTime); + this.UpdateTime(partition, partition.nextRightTime); break; } - UpdateTime(partition, partition.nextLeftTime); + this.UpdateTime(partition, partition.nextLeftTime); if (leftEntry.Other != long.MinValue) { - ProcessLeftEvent( + this.ProcessLeftEvent( partition, partition.nextLeftTime, leftEntry.Other, @@ -360,7 +364,7 @@ private void ProcessPendingEntries() else if (partition.currTime > old) { var r = default(TRight); - AddToBatch( + this.AddToBatch( partition.currTime, long.MinValue, ref leftEntry.Key, @@ -381,15 +385,15 @@ private void ProcessPendingEntries() // If we have not yet reached the lesser of the two sides (in this case, left), and we don't // have input from that side, reach that time now. This can happen with low watermarks. if (partition.currTime < partition.nextLeftTime) - UpdateTime(partition, partition.nextLeftTime); + this.UpdateTime(partition, partition.nextLeftTime); break; } - UpdateTime(partition, partition.nextRightTime); + this.UpdateTime(partition, partition.nextRightTime); if (rightEntry.Other != long.MinValue) { - ProcessRightEvent( + this.ProcessRightEvent( partition, partition.nextRightTime, rightEntry.Other, @@ -400,7 +404,7 @@ private void ProcessPendingEntries() else if (partition.currTime > old) { var l = default(TLeft); - AddToBatch( + this.AddToBatch( partition.currTime, long.MinValue, ref rightEntry.Key, @@ -418,7 +422,7 @@ private void ProcessPendingEntries() if (partition.nextRightTime < this.lastRightCTI) UpdateNextRightTime(partition, this.lastRightCTI); - UpdateTime(partition, Math.Min(this.lastLeftCTI, this.lastRightCTI)); + this.UpdateTime(partition, Math.Min(this.lastLeftCTI, this.lastRightCTI)); if (partition.IsClean()) this.cleanKeys.Add(pKey); break; @@ -429,7 +433,7 @@ private void ProcessPendingEntries() if (this.emitCTI) { var earliest = Math.Min(this.lastLeftCTI, this.lastRightCTI); - AddLowWatermarkToBatch(earliest); + this.AddLowWatermarkToBatch(earliest); this.emitCTI = false; foreach (var p in this.cleanKeys) { @@ -449,9 +453,9 @@ private void UpdateTime(PartitionEntry partition, long time) { if (time > partition.currTime) { - LeaveTime(partition); + this.LeaveTime(partition); partition.currTime = time; - ReachTime(partition); + this.ReachTime(partition); } } @@ -473,7 +477,7 @@ private void ProcessLeftEvent(PartitionEntry partition, long start, long end, re partition.leftEdgeMap.Values[index].Populate(start, ref key, ref payload); } - CreateOutputForStartEdge(partition, start, ref key, ref payload, hash); + this.CreateOutputForStartEdge(partition, start, ref key, ref payload, hash); } else { @@ -488,7 +492,7 @@ private void ProcessLeftEvent(PartitionEntry partition, long start, long end, re { int index = partition.leftIntervalMap.Insert(hash); partition.leftIntervalMap.Values[index].Populate(start, end, ref key, ref payload); - CreateOutputForStartInterval(partition, start, end, ref key, ref payload, hash); + this.CreateOutputForStartInterval(partition, start, end, ref key, ref payload, hash); partition.endPointHeap.Insert(end, index); } else @@ -508,7 +512,7 @@ private void ProcessLeftEvent(PartitionEntry partition, long start, long end, re var edges = partition.leftEdgeMap.Find(hash); while (edges.Next(out int index)) { - if (AreSame(end, ref key, ref payload, ref partition.leftEdgeMap.Values[index])) + if (this.AreSame(end, ref key, ref payload, ref partition.leftEdgeMap.Values[index])) { edges.Remove(); break; @@ -517,7 +521,7 @@ private void ProcessLeftEvent(PartitionEntry partition, long start, long end, re } // Output end edges. - CreateOutputForEndEdge(partition, start, end, ref key, ref payload, hash); + this.CreateOutputForEndEdge(partition, start, end, ref key, ref payload, hash); } } @@ -539,7 +543,7 @@ private void ProcessRightEvent(PartitionEntry partition, long start, long end, r partition.rightEdgeMap.Values[index].Populate(start, ref key, ref payload); } - CreateOutputForStartEdge(partition, start, ref key, ref payload, hash); + this.CreateOutputForStartEdge(partition, start, ref key, ref payload, hash); } else { @@ -554,7 +558,7 @@ private void ProcessRightEvent(PartitionEntry partition, long start, long end, r { int index = partition.rightIntervalMap.Insert(hash); partition.rightIntervalMap.Values[index].Populate(start, end, ref key, ref payload); - CreateOutputForStartInterval(partition, start, end, ref key, ref payload, hash); + this.CreateOutputForStartInterval(partition, start, end, ref key, ref payload, hash); partition.endPointHeap.Insert(end, ~index); } else @@ -574,7 +578,7 @@ private void ProcessRightEvent(PartitionEntry partition, long start, long end, r var edges = partition.rightEdgeMap.Find(hash); while (edges.Next(out int index)) { - if (AreSame(end, ref key, ref payload, ref partition.rightEdgeMap.Values[index])) + if (this.AreSame(end, ref key, ref payload, ref partition.rightEdgeMap.Values[index])) { edges.Remove(); break; @@ -583,7 +587,7 @@ private void ProcessRightEvent(PartitionEntry partition, long start, long end, r } // Output end edges. - CreateOutputForEndEdge(partition, start, end, ref key, ref payload, hash); + this.CreateOutputForEndEdge(partition, start, end, ref key, ref payload, hash); } } @@ -593,7 +597,7 @@ private void LeaveTime(PartitionEntry partition) var leftEdges = partition.leftEdgeMap.TraverseInvisible(); while (leftEdges.Next(out int index, out int hash)) { - CreateOutputForStartEdge( + this.CreateOutputForStartEdge( partition, partition.currTime, ref partition.leftEdgeMap.Values[index].Key, @@ -606,7 +610,7 @@ private void LeaveTime(PartitionEntry partition) while (leftIntervals.Next(out int index, out int hash)) { long end = partition.leftIntervalMap.Values[index].End; - CreateOutputForStartInterval( + this.CreateOutputForStartInterval( partition, partition.currTime, end, @@ -620,7 +624,7 @@ private void LeaveTime(PartitionEntry partition) var rightEdges = partition.rightEdgeMap.TraverseInvisible(); while (rightEdges.Next(out int index, out int hash)) { - CreateOutputForStartEdge( + this.CreateOutputForStartEdge( partition, partition.currTime, ref partition.rightEdgeMap.Values[index].Key, @@ -633,7 +637,7 @@ private void LeaveTime(PartitionEntry partition) while (rightIntervals.Next(out int index, out int hash)) { long end = partition.rightIntervalMap.Values[index].End; - CreateOutputForStartInterval( + this.CreateOutputForStartInterval( partition, partition.currTime, end, @@ -659,7 +663,7 @@ private void ReachTime(PartitionEntry partition) if (index >= 0) { // Endpoint is left interval ending. - CreateOutputForEndInterval( + this.CreateOutputForEndInterval( partition, endPointTime, partition.leftIntervalMap.Values[index].Start, @@ -672,7 +676,7 @@ private void ReachTime(PartitionEntry partition) { // Endpoint is right interval ending. index = ~index; - CreateOutputForEndInterval( + this.CreateOutputForEndInterval( partition, endPointTime, partition.rightIntervalMap.Values[index].Start, @@ -695,7 +699,7 @@ private void CreateOutputForEndEdge(PartitionEntry partition, long currentTime, if (this.keyComparerEquals(key, partition.rightEdgeMap.Values[index].Key)) { long rightStart = partition.rightEdgeMap.Values[index].Start; - AddToBatch( + this.AddToBatch( currentTime, start > rightStart ? start : rightStart, ref key, @@ -712,7 +716,7 @@ private void CreateOutputForEndEdge(PartitionEntry partition, long currentTime, if (this.keyComparerEquals(key, partition.rightIntervalMap.Values[index].Key)) { long rightStart = partition.rightIntervalMap.Values[index].Start; - AddToBatch( + this.AddToBatch( currentTime, start > rightStart ? start : rightStart, ref key, @@ -734,7 +738,7 @@ private void CreateOutputForEndEdge(PartitionEntry partition, long currentTime, if (this.keyComparerEquals(key, partition.leftEdgeMap.Values[index].Key)) { long leftStart = partition.leftEdgeMap.Values[index].Start; - AddToBatch( + this.AddToBatch( currentTime, start > leftStart ? start : leftStart, ref key, @@ -751,7 +755,7 @@ private void CreateOutputForEndEdge(PartitionEntry partition, long currentTime, if (this.keyComparerEquals(key, partition.leftIntervalMap.Values[index].Key)) { long leftStart = partition.leftIntervalMap.Values[index].Start; - AddToBatch( + this.AddToBatch( currentTime, start > leftStart ? start : leftStart, ref key, @@ -772,7 +776,7 @@ private void CreateOutputForStartEdge(PartitionEntry partition, long currentTime { if (this.keyComparerEquals(key, partition.rightEdgeMap.Values[index].Key)) { - AddToBatch( + this.AddToBatch( currentTime, StreamEvent.InfinitySyncTime, ref key, @@ -788,7 +792,7 @@ private void CreateOutputForStartEdge(PartitionEntry partition, long currentTime { if (this.keyComparerEquals(key, partition.rightIntervalMap.Values[index].Key)) { - AddToBatch( + this.AddToBatch( currentTime, StreamEvent.InfinitySyncTime, ref key, @@ -809,7 +813,7 @@ private void CreateOutputForStartEdge(PartitionEntry partition, long currentTime { if (this.keyComparerEquals(key, partition.leftEdgeMap.Values[index].Key)) { - AddToBatch( + this.AddToBatch( currentTime, StreamEvent.InfinitySyncTime, ref key, @@ -825,7 +829,7 @@ private void CreateOutputForStartEdge(PartitionEntry partition, long currentTime { if (this.keyComparerEquals(key, partition.leftIntervalMap.Values[index].Key)) { - AddToBatch( + this.AddToBatch( currentTime, StreamEvent.InfinitySyncTime, ref key, @@ -846,7 +850,7 @@ private void CreateOutputForStartInterval(PartitionEntry partition, long current { if (this.keyComparerEquals(key, partition.rightEdgeMap.Values[index].Key)) { - AddToBatch( + this.AddToBatch( currentTime, StreamEvent.InfinitySyncTime, ref key, @@ -863,7 +867,7 @@ private void CreateOutputForStartInterval(PartitionEntry partition, long current if (this.keyComparerEquals(key, partition.rightIntervalMap.Values[index].Key)) { long rightEnd = partition.rightIntervalMap.Values[index].End; - AddToBatch( + this.AddToBatch( currentTime, end < rightEnd ? end : rightEnd, ref key, @@ -884,7 +888,7 @@ private void CreateOutputForStartInterval(PartitionEntry partition, long current { if (this.keyComparerEquals(key, partition.leftEdgeMap.Values[index].Key)) { - AddToBatch( + this.AddToBatch( currentTime, StreamEvent.InfinitySyncTime, ref key, @@ -901,7 +905,7 @@ private void CreateOutputForStartInterval(PartitionEntry partition, long current if (this.keyComparerEquals(key, partition.leftIntervalMap.Values[index].Key)) { long leftEnd = partition.leftIntervalMap.Values[index].End; - AddToBatch( + this.AddToBatch( currentTime, end < leftEnd ? end : leftEnd, ref key, @@ -922,7 +926,7 @@ private void CreateOutputForEndInterval(PartitionEntry partition, long currentTi if (this.keyComparerEquals(key, partition.rightEdgeMap.Values[index].Key)) { long rightStart = partition.rightEdgeMap.Values[index].Start; - AddToBatch( + this.AddToBatch( currentTime, start > rightStart ? start : rightStart, ref key, @@ -943,7 +947,7 @@ private void CreateOutputForEndInterval(PartitionEntry partition, long currentTi if (this.keyComparerEquals(key, partition.leftEdgeMap.Values[index].Key)) { long leftStart = partition.leftEdgeMap.Values[index].Start; - AddToBatch( + this.AddToBatch( currentTime, start > leftStart ? start : leftStart, ref key, @@ -969,7 +973,7 @@ private void AddLowWatermarkToBatch(long start) this.output.hash.col[index] = 0; this.output.bitvector.col[index >> 6] |= (1L << (index & 0x3f)); - if (this.output.Count == Config.DataBatchSize) FlushContents(); + if (this.output.Count == Config.DataBatchSize) this.FlushContents(); } } @@ -991,7 +995,7 @@ private void AddToBatch(long start, long end, ref TKey key, ref TLeft leftPayloa this.output.bitvector.col[index >> 6] |= (1L << (index & 0x3f)); else this.output[index] = this.selector(leftPayload, rightPayload); - if (this.output.Count == Config.DataBatchSize) FlushContents(); + if (this.output.Count == Config.DataBatchSize) this.FlushContents(); } [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -1100,7 +1104,7 @@ public void Populate(long start, long end, ref TKey key, ref TPayload payload) this.Payload = payload; } - public override string ToString() => "[Start=" + this.Start + ", End=" + this.End + ", Key='" + this.Key + "', Payload='" + this.Payload + "']"; + public override readonly string ToString() => "[Start=" + this.Start + ", End=" + this.End + ", Key='" + this.Key + "', Payload='" + this.Payload + "']"; } [DataContract] @@ -1121,7 +1125,7 @@ public void Populate(long start, ref TKey key, ref TPayload payload) this.Payload = payload; } - public override string ToString() => "[Start=" + this.Start + ", Key='" + this.Key + "', Payload='" + this.Payload + "']"; + public override readonly string ToString() => "[Start=" + this.Start + ", Key='" + this.Key + "', Payload='" + this.Payload + "']"; } public override bool LeftInputHasState @@ -1186,7 +1190,7 @@ private sealed class PartitionEntry /// left edge is processable. /// [DataMember] - public FastMap> leftIntervalMap = new FastMap>(); + public FastMap> leftIntervalMap = new(); /// /// Stores left start edges at @@ -1194,7 +1198,7 @@ private sealed class PartitionEntry /// left edge is processable. /// [DataMember] - public FastMap> leftEdgeMap = new FastMap>(); + public FastMap> leftEdgeMap = new(); /// /// Stores end edges for the current join at some point in the future, i.e. after . @@ -1209,7 +1213,7 @@ private sealed class PartitionEntry /// right edge is processable. /// [DataMember] - public FastMap> rightIntervalMap = new FastMap>(); + public FastMap> rightIntervalMap = new(); /// /// Stores right start edges at @@ -1217,7 +1221,7 @@ private sealed class PartitionEntry /// right edge is processable. /// [DataMember] - public FastMap> rightEdgeMap = new FastMap>(); + public FastMap> rightEdgeMap = new(); [DataMember] public long nextLeftTime = long.MinValue; diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/EquiJoin/Basic/PartitionedEquiJoinPipeCompound.cs b/Sources/Core/Microsoft.StreamProcessing/Operators/EquiJoin/Basic/PartitionedEquiJoinPipeCompound.cs index 29f18f0cb..822ceccb4 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/EquiJoin/Basic/PartitionedEquiJoinPipeCompound.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/EquiJoin/Basic/PartitionedEquiJoinPipeCompound.cs @@ -32,21 +32,21 @@ internal sealed class PartitionedEquiJoinPipeCompound rightComparerEquals; [DataMember] - private FastDictionary2> leftQueue = new FastDictionary2>(); + private FastDictionary2> leftQueue = new(); [DataMember] - private FastDictionary2> rightQueue = new FastDictionary2>(); + private FastDictionary2> rightQueue = new(); [DataMember] - private HashSet processQueue = new HashSet(); + private HashSet processQueue = []; [DataMember] - private HashSet seenKeys = new HashSet(); + private HashSet seenKeys = []; [DataMember] - private HashSet cleanKeys = new HashSet(); + private HashSet cleanKeys = []; [DataMember] private StreamMessage, TGroupKey>, TResult> output; [DataMember] - private FastDictionary partitionData = new FastDictionary(); + private FastDictionary partitionData = new(); [DataMember] private long lastLeftCTI = long.MinValue; [DataMember] @@ -142,8 +142,8 @@ private void NewPartition(TPartitionKey pKey) protected override void ProcessBothBatches(StreamMessage, TGroupKey>, TLeft> leftBatch, StreamMessage, TGroupKey>, TRight> rightBatch, out bool leftBatchDone, out bool rightBatchDone, out bool leftBatchFree, out bool rightBatchFree) { - ProcessLeftBatch(leftBatch, out leftBatchDone, out leftBatchFree); - ProcessRightBatch(rightBatch, out rightBatchDone, out rightBatchFree); + this.ProcessLeftBatch(leftBatch, out leftBatchDone, out leftBatchFree); + this.ProcessRightBatch(rightBatch, out rightBatchDone, out rightBatchFree); } protected override void ProcessLeftBatch(StreamMessage, TGroupKey>, TLeft> batch, out bool leftBatchDone, out bool leftBatchFree) @@ -172,7 +172,7 @@ protected override void ProcessLeftBatch(StreamMessage, TGroupKey>, TRight> batch, out bool rightBatchDone, out bool rightBatchFree) @@ -219,7 +219,7 @@ protected override void ProcessRightBatch(StreamMessage this.output.Free(); + protected override void DisposeState() + { + this.partitionData.Dispose(); + this.output.Free(); + } [MethodImpl(MethodImplOptions.AggressiveInlining)] private void ProcessPendingEntries() @@ -276,11 +280,11 @@ private void ProcessPendingEntries() if (partition.nextLeftTime < partition.nextRightTime) { - UpdateTime(partition, partition.nextLeftTime); + this.UpdateTime(partition, partition.nextLeftTime); if (leftEntry.Other != long.MinValue) { - ProcessLeftEvent( + this.ProcessLeftEvent( partition, partition.nextLeftTime, leftEntry.Other, @@ -291,7 +295,7 @@ private void ProcessPendingEntries() else if (partition.currTime > old) { var r = default(TRight); - AddToBatch( + this.AddToBatch( partition.currTime, long.MinValue, ref leftEntry.Key, @@ -305,11 +309,11 @@ private void ProcessPendingEntries() } else { - UpdateTime(partition, partition.nextRightTime); + this.UpdateTime(partition, partition.nextRightTime); if (rightEntry.Other != long.MinValue) { - ProcessRightEvent( + this.ProcessRightEvent( partition, partition.nextRightTime, rightEntry.Other, @@ -320,7 +324,7 @@ private void ProcessPendingEntries() else if (partition.currTime > old) { var l = default(TLeft); - AddToBatch( + this.AddToBatch( partition.currTime, long.MinValue, ref rightEntry.Key, @@ -343,15 +347,15 @@ private void ProcessPendingEntries() // If we have not yet reached the lesser of the two sides (in this case, right), and we don't // have input from that side, reach that time now. This can happen with low watermarks. if (partition.currTime < partition.nextRightTime) - UpdateTime(partition, partition.nextRightTime); + this.UpdateTime(partition, partition.nextRightTime); break; } - UpdateTime(partition, partition.nextLeftTime); + this.UpdateTime(partition, partition.nextLeftTime); if (leftEntry.Other != long.MinValue) { - ProcessLeftEvent( + this.ProcessLeftEvent( partition, partition.nextLeftTime, leftEntry.Other, @@ -362,7 +366,7 @@ private void ProcessPendingEntries() else if (partition.currTime > old) { var r = default(TRight); - AddToBatch( + this.AddToBatch( partition.currTime, long.MinValue, ref leftEntry.Key, @@ -384,15 +388,15 @@ private void ProcessPendingEntries() // If we have not yet reached the lesser of the two sides (in this case, left), and we don't // have input from that side, reach that time now. This can happen with low watermarks. if (partition.currTime < partition.nextLeftTime) - UpdateTime(partition, partition.nextLeftTime); + this.UpdateTime(partition, partition.nextLeftTime); break; } - UpdateTime(partition, partition.nextRightTime); + this.UpdateTime(partition, partition.nextRightTime); if (rightEntry.Other != long.MinValue) { - ProcessRightEvent( + this.ProcessRightEvent( partition, partition.nextRightTime, rightEntry.Other, @@ -403,7 +407,7 @@ private void ProcessPendingEntries() else if (partition.currTime > old) { var l = default(TLeft); - AddToBatch( + this.AddToBatch( partition.currTime, long.MinValue, ref rightEntry.Key, @@ -422,7 +426,7 @@ private void ProcessPendingEntries() if (partition.nextRightTime < this.lastRightCTI) UpdateNextRightTime(partition, this.lastRightCTI); - UpdateTime(partition, Math.Min(this.lastLeftCTI, this.lastRightCTI)); + this.UpdateTime(partition, Math.Min(this.lastLeftCTI, this.lastRightCTI)); if (partition.IsClean()) this.cleanKeys.Add(pKey); break; @@ -433,7 +437,7 @@ private void ProcessPendingEntries() if (this.emitCTI) { var earliest = Math.Min(this.lastLeftCTI, this.lastRightCTI); - AddLowWatermarkToBatch(earliest); + this.AddLowWatermarkToBatch(earliest); this.emitCTI = false; foreach (var p in this.cleanKeys) { @@ -453,9 +457,9 @@ private void UpdateTime(PartitionEntry partition, long time) { if (time > partition.currTime) { - LeaveTime(partition); + this.LeaveTime(partition); partition.currTime = time; - ReachTime(partition); + this.ReachTime(partition); } } @@ -477,7 +481,7 @@ private void ProcessLeftEvent(PartitionEntry partition, long start, long end, re partition.leftEdgeMap.Values[index].Populate(start, ref key, ref payload); } - CreateOutputForStartEdge(partition, start, ref key, ref payload, hash); + this.CreateOutputForStartEdge(partition, start, ref key, ref payload, hash); } else { @@ -492,7 +496,7 @@ private void ProcessLeftEvent(PartitionEntry partition, long start, long end, re { int index = partition.leftIntervalMap.Insert(hash); partition.leftIntervalMap.Values[index].Populate(start, end, ref key, ref payload); - CreateOutputForStartInterval(partition, start, end, ref key, ref payload, hash); + this.CreateOutputForStartInterval(partition, start, end, ref key, ref payload, hash); partition.endPointHeap.Insert(end, index); } else @@ -512,7 +516,7 @@ private void ProcessLeftEvent(PartitionEntry partition, long start, long end, re var edges = partition.leftEdgeMap.Find(hash); while (edges.Next(out int index)) { - if (AreSame(end, ref key, ref payload, ref partition.leftEdgeMap.Values[index])) + if (this.AreSame(end, ref key, ref payload, ref partition.leftEdgeMap.Values[index])) { edges.Remove(); break; @@ -521,7 +525,7 @@ private void ProcessLeftEvent(PartitionEntry partition, long start, long end, re } // Output end edges. - CreateOutputForEndEdge(partition, start, end, ref key, ref payload, hash); + this.CreateOutputForEndEdge(partition, start, end, ref key, ref payload, hash); } } @@ -543,7 +547,7 @@ private void ProcessRightEvent(PartitionEntry partition, long start, long end, r partition.rightEdgeMap.Values[index].Populate(start, ref key, ref payload); } - CreateOutputForStartEdge(partition, start, ref key, ref payload, hash); + this.CreateOutputForStartEdge(partition, start, ref key, ref payload, hash); } else { @@ -558,7 +562,7 @@ private void ProcessRightEvent(PartitionEntry partition, long start, long end, r { int index = partition.rightIntervalMap.Insert(hash); partition.rightIntervalMap.Values[index].Populate(start, end, ref key, ref payload); - CreateOutputForStartInterval(partition, start, end, ref key, ref payload, hash); + this.CreateOutputForStartInterval(partition, start, end, ref key, ref payload, hash); partition.endPointHeap.Insert(end, ~index); } else @@ -578,7 +582,7 @@ private void ProcessRightEvent(PartitionEntry partition, long start, long end, r var edges = partition.rightEdgeMap.Find(hash); while (edges.Next(out int index)) { - if (AreSame(end, ref key, ref payload, ref partition.rightEdgeMap.Values[index])) + if (this.AreSame(end, ref key, ref payload, ref partition.rightEdgeMap.Values[index])) { edges.Remove(); break; @@ -587,7 +591,7 @@ private void ProcessRightEvent(PartitionEntry partition, long start, long end, r } // Output end edges. - CreateOutputForEndEdge(partition, start, end, ref key, ref payload, hash); + this.CreateOutputForEndEdge(partition, start, end, ref key, ref payload, hash); } } @@ -597,7 +601,7 @@ private void LeaveTime(PartitionEntry partition) var leftEdges = partition.leftEdgeMap.TraverseInvisible(); while (leftEdges.Next(out int index, out int hash)) { - CreateOutputForStartEdge( + this.CreateOutputForStartEdge( partition, partition.currTime, ref partition.leftEdgeMap.Values[index].Key, @@ -610,7 +614,7 @@ private void LeaveTime(PartitionEntry partition) while (leftIntervals.Next(out int index, out int hash)) { long end = partition.leftIntervalMap.Values[index].End; - CreateOutputForStartInterval( + this.CreateOutputForStartInterval( partition, partition.currTime, end, @@ -624,7 +628,7 @@ private void LeaveTime(PartitionEntry partition) var rightEdges = partition.rightEdgeMap.TraverseInvisible(); while (rightEdges.Next(out int index, out int hash)) { - CreateOutputForStartEdge( + this.CreateOutputForStartEdge( partition, partition.currTime, ref partition.rightEdgeMap.Values[index].Key, @@ -637,7 +641,7 @@ private void LeaveTime(PartitionEntry partition) while (rightIntervals.Next(out int index, out int hash)) { long end = partition.rightIntervalMap.Values[index].End; - CreateOutputForStartInterval( + this.CreateOutputForStartInterval( partition, partition.currTime, end, @@ -663,7 +667,7 @@ private void ReachTime(PartitionEntry partition) if (index >= 0) { // Endpoint is left interval ending. - CreateOutputForEndInterval( + this.CreateOutputForEndInterval( partition, endPointTime, partition.leftIntervalMap.Values[index].Start, @@ -676,7 +680,7 @@ private void ReachTime(PartitionEntry partition) { // Endpoint is right interval ending. index = ~index; - CreateOutputForEndInterval( + this.CreateOutputForEndInterval( partition, endPointTime, partition.rightIntervalMap.Values[index].Start, @@ -699,7 +703,7 @@ private void CreateOutputForEndEdge(PartitionEntry partition, long currentTime, if (this.keyComparerEquals(key, partition.rightEdgeMap.Values[index].Key)) { long rightStart = partition.rightEdgeMap.Values[index].Start; - AddToBatch( + this.AddToBatch( currentTime, start > rightStart ? start : rightStart, ref key, @@ -717,7 +721,7 @@ private void CreateOutputForEndEdge(PartitionEntry partition, long currentTime, if (this.keyComparerEquals(key, partition.rightIntervalMap.Values[index].Key)) { long rightStart = partition.rightIntervalMap.Values[index].Start; - AddToBatch( + this.AddToBatch( currentTime, start > rightStart ? start : rightStart, ref key, @@ -740,7 +744,7 @@ private void CreateOutputForEndEdge(PartitionEntry partition, long currentTime, if (this.keyComparerEquals(key, partition.leftEdgeMap.Values[index].Key)) { long leftStart = partition.leftEdgeMap.Values[index].Start; - AddToBatch( + this.AddToBatch( currentTime, start > leftStart ? start : leftStart, ref key, @@ -758,7 +762,7 @@ private void CreateOutputForEndEdge(PartitionEntry partition, long currentTime, if (this.keyComparerEquals(key, partition.leftIntervalMap.Values[index].Key)) { long leftStart = partition.leftIntervalMap.Values[index].Start; - AddToBatch( + this.AddToBatch( currentTime, start > leftStart ? start : leftStart, ref key, @@ -780,7 +784,7 @@ private void CreateOutputForStartEdge(PartitionEntry partition, long currentTime { if (this.keyComparerEquals(key, partition.rightEdgeMap.Values[index].Key)) { - AddToBatch( + this.AddToBatch( currentTime, StreamEvent.InfinitySyncTime, ref key, @@ -797,7 +801,7 @@ private void CreateOutputForStartEdge(PartitionEntry partition, long currentTime { if (this.keyComparerEquals(key, partition.rightIntervalMap.Values[index].Key)) { - AddToBatch( + this.AddToBatch( currentTime, StreamEvent.InfinitySyncTime, ref key, @@ -819,7 +823,7 @@ private void CreateOutputForStartEdge(PartitionEntry partition, long currentTime { if (this.keyComparerEquals(key, partition.leftEdgeMap.Values[index].Key)) { - AddToBatch( + this.AddToBatch( currentTime, StreamEvent.InfinitySyncTime, ref key, @@ -836,7 +840,7 @@ private void CreateOutputForStartEdge(PartitionEntry partition, long currentTime { if (this.keyComparerEquals(key, partition.leftIntervalMap.Values[index].Key)) { - AddToBatch( + this.AddToBatch( currentTime, StreamEvent.InfinitySyncTime, ref key, @@ -858,7 +862,7 @@ private void CreateOutputForStartInterval(PartitionEntry partition, long current { if (this.keyComparerEquals(key, partition.rightEdgeMap.Values[index].Key)) { - AddToBatch( + this.AddToBatch( currentTime, StreamEvent.InfinitySyncTime, ref key, @@ -876,7 +880,7 @@ private void CreateOutputForStartInterval(PartitionEntry partition, long current if (this.keyComparerEquals(key, partition.rightIntervalMap.Values[index].Key)) { long rightEnd = partition.rightIntervalMap.Values[index].End; - AddToBatch( + this.AddToBatch( currentTime, end < rightEnd ? end : rightEnd, ref key, @@ -898,7 +902,7 @@ private void CreateOutputForStartInterval(PartitionEntry partition, long current { if (this.keyComparerEquals(key, partition.leftEdgeMap.Values[index].Key)) { - AddToBatch( + this.AddToBatch( currentTime, StreamEvent.InfinitySyncTime, ref key, @@ -916,7 +920,7 @@ private void CreateOutputForStartInterval(PartitionEntry partition, long current if (this.keyComparerEquals(key, partition.leftIntervalMap.Values[index].Key)) { long leftEnd = partition.leftIntervalMap.Values[index].End; - AddToBatch( + this.AddToBatch( currentTime, end < leftEnd ? end : leftEnd, ref key, @@ -938,7 +942,7 @@ private void CreateOutputForEndInterval(PartitionEntry partition, long currentTi if (this.keyComparerEquals(key, partition.rightEdgeMap.Values[index].Key)) { long rightStart = partition.rightEdgeMap.Values[index].Start; - AddToBatch( + this.AddToBatch( currentTime, start > rightStart ? start : rightStart, ref key, @@ -960,7 +964,7 @@ private void CreateOutputForEndInterval(PartitionEntry partition, long currentTi if (this.keyComparerEquals(key, partition.leftEdgeMap.Values[index].Key)) { long leftStart = partition.leftEdgeMap.Values[index].Start; - AddToBatch( + this.AddToBatch( currentTime, start > leftStart ? start : leftStart, ref key, @@ -987,7 +991,7 @@ private void AddLowWatermarkToBatch(long start) this.output.hash.col[index] = 0; this.output.bitvector.col[index >> 6] |= (1L << (index & 0x3f)); - if (this.output.Count == Config.DataBatchSize) FlushContents(); + if (this.output.Count == Config.DataBatchSize) this.FlushContents(); } } @@ -1009,7 +1013,7 @@ private void AddToBatch(long start, long end, ref TGroupKey key, ref TPartitionK this.output.bitvector.col[index >> 6] |= (1L << (index & 0x3f)); else this.output[index] = this.selector(leftPayload, rightPayload); - if (this.output.Count == Config.DataBatchSize) FlushContents(); + if (this.output.Count == Config.DataBatchSize) this.FlushContents(); } [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -1118,7 +1122,7 @@ public void Populate(long start, long end, ref TGroupKey key, ref TPayload paylo this.Payload = payload; } - public override string ToString() => "[Start=" + this.Start + ", End=" + this.End + ", Key='" + this.Key + "', Payload='" + this.Payload + "']"; + public override readonly string ToString() => "[Start=" + this.Start + ", End=" + this.End + ", Key='" + this.Key + "', Payload='" + this.Payload + "']"; } [DataContract] @@ -1139,7 +1143,7 @@ public void Populate(long start, ref TGroupKey key, ref TPayload payload) this.Payload = payload; } - public override string ToString() => "[Start=" + this.Start + ", Key='" + this.Key + "', Payload='" + this.Payload + "']"; + public override readonly string ToString() => "[Start=" + this.Start + ", Key='" + this.Key + "', Payload='" + this.Payload + "']"; } public override bool LeftInputHasState @@ -1204,7 +1208,7 @@ private sealed class PartitionEntry /// left edge is processable. /// [DataMember] - public FastMap> leftIntervalMap = new FastMap>(); + public FastMap> leftIntervalMap = new(); /// /// Stores left start edges at @@ -1212,7 +1216,7 @@ private sealed class PartitionEntry /// left edge is processable. /// [DataMember] - public FastMap> leftEdgeMap = new FastMap>(); + public FastMap> leftEdgeMap = new(); /// /// Stores end edges for the current join at some point in the future, i.e. after . @@ -1227,7 +1231,7 @@ private sealed class PartitionEntry /// right edge is processable. /// [DataMember] - public FastMap> rightIntervalMap = new FastMap>(); + public FastMap> rightIntervalMap = new(); /// /// Stores right start edges at @@ -1235,7 +1239,7 @@ private sealed class PartitionEntry /// right edge is processable. /// [DataMember] - public FastMap> rightEdgeMap = new FastMap>(); + public FastMap> rightEdgeMap = new(); [DataMember] public long nextLeftTime = long.MinValue; diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/EquiJoin/Basic/PartitionedEquiJoinPipeSimple.cs b/Sources/Core/Microsoft.StreamProcessing/Operators/EquiJoin/Basic/PartitionedEquiJoinPipeSimple.cs index 7d3237d9e..d550bc9f4 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/EquiJoin/Basic/PartitionedEquiJoinPipeSimple.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/EquiJoin/Basic/PartitionedEquiJoinPipeSimple.cs @@ -31,21 +31,21 @@ internal sealed class PartitionedEquiJoinPipeSimple rightComparerEquals; [DataMember] - private FastDictionary2> leftQueue = new FastDictionary2>(); + private FastDictionary2> leftQueue = new(); [DataMember] - private FastDictionary2> rightQueue = new FastDictionary2>(); + private FastDictionary2> rightQueue = new(); [DataMember] - private HashSet processQueue = new HashSet(); + private HashSet processQueue = []; [DataMember] - private HashSet seenKeys = new HashSet(); + private HashSet seenKeys = []; [DataMember] - private HashSet cleanKeys = new HashSet(); + private HashSet cleanKeys = []; [DataMember] private StreamMessage, TResult> output; [DataMember] - private FastDictionary partitionData = new FastDictionary(); + private FastDictionary partitionData = new(); [DataMember] private long lastLeftCTI = long.MinValue; [DataMember] @@ -142,8 +142,8 @@ private void NewPartition(TPartitionKey pKey, int hash) protected override void ProcessBothBatches(StreamMessage, TLeft> leftBatch, StreamMessage, TRight> rightBatch, out bool leftBatchDone, out bool rightBatchDone, out bool leftBatchFree, out bool rightBatchFree) { - ProcessLeftBatch(leftBatch, out leftBatchDone, out leftBatchFree); - ProcessRightBatch(rightBatch, out rightBatchDone, out rightBatchFree); + this.ProcessLeftBatch(leftBatch, out leftBatchDone, out leftBatchFree); + this.ProcessRightBatch(rightBatch, out rightBatchDone, out rightBatchFree); } protected override void ProcessLeftBatch(StreamMessage, TLeft> batch, out bool leftBatchDone, out bool leftBatchFree) @@ -172,7 +172,7 @@ protected override void ProcessLeftBatch(StreamMessage, TRight> batch, out bool rightBatchDone, out bool rightBatchFree) @@ -217,7 +217,7 @@ protected override void ProcessRightBatch(StreamMessage this.output.Free(); + protected override void DisposeState() + { + this.partitionData.Dispose(); + this.output.Free(); + } [MethodImpl(MethodImplOptions.AggressiveInlining)] private void ProcessPendingEntries() @@ -272,11 +276,11 @@ private void ProcessPendingEntries() if (partition.nextLeftTime < partition.nextRightTime) { - UpdateTime(partition, partition.nextLeftTime); + this.UpdateTime(partition, partition.nextLeftTime); if (leftEntry.Other != long.MinValue) { - ProcessLeftEvent( + this.ProcessLeftEvent( partition, partition.nextLeftTime, leftEntry.Other, @@ -285,7 +289,7 @@ private void ProcessPendingEntries() else if (partition.currTime > old) { var r = default(TRight); - AddToBatch( + this.AddToBatch( partition.currTime, long.MinValue, partition, @@ -297,11 +301,11 @@ private void ProcessPendingEntries() } else { - UpdateTime(partition, partition.nextRightTime); + this.UpdateTime(partition, partition.nextRightTime); if (rightEntry.Other != long.MinValue) { - ProcessRightEvent( + this.ProcessRightEvent( partition, partition.nextRightTime, rightEntry.Other, @@ -310,7 +314,7 @@ private void ProcessPendingEntries() else if (partition.currTime > old) { var l = default(TLeft); - AddToBatch( + this.AddToBatch( partition.currTime, long.MinValue, partition, @@ -331,15 +335,15 @@ private void ProcessPendingEntries() // If we have not yet reached the lesser of the two sides (in this case, right), and we don't // have input from that side, reach that time now. This can happen with low watermarks. if (partition.currTime < partition.nextRightTime) - UpdateTime(partition, partition.nextRightTime); + this.UpdateTime(partition, partition.nextRightTime); break; } - UpdateTime(partition, partition.nextLeftTime); + this.UpdateTime(partition, partition.nextLeftTime); if (leftEntry.Other != long.MinValue) { - ProcessLeftEvent( + this.ProcessLeftEvent( partition, partition.nextLeftTime, leftEntry.Other, @@ -348,7 +352,7 @@ private void ProcessPendingEntries() else if (partition.currTime > old) { var r = default(TRight); - AddToBatch( + this.AddToBatch( partition.currTime, long.MinValue, partition, @@ -368,15 +372,15 @@ private void ProcessPendingEntries() // If we have not yet reached the lesser of the two sides (in this case, left), and we don't // have input from that side, reach that time now. This can happen with low watermarks. if (partition.currTime < partition.nextLeftTime) - UpdateTime(partition, partition.nextLeftTime); + this.UpdateTime(partition, partition.nextLeftTime); break; } - UpdateTime(partition, partition.nextRightTime); + this.UpdateTime(partition, partition.nextRightTime); if (rightEntry.Other != long.MinValue) { - ProcessRightEvent( + this.ProcessRightEvent( partition, partition.nextRightTime, rightEntry.Other, @@ -385,7 +389,7 @@ private void ProcessPendingEntries() else if (partition.currTime > old) { var l = default(TLeft); - AddToBatch( + this.AddToBatch( partition.currTime, long.MinValue, partition, @@ -402,7 +406,7 @@ private void ProcessPendingEntries() if (partition.nextRightTime < this.lastRightCTI) UpdateNextRightTime(partition, this.lastRightCTI); - UpdateTime(partition, Math.Min(this.lastLeftCTI, this.lastRightCTI)); + this.UpdateTime(partition, Math.Min(this.lastLeftCTI, this.lastRightCTI)); if (partition.IsClean()) this.cleanKeys.Add(pKey); break; @@ -413,7 +417,7 @@ private void ProcessPendingEntries() if (this.emitCTI) { var earliest = Math.Min(this.lastLeftCTI, this.lastRightCTI); - AddLowWatermarkToBatch(earliest); + this.AddLowWatermarkToBatch(earliest); this.emitCTI = false; foreach (var p in this.cleanKeys) { @@ -433,9 +437,9 @@ private void UpdateTime(PartitionEntry partition, long time) { if (time > partition.currTime) { - LeaveTime(partition); + this.LeaveTime(partition); partition.currTime = time; - ReachTime(partition); + this.ReachTime(partition); } } @@ -457,7 +461,7 @@ private void ProcessLeftEvent(PartitionEntry partition, long start, long end, TL partition.leftEdgeMap.Values[index].Populate(start, ref payload); } - CreateOutputForStartEdge(partition, start, ref payload); + this.CreateOutputForStartEdge(partition, start, ref payload); } else { @@ -472,7 +476,7 @@ private void ProcessLeftEvent(PartitionEntry partition, long start, long end, TL { int index = partition.leftIntervalMap.Insert(partition.hash); partition.leftIntervalMap.Values[index].Populate(start, end, ref payload); - CreateOutputForStartInterval(partition, start, end, ref payload); + this.CreateOutputForStartInterval(partition, start, end, ref payload); partition.endPointHeap.Insert(end, index); } else @@ -492,7 +496,7 @@ private void ProcessLeftEvent(PartitionEntry partition, long start, long end, TL var edges = partition.leftEdgeMap.Find(partition.hash); while (edges.Next(out int index)) { - if (AreSame(end, ref payload, ref partition.leftEdgeMap.Values[index])) + if (this.AreSame(end, ref payload, ref partition.leftEdgeMap.Values[index])) { edges.Remove(); break; @@ -501,7 +505,7 @@ private void ProcessLeftEvent(PartitionEntry partition, long start, long end, TL } // Output end edges. - CreateOutputForEndEdge(partition, start, end, ref payload); + this.CreateOutputForEndEdge(partition, start, end, ref payload); } } @@ -523,7 +527,7 @@ private void ProcessRightEvent(PartitionEntry partition, long start, long end, T partition.rightEdgeMap.Values[index].Populate(start, ref payload); } - CreateOutputForStartEdge(partition, start, ref payload); + this.CreateOutputForStartEdge(partition, start, ref payload); } else { @@ -538,7 +542,7 @@ private void ProcessRightEvent(PartitionEntry partition, long start, long end, T { int index = partition.rightIntervalMap.Insert(partition.hash); partition.rightIntervalMap.Values[index].Populate(start, end, ref payload); - CreateOutputForStartInterval(partition, start, end, ref payload); + this.CreateOutputForStartInterval(partition, start, end, ref payload); partition.endPointHeap.Insert(end, ~index); } else @@ -558,7 +562,7 @@ private void ProcessRightEvent(PartitionEntry partition, long start, long end, T var edges = partition.rightEdgeMap.Find(partition.hash); while (edges.Next(out int index)) { - if (AreSame(end, ref payload, ref partition.rightEdgeMap.Values[index])) + if (this.AreSame(end, ref payload, ref partition.rightEdgeMap.Values[index])) { edges.Remove(); break; @@ -567,7 +571,7 @@ private void ProcessRightEvent(PartitionEntry partition, long start, long end, T } // Output end edges. - CreateOutputForEndEdge(partition, start, end, ref payload); + this.CreateOutputForEndEdge(partition, start, end, ref payload); } } @@ -577,7 +581,7 @@ private void LeaveTime(PartitionEntry partition) var leftEdges = partition.leftEdgeMap.TraverseInvisible(); while (leftEdges.Next(out int index, out _)) { - CreateOutputForStartEdge( + this.CreateOutputForStartEdge( partition, partition.currTime, ref partition.leftEdgeMap.Values[index].Payload); @@ -588,7 +592,7 @@ private void LeaveTime(PartitionEntry partition) while (leftIntervals.Next(out int index, out _)) { long end = partition.leftIntervalMap.Values[index].End; - CreateOutputForStartInterval( + this.CreateOutputForStartInterval( partition, partition.currTime, end, @@ -600,7 +604,7 @@ private void LeaveTime(PartitionEntry partition) var rightEdges = partition.rightEdgeMap.TraverseInvisible(); while (rightEdges.Next(out int index, out _)) { - CreateOutputForStartEdge( + this.CreateOutputForStartEdge( partition, partition.currTime, ref partition.rightEdgeMap.Values[index].Payload); @@ -611,7 +615,7 @@ private void LeaveTime(PartitionEntry partition) while (rightIntervals.Next(out int index, out _)) { long end = partition.rightIntervalMap.Values[index].End; - CreateOutputForStartInterval( + this.CreateOutputForStartInterval( partition, partition.currTime, end, @@ -635,7 +639,7 @@ private void ReachTime(PartitionEntry partition) if (index >= 0) { // Endpoint is left interval ending. - CreateOutputForEndInterval( + this.CreateOutputForEndInterval( partition, endPointTime, partition.leftIntervalMap.Values[index].Start, @@ -646,7 +650,7 @@ private void ReachTime(PartitionEntry partition) { // Endpoint is right interval ending. index = ~index; - CreateOutputForEndInterval( + this.CreateOutputForEndInterval( partition, endPointTime, partition.rightIntervalMap.Values[index].Start, @@ -665,7 +669,7 @@ private void CreateOutputForEndEdge(PartitionEntry partition, long currentTime, while (edges.Next(out index)) { long rightStart = partition.rightEdgeMap.Values[index].Start; - AddToBatch( + this.AddToBatch( currentTime, start > rightStart ? start : rightStart, partition, @@ -678,7 +682,7 @@ private void CreateOutputForEndEdge(PartitionEntry partition, long currentTime, while (intervals.Next(out index)) { long rightStart = partition.rightIntervalMap.Values[index].Start; - AddToBatch( + this.AddToBatch( currentTime, start > rightStart ? start : rightStart, partition, @@ -696,7 +700,7 @@ private void CreateOutputForEndEdge(PartitionEntry partition, long currentTime, while (edges.Next(out index)) { long leftStart = partition.leftEdgeMap.Values[index].Start; - AddToBatch( + this.AddToBatch( currentTime, start > leftStart ? start : leftStart, partition, @@ -709,7 +713,7 @@ private void CreateOutputForEndEdge(PartitionEntry partition, long currentTime, while (intervals.Next(out index)) { long leftStart = partition.leftIntervalMap.Values[index].Start; - AddToBatch( + this.AddToBatch( currentTime, start > leftStart ? start : leftStart, partition, @@ -726,7 +730,7 @@ private void CreateOutputForStartEdge(PartitionEntry partition, long currentTime int index; while (edges.Next(out index)) { - AddToBatch( + this.AddToBatch( currentTime, StreamEvent.InfinitySyncTime, partition, @@ -738,7 +742,7 @@ private void CreateOutputForStartEdge(PartitionEntry partition, long currentTime var intervals = partition.rightIntervalMap.Find(partition.hash); while (intervals.Next(out index)) { - AddToBatch( + this.AddToBatch( currentTime, StreamEvent.InfinitySyncTime, partition, @@ -755,7 +759,7 @@ private void CreateOutputForStartEdge(PartitionEntry partition, long currentTime int index; while (edges.Next(out index)) { - AddToBatch( + this.AddToBatch( currentTime, StreamEvent.InfinitySyncTime, partition, @@ -767,7 +771,7 @@ private void CreateOutputForStartEdge(PartitionEntry partition, long currentTime var intervals = partition.leftIntervalMap.Find(partition.hash); while (intervals.Next(out index)) { - AddToBatch( + this.AddToBatch( currentTime, StreamEvent.InfinitySyncTime, partition, @@ -784,7 +788,7 @@ private void CreateOutputForStartInterval(PartitionEntry partition, long current int index; while (edges.Next(out index)) { - AddToBatch( + this.AddToBatch( currentTime, StreamEvent.InfinitySyncTime, partition, @@ -797,7 +801,7 @@ private void CreateOutputForStartInterval(PartitionEntry partition, long current while (intervals.Next(out index)) { long rightEnd = partition.rightIntervalMap.Values[index].End; - AddToBatch( + this.AddToBatch( currentTime, end < rightEnd ? end : rightEnd, partition, @@ -814,7 +818,7 @@ private void CreateOutputForStartInterval(PartitionEntry partition, long current int index; while (edges.Next(out index)) { - AddToBatch( + this.AddToBatch( currentTime, StreamEvent.InfinitySyncTime, partition, @@ -827,7 +831,7 @@ private void CreateOutputForStartInterval(PartitionEntry partition, long current while (intervals.Next(out index)) { long leftEnd = partition.leftIntervalMap.Values[index].End; - AddToBatch( + this.AddToBatch( currentTime, end < leftEnd ? end : leftEnd, partition, @@ -844,7 +848,7 @@ private void CreateOutputForEndInterval(PartitionEntry partition, long currentTi while (edges.Next(out int index)) { long rightStart = partition.rightEdgeMap.Values[index].Start; - AddToBatch( + this.AddToBatch( currentTime, start > rightStart ? start : rightStart, partition, @@ -861,7 +865,7 @@ private void CreateOutputForEndInterval(PartitionEntry partition, long currentTi while (edges.Next(out int index)) { long leftStart = partition.leftEdgeMap.Values[index].Start; - AddToBatch( + this.AddToBatch( currentTime, start > leftStart ? start : leftStart, partition, @@ -885,7 +889,7 @@ private void AddLowWatermarkToBatch(long start) this.output.hash.col[index] = 0; this.output.bitvector.col[index >> 6] |= 1L << (index & 0x3f); - if (this.output.Count == Config.DataBatchSize) FlushContents(); + if (this.output.Count == Config.DataBatchSize) this.FlushContents(); } } @@ -907,7 +911,7 @@ private void AddToBatch(long start, long end, PartitionEntry partition, ref TLef this.output.bitvector.col[index >> 6] |= 1L << (index & 0x3f); else this.output[index] = this.selector(leftPayload, rightPayload); - if (this.output.Count == Config.DataBatchSize) FlushContents(); + if (this.output.Count == Config.DataBatchSize) this.FlushContents(); } [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -1013,7 +1017,7 @@ public void Populate(long start, long end, ref TPayload payload) this.Payload = payload; } - public override string ToString() => "[Start=" + this.Start + ", End=" + this.End + ", Payload='" + this.Payload + "']"; + public override readonly string ToString() => "[Start=" + this.Start + ", End=" + this.End + ", Payload='" + this.Payload + "']"; } [DataContract] @@ -1031,7 +1035,7 @@ public void Populate(long start, ref TPayload payload) this.Payload = payload; } - public override string ToString() => "[Start=" + this.Start + ", Payload='" + this.Payload + "']"; + public override readonly string ToString() => "[Start=" + this.Start + ", Payload='" + this.Payload + "']"; } public override bool LeftInputHasState @@ -1090,7 +1094,7 @@ private sealed class PartitionEntry /// left edge is processable. /// [DataMember] - public FastMap> leftIntervalMap = new FastMap>(); + public FastMap> leftIntervalMap = new(); /// /// Stores left start edges at @@ -1098,7 +1102,7 @@ private sealed class PartitionEntry /// left edge is processable. /// [DataMember] - public FastMap> leftEdgeMap = new FastMap>(); + public FastMap> leftEdgeMap = new(); /// /// Stores end edges for the current join at some point in the future, i.e. after . @@ -1113,7 +1117,7 @@ private sealed class PartitionEntry /// right edge is processable. /// [DataMember] - public FastMap> rightIntervalMap = new FastMap>(); + public FastMap> rightIntervalMap = new(); /// /// Stores right start edges at @@ -1121,7 +1125,7 @@ private sealed class PartitionEntry /// right edge is processable. /// [DataMember] - public FastMap> rightEdgeMap = new FastMap>(); + public FastMap> rightEdgeMap = new(); [DataMember] public long nextLeftTime = long.MinValue; diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/EquiJoin/EquiJoinStreamable.cs b/Sources/Core/Microsoft.StreamProcessing/Operators/EquiJoin/EquiJoinStreamable.cs index 4624db258..c3d75c9ea 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/EquiJoin/EquiJoinStreamable.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/EquiJoin/EquiJoinStreamable.cs @@ -11,8 +11,10 @@ namespace Microsoft.StreamProcessing { internal sealed class EquiJoinStreamable : BinaryStreamable { - private static readonly SafeConcurrentDictionary> cachedPipes - = new SafeConcurrentDictionary>(); + // Internal (not private) so test code can call cachedPipes.Clear() to ensure + // deterministic behavior in tests that depend on a fresh codegen compile. + internal static readonly SafeConcurrentDictionary> cachedPipes + = new(); private readonly JoinKind joinKind; private readonly Func> columnarGenerator; @@ -25,7 +27,7 @@ private static readonly SafeConcurrentDictionary> cachedPipe public EquiJoinStreamable(IStreamable left, IStreamable right, Expression> selector) : base(left.Properties.Join(right.Properties, selector), left, right) { - Contract.Requires(selector != null); + ArgumentNullException.ThrowIfNull(selector); this.Selector = selector; @@ -71,7 +73,7 @@ public EquiJoinStreamable(IStreamable left, IStreamable EquiJoinTemplate.Generate(this, this.Selector); } - Initialize(); + this.Initialize(); } private static Type CreatePartitionedEquiJoinType() @@ -142,7 +144,7 @@ protected override IBinaryObserver CreatePipe(IStr => typeof(TKey).GetPartitionType() != null ? this.partitionedGenerator(this, this.Selector, observer) : this.properties.IsColumnar - ? GetPipe(observer) + ? this.GetPipe(observer) : this.fallbackGenerator(this, this.Selector, observer); protected override bool CanGenerateColumnar() diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/EquiJoin/FixedInterval/FixedIntervalEquiJoinPipe.cs b/Sources/Core/Microsoft.StreamProcessing/Operators/EquiJoin/FixedInterval/FixedIntervalEquiJoinPipe.cs index 2769de8ef..565bc98f6 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/EquiJoin/FixedInterval/FixedIntervalEquiJoinPipe.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/EquiJoin/FixedInterval/FixedIntervalEquiJoinPipe.cs @@ -35,14 +35,14 @@ internal sealed class FixedIntervalEquiJoinPipe : /// FastMap visibility is not used. /// [DataMember] - private FastMap> leftIntervalMap = new FastMap>(); + private FastMap> leftIntervalMap = new(); /// /// Stores right intervals valid for . /// FastMap visibility is not used. /// [DataMember] - private FastMap> rightIntervalMap = new FastMap>(); + private FastMap> rightIntervalMap = new(); /// /// Stores end edges for the current join intervals, i.e. after . @@ -126,14 +126,14 @@ protected override void ProcessBothBatches(StreamMessage leftBatch, { if (this.nextLeftTime <= this.nextRightTime) { - UpdateTime(this.nextLeftTime); + this.UpdateTime(this.nextLeftTime); if (leftBatch.vother.col[leftBatch.iter] == StreamEvent.PunctuationOtherTime) { - AddPunctuationToBatch(this.nextLeftTime); + this.AddPunctuationToBatch(this.nextLeftTime); } else { - ProcessLeftEvent( + this.ProcessLeftEvent( this.nextLeftTime, ref leftBatch.key.col[leftBatch.iter], leftBatch[leftBatch.iter], @@ -153,14 +153,14 @@ protected override void ProcessBothBatches(StreamMessage leftBatch, } else { - UpdateTime(this.nextRightTime); + this.UpdateTime(this.nextRightTime); if (rightBatch.vother.col[rightBatch.iter] == StreamEvent.PunctuationOtherTime) { - AddPunctuationToBatch(this.nextRightTime); + this.AddPunctuationToBatch(this.nextRightTime); } else { - ProcessRightEvent( + this.ProcessRightEvent( this.nextRightTime, ref rightBatch.key.col[rightBatch.iter], rightBatch[rightBatch.iter], @@ -201,15 +201,15 @@ protected override void ProcessLeftBatch(StreamMessage batch, out b return; } - UpdateTime(this.nextLeftTime); + this.UpdateTime(this.nextLeftTime); if (batch.vother.col[batch.iter] == StreamEvent.PunctuationOtherTime) { - AddPunctuationToBatch(this.nextLeftTime); + this.AddPunctuationToBatch(this.nextLeftTime); } else { - ProcessLeftEvent( + this.ProcessLeftEvent( this.nextLeftTime, ref batch.key.col[batch.iter], batch[batch.iter], @@ -240,15 +240,15 @@ protected override void ProcessRightBatch(StreamMessage batch, out return; } - UpdateTime(this.nextRightTime); + this.UpdateTime(this.nextRightTime); if (batch.vother.col[batch.iter] == StreamEvent.PunctuationOtherTime) { - AddPunctuationToBatch(this.nextRightTime); + this.AddPunctuationToBatch(this.nextRightTime); } else { - ProcessRightEvent( + this.ProcessRightEvent( this.nextRightTime, ref batch.key.col[batch.iter], batch[batch.iter], @@ -274,7 +274,7 @@ private void UpdateTime(long time) if (time != this.currTime) { this.currTime = time; - ReachTime(); + this.ReachTime(); } } @@ -283,7 +283,7 @@ private void ProcessLeftEvent(long start, ref TKey key, TLeft payload, int hash) { int index = this.leftIntervalMap.Insert(hash); this.leftIntervalMap.Values[index].Populate(start, ref key, ref payload); - CreateOutputForStartInterval(start, ref key, ref payload, hash); + this.CreateOutputForStartInterval(start, ref key, ref payload, hash); this.endPointHeap.Insert(start + this.leftDuration, index); } @@ -292,7 +292,7 @@ private void ProcessRightEvent(long start, ref TKey key, TRight payload, int has { int index = this.rightIntervalMap.Insert(hash); this.rightIntervalMap.Values[index].Populate(start, ref key, ref payload); - CreateOutputForStartInterval(start, ref key, ref payload, hash); + this.CreateOutputForStartInterval(start, ref key, ref payload, hash); this.endPointHeap.Insert(start + this.rightDuration, ~index); } @@ -324,7 +324,7 @@ private void CreateOutputForStartInterval(long currentTime, ref TKey key, ref TL { long leftEnd = currentTime + this.leftDuration; long rightEnd = rin.Start + this.rightDuration; - AddToBatch( + this.AddToBatch( currentTime, leftEnd < rightEnd ? leftEnd : rightEnd, ref key, @@ -347,7 +347,7 @@ private void CreateOutputForStartInterval(long currentTime, ref TKey key, ref TR { long rightEnd = currentTime + this.rightDuration; long leftEnd = lin.Start + this.leftDuration; - AddToBatch( + this.AddToBatch( currentTime, rightEnd < leftEnd ? rightEnd : leftEnd, ref key, @@ -373,7 +373,7 @@ private void AddPunctuationToBatch(long start) this.output.hash.col[index] = 0; this.output.bitvector.col[index >> 6] |= 1L << (index & 0x3f); - if (this.output.Count == Config.DataBatchSize) FlushContents(); + if (this.output.Count == Config.DataBatchSize) this.FlushContents(); } } @@ -387,7 +387,7 @@ private void AddToBatch(long start, long end, ref TKey key, ref TLeft leftPayloa this.output[index] = this.selector(leftPayload, rightPayload); this.output.hash.col[index] = hash; - if (this.output.Count == Config.DataBatchSize) FlushContents(); + if (this.output.Count == Config.DataBatchSize) this.FlushContents(); } protected override void FlushContents() @@ -421,7 +421,7 @@ public void Populate(long start, ref TKey key, ref TPayload payload) this.Payload = payload; } - public override string ToString() => "[Start=" + this.Start + ", Key='" + this.Key + "', Payload='" + this.Payload + "']"; + public override readonly string ToString() => "[Start=" + this.Start + ", Key='" + this.Key + "', Payload='" + this.Payload + "']"; } } } \ No newline at end of file diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/EquiJoin/FixedInterval/FixedIntervalEquiJoinTemplate.cs b/Sources/Core/Microsoft.StreamProcessing/Operators/EquiJoin/FixedInterval/FixedIntervalEquiJoinTemplate.cs index 513302ca3..081239b50 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/EquiJoin/FixedInterval/FixedIntervalEquiJoinTemplate.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/EquiJoin/FixedInterval/FixedIntervalEquiJoinTemplate.cs @@ -531,7 +531,7 @@ protected override void FlushContents() } "); - if (!this.leftType.GetTypeInfo().IsValueType) { + if (!this.leftType.IsValueType) { this.Write(" [DataContract]\r\n private struct "); this.Write(this.ToStringHelper.ToStringWithCulture(ActiveEventTypeLeft)); this.Write("\r\n {\r\n "); @@ -544,7 +544,7 @@ protected override void FlushContents() } this.Write(" }\r\n"); } - if (!this.rightType.GetTypeInfo().IsValueType) { + if (!this.rightType.IsValueType) { this.Write(" [DataContract]\r\n private struct "); this.Write(this.ToStringHelper.ToStringWithCulture(ActiveEventTypeRight)); this.Write("\r\n {\r\n "); diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/EquiJoin/FixedInterval/FixedIntervalEquiJoinTemplate.tt b/Sources/Core/Microsoft.StreamProcessing/Operators/EquiJoin/FixedInterval/FixedIntervalEquiJoinTemplate.tt index 08396a303..8cbf1da8d 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/EquiJoin/FixedInterval/FixedIntervalEquiJoinTemplate.tt +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/EquiJoin/FixedInterval/FixedIntervalEquiJoinTemplate.tt @@ -478,7 +478,7 @@ internal sealed class <#= className #><#= genericParameters #> : BinaryPipe<<#= GetOutputBatch(); } -<# if (!this.leftType.GetTypeInfo().IsValueType) { #> +<# if (!this.leftType.IsValueType) { #> [DataContract] private struct <#= ActiveEventTypeLeft #> { @@ -488,7 +488,7 @@ internal sealed class <#= className #><#= genericParameters #> : BinaryPipe<<#= <# } #> } <# } #> -<# if (!this.rightType.GetTypeInfo().IsValueType) { #> +<# if (!this.rightType.IsValueType) { #> [DataContract] private struct <#= ActiveEventTypeRight #> { diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/EquiJoin/FixedInterval/FixedIntervalEquijoinTransformer.cs b/Sources/Core/Microsoft.StreamProcessing/Operators/EquiJoin/FixedInterval/FixedIntervalEquijoinTransformer.cs index cf89573a2..8b2155471 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/EquiJoin/FixedInterval/FixedIntervalEquijoinTransformer.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/EquiJoin/FixedInterval/FixedIntervalEquijoinTransformer.cs @@ -39,8 +39,8 @@ internal static Tuple Generate( BinaryStreamable stream, Expression> selector) { - Contract.Requires(stream != null); - Contract.Ensures(Contract.Result>() == null || typeof(BinaryPipe).GetTypeInfo().IsAssignableFrom(Contract.Result>().Item1)); + ArgumentNullException.ThrowIfNull(stream); + Contract.Ensures(Contract.Result>() == null || typeof(BinaryPipe).IsAssignableFrom(Contract.Result>().Item1)); string errorMessages = null; try @@ -71,8 +71,8 @@ internal static Tuple Generate( template.rightFields = template.rightMessageRepresentation.AllFields; template.resultFields = resultMessageRepresentation.AllFields; - template.ActiveEventTypeLeft = template.leftType.GetTypeInfo().IsValueType ? template.TLeft : "Active_Event_Left"; - template.ActiveEventTypeRight = template.rightType.GetTypeInfo().IsValueType ? template.TRight : "Active_Event_Right"; + template.ActiveEventTypeLeft = template.leftType.IsValueType ? template.TLeft : "Active_Event_Left"; + template.ActiveEventTypeRight = template.rightType.IsValueType ? template.TRight : "Active_Event_Right"; #region Key Equals var keyComparer = stream.Properties.KeyEqualityComparer.GetEqualsExpr(); diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/EquiJoin/FixedInterval/PartitionedFixedIntervalEquiJoinPipe.cs b/Sources/Core/Microsoft.StreamProcessing/Operators/EquiJoin/FixedInterval/PartitionedFixedIntervalEquiJoinPipe.cs index 640b4a1cb..271d0c419 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/EquiJoin/FixedInterval/PartitionedFixedIntervalEquiJoinPipe.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/EquiJoin/FixedInterval/PartitionedFixedIntervalEquiJoinPipe.cs @@ -31,21 +31,21 @@ internal sealed class PartitionedFixedIntervalEquiJoinPipe> leftQueue = new FastDictionary2>(); + private FastDictionary2> leftQueue = new(); [DataMember] - private FastDictionary2> rightQueue = new FastDictionary2>(); + private FastDictionary2> rightQueue = new(); [DataMember] - private HashSet processQueue = new HashSet(); + private HashSet processQueue = []; [DataMember] - private HashSet seenKeys = new HashSet(); + private HashSet seenKeys = []; [DataMember] - private HashSet cleanKeys = new HashSet(); + private HashSet cleanKeys = []; [DataMember] private StreamMessage output; [DataMember] - private FastDictionary partitionData = new FastDictionary(); + private FastDictionary partitionData = new(); [DataMember] private long lastLeftCTI = long.MinValue; [DataMember] @@ -104,8 +104,8 @@ private void NewPartition(TPartitionKey pKey) protected override void ProcessBothBatches(StreamMessage leftBatch, StreamMessage rightBatch, out bool leftBatchDone, out bool rightBatchDone, out bool leftBatchFree, out bool rightBatchFree) { - ProcessLeftBatch(leftBatch, out leftBatchDone, out leftBatchFree); - ProcessRightBatch(rightBatch, out rightBatchDone, out rightBatchFree); + this.ProcessLeftBatch(leftBatch, out leftBatchDone, out leftBatchFree); + this.ProcessRightBatch(rightBatch, out rightBatchDone, out rightBatchFree); } protected override void ProcessLeftBatch(StreamMessage batch, out bool leftBatchDone, out bool leftBatchFree) @@ -134,7 +134,7 @@ protected override void ProcessLeftBatch(StreamMessage batch, out b var partitionKey = this.getPartitionKey(batch.key.col[i]); if (first || !partitionKey.Equals(previous)) { - if (this.seenKeys.Add(partitionKey)) NewPartition(partitionKey); + if (this.seenKeys.Add(partitionKey)) this.NewPartition(partitionKey); this.leftQueue.Lookup(partitionKey, out int index); queue = this.leftQueue.entries[index].value; this.processQueue.Add(partitionKey); @@ -152,7 +152,7 @@ protected override void ProcessLeftBatch(StreamMessage batch, out b previous = partitionKey; } - ProcessPendingEntries(); + this.ProcessPendingEntries(); } protected override void ProcessRightBatch(StreamMessage batch, out bool rightBatchDone, out bool rightBatchFree) @@ -180,7 +180,7 @@ protected override void ProcessRightBatch(StreamMessage batch, out var partitionKey = this.getPartitionKey(batch.key.col[i]); if (first || !partitionKey.Equals(previous)) { - if (this.seenKeys.Add(partitionKey)) NewPartition(partitionKey); + if (this.seenKeys.Add(partitionKey)) this.NewPartition(partitionKey); this.rightQueue.Lookup(partitionKey, out int index); queue = this.rightQueue.entries[index].value; this.processQueue.Add(partitionKey); @@ -198,11 +198,15 @@ protected override void ProcessRightBatch(StreamMessage batch, out previous = partitionKey; } - ProcessPendingEntries(); + this.ProcessPendingEntries(); } [MethodImpl(MethodImplOptions.AggressiveInlining)] - protected override void DisposeState() => this.output.Free(); + protected override void DisposeState() + { + this.partitionData.Dispose(); + this.output.Free(); + } [MethodImpl(MethodImplOptions.AggressiveInlining)] private void ProcessPendingEntries() @@ -237,11 +241,11 @@ private void ProcessPendingEntries() if (partition.nextLeftTime < partition.nextRightTime) { - UpdateTime(partition, partition.nextLeftTime); + this.UpdateTime(partition, partition.nextLeftTime); if (!leftEntry.IsPunctuation) { - ProcessLeftEvent( + this.ProcessLeftEvent( partition, partition.nextLeftTime, ref leftEntry.Key, @@ -251,7 +255,7 @@ private void ProcessPendingEntries() else if (partition.currTime > old) { var r = default(TRight); - AddToBatch( + this.AddToBatch( partition.currTime, StreamEvent.PunctuationOtherTime, ref leftEntry.Key, @@ -264,11 +268,11 @@ private void ProcessPendingEntries() } else { - UpdateTime(partition, partition.nextRightTime); + this.UpdateTime(partition, partition.nextRightTime); if (!rightEntry.IsPunctuation) { - ProcessRightEvent( + this.ProcessRightEvent( partition, partition.nextRightTime, ref rightEntry.Key, @@ -278,7 +282,7 @@ private void ProcessPendingEntries() else if (partition.currTime > old) { var l = default(TLeft); - AddToBatch( + this.AddToBatch( partition.currTime, StreamEvent.PunctuationOtherTime, ref rightEntry.Key, @@ -300,15 +304,15 @@ private void ProcessPendingEntries() // If we have not yet reached the lesser of the two sides (in this case, right), and we don't // have input from that side, reach that time now. This can happen with low watermarks. if (partition.currTime < partition.nextRightTime) - UpdateTime(partition, partition.nextRightTime); + this.UpdateTime(partition, partition.nextRightTime); break; } - UpdateTime(partition, partition.nextLeftTime); + this.UpdateTime(partition, partition.nextLeftTime); if (!leftEntry.IsPunctuation) { - ProcessLeftEvent( + this.ProcessLeftEvent( partition, partition.nextLeftTime, ref leftEntry.Key, @@ -318,7 +322,7 @@ private void ProcessPendingEntries() else if (partition.currTime > old) { var r = default(TRight); - AddToBatch( + this.AddToBatch( partition.currTime, StreamEvent.PunctuationOtherTime, ref leftEntry.Key, @@ -339,15 +343,15 @@ private void ProcessPendingEntries() // If we have not yet reached the lesser of the two sides (in this case, left), and we don't // have input from that side, reach that time now. This can happen with low watermarks. if (partition.currTime < partition.nextLeftTime) - UpdateTime(partition, partition.nextLeftTime); + this.UpdateTime(partition, partition.nextLeftTime); break; } - UpdateTime(partition, partition.nextRightTime); + this.UpdateTime(partition, partition.nextRightTime); if (!rightEntry.IsPunctuation) { - ProcessRightEvent( + this.ProcessRightEvent( partition, partition.nextRightTime, ref rightEntry.Key, @@ -357,7 +361,7 @@ private void ProcessPendingEntries() else if (partition.currTime > old) { var l = default(TLeft); - AddToBatch( + this.AddToBatch( partition.currTime, StreamEvent.PunctuationOtherTime, ref rightEntry.Key, @@ -373,7 +377,7 @@ private void ProcessPendingEntries() if (partition.nextLeftTime < this.lastLeftCTI) partition.nextLeftTime = this.lastLeftCTI; if (partition.nextRightTime < this.lastRightCTI) partition.nextRightTime = this.lastRightCTI; - UpdateTime(partition, Math.Min(this.lastLeftCTI, this.lastRightCTI)); + this.UpdateTime(partition, Math.Min(this.lastLeftCTI, this.lastRightCTI)); if (partition.IsClean()) this.cleanKeys.Add(pKey); break; } @@ -383,7 +387,7 @@ private void ProcessPendingEntries() if (this.emitCTI) { var earliest = Math.Min(this.lastLeftCTI, this.lastRightCTI); - AddLowWatermarkToBatch(earliest); + this.AddLowWatermarkToBatch(earliest); this.emitCTI = false; foreach (var p in this.cleanKeys) { @@ -404,7 +408,7 @@ private void UpdateTime(PartitionEntry partition, long time) if (time > partition.currTime) { partition.currTime = time; - ReachTime(partition); + this.ReachTime(partition); } } @@ -413,7 +417,7 @@ private void ProcessLeftEvent(PartitionEntry partition, long start, ref TKey key { int index = partition.leftIntervalMap.Insert(hash); partition.leftIntervalMap.Values[index].Populate(start, ref key, ref payload); - CreateOutputForStartInterval(partition, start, ref key, ref payload, hash); + this.CreateOutputForStartInterval(partition, start, ref key, ref payload, hash); partition.endPointHeap.Insert(start + this.leftDuration, index); } @@ -422,7 +426,7 @@ private void ProcessRightEvent(PartitionEntry partition, long start, ref TKey ke { int index = partition.rightIntervalMap.Insert(hash); partition.rightIntervalMap.Values[index].Populate(start, ref key, ref payload); - CreateOutputForStartInterval(partition, start, ref key, ref payload, hash); + this.CreateOutputForStartInterval(partition, start, ref key, ref payload, hash); partition.endPointHeap.Insert(start + this.rightDuration, ~index); } @@ -453,7 +457,7 @@ private void CreateOutputForStartInterval(PartitionEntry partition, long current { long leftEnd = currentTime + this.leftDuration; long rightEnd = partition.rightIntervalMap.Values[index].Start + this.rightDuration; - AddToBatch( + this.AddToBatch( currentTime, leftEnd < rightEnd ? leftEnd : rightEnd, ref key, @@ -475,7 +479,7 @@ private void CreateOutputForStartInterval(PartitionEntry partition, long current { long rightEnd = currentTime + this.rightDuration; long leftEnd = partition.leftIntervalMap.Values[index].Start + this.rightDuration; - AddToBatch( + this.AddToBatch( currentTime, rightEnd < leftEnd ? rightEnd : leftEnd, ref key, @@ -501,7 +505,7 @@ private void AddLowWatermarkToBatch(long start) this.output.hash.col[index] = 0; this.output.bitvector.col[index >> 6] |= 1L << (index & 0x3f); - if (this.output.Count == Config.DataBatchSize) FlushContents(); + if (this.output.Count == Config.DataBatchSize) this.FlushContents(); } } @@ -518,7 +522,7 @@ private void AddToBatch(long start, long end, ref TKey key, ref TLeft leftPayloa this.output.bitvector.col[index >> 6] |= 1L << (index & 0x3f); else this.output[index] = this.selector(leftPayload, rightPayload); - if (this.output.Count == Config.DataBatchSize) FlushContents(); + if (this.output.Count == Config.DataBatchSize) this.FlushContents(); } protected override void FlushContents() @@ -614,7 +618,7 @@ public void Populate(long start, ref TKey key, ref TPayload payload) this.Payload = payload; } - public override string ToString() => "[Start=" + this.Start + ", Key='" + this.Key + "', Payload='" + this.Payload + "']"; + public override readonly string ToString() => "[Start=" + this.Start + ", Key='" + this.Key + "', Payload='" + this.Payload + "']"; } public override bool LeftInputHasState @@ -673,9 +677,9 @@ private sealed class PartitionEntry [DataMember] public TPartitionKey key; [DataMember] - public FastMap> leftIntervalMap = new FastMap>(); + public FastMap> leftIntervalMap = new(); [DataMember] - public FastMap> rightIntervalMap = new FastMap>(); + public FastMap> rightIntervalMap = new(); [DataMember] public IEndPointOrderer endPointHeap; [DataMember] diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/EquiJoin/FixedInterval/PartitionedFixedIntervalEquiJoinPipeCompound.cs b/Sources/Core/Microsoft.StreamProcessing/Operators/EquiJoin/FixedInterval/PartitionedFixedIntervalEquiJoinPipeCompound.cs index 814ef34ce..6d7ef8556 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/EquiJoin/FixedInterval/PartitionedFixedIntervalEquiJoinPipeCompound.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/EquiJoin/FixedInterval/PartitionedFixedIntervalEquiJoinPipeCompound.cs @@ -30,21 +30,21 @@ internal sealed class PartitionedFixedIntervalEquiJoinPipeCompound> leftQueue = new FastDictionary2>(); + private FastDictionary2> leftQueue = new(); [DataMember] - private FastDictionary2> rightQueue = new FastDictionary2>(); + private FastDictionary2> rightQueue = new(); [DataMember] - private HashSet processQueue = new HashSet(); + private HashSet processQueue = []; [DataMember] - private HashSet seenKeys = new HashSet(); + private HashSet seenKeys = []; [DataMember] - private HashSet cleanKeys = new HashSet(); + private HashSet cleanKeys = []; [DataMember] private StreamMessage, TGroupKey>, TResult> output; [DataMember] - private FastDictionary partitionData = new FastDictionary(); + private FastDictionary partitionData = new(); [DataMember] private long lastLeftCTI = long.MinValue; [DataMember] @@ -103,8 +103,8 @@ private void NewPartition(TPartitionKey pKey) protected override void ProcessBothBatches(StreamMessage, TGroupKey>, TLeft> leftBatch, StreamMessage, TGroupKey>, TRight> rightBatch, out bool leftBatchDone, out bool rightBatchDone, out bool leftBatchFree, out bool rightBatchFree) { - ProcessLeftBatch(leftBatch, out leftBatchDone, out leftBatchFree); - ProcessRightBatch(rightBatch, out rightBatchDone, out rightBatchFree); + this.ProcessLeftBatch(leftBatch, out leftBatchDone, out leftBatchFree); + this.ProcessRightBatch(rightBatch, out rightBatchDone, out rightBatchFree); } protected override void ProcessLeftBatch(StreamMessage, TGroupKey>, TLeft> batch, out bool leftBatchDone, out bool leftBatchFree) @@ -133,7 +133,7 @@ protected override void ProcessLeftBatch(StreamMessage, TGroupKey>, TRight> batch, out bool rightBatchDone, out bool rightBatchFree) @@ -180,7 +180,7 @@ protected override void ProcessRightBatch(StreamMessage this.output.Free(); + protected override void DisposeState() + { + this.partitionData.Dispose(); + this.output.Free(); + } [MethodImpl(MethodImplOptions.AggressiveInlining)] private void ProcessPendingEntries() @@ -237,11 +241,11 @@ private void ProcessPendingEntries() if (partition.nextLeftTime < partition.nextRightTime) { - UpdateTime(partition, partition.nextLeftTime); + this.UpdateTime(partition, partition.nextLeftTime); if (!leftEntry.IsPunctuation) { - ProcessLeftEvent( + this.ProcessLeftEvent( partition, partition.nextLeftTime, ref leftEntry.Key, @@ -251,7 +255,7 @@ private void ProcessPendingEntries() else if (partition.currTime > old) { var r = default(TRight); - AddToBatch( + this.AddToBatch( partition.currTime, StreamEvent.PunctuationOtherTime, ref leftEntry.Key, @@ -265,11 +269,11 @@ private void ProcessPendingEntries() } else { - UpdateTime(partition, partition.nextRightTime); + this.UpdateTime(partition, partition.nextRightTime); if (!rightEntry.IsPunctuation) { - ProcessRightEvent( + this.ProcessRightEvent( partition, partition.nextRightTime, ref rightEntry.Key, @@ -279,7 +283,7 @@ private void ProcessPendingEntries() else if (partition.currTime > old) { var l = default(TLeft); - AddToBatch( + this.AddToBatch( partition.currTime, StreamEvent.PunctuationOtherTime, ref rightEntry.Key, @@ -302,15 +306,15 @@ private void ProcessPendingEntries() // If we have not yet reached the lesser of the two sides (in this case, right), and we don't // have input from that side, reach that time now. This can happen with low watermarks. if (partition.currTime < partition.nextRightTime) - UpdateTime(partition, partition.nextRightTime); + this.UpdateTime(partition, partition.nextRightTime); break; } - UpdateTime(partition, partition.nextLeftTime); + this.UpdateTime(partition, partition.nextLeftTime); if (!leftEntry.IsPunctuation) { - ProcessLeftEvent( + this.ProcessLeftEvent( partition, partition.nextLeftTime, ref leftEntry.Key, @@ -320,7 +324,7 @@ private void ProcessPendingEntries() else if (partition.currTime > old) { var r = default(TRight); - AddToBatch( + this.AddToBatch( partition.currTime, StreamEvent.PunctuationOtherTime, ref leftEntry.Key, @@ -342,15 +346,15 @@ private void ProcessPendingEntries() // If we have not yet reached the lesser of the two sides (in this case, left), and we don't // have input from that side, reach that time now. This can happen with low watermarks. if (partition.currTime < partition.nextLeftTime) - UpdateTime(partition, partition.nextLeftTime); + this.UpdateTime(partition, partition.nextLeftTime); break; } - UpdateTime(partition, partition.nextRightTime); + this.UpdateTime(partition, partition.nextRightTime); if (!rightEntry.IsPunctuation) { - ProcessRightEvent( + this.ProcessRightEvent( partition, partition.nextRightTime, ref rightEntry.Key, @@ -360,7 +364,7 @@ private void ProcessPendingEntries() else if (partition.currTime > old) { var l = default(TLeft); - AddToBatch( + this.AddToBatch( partition.currTime, StreamEvent.PunctuationOtherTime, ref rightEntry.Key, @@ -377,7 +381,7 @@ private void ProcessPendingEntries() if (partition.nextLeftTime < this.lastLeftCTI) partition.nextLeftTime = this.lastLeftCTI; if (partition.nextRightTime < this.lastRightCTI) partition.nextRightTime = this.lastRightCTI; - UpdateTime(partition, Math.Min(this.lastLeftCTI, this.lastRightCTI)); + this.UpdateTime(partition, Math.Min(this.lastLeftCTI, this.lastRightCTI)); if (partition.IsClean()) this.cleanKeys.Add(pKey); break; } @@ -387,7 +391,7 @@ private void ProcessPendingEntries() if (this.emitCTI) { var earliest = Math.Min(this.lastLeftCTI, this.lastRightCTI); - AddLowWatermarkToBatch(earliest); + this.AddLowWatermarkToBatch(earliest); this.emitCTI = false; foreach (var p in this.cleanKeys) { @@ -408,7 +412,7 @@ private void UpdateTime(PartitionEntry partition, long time) if (time > partition.currTime) { partition.currTime = time; - ReachTime(partition); + this.ReachTime(partition); } } @@ -417,7 +421,7 @@ private void ProcessLeftEvent(PartitionEntry partition, long start, ref TGroupKe { int index = partition.leftIntervalMap.Insert(hash); partition.leftIntervalMap.Values[index].Populate(start, ref key, ref payload); - CreateOutputForStartInterval(partition, start, ref key, ref payload, hash); + this.CreateOutputForStartInterval(partition, start, ref key, ref payload, hash); partition.endPointHeap.Insert(start + this.leftDuration, index); } @@ -426,7 +430,7 @@ private void ProcessRightEvent(PartitionEntry partition, long start, ref TGroupK { int index = partition.rightIntervalMap.Insert(hash); partition.rightIntervalMap.Values[index].Populate(start, ref key, ref payload); - CreateOutputForStartInterval(partition, start, ref key, ref payload, hash); + this.CreateOutputForStartInterval(partition, start, ref key, ref payload, hash); partition.endPointHeap.Insert(start + this.rightDuration, ~index); } @@ -457,7 +461,7 @@ private void CreateOutputForStartInterval(PartitionEntry partition, long current { long leftEnd = currentTime + this.leftDuration; long rightEnd = partition.rightIntervalMap.Values[index].Start + this.rightDuration; - AddToBatch( + this.AddToBatch( currentTime, leftEnd < rightEnd ? leftEnd : rightEnd, ref key, @@ -480,7 +484,7 @@ private void CreateOutputForStartInterval(PartitionEntry partition, long current { long rightEnd = currentTime + this.rightDuration; long leftEnd = partition.leftIntervalMap.Values[index].Start + this.leftDuration; - AddToBatch( + this.AddToBatch( currentTime, rightEnd < leftEnd ? rightEnd : leftEnd, ref key, @@ -507,7 +511,7 @@ private void AddLowWatermarkToBatch(long start) this.output.hash.col[index] = 0; this.output.bitvector.col[index >> 6] |= 1L << (index & 0x3f); - if (this.output.Count == Config.DataBatchSize) FlushContents(); + if (this.output.Count == Config.DataBatchSize) this.FlushContents(); } } @@ -524,7 +528,7 @@ private void AddToBatch(long start, long end, ref TGroupKey key, ref TPartitionK this.output.bitvector.col[index >> 6] |= 1L << (index & 0x3f); else this.output[index] = this.selector(leftPayload, rightPayload); - if (this.output.Count == Config.DataBatchSize) FlushContents(); + if (this.output.Count == Config.DataBatchSize) this.FlushContents(); } protected override void FlushContents() @@ -620,7 +624,7 @@ public void Populate(long start, ref TGroupKey key, ref TPayload payload) this.Payload = payload; } - public override string ToString() => "[Start=" + this.Start + ", Key='" + this.Key + "', Payload='" + this.Payload + "']"; + public override readonly string ToString() => "[Start=" + this.Start + ", Key='" + this.Key + "', Payload='" + this.Payload + "']"; } public override bool LeftInputHasState @@ -679,9 +683,9 @@ private sealed class PartitionEntry [DataMember] public TPartitionKey key; [DataMember] - public FastMap> leftIntervalMap = new FastMap>(); + public FastMap> leftIntervalMap = new(); [DataMember] - public FastMap> rightIntervalMap = new FastMap>(); + public FastMap> rightIntervalMap = new(); [DataMember] public IEndPointOrderer endPointHeap; [DataMember] diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/EquiJoin/FixedInterval/PartitionedFixedIntervalEquiJoinPipeSimple.cs b/Sources/Core/Microsoft.StreamProcessing/Operators/EquiJoin/FixedInterval/PartitionedFixedIntervalEquiJoinPipeSimple.cs index 0cfe92511..cdb337837 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/EquiJoin/FixedInterval/PartitionedFixedIntervalEquiJoinPipeSimple.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/EquiJoin/FixedInterval/PartitionedFixedIntervalEquiJoinPipeSimple.cs @@ -29,21 +29,21 @@ internal sealed class PartitionedFixedIntervalEquiJoinPipeSimple> leftQueue = new FastDictionary2>(); + private FastDictionary2> leftQueue = new(); [DataMember] - private FastDictionary2> rightQueue = new FastDictionary2>(); + private FastDictionary2> rightQueue = new(); [DataMember] - private HashSet processQueue = new HashSet(); + private HashSet processQueue = []; [DataMember] - private HashSet seenKeys = new HashSet(); + private HashSet seenKeys = []; [DataMember] - private HashSet cleanKeys = new HashSet(); + private HashSet cleanKeys = []; [DataMember] private StreamMessage, TResult> output; [DataMember] - private FastDictionary partitionData = new FastDictionary(); + private FastDictionary partitionData = new(); [DataMember] private long lastLeftCTI = long.MinValue; [DataMember] @@ -103,8 +103,8 @@ private void NewPartition(TPartitionKey pKey, int hash) protected override void ProcessBothBatches(StreamMessage, TLeft> leftBatch, StreamMessage, TRight> rightBatch, out bool leftBatchDone, out bool rightBatchDone, out bool leftBatchFree, out bool rightBatchFree) { - ProcessLeftBatch(leftBatch, out leftBatchDone, out leftBatchFree); - ProcessRightBatch(rightBatch, out rightBatchDone, out rightBatchFree); + this.ProcessLeftBatch(leftBatch, out leftBatchDone, out leftBatchFree); + this.ProcessRightBatch(rightBatch, out rightBatchDone, out rightBatchFree); } protected override void ProcessLeftBatch(StreamMessage, TLeft> batch, out bool leftBatchDone, out bool leftBatchFree) @@ -133,7 +133,7 @@ protected override void ProcessLeftBatch(StreamMessage, TRight> batch, out bool rightBatchDone, out bool rightBatchFree) @@ -178,7 +178,7 @@ protected override void ProcessRightBatch(StreamMessage this.output.Free(); + protected override void DisposeState() + { + this.partitionData.Dispose(); + this.output.Free(); + } [MethodImpl(MethodImplOptions.AggressiveInlining)] private void ProcessPendingEntries() @@ -233,11 +237,11 @@ private void ProcessPendingEntries() if (partition.nextLeftTime < partition.nextRightTime) { - UpdateTime(partition, partition.nextLeftTime); + this.UpdateTime(partition, partition.nextLeftTime); if (!leftEntry.IsPunctuation) { - ProcessLeftEvent( + this.ProcessLeftEvent( partition, partition.nextLeftTime, leftEntry.Payload); @@ -245,7 +249,7 @@ private void ProcessPendingEntries() else if (partition.currTime > old) { var r = default(TRight); - AddToBatch( + this.AddToBatch( partition.currTime, StreamEvent.PunctuationOtherTime, partition, @@ -257,11 +261,11 @@ private void ProcessPendingEntries() } else { - UpdateTime(partition, partition.nextRightTime); + this.UpdateTime(partition, partition.nextRightTime); if (!rightEntry.IsPunctuation) { - ProcessRightEvent( + this.ProcessRightEvent( partition, partition.nextRightTime, rightEntry.Payload); @@ -269,7 +273,7 @@ private void ProcessPendingEntries() else if (partition.currTime > old) { var l = default(TLeft); - AddToBatch( + this.AddToBatch( partition.currTime, StreamEvent.PunctuationOtherTime, partition, @@ -290,15 +294,15 @@ private void ProcessPendingEntries() // If we have not yet reached the lesser of the two sides (in this case, right), and we don't // have input from that side, reach that time now. This can happen with low watermarks. if (partition.currTime < partition.nextRightTime) - UpdateTime(partition, partition.nextRightTime); + this.UpdateTime(partition, partition.nextRightTime); break; } - UpdateTime(partition, partition.nextLeftTime); + this.UpdateTime(partition, partition.nextLeftTime); if (!leftEntry.IsPunctuation) { - ProcessLeftEvent( + this.ProcessLeftEvent( partition, partition.nextLeftTime, leftEntry.Payload); @@ -306,7 +310,7 @@ private void ProcessPendingEntries() else if (partition.currTime > old) { var r = default(TRight); - AddToBatch( + this.AddToBatch( partition.currTime, StreamEvent.PunctuationOtherTime, partition, @@ -326,15 +330,15 @@ private void ProcessPendingEntries() // If we have not yet reached the lesser of the two sides (in this case, left), and we don't // have input from that side, reach that time now. This can happen with low watermarks. if (partition.currTime < partition.nextLeftTime) - UpdateTime(partition, partition.nextLeftTime); + this.UpdateTime(partition, partition.nextLeftTime); break; } - UpdateTime(partition, partition.nextRightTime); + this.UpdateTime(partition, partition.nextRightTime); if (!rightEntry.IsPunctuation) { - ProcessRightEvent( + this.ProcessRightEvent( partition, partition.nextRightTime, rightEntry.Payload); @@ -342,7 +346,7 @@ private void ProcessPendingEntries() else if (partition.currTime > old) { var l = default(TLeft); - AddToBatch( + this.AddToBatch( partition.currTime, StreamEvent.PunctuationOtherTime, partition, @@ -357,7 +361,7 @@ private void ProcessPendingEntries() if (partition.nextLeftTime < this.lastLeftCTI) partition.nextLeftTime = this.lastLeftCTI; if (partition.nextRightTime < this.lastRightCTI) partition.nextRightTime = this.lastRightCTI; - UpdateTime(partition, Math.Min(this.lastLeftCTI, this.lastRightCTI)); + this.UpdateTime(partition, Math.Min(this.lastLeftCTI, this.lastRightCTI)); if (partition.IsClean()) this.cleanKeys.Add(pKey); break; } @@ -367,7 +371,7 @@ private void ProcessPendingEntries() if (this.emitCTI) { var earliest = Math.Min(this.lastLeftCTI, this.lastRightCTI); - AddLowWatermarkToBatch(earliest); + this.AddLowWatermarkToBatch(earliest); this.emitCTI = false; foreach (var p in this.cleanKeys) { @@ -388,7 +392,7 @@ private void UpdateTime(PartitionEntry partition, long time) if (time > partition.currTime) { partition.currTime = time; - ReachTime(partition); + this.ReachTime(partition); } } @@ -397,7 +401,7 @@ private void ProcessLeftEvent(PartitionEntry partition, long start, TLeft payloa { int index = partition.leftIntervalMap.Insert(partition.hash); partition.leftIntervalMap.Values[index].Populate(start, ref payload); - CreateOutputForStartInterval(partition, start, ref payload); + this.CreateOutputForStartInterval(partition, start, ref payload); partition.endPointHeap.Insert(start + this.leftDuration, index); } @@ -406,7 +410,7 @@ private void ProcessRightEvent(PartitionEntry partition, long start, TRight payl { int index = partition.rightIntervalMap.Insert(partition.hash); partition.rightIntervalMap.Values[index].Populate(start, ref payload); - CreateOutputForStartInterval(partition, start, ref payload); + this.CreateOutputForStartInterval(partition, start, ref payload); partition.endPointHeap.Insert(start + this.rightDuration, ~index); } @@ -419,7 +423,7 @@ private void CreateOutputForStartInterval(PartitionEntry partition, long current { long leftEnd = currentTime + this.leftDuration; long rightEnd = partition.rightIntervalMap.Values[index].Start + this.rightDuration; - AddToBatch( + this.AddToBatch( currentTime, leftEnd < rightEnd ? leftEnd : rightEnd, partition, @@ -453,7 +457,7 @@ private void CreateOutputForStartInterval(PartitionEntry partition, long current { long rightEnd = currentTime + this.rightDuration; long leftEnd = partition.leftIntervalMap.Values[index].Start + this.leftDuration; - AddToBatch( + this.AddToBatch( currentTime, rightEnd < leftEnd ? rightEnd : leftEnd, partition, @@ -477,7 +481,7 @@ private void AddLowWatermarkToBatch(long start) this.output.hash.col[index] = 0; this.output.bitvector.col[index >> 6] |= 1L << (index & 0x3f); - if (this.output.Count == Config.DataBatchSize) FlushContents(); + if (this.output.Count == Config.DataBatchSize) this.FlushContents(); } } @@ -494,7 +498,7 @@ private void AddToBatch(long start, long end, PartitionEntry partition, ref TLef this.output.bitvector.col[index >> 6] |= 1L << (index & 0x3f); else this.output[index] = this.selector(leftPayload, rightPayload); - if (this.output.Count == Config.DataBatchSize) FlushContents(); + if (this.output.Count == Config.DataBatchSize) this.FlushContents(); } protected override void FlushContents() @@ -587,7 +591,7 @@ public void Populate(long start, ref TPayload payload) this.Payload = payload; } - public override string ToString() => "[Start=" + this.Start + ", Payload='" + this.Payload + "']"; + public override readonly string ToString() => "[Start=" + this.Start + ", Payload='" + this.Payload + "']"; } public override bool LeftInputHasState @@ -640,9 +644,9 @@ private sealed class PartitionEntry [DataMember] public int hash; [DataMember] - public FastMap> leftIntervalMap = new FastMap>(); + public FastMap> leftIntervalMap = new(); [DataMember] - public FastMap> rightIntervalMap = new FastMap>(); + public FastMap> rightIntervalMap = new(); [DataMember] public IEndPointOrderer endPointHeap; [DataMember] diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/EquiJoin/IncreasingOrder/IncreasingOrderEquiJoinPipe.cs b/Sources/Core/Microsoft.StreamProcessing/Operators/EquiJoin/IncreasingOrder/IncreasingOrderEquiJoinPipe.cs index 026eccaa6..54594e184 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/EquiJoin/IncreasingOrder/IncreasingOrderEquiJoinPipe.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/EquiJoin/IncreasingOrder/IncreasingOrderEquiJoinPipe.cs @@ -62,8 +62,8 @@ public IncreasingOrderEquiJoinPipe( this.joinKeyOrderComparerExpression = stream.Left.Properties.KeyComparer.GetCompareExpr(); this.joinKeyOrderComparer = this.joinKeyOrderComparerExpression.Compile(); - this.currentLeftList = new List>(); - this.currentRightList = new List>(); + this.currentLeftList = []; + this.currentRightList = []; this.errorMessages = stream.ErrorMessages; this.pool = MemoryManager.GetMemoryPool(stream.Properties.IsColumnar); @@ -96,7 +96,7 @@ protected override void ProcessBothBatches(StreamMessage leftBatch, return; } - UpdateNextLeftTime(leftBatch.vsync.col[leftBatch.iter]); + this.UpdateNextLeftTime(leftBatch.vsync.col[leftBatch.iter]); this.nextLeftKey = leftBatch.key.col[leftBatch.iter]; if (!GoToVisibleRow(rightBatch)) @@ -106,7 +106,7 @@ protected override void ProcessBothBatches(StreamMessage leftBatch, return; } - UpdateNextRightTime(rightBatch.vsync.col[rightBatch.iter]); + this.UpdateNextRightTime(rightBatch.vsync.col[rightBatch.iter]); this.nextRightKey = rightBatch.key.col[rightBatch.iter]; while (true) @@ -123,7 +123,7 @@ protected override void ProcessBothBatches(StreamMessage leftBatch, // process left if (leftPunctuation) { - AddPunctuationToBatch(this.nextLeftTime); + this.AddPunctuationToBatch(this.nextLeftTime); } else { @@ -151,7 +151,7 @@ protected override void ProcessBothBatches(StreamMessage leftBatch, { ActiveEvent t = this.currentRightList[i]; var nextLeftKeyTemp = this.nextLeftKey; - OutputStartEdge(this.nextLeftTime > t.Timestamp ? this.nextLeftTime : t.Timestamp, ref nextLeftKeyTemp, ref payload, ref t.Payload, leftBatch.hash.col[leftBatch.iter]); + this.OutputStartEdge(this.nextLeftTime > t.Timestamp ? this.nextLeftTime : t.Timestamp, ref nextLeftKeyTemp, ref payload, ref t.Payload, leftBatch.hash.col[leftBatch.iter]); } } else @@ -195,7 +195,7 @@ protected override void ProcessBothBatches(StreamMessage leftBatch, // process right if (rightPunctuation) { - AddPunctuationToBatch(this.nextRightTime); + this.AddPunctuationToBatch(this.nextRightTime); } else { @@ -231,7 +231,7 @@ protected override void ProcessBothBatches(StreamMessage leftBatch, this.output[index] = this.selector(t.Payload, rightP); this.output.hash.col[index] = rightBatch.hash.col[rightBatch.iter]; - if (this.output.Count == Config.DataBatchSize) FlushContents(); + if (this.output.Count == Config.DataBatchSize) this.FlushContents(); #endregion } } @@ -317,7 +317,7 @@ protected override void ProcessBothBatches(StreamMessage leftBatch, { ActiveEvent t = this.currentRightList[i]; var temp = this.nextLeftKey; - OutputStartEdge(this.nextLeftTime > t.Timestamp ? this.nextLeftTime : t.Timestamp, ref temp, ref payload, ref t.Payload, leftBatch.hash.col[leftBatch.iter]); + this.OutputStartEdge(this.nextLeftTime > t.Timestamp ? this.nextLeftTime : t.Timestamp, ref temp, ref payload, ref t.Payload, leftBatch.hash.col[leftBatch.iter]); } } else @@ -408,7 +408,7 @@ protected override void ProcessBothBatches(StreamMessage leftBatch, this.output[index] = this.selector(t.Payload, rightP); this.output.hash.col[index] = rightBatch.hash.col[rightBatch.iter]; - if (this.output.Count == Config.DataBatchSize) FlushContents(); + if (this.output.Count == Config.DataBatchSize) this.FlushContents(); #endregion } } @@ -481,7 +481,7 @@ protected override void ProcessLeftBatch(StreamMessage batch, out b return; } - UpdateNextLeftTime(batch.vsync.col[batch.iter]); + this.UpdateNextLeftTime(batch.vsync.col[batch.iter]); if (batch.vother.col[batch.iter] == StreamEvent.PunctuationOtherTime) { @@ -491,7 +491,7 @@ protected override void ProcessLeftBatch(StreamMessage batch, out b return; } - AddPunctuationToBatch(batch.vsync.col[batch.iter]); + this.AddPunctuationToBatch(batch.vsync.col[batch.iter]); batch.iter++; continue; @@ -502,7 +502,7 @@ protected override void ProcessLeftBatch(StreamMessage batch, out b int compare = this.joinKeyOrderComparer(this.nextLeftKey, this.nextRightKey); if ((compare == 0) && (this.nextLeftTime <= this.nextRightTime)) { - ProcessLeftStartEdge( + this.ProcessLeftStartEdge( this.nextLeftTime, ref batch.key.col[batch.iter], batch[batch.iter], @@ -530,7 +530,7 @@ protected override void ProcessRightBatch(StreamMessage batch, out return; } - UpdateNextRightTime(batch.vsync.col[batch.iter]); + this.UpdateNextRightTime(batch.vsync.col[batch.iter]); if (batch.vother.col[batch.iter] == StreamEvent.PunctuationOtherTime) { @@ -540,7 +540,7 @@ protected override void ProcessRightBatch(StreamMessage batch, out return; } - AddPunctuationToBatch(batch.vsync.col[batch.iter]); + this.AddPunctuationToBatch(batch.vsync.col[batch.iter]); batch.iter++; continue; @@ -551,7 +551,7 @@ protected override void ProcessRightBatch(StreamMessage batch, out int compare = this.joinKeyOrderComparer(this.nextLeftKey, this.nextRightKey); if ((compare == 0) && (this.nextRightTime <= this.nextLeftTime)) { - ProcessRightStartEdge( + this.ProcessRightStartEdge( this.nextRightTime, ref batch.key.col[batch.iter], batch[batch.iter], @@ -599,7 +599,7 @@ private void ProcessLeftStartEdge(long start, ref TKey key, TLeft payload, int h for (int i = 0; i < this.currentRightList.Count; i++) { ActiveEvent t = this.currentRightList[i]; - OutputStartEdge(start > t.Timestamp ? start : t.Timestamp, ref key, ref payload, ref t.Payload, hash); + this.OutputStartEdge(start > t.Timestamp ? start : t.Timestamp, ref key, ref payload, ref t.Payload, hash); } } else @@ -640,7 +640,7 @@ private void ProcessRightStartEdge(long start, ref TKey key, TRight payload, int for (int i = 0; i < this.currentLeftList.Count; i++) { ActiveEvent t = this.currentLeftList[i]; - OutputStartEdge(start > t.Timestamp ? start : t.Timestamp, ref key, ref t.Payload, ref payload, hash); + this.OutputStartEdge(start > t.Timestamp ? start : t.Timestamp, ref key, ref t.Payload, ref payload, hash); } } else @@ -681,7 +681,7 @@ private void AddPunctuationToBatch(long start) this.output.hash.col[index] = 0; this.output.bitvector.col[index >> 6] |= (1L << (index & 0x3f)); - if (this.output.Count == Config.DataBatchSize) FlushContents(); + if (this.output.Count == Config.DataBatchSize) this.FlushContents(); } } @@ -695,7 +695,7 @@ private void OutputStartEdge(long start, ref TKey key, ref TLeft leftPayload, re this.output[index] = this.selector(leftPayload, rightPayload); this.output.hash.col[index] = hash; - if (this.output.Count == Config.DataBatchSize) FlushContents(); + if (this.output.Count == Config.DataBatchSize) this.FlushContents(); } protected override void FlushContents() @@ -726,7 +726,7 @@ public void Populate(ref long timestamp, ref TPayload payload) this.Payload = payload; } - public override string ToString() => "[Timestamp='" + this.Timestamp + "', Payload='" + this.Payload + "']"; + public override readonly string ToString() => "[Timestamp='" + this.Timestamp + "', Payload='" + this.Payload + "']"; } } } diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/EquiJoin/IncreasingOrder/IncreasingOrderEquiJoinTransformer.cs b/Sources/Core/Microsoft.StreamProcessing/Operators/EquiJoin/IncreasingOrder/IncreasingOrderEquiJoinTransformer.cs index 0da2d4395..7dd9d124b 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/EquiJoin/IncreasingOrder/IncreasingOrderEquiJoinTransformer.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/EquiJoin/IncreasingOrder/IncreasingOrderEquiJoinTransformer.cs @@ -52,8 +52,8 @@ internal static Tuple Generate( BinaryStreamable stream, Expression> selector) { - Contract.Requires(stream != null); - Contract.Ensures(Contract.Result>() == null || typeof(BinaryPipe).GetTypeInfo().IsAssignableFrom(Contract.Result>().Item1)); + ArgumentNullException.ThrowIfNull(stream); + Contract.Ensures(Contract.Result>() == null || typeof(BinaryPipe).IsAssignableFrom(Contract.Result>().Item1)); string errorMessages = null; try diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/EquiJoin/StartEdge/PartitionedStartEdgeEquiJoinPipe.cs b/Sources/Core/Microsoft.StreamProcessing/Operators/EquiJoin/StartEdge/PartitionedStartEdgeEquiJoinPipe.cs index f9371bb6d..df92c7717 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/EquiJoin/StartEdge/PartitionedStartEdgeEquiJoinPipe.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/EquiJoin/StartEdge/PartitionedStartEdgeEquiJoinPipe.cs @@ -28,20 +28,20 @@ internal sealed class PartitionedStartEdgeEquiJoinPipe keyComparer; [DataMember] - private FastDictionary2> leftQueue = new FastDictionary2>(); + private FastDictionary2> leftQueue = new(); [DataMember] - private FastDictionary2> rightQueue = new FastDictionary2>(); + private FastDictionary2> rightQueue = new(); [DataMember] - private HashSet processQueue = new HashSet(); + private HashSet processQueue = []; [DataMember] - private HashSet seenKeys = new HashSet(); + private HashSet seenKeys = []; [DataMember] - private HashSet cleanKeys = new HashSet(); + private HashSet cleanKeys = []; [DataMember] private StreamMessage output; [DataMember] - private FastDictionary partitionData = new FastDictionary(); + private FastDictionary partitionData = new(); [DataMember] private long lastLeftCTI = long.MinValue; [DataMember] @@ -99,8 +99,8 @@ protected override void ProduceBinaryQueryPlan(PlanNode left, PlanNode right) private void NewPartition(TPartitionKey pKey) { - this.leftQueue.Insert(pKey, new PooledElasticCircularBuffer()); - this.rightQueue.Insert(pKey, new PooledElasticCircularBuffer()); + this.leftQueue.Insert(pKey, []); + this.rightQueue.Insert(pKey, []); if (!this.partitionData.Lookup(pKey, out int index)) this.partitionData.Insert(ref index, pKey, new PartitionEntry { key = pKey }); } @@ -113,13 +113,14 @@ protected override void DisposeState() while (this.leftQueue.Iterate(ref iter)) this.leftQueue.entries[iter].value.Dispose(); iter = FastDictionary.IteratorStart; while (this.rightQueue.Iterate(ref iter)) this.rightQueue.entries[iter].value.Dispose(); + this.partitionData.Dispose(); this.output.Free(); } protected override void ProcessBothBatches(StreamMessage leftBatch, StreamMessage rightBatch, out bool leftBatchDone, out bool rightBatchDone, out bool leftBatchFree, out bool rightBatchFree) { - ProcessLeftBatch(leftBatch, out leftBatchDone, out leftBatchFree); - ProcessRightBatch(rightBatch, out rightBatchDone, out rightBatchFree); + this.ProcessLeftBatch(leftBatch, out leftBatchDone, out leftBatchFree); + this.ProcessRightBatch(rightBatch, out rightBatchDone, out rightBatchFree); } protected override void ProcessLeftBatch(StreamMessage batch, out bool leftBatchDone, out bool leftBatchFree) @@ -148,7 +149,7 @@ protected override void ProcessLeftBatch(StreamMessage batch, out b var partitionKey = this.getPartitionKey(batch.key.col[i]); if (first || !partitionKey.Equals(previous)) { - if (this.seenKeys.Add(partitionKey)) NewPartition(partitionKey); + if (this.seenKeys.Add(partitionKey)) this.NewPartition(partitionKey); this.leftQueue.Lookup(partitionKey, out int index); queue = this.leftQueue.entries[index].value; this.processQueue.Add(partitionKey); @@ -166,7 +167,7 @@ protected override void ProcessLeftBatch(StreamMessage batch, out b previous = partitionKey; } - ProcessPendingEntries(); + this.ProcessPendingEntries(); } protected override void ProcessRightBatch(StreamMessage batch, out bool rightBatchDone, out bool rightBatchFree) @@ -195,7 +196,7 @@ protected override void ProcessRightBatch(StreamMessage batch, out var partitionKey = this.getPartitionKey(batch.key.col[i]); if (first || !partitionKey.Equals(previous)) { - if (this.seenKeys.Add(partitionKey)) NewPartition(partitionKey); + if (this.seenKeys.Add(partitionKey)) this.NewPartition(partitionKey); this.rightQueue.Lookup(partitionKey, out int index); queue = this.rightQueue.entries[index].value; this.processQueue.Add(partitionKey); @@ -213,7 +214,7 @@ protected override void ProcessRightBatch(StreamMessage batch, out previous = partitionKey; } - ProcessPendingEntries(); + this.ProcessPendingEntries(); } [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -261,7 +262,7 @@ private void ProcessPendingEntries() { if (this.keyComparer(key, rightEdgeMapForPartition.Values[rightIndex].Key)) { - OutputStartEdge(partition.nextLeftTime, ref key, ref leftEntry.Payload, ref rightEdgeMapForPartition.Values[rightIndex].Payload, hash); + this.OutputStartEdge(partition.nextLeftTime, ref key, ref leftEntry.Payload, ref rightEdgeMapForPartition.Values[rightIndex].Payload, hash); } } } @@ -275,7 +276,7 @@ private void ProcessPendingEntries() } else { - OutputPunctuation(leftEntry.Sync, ref leftEntry.Key, leftEntry.Hash); + this.OutputPunctuation(leftEntry.Sync, ref leftEntry.Key, leftEntry.Hash); } leftWorking.Dequeue(); @@ -293,7 +294,7 @@ private void ProcessPendingEntries() { if (this.keyComparer(key, leftEdgeMapForPartition.Values[leftIndex].Key)) { - OutputStartEdge(partition.nextRightTime, ref key, ref leftEdgeMapForPartition.Values[leftIndex].Payload, ref rightEntry.Payload, hash); + this.OutputStartEdge(partition.nextRightTime, ref key, ref leftEdgeMapForPartition.Values[leftIndex].Payload, ref rightEntry.Payload, hash); } } } @@ -307,7 +308,7 @@ private void ProcessPendingEntries() } else { - OutputPunctuation(rightEntry.Sync, ref rightEntry.Key, rightEntry.Hash); + this.OutputPunctuation(rightEntry.Sync, ref rightEntry.Key, rightEntry.Hash); } rightWorking.Dequeue(); @@ -328,7 +329,7 @@ private void ProcessPendingEntries() { if (this.keyComparer(key, rightEdgeMapForPartition.Values[rightIndex].Key)) { - OutputStartEdge(partition.nextLeftTime, ref key, ref leftEntry.Payload, ref rightEdgeMapForPartition.Values[rightIndex].Payload, hash); + this.OutputStartEdge(partition.nextLeftTime, ref key, ref leftEntry.Payload, ref rightEdgeMapForPartition.Values[rightIndex].Payload, hash); } } } @@ -342,7 +343,7 @@ private void ProcessPendingEntries() } else { - OutputPunctuation(leftEntry.Sync, ref leftEntry.Key, leftEntry.Hash); + this.OutputPunctuation(leftEntry.Sync, ref leftEntry.Key, leftEntry.Hash); return; } @@ -363,7 +364,7 @@ private void ProcessPendingEntries() { if (this.keyComparer(key, leftEdgeMapForPartition.Values[leftIndex].Key)) { - OutputStartEdge(partition.nextRightTime, ref key, ref leftEdgeMapForPartition.Values[leftIndex].Payload, ref rightEntry.Payload, hash); + this.OutputStartEdge(partition.nextRightTime, ref key, ref leftEdgeMapForPartition.Values[leftIndex].Payload, ref rightEntry.Payload, hash); } } } @@ -377,7 +378,7 @@ private void ProcessPendingEntries() } else { - OutputPunctuation(rightEntry.Sync, ref rightEntry.Key, rightEntry.Hash); + this.OutputPunctuation(rightEntry.Sync, ref rightEntry.Key, rightEntry.Hash); } rightWorking.Dequeue(); @@ -397,7 +398,7 @@ private void ProcessPendingEntries() if (this.emitCTI) { var earliest = Math.Min(this.lastLeftCTI, this.lastRightCTI); - AddLowWatermarkToBatch(earliest); + this.AddLowWatermarkToBatch(earliest); this.emitCTI = false; foreach (var p in this.cleanKeys) { @@ -431,7 +432,7 @@ private void AddLowWatermarkToBatch(long start) this.output.hash.col[index] = 0; this.output.bitvector.col[index >> 6] |= (1L << (index & 0x3f)); - if (this.output.Count == Config.DataBatchSize) FlushContents(); + if (this.output.Count == Config.DataBatchSize) this.FlushContents(); } } @@ -450,7 +451,7 @@ private void OutputStartEdge(long start, ref TKey key, ref TLeft leftPayload, re this.output[index] = this.selector(leftPayload, rightPayload); this.output.hash.col[index] = hash; - if (this.output.Count == Config.DataBatchSize) FlushContents(); + if (this.output.Count == Config.DataBatchSize) this.FlushContents(); } [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -469,7 +470,7 @@ private void OutputPunctuation(long start, ref TKey key, int hash) this.output.hash.col[index] = hash; this.output.bitvector.col[index >> 6] |= (1L << (index & 0x3f)); - if (this.output.Count == Config.DataBatchSize) FlushContents(); + if (this.output.Count == Config.DataBatchSize) this.FlushContents(); } protected override void FlushContents() @@ -547,7 +548,7 @@ public void Populate(ref TKey key, ref TPayload payload) this.Payload = payload; } - public override string ToString() => "[Key='" + this.Key + "', Payload='" + this.Payload + "']"; + public override readonly string ToString() => "[Key='" + this.Key + "', Payload='" + this.Payload + "']"; } public override bool LeftInputHasState @@ -612,13 +613,13 @@ private sealed class PartitionEntry /// Currently active left start edges /// [DataMember] - public FastMap> leftEdgeMap = new FastMap>(); + public FastMap> leftEdgeMap = new(); /// /// Currently active right start edges /// [DataMember] - public FastMap> rightEdgeMap = new FastMap>(); + public FastMap> rightEdgeMap = new(); [DataMember] public long nextLeftTime = long.MinValue; diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/EquiJoin/StartEdge/StartEdgeEquiJoinPipe.cs b/Sources/Core/Microsoft.StreamProcessing/Operators/EquiJoin/StartEdge/StartEdgeEquiJoinPipe.cs index ef9d06e7f..705eca43b 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/EquiJoin/StartEdge/StartEdgeEquiJoinPipe.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/EquiJoin/StartEdge/StartEdgeEquiJoinPipe.cs @@ -29,9 +29,9 @@ internal sealed class StartEdgeEquiJoinPipe : Bina private StreamMessage output; [DataMember] - private FastMap> leftEdgeMap = new FastMap>(DefaultCapacity); + private FastMap> leftEdgeMap = new(DefaultCapacity); [DataMember] - private FastMap> rightEdgeMap = new FastMap>(DefaultCapacity); + private FastMap> rightEdgeMap = new(DefaultCapacity); [DataMember] private long nextLeftTime = long.MinValue; [DataMember] @@ -89,7 +89,7 @@ protected override void ProcessBothBatches(StreamMessage leftBatch, return; } - UpdateNextLeftTime(leftBatch.vsync.col[leftBatch.iter]); + this.UpdateNextLeftTime(leftBatch.vsync.col[leftBatch.iter]); if (!GoToVisibleRow(rightBatch)) { @@ -98,7 +98,7 @@ protected override void ProcessBothBatches(StreamMessage leftBatch, return; } - UpdateNextRightTime(rightBatch.vsync.col[rightBatch.iter]); + this.UpdateNextRightTime(rightBatch.vsync.col[rightBatch.iter]); FastMap>.FindTraverser rightEdges = default; FastMap>.FindTraverser leftEdges = default; @@ -111,7 +111,7 @@ protected override void ProcessBothBatches(StreamMessage leftBatch, { if (leftPunctuation) { - AddPunctuationToBatch(this.nextLeftTime); + this.AddPunctuationToBatch(this.nextLeftTime); } else { @@ -129,7 +129,7 @@ protected override void ProcessBothBatches(StreamMessage leftBatch, if (this.keyComparer(key, this.rightEdgeMap.Values[rightIndex].Key)) { payload = leftBatch[leftBatch.iter]; - OutputStartEdge(this.nextLeftTime, ref key, ref payload, ref this.rightEdgeMap.Values[rightIndex].Payload, hash); + this.OutputStartEdge(this.nextLeftTime, ref key, ref payload, ref this.rightEdgeMap.Values[rightIndex].Payload, hash); } } } @@ -154,13 +154,13 @@ protected override void ProcessBothBatches(StreamMessage leftBatch, return; } - UpdateNextLeftTime(leftBatch.vsync.col[leftBatch.iter]); + this.UpdateNextLeftTime(leftBatch.vsync.col[leftBatch.iter]); } else { if (rightPunctuation) { - AddPunctuationToBatch(this.nextRightTime); + this.AddPunctuationToBatch(this.nextRightTime); } else { @@ -178,7 +178,7 @@ protected override void ProcessBothBatches(StreamMessage leftBatch, if (this.keyComparer(key, this.leftEdgeMap.Values[leftIndex].Key)) { payload = rightBatch[rightBatch.iter]; - OutputStartEdge(this.nextRightTime, ref key, ref this.leftEdgeMap.Values[leftIndex].Payload, ref payload, hash); + this.OutputStartEdge(this.nextRightTime, ref key, ref this.leftEdgeMap.Values[leftIndex].Payload, ref payload, hash); } } } @@ -201,7 +201,7 @@ protected override void ProcessBothBatches(StreamMessage leftBatch, return; } - UpdateNextRightTime(rightBatch.vsync.col[rightBatch.iter]); + this.UpdateNextRightTime(rightBatch.vsync.col[rightBatch.iter]); } } } @@ -218,7 +218,7 @@ protected override void ProcessLeftBatch(StreamMessage batch, out b return; } - UpdateNextLeftTime(batch.vsync.col[batch.iter]); + this.UpdateNextLeftTime(batch.vsync.col[batch.iter]); if (this.nextLeftTime > this.nextRightTime) { @@ -228,7 +228,7 @@ protected override void ProcessLeftBatch(StreamMessage batch, out b if (batch.vother.col[batch.iter] == StreamEvent.PunctuationOtherTime) { - AddPunctuationToBatch(batch.vsync.col[batch.iter]); + this.AddPunctuationToBatch(batch.vsync.col[batch.iter]); batch.iter++; continue; } @@ -248,7 +248,7 @@ protected override void ProcessLeftBatch(StreamMessage batch, out b if (this.keyComparer(key, this.rightEdgeMap.Values[rightIndex].Key)) { payload = batch[batch.iter]; - OutputStartEdge(this.nextLeftTime, ref key, ref payload, ref this.rightEdgeMap.Values[rightIndex].Payload, hash); + this.OutputStartEdge(this.nextLeftTime, ref key, ref payload, ref this.rightEdgeMap.Values[rightIndex].Payload, hash); } } } @@ -278,7 +278,7 @@ protected override void ProcessRightBatch(StreamMessage batch, out return; } - UpdateNextRightTime(batch.vsync.col[batch.iter]); + this.UpdateNextRightTime(batch.vsync.col[batch.iter]); if (this.nextRightTime > this.nextLeftTime) { @@ -288,7 +288,7 @@ protected override void ProcessRightBatch(StreamMessage batch, out if (batch.vother.col[batch.iter] == StreamEvent.PunctuationOtherTime) { - AddPunctuationToBatch(batch.vsync.col[batch.iter]); + this.AddPunctuationToBatch(batch.vsync.col[batch.iter]); batch.iter++; continue; } @@ -308,7 +308,7 @@ protected override void ProcessRightBatch(StreamMessage batch, out if (this.keyComparer(key, this.leftEdgeMap.Values[leftIndex].Key)) { payload = batch[batch.iter]; - OutputStartEdge(this.nextRightTime, ref key, ref this.leftEdgeMap.Values[leftIndex].Payload, ref payload, hash); + this.OutputStartEdge(this.nextRightTime, ref key, ref this.leftEdgeMap.Values[leftIndex].Payload, ref payload, hash); } } } @@ -372,7 +372,7 @@ private void AddPunctuationToBatch(long start) this.output.hash.col[index] = 0; this.output.bitvector.col[index >> 6] |= (1L << (index & 0x3f)); - if (this.output.Count == Config.DataBatchSize) FlushContents(); + if (this.output.Count == Config.DataBatchSize) this.FlushContents(); } } @@ -386,7 +386,7 @@ private void OutputStartEdge(long start, ref TKey key, ref TLeft leftPayload, re this.output[index] = this.selector(leftPayload, rightPayload); this.output.hash.col[index] = hash; - if (this.output.Count == Config.DataBatchSize) FlushContents(); + if (this.output.Count == Config.DataBatchSize) this.FlushContents(); } protected override void FlushContents() @@ -414,7 +414,7 @@ public void Populate(ref TKey key, ref TPayload payload) this.Payload = payload; } - public override string ToString() + public override readonly string ToString() { return "[Key='" + this.Key + "', Payload='" + this.Payload + "']"; } diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/EquiJoin/StartEdge/StartEdgeEquiJoinTransformer.cs b/Sources/Core/Microsoft.StreamProcessing/Operators/EquiJoin/StartEdge/StartEdgeEquiJoinTransformer.cs index 060b43d6d..a8a66f43a 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/EquiJoin/StartEdge/StartEdgeEquiJoinTransformer.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/EquiJoin/StartEdge/StartEdgeEquiJoinTransformer.cs @@ -36,8 +36,8 @@ internal static Tuple Generate( BinaryStreamable stream, Expression> selector) { - Contract.Requires(stream != null); - Contract.Ensures(Contract.Result>() == null || typeof(BinaryPipe).GetTypeInfo().IsAssignableFrom(Contract.Result>().Item1)); + ArgumentNullException.ThrowIfNull(stream); + Contract.Ensures(Contract.Result>() == null || typeof(BinaryPipe).IsAssignableFrom(Contract.Result>().Item1)); string errorMessages = null; try diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/ExtendLifetime/ExtendLifetimeNegativePipe.cs b/Sources/Core/Microsoft.StreamProcessing/Operators/ExtendLifetime/ExtendLifetimeNegativePipe.cs index b03a53aeb..3995efb61 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/ExtendLifetime/ExtendLifetimeNegativePipe.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/ExtendLifetime/ExtendLifetimeNegativePipe.cs @@ -25,11 +25,11 @@ internal sealed class ExtendLifetimeNegativePipe : UnaryPipe output; [DataMember] - private FastMap syncTimeMap = new FastMap(); + private FastMap syncTimeMap = new(); [DataMember] - private EndPointHeap endPointHeap = new EndPointHeap(); + private EndPointHeap endPointHeap = new(); [DataMember] - private Dictionary> contractedToZero = new Dictionary>(); + private Dictionary> contractedToZero = []; [SchemaSerialization] private readonly Expression> keyComparerExpr; @@ -99,7 +99,7 @@ private void ReachTime(long timestamp) this.output.hash.col[ind] = activeEvent.Hash; } - if (this.output.Count == Config.DataBatchSize) FlushContents(); + if (this.output.Count == Config.DataBatchSize) this.FlushContents(); this.syncTimeMap.Remove(index); } @@ -115,7 +115,7 @@ public override unsafe void OnNext(StreamMessage batch) { if ((bv[i >> 6] & (1L << (i & 0x3f))) == 0) { - if (batch.vsync.col[i] >= StreamEvent.MinSyncTime + this.duration) ReachTime(batch.vsync.col[i] - this.duration); + if (batch.vsync.col[i] >= StreamEvent.MinSyncTime + this.duration) this.ReachTime(batch.vsync.col[i] - this.duration); if (batch.vother.col[i] == StreamEvent.InfinitySyncTime) { @@ -164,14 +164,14 @@ public override unsafe void OnNext(StreamMessage batch) this.output[ind] = batch[i]; this.output.hash.col[ind] = batch.hash.col[i]; - if (this.output.Count == Config.DataBatchSize) FlushContents(); + if (this.output.Count == Config.DataBatchSize) this.FlushContents(); } } } else if (batch.vother.col[i] == long.MinValue) { long syncTime = (batch.vsync.col[i] == StreamEvent.InfinitySyncTime ? StreamEvent.InfinitySyncTime : batch.vsync.col[i] - this.duration); - ReachTime(syncTime); + this.ReachTime(syncTime); int ind = this.output.Count++; this.output.vsync.col[ind] = syncTime; @@ -181,7 +181,7 @@ public override unsafe void OnNext(StreamMessage batch) this.output.hash.col[ind] = batch.hash.col[i]; this.output.bitvector.col[ind >> 6] |= 1L << (ind & 0x3f); - if (this.output.Count == Config.DataBatchSize) FlushContents(); + if (this.output.Count == Config.DataBatchSize) this.FlushContents(); } } } @@ -226,7 +226,7 @@ public void Populate(TKey key, TPayload payload, long sync, long other, int hash this.Hash = hash; } - public override string ToString() => "Key='" + this.Key + "', Payload='" + this.Payload; + public override readonly string ToString() => "Key='" + this.Key + "', Payload='" + this.Payload; } } } \ No newline at end of file diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/ExtendLifetime/ExtendLifetimeNegativeTemplate.cs b/Sources/Core/Microsoft.StreamProcessing/Operators/ExtendLifetime/ExtendLifetimeNegativeTemplate.cs index a1e4023f5..0ccccee11 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/ExtendLifetime/ExtendLifetimeNegativeTemplate.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/ExtendLifetime/ExtendLifetimeNegativeTemplate.cs @@ -259,7 +259,7 @@ private void ReachTime(long timestamp) "ree();\r\n\r\n public override int CurrentlyBufferedOutputCount => output.Count;\r" + "\n\r\n public override int CurrentlyBufferedInputCount => syncTimeMap.Count + co" + "ntractedToZero.Values.Select(o => o.Count).Sum();\r\n\r\n"); - if (!noFields && !this.payloadType.GetTypeInfo().IsValueType) { + if (!noFields && !this.payloadType.IsValueType) { this.Write(" [DataContract]\r\n private struct "); this.Write(this.ToStringHelper.ToStringWithCulture(ActiveEventType)); this.Write("\r\n {\r\n "); diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/ExtendLifetime/ExtendLifetimeNegativeTemplate.tt b/Sources/Core/Microsoft.StreamProcessing/Operators/ExtendLifetime/ExtendLifetimeNegativeTemplate.tt index 0203d42e4..09813e3b5 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/ExtendLifetime/ExtendLifetimeNegativeTemplate.tt +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/ExtendLifetime/ExtendLifetimeNegativeTemplate.tt @@ -243,7 +243,7 @@ internal sealed class <#= className #><#= TKeyTPayloadGenericParameters #> : Una public override int CurrentlyBufferedInputCount => syncTimeMap.Count + contractedToZero.Values.Select(o => o.Count).Sum(); -<# if (!noFields && !this.payloadType.GetTypeInfo().IsValueType) { #> +<# if (!noFields && !this.payloadType.IsValueType) { #> [DataContract] private struct <#= ActiveEventType #> { diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/ExtendLifetime/ExtendLifetimePipe.cs b/Sources/Core/Microsoft.StreamProcessing/Operators/ExtendLifetime/ExtendLifetimePipe.cs index f4f697558..e87aaf1c9 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/ExtendLifetime/ExtendLifetimePipe.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/ExtendLifetime/ExtendLifetimePipe.cs @@ -24,9 +24,9 @@ internal sealed class ExtendLifetimePipe : UnaryPipe endPointMap = new FastMap(); + private FastMap endPointMap = new(); [DataMember] - private EndPointHeap endPointHeap = new EndPointHeap(); + private EndPointHeap endPointHeap = new(); [Obsolete("Used only by serialization. Do not call directly.")] @@ -60,7 +60,7 @@ private void ReachTime(long timestamp) this.output[ind] = activeEvent.Payload; this.output.hash.col[ind] = activeEvent.Hash; - if (this.output.Count == Config.DataBatchSize) FlushContents(); + if (this.output.Count == Config.DataBatchSize) this.FlushContents(); this.endPointMap.Remove(index); } @@ -78,7 +78,7 @@ public override unsafe void OnNext(StreamMessage batch) { if ((bv[i >> 6] & (1L << (i & 0x3f))) == 0) { - if (batch.vsync.col[i] > this.lastSyncTime) ReachTime(batch.vsync.col[i]); + if (batch.vsync.col[i] > this.lastSyncTime) this.ReachTime(batch.vsync.col[i]); if (batch.vother.col[i] == StreamEvent.InfinitySyncTime) // For start events, copy directly across { @@ -89,7 +89,7 @@ public override unsafe void OnNext(StreamMessage batch) this.output[ind] = batch[i]; this.output.hash.col[ind] = batch.hash.col[i]; - if (this.output.Count == Config.DataBatchSize) FlushContents(); + if (this.output.Count == Config.DataBatchSize) this.FlushContents(); } else if (batch.vother.col[i] > batch.vsync.col[i]) // For intervals, just extend the duration { @@ -100,7 +100,7 @@ public override unsafe void OnNext(StreamMessage batch) this.output[ind] = batch[i]; this.output.hash.col[ind] = batch.hash.col[i]; - if (this.output.Count == Config.DataBatchSize) FlushContents(); + if (this.output.Count == Config.DataBatchSize) this.FlushContents(); } else { @@ -112,7 +112,7 @@ public override unsafe void OnNext(StreamMessage batch) } else if (batch.vother.col[i] == long.MinValue) { - ReachTime(batch.vsync.col[i]); + this.ReachTime(batch.vsync.col[i]); int ind = this.output.Count++; this.output.vsync.col[ind] = batch.vsync.col[i]; @@ -122,7 +122,7 @@ public override unsafe void OnNext(StreamMessage batch) this.output.hash.col[ind] = batch.hash.col[i]; this.output.bitvector.col[ind >> 6] |= 1L << (ind & 0x3f); - if (this.output.Count == Config.DataBatchSize) FlushContents(); + if (this.output.Count == Config.DataBatchSize) this.FlushContents(); } } } @@ -164,7 +164,7 @@ public void Populate(TKey key, TPayload payload, long startEdge, int hash) this.Hash = hash; } - public override string ToString() => "Key='" + this.Key + "', Payload='" + this.Payload; + public override readonly string ToString() => "Key='" + this.Key + "', Payload='" + this.Payload; } } } \ No newline at end of file diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/ExtendLifetime/ExtendLifetimeStreamable.cs b/Sources/Core/Microsoft.StreamProcessing/Operators/ExtendLifetime/ExtendLifetimeStreamable.cs index 2518d19c2..4a696b310 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/ExtendLifetime/ExtendLifetimeStreamable.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/ExtendLifetime/ExtendLifetimeStreamable.cs @@ -10,7 +10,7 @@ namespace Microsoft.StreamProcessing internal sealed class ExtendLifetimeStreamable : UnaryStreamable { private static readonly SafeConcurrentDictionary> cachedPipes - = new SafeConcurrentDictionary>(); + = new(); private readonly long duration; public ExtendLifetimeStreamable(IStreamable source, long duration) @@ -24,7 +24,7 @@ public ExtendLifetimeStreamable(IStreamable source, long duratio throw new InvalidOperationException($"Type of payload, '{typeof(TPayload).FullName}', to ExtendLifetime does not have a valid equality operator for columnar mode."); } - Initialize(); + this.Initialize(); } internal override IStreamObserver CreatePipe(IStreamObserver observer) @@ -36,7 +36,7 @@ internal override IStreamObserver CreatePipe(IStreamObserver(this, observer, -this.duration); } var outputType = typeof(PartitionedExtendLifetimeNegativePipe<,,>).MakeGenericType( @@ -51,7 +51,7 @@ internal override IStreamObserver CreatePipe(IStreamObserver(this, observer, this.duration); } var outputType = typeof(PartitionedExtendLifetimePipe<,,>).MakeGenericType( diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/ExtendLifetime/ExtendLifetimeTransformer.cs b/Sources/Core/Microsoft.StreamProcessing/Operators/ExtendLifetime/ExtendLifetimeTransformer.cs index f15e269d5..470cf894d 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/ExtendLifetime/ExtendLifetimeTransformer.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/ExtendLifetime/ExtendLifetimeTransformer.cs @@ -3,6 +3,9 @@ // Licensed under the MIT License // ********************************************************************* using System; +#if CODEGEN_TIMING +using System.Diagnostics; +#endif using System.Diagnostics.Contracts; using System.Reflection; @@ -32,8 +35,8 @@ protected ExtendLifetimeBaseTemplate(string className, Type keyType, Type payloa /// internal static Tuple Generate(ExtendLifetimeStreamable stream, long duration) { - Contract.Requires(stream != null); - Contract.Ensures(Contract.Result>() == null || typeof(UnaryPipe).GetTypeInfo().IsAssignableFrom(Contract.Result>().Item1)); + ArgumentNullException.ThrowIfNull(stream); + Contract.Ensures(Contract.Result>() == null || typeof(UnaryPipe).IsAssignableFrom(Contract.Result>().Item1)); var result = Generate(stream, duration, false, false); if (duration >= 0) return result; // only negative pipe uses comparers @@ -48,8 +51,8 @@ internal static Tuple Generate(ExtendLifetimeStrea internal static Tuple Generate(ExtendLifetimeStreamable stream, long duration, bool useCompiledKeyComparer, bool useCompiledPayloadComparer) { - Contract.Requires(stream != null); - Contract.Ensures(Contract.Result>() == null || typeof(UnaryPipe).GetTypeInfo().IsAssignableFrom(Contract.Result>().Item1)); + ArgumentNullException.ThrowIfNull(stream); + Contract.Ensures(Contract.Result>() == null || typeof(UnaryPipe).IsAssignableFrom(Contract.Result>().Item1)); #if CODEGEN_TIMING Stopwatch sw = new Stopwatch(); @@ -62,7 +65,7 @@ internal static Tuple Generate(ExtendLifetimeStrea ? new ExtendLifetimeNegativeTemplate(className, typeof(TKey), typeof(TPayload)) : (ExtendLifetimeBaseTemplate)new ExtendLifetimeTemplate(className, typeof(TKey), typeof(TPayload)); - template.ActiveEventType = typeof(TPayload).GetTypeInfo().IsValueType ? template.TPayload : "Active_Event"; + template.ActiveEventType = typeof(TPayload).IsValueType ? template.TPayload : "Active_Event"; #region Key Comparer template.useCompiledKeyComparer = useCompiledKeyComparer; diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/ExtendLifetime/PartitionedExtendLifetimeNegativePipe.cs b/Sources/Core/Microsoft.StreamProcessing/Operators/ExtendLifetime/PartitionedExtendLifetimeNegativePipe.cs index 1eb007e64..48f9d05a8 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/ExtendLifetime/PartitionedExtendLifetimeNegativePipe.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/ExtendLifetime/PartitionedExtendLifetimeNegativePipe.cs @@ -25,13 +25,13 @@ internal sealed class PartitionedExtendLifetimeNegativePipe output; [DataMember] - private FastDictionary lastSyncTimeDictionary = new FastDictionary(); + private FastDictionary lastSyncTimeDictionary = new(); [DataMember] - private FastDictionary> syncTimeMapDictionary = new FastDictionary>(); + private FastDictionary> syncTimeMapDictionary = new(); [DataMember] - private FastDictionary endPointHeapDictionary = new FastDictionary(); + private FastDictionary endPointHeapDictionary = new(); [DataMember] - private FastDictionary>> contractedToZeroDictionary = new FastDictionary>>(); + private FastDictionary>> contractedToZeroDictionary = new(); [Obsolete("Used only by serialization. Do not call directly.")] public PartitionedExtendLifetimeNegativePipe() { } @@ -55,7 +55,7 @@ public override void ProduceQueryPlan(PlanNode previous) private void ReachTime(long timestamp) { int partitionKey = FastDictionary.IteratorStart; - while (this.lastSyncTimeDictionary.Iterate(ref partitionKey)) ReachTime(this.lastSyncTimeDictionary.entries[partitionKey].key, timestamp); + while (this.lastSyncTimeDictionary.Iterate(ref partitionKey)) this.ReachTime(this.lastSyncTimeDictionary.entries[partitionKey].key, timestamp); } private void ReachTime(TPartitionKey pKey, long timestamp) @@ -101,7 +101,7 @@ private void ReachTime(TPartitionKey pKey, long timestamp) this.output[ind] = syncTimeMap.Values[index].Payload; this.output.hash.col[ind] = syncTimeMap.Values[index].Hash; - if (this.output.Count == Config.DataBatchSize) FlushContents(); + if (this.output.Count == Config.DataBatchSize) this.FlushContents(); syncTimeMap.Remove(index); } @@ -118,7 +118,7 @@ private void AllocatePartition(TPartitionKey pKey, long timestamp) this.lastSyncTimeDictionary.Lookup(pKey, out int timeIndex); this.lastSyncTimeDictionary.Insert(ref timeIndex, pKey, timestamp); this.contractedToZeroDictionary.Lookup(pKey, out int collapseIndex); - this.contractedToZeroDictionary.Insert(ref collapseIndex, pKey, new Dictionary>()); + this.contractedToZeroDictionary.Insert(ref collapseIndex, pKey, []); } public override unsafe void OnNext(StreamMessage batch) @@ -134,10 +134,10 @@ public override unsafe void OnNext(StreamMessage batch) var partition = this.getPartitionKey(batch.key.col[i]); if (!this.lastSyncTimeDictionary.Lookup(partition, out int timeIndex)) { - AllocatePartition(partition, batch.vsync.col[i]); + this.AllocatePartition(partition, batch.vsync.col[i]); } else if (batch.vsync.col[i] >= StreamEvent.MinSyncTime + this.duration - && batch.vsync.col[i] > this.lastSyncTimeDictionary.entries[timeIndex].value) ReachTime(partition, batch.vsync.col[i] - this.duration); + && batch.vsync.col[i] > this.lastSyncTimeDictionary.entries[timeIndex].value) this.ReachTime(partition, batch.vsync.col[i] - this.duration); if (batch.vother.col[i] == StreamEvent.InfinitySyncTime) { @@ -202,14 +202,14 @@ public override unsafe void OnNext(StreamMessage batch) this.output[ind] = batch[i]; this.output.hash.col[ind] = batch.hash.col[i]; - if (this.output.Count == Config.DataBatchSize) FlushContents(); + if (this.output.Count == Config.DataBatchSize) this.FlushContents(); } } } else if (batch.vother.col[i] == PartitionedStreamEvent.LowWatermarkOtherTime) { long syncTime = (batch.vsync.col[i] == StreamEvent.InfinitySyncTime ? StreamEvent.InfinitySyncTime : batch.vsync.col[i] - this.duration); - ReachTime(syncTime); + this.ReachTime(syncTime); int ind = this.output.Count++; this.output.vsync.col[ind] = syncTime; @@ -219,13 +219,13 @@ public override unsafe void OnNext(StreamMessage batch) this.output.hash.col[ind] = batch.hash.col[i]; this.output.bitvector.col[ind >> 6] |= 1L << (ind & 0x3f); - if (this.output.Count == Config.DataBatchSize) FlushContents(); + if (this.output.Count == Config.DataBatchSize) this.FlushContents(); } else if (batch.vother.col[i] == PartitionedStreamEvent.PunctuationOtherTime) { var partition = this.getPartitionKey(batch.key.col[i]); long syncTime = batch.vsync.col[i] == StreamEvent.InfinitySyncTime ? StreamEvent.InfinitySyncTime : batch.vsync.col[i] - this.duration; - ReachTime(partition, syncTime); + this.ReachTime(partition, syncTime); int ind = this.output.Count++; this.output.vsync.col[ind] = syncTime; @@ -235,7 +235,7 @@ public override unsafe void OnNext(StreamMessage batch) this.output.hash.col[ind] = batch.hash.col[i]; this.output.bitvector.col[ind >> 6] |= (1L << (ind & 0x3f)); - if (this.output.Count == Config.DataBatchSize) FlushContents(); + if (this.output.Count == Config.DataBatchSize) this.FlushContents(); } } } @@ -251,7 +251,14 @@ protected override void FlushContents() this.output.Allocate(); } - protected override void DisposeState() => this.output.Free(); + protected override void DisposeState() + { + this.lastSyncTimeDictionary.Dispose(); + this.syncTimeMapDictionary.Dispose(); + this.endPointHeapDictionary.Dispose(); + this.contractedToZeroDictionary.Dispose(); + this.output.Free(); + } public override int CurrentlyBufferedOutputCount => this.output.Count; @@ -291,7 +298,7 @@ public void Populate(TKey key, TPayload payload, long sync, long other, int hash this.Hash = hash; } - public override string ToString() => "Key='" + this.Key + "', Payload='" + this.Payload; + public override readonly string ToString() => "Key='" + this.Key + "', Payload='" + this.Payload; } } } \ No newline at end of file diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/ExtendLifetime/PartitionedExtendLifetimePipe.cs b/Sources/Core/Microsoft.StreamProcessing/Operators/ExtendLifetime/PartitionedExtendLifetimePipe.cs index 751f6ee3c..071136476 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/ExtendLifetime/PartitionedExtendLifetimePipe.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/ExtendLifetime/PartitionedExtendLifetimePipe.cs @@ -23,11 +23,11 @@ internal sealed class PartitionedExtendLifetimePipe output; [DataMember] - private FastDictionary lastSyncTimeDictionary = new FastDictionary(); + private FastDictionary lastSyncTimeDictionary = new(); [DataMember] - private FastDictionary> endPointMapDictionary = new FastDictionary>(); + private FastDictionary> endPointMapDictionary = new(); [DataMember] - private FastDictionary endPointHeapDictionary = new FastDictionary(); + private FastDictionary endPointHeapDictionary = new(); [Obsolete("Used only by serialization. Do not call directly.")] public PartitionedExtendLifetimePipe() { } @@ -51,7 +51,7 @@ public override void ProduceQueryPlan(PlanNode previous) private void ReachTime(long timestamp) { int partitionKey = FastDictionary.IteratorStart; - while (this.lastSyncTimeDictionary.Iterate(ref partitionKey)) ReachTime(this.lastSyncTimeDictionary.entries[partitionKey].key, timestamp); + while (this.lastSyncTimeDictionary.Iterate(ref partitionKey)) this.ReachTime(this.lastSyncTimeDictionary.entries[partitionKey].key, timestamp); } private void ReachTime(TPartitionKey pKey, long timestamp) @@ -71,7 +71,7 @@ private void ReachTime(TPartitionKey pKey, long timestamp) this.output[ind] = endPointMap.Values[index].Payload; this.output.hash.col[ind] = endPointMap.Values[index].Hash; - if (this.output.Count == Config.DataBatchSize) FlushContents(); + if (this.output.Count == Config.DataBatchSize) this.FlushContents(); endPointMap.Remove(index); } @@ -102,9 +102,9 @@ public override unsafe void OnNext(StreamMessage batch) var partition = this.getPartitionKey(batch.key.col[i]); if (!this.lastSyncTimeDictionary.Lookup(partition, out int timeIndex)) { - AllocatePartition(partition, batch.vsync.col[i]); + this.AllocatePartition(partition, batch.vsync.col[i]); } - else if (batch.vsync.col[i] > this.lastSyncTimeDictionary.entries[timeIndex].value) ReachTime(batch.vsync.col[i]); + else if (batch.vsync.col[i] > this.lastSyncTimeDictionary.entries[timeIndex].value) this.ReachTime(batch.vsync.col[i]); if (batch.vother.col[i] == StreamEvent.InfinitySyncTime) // For start events, copy directly across { @@ -115,7 +115,7 @@ public override unsafe void OnNext(StreamMessage batch) this.output[ind] = batch[i]; this.output.hash.col[ind] = batch.hash.col[i]; - if (this.output.Count == Config.DataBatchSize) FlushContents(); + if (this.output.Count == Config.DataBatchSize) this.FlushContents(); } else if (batch.vother.col[i] > batch.vsync.col[i]) // For intervals, just extend the duration { @@ -126,7 +126,7 @@ public override unsafe void OnNext(StreamMessage batch) this.output[ind] = batch[i]; this.output.hash.col[ind] = batch.hash.col[i]; - if (this.output.Count == Config.DataBatchSize) FlushContents(); + if (this.output.Count == Config.DataBatchSize) this.FlushContents(); } else { @@ -143,7 +143,7 @@ public override unsafe void OnNext(StreamMessage batch) } else if (batch.vother.col[i] == PartitionedStreamEvent.LowWatermarkOtherTime) { - ReachTime(batch.vsync.col[i]); + this.ReachTime(batch.vsync.col[i]); int ind = this.output.Count++; this.output.vsync.col[ind] = batch.vsync.col[i]; @@ -153,12 +153,12 @@ public override unsafe void OnNext(StreamMessage batch) this.output.hash.col[ind] = batch.hash.col[i]; this.output.bitvector.col[ind >> 6] |= 1L << (ind & 0x3f); - if (this.output.Count == Config.DataBatchSize) FlushContents(); + if (this.output.Count == Config.DataBatchSize) this.FlushContents(); } else if (batch.vother.col[i] == PartitionedStreamEvent.PunctuationOtherTime) { var partition = this.getPartitionKey(batch.key.col[i]); - ReachTime(partition, batch.vsync.col[i]); + this.ReachTime(partition, batch.vsync.col[i]); int ind = this.output.Count++; this.output.vsync.col[ind] = batch.vsync.col[i]; @@ -168,7 +168,7 @@ public override unsafe void OnNext(StreamMessage batch) this.output.hash.col[ind] = batch.hash.col[i]; this.output.bitvector.col[ind >> 6] |= 1L << (ind & 0x3f); - if (this.output.Count == Config.DataBatchSize) FlushContents(); + if (this.output.Count == Config.DataBatchSize) this.FlushContents(); } } } @@ -184,7 +184,13 @@ protected override void FlushContents() this.output.Allocate(); } - protected override void DisposeState() => this.output.Free(); + protected override void DisposeState() + { + this.lastSyncTimeDictionary.Dispose(); + this.endPointMapDictionary.Dispose(); + this.endPointHeapDictionary.Dispose(); + this.output.Free(); + } public override int CurrentlyBufferedOutputCount => this.output.Count; @@ -219,7 +225,7 @@ public void Populate(TKey key, TPayload payload, long startEdge, int hash) this.Hash = hash; } - public override string ToString() => "Key='" + this.Key + "', Payload='" + this.Payload; + public override readonly string ToString() => "Key='" + this.Key + "', Payload='" + this.Payload; } } diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/Group/GroupPlanNode.cs b/Sources/Core/Microsoft.StreamProcessing/Operators/Group/GroupPlanNode.cs index 479072e4d..2e16373f3 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/Group/GroupPlanNode.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/Group/GroupPlanNode.cs @@ -67,7 +67,7 @@ internal GroupPlanNode( internal override void PrintConciseSummary(System.Text.StringBuilder builder, int indentLevel) { - PrintConciseGeneralState(builder, indentLevel); + this.PrintConciseGeneralState(builder, indentLevel); builder.AppendLine(new string('\t', indentLevel + 1) + "Previous: "); this.Previous.PrintConciseSummary(builder, indentLevel + 2); } diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/Group/GroupStreamable.cs b/Sources/Core/Microsoft.StreamProcessing/Operators/Group/GroupStreamable.cs index 3d816a3e2..c4c18f788 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/Group/GroupStreamable.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/Group/GroupStreamable.cs @@ -12,7 +12,7 @@ namespace Microsoft.StreamProcessing internal sealed class GroupNestedStreamable : Streamable, TSource> { private static readonly SafeConcurrentDictionary> cachedPipes - = new SafeConcurrentDictionary>(); + = new(); [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes", Justification="Used to avoid creating redundant readonly property.")] public readonly Expression> KeySelector; @@ -23,25 +23,25 @@ public GroupNestedStreamable( IStreamable source, Expression> keySelector) : base(source.Properties.GroupNested(keySelector)) { - Contract.Requires(source != null); - Contract.Requires(keySelector != null); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(keySelector); - Source = source; - KeySelector = keySelector; + this.Source = source; + this.KeySelector = keySelector; - if (Source.Properties.IsColumnar && !CanGenerateColumnar()) + if (this.Source.Properties.IsColumnar && !this.CanGenerateColumnar()) { - properties = properties.ToRowBased(); - Source = Source.ColumnToRow(); + this.properties = this.properties.ToRowBased(); + this.Source = this.Source.ColumnToRow(); } } public override IDisposable Subscribe(IStreamObserver, TSource> observer) { - var pipe = Properties.IsColumnar - ? GetPipe(observer) - : CreatePipe(observer); - return Source.Subscribe(pipe); + var pipe = this.Properties.IsColumnar + ? this.GetPipe(observer) + : this.CreatePipe(observer); + return this.Source.Subscribe(pipe); } private IStreamObserver CreatePipe(IStreamObserver, TSource> observer) @@ -60,35 +60,35 @@ private bool CanGenerateColumnar() if (typeOfTOuterKey.GetPartitionType() != null) return false; if (typeOfTInnerKey.GetPartitionType() != null) return false; - var lookupKey = CacheKey.Create(KeySelector.ToString()); + var lookupKey = CacheKey.Create(this.KeySelector.ToString()); - var comparer = (Properties.KeyEqualityComparer as CompoundGroupKeyEqualityComparer).innerComparer.GetGetHashCodeExpr(); - var generatedPipeType = cachedPipes.GetOrAdd(lookupKey, key => GroupTemplate.Generate(comparer, KeySelector, true)); + var comparer = (this.Properties.KeyEqualityComparer as CompoundGroupKeyEqualityComparer).innerComparer.GetGetHashCodeExpr(); + var generatedPipeType = cachedPipes.GetOrAdd(lookupKey, key => GroupTemplate.Generate(comparer, this.KeySelector, true)); - errorMessages = generatedPipeType.Item2; + this.errorMessages = generatedPipeType.Item2; return generatedPipeType.Item1 != null; } private IStreamObserver GetPipe(IStreamObserver, TSource> observer) { - var lookupKey = CacheKey.Create(KeySelector.ToString()); + var lookupKey = CacheKey.Create(this.KeySelector.ToString()); - var comparer = (Properties.KeyEqualityComparer as CompoundGroupKeyEqualityComparer).innerComparer.GetGetHashCodeExpr(); - var generatedPipeType = cachedPipes.GetOrAdd(lookupKey, key => GroupTemplate.Generate(comparer, KeySelector, true)); + var comparer = (this.Properties.KeyEqualityComparer as CompoundGroupKeyEqualityComparer).innerComparer.GetGetHashCodeExpr(); + var generatedPipeType = cachedPipes.GetOrAdd(lookupKey, key => GroupTemplate.Generate(comparer, this.KeySelector, true)); Func planNode = ((PlanNode p, IQueryObject o) => new GroupPlanNode( p, o, typeof(TOuterKey), typeof(CompoundGroupKey), typeof(TSource), - KeySelector, + this.KeySelector, int.MinValue, 1, false, true, generatedPipeType.Item2)); - var instance = Activator.CreateInstance(generatedPipeType.Item1, this, observer, comparer, KeySelector, planNode); + var instance = Activator.CreateInstance(generatedPipeType.Item1, this, observer, comparer, this.KeySelector, planNode); var returnValue = (IStreamObserver)instance; return returnValue; } @@ -97,7 +97,7 @@ private IStreamObserver GetPipe(IStreamObserver : Streamable { private static readonly SafeConcurrentDictionary> cachedPipes - = new SafeConcurrentDictionary>(); + = new(); [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes", Justification="Used to avoid creating redundant readonly property.")] public readonly Expression> KeySelector; @@ -108,25 +108,25 @@ public GroupStreamable( IStreamable source, Expression> keySelector) : base(source.Properties.Group(keySelector)) { - Contract.Requires(source != null); - Contract.Requires(keySelector != null); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(keySelector); - Source = source; - KeySelector = keySelector; + this.Source = source; + this.KeySelector = keySelector; - if (Source.Properties.IsColumnar && !CanGenerateColumnar()) + if (this.Source.Properties.IsColumnar && !this.CanGenerateColumnar()) { - properties = properties.ToRowBased(); - Source = Source.ColumnToRow(); + this.properties = this.properties.ToRowBased(); + this.Source = this.Source.ColumnToRow(); } } public override IDisposable Subscribe(IStreamObserver observer) { - var pipe = Properties.IsColumnar - ? GetPipe(observer) - : CreatePipe(observer); - return Source.Subscribe(pipe); + var pipe = this.Properties.IsColumnar + ? this.GetPipe(observer) + : this.CreatePipe(observer); + return this.Source.Subscribe(pipe); } private IStreamObserver CreatePipe(IStreamObserver observer) @@ -147,35 +147,35 @@ private bool CanGenerateColumnar() // For now, restrict the inner key to be anything other than an anonymous type since those can't be ungrouped without using reflection. if (typeOfTInnerKey.IsAnonymousType()) return false; - var lookupKey = CacheKey.Create(KeySelector.ToString()); + var lookupKey = CacheKey.Create(this.KeySelector.ToString()); - var comparer = Properties.KeyEqualityComparer.GetGetHashCodeExpr(); - var generatedPipeType = cachedPipes.GetOrAdd(lookupKey, key => GroupTemplate.Generate(comparer, KeySelector, false)); + var comparer = this.Properties.KeyEqualityComparer.GetGetHashCodeExpr(); + var generatedPipeType = cachedPipes.GetOrAdd(lookupKey, key => GroupTemplate.Generate(comparer, this.KeySelector, false)); - errorMessages = generatedPipeType.Item2; + this.errorMessages = generatedPipeType.Item2; return generatedPipeType.Item1 != null; } private IStreamObserver GetPipe(IStreamObserver observer) { - var lookupKey = CacheKey.Create(KeySelector.ToString()); + var lookupKey = CacheKey.Create(this.KeySelector.ToString()); - var comparer = Properties.KeyEqualityComparer.GetGetHashCodeExpr(); - var generatedPipeType = cachedPipes.GetOrAdd(lookupKey, key => GroupTemplate.Generate(comparer, KeySelector, false)); + var comparer = this.Properties.KeyEqualityComparer.GetGetHashCodeExpr(); + var generatedPipeType = cachedPipes.GetOrAdd(lookupKey, key => GroupTemplate.Generate(comparer, this.KeySelector, false)); Func planNode = ((PlanNode p, IQueryObject o) => new GroupPlanNode( p, o, typeof(TOuterKey), typeof(TInnerKey), typeof(TSource), - KeySelector, + this.KeySelector, int.MinValue, 1, false, true, generatedPipeType.Item2)); - var instance = Activator.CreateInstance(generatedPipeType.Item1, this, observer, comparer, KeySelector, planNode); + var instance = Activator.CreateInstance(generatedPipeType.Item1, this, observer, comparer, this.KeySelector, planNode); var returnValue = (IStreamObserver)instance; return returnValue; } diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/Group/GroupStreamable.tt b/Sources/Core/Microsoft.StreamProcessing/Operators/Group/GroupStreamable.tt index f46447bd1..f840fc21f 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/Group/GroupStreamable.tt +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/Group/GroupStreamable.tt @@ -39,8 +39,8 @@ else { #> : base(source.Properties.Group(keySelector)) <# } #> { - Contract.Requires(source != null); - Contract.Requires(keySelector != null); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(keySelector); Source = source; KeySelector = keySelector; diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/Group/GroupTransformer.cs b/Sources/Core/Microsoft.StreamProcessing/Operators/Group/GroupTransformer.cs index 6f62f8ad3..e2ef93ce5 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/Group/GroupTransformer.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/Group/GroupTransformer.cs @@ -35,10 +35,10 @@ private GroupTemplate( string inlinedHashCodeComputation, bool nested) : base(className) { - Contract.Requires(className != null); - Contract.Requires(outerKeyType != null); - Contract.Requires(sourceType != null); - Contract.Requires(innerKeyType != null); + ArgumentNullException.ThrowIfNull(className); + ArgumentNullException.ThrowIfNull(outerKeyType); + ArgumentNullException.ThrowIfNull(sourceType); + ArgumentNullException.ThrowIfNull(innerKeyType); this.outerKeyType = outerKeyType; this.sourceType = sourceType; @@ -137,7 +137,7 @@ public static Tuple Generate( expandedCode = template.TransformText(); assemblyReferences = Transformer.AssemblyReferencesNeededFor(typeOfTOuterKey, typeOfTSource, typeOfTInnerKey); - assemblyReferences.Add(typeof(IStreamable<,>).GetTypeInfo().Assembly); + assemblyReferences.Add(typeof(IStreamable<,>).Assembly); assemblyReferences.Add(Transformer.GeneratedStreamMessageAssembly()); if (nested) { @@ -152,15 +152,13 @@ public static Tuple Generate( } assemblyReferences.AddRange(Transformer.AssemblyReferencesNeededFor(keySelector)); - var a = Transformer.CompileSourceCode(expandedCode, assemblyReferences, out errorMessages); + generatedClassName = generatedClassName.AddNumberOfNecessaryGenericArguments(typeOfTOuterKey, typeOfTSource, typeOfTInnerKey); + var t = Transformer.CompileSourceCode(expandedCode, assemblyReferences, a => a.GetType(generatedClassName), out errorMessages); if (typeOfTInnerKey.IsAnonymousTypeName()) { - if (errorMessages == null) errorMessages = string.Empty; + errorMessages ??= string.Empty; errorMessages += "\nCodegen Warning: The inner key type for Group is anonymous, causing the use of Activator.CreateInstance in an inner loop. This will lead to poor performance.\n"; } - - generatedClassName = generatedClassName.AddNumberOfNecessaryGenericArguments(typeOfTOuterKey, typeOfTSource, typeOfTInnerKey); - var t = a.GetType(generatedClassName); t = t.InstantiateAsNecessary(typeOfTOuterKey, typeOfTSource, typeOfTInnerKey); return Tuple.Create(t, errorMessages); diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/GroupedWindow/GroupedWindowPipe.cs b/Sources/Core/Microsoft.StreamProcessing/Operators/GroupedWindow/GroupedWindowPipe.cs index 736e69757..f49435ce6 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/GroupedWindow/GroupedWindowPipe.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/GroupedWindow/GroupedWindowPipe.cs @@ -121,7 +121,7 @@ public override unsafe void OnNext(StreamMessage batch) if (col_vother[i] == long.MinValue) { // We have found a row that corresponds to punctuation - OnPunctuation(col_vsync[i]); + this.OnPunctuation(col_vsync[i]); int c = this.batch.Count; this.batch.vsync.col[c] = col_vsync[i]; @@ -130,7 +130,7 @@ public override unsafe void OnNext(StreamMessage batch) this.batch.hash.col[c] = 0; this.batch.bitvector.col[c >> 6] |= 1L << (c & 0x3f); this.batch.Count++; - if (this.batch.Count == Config.DataBatchSize) FlushContents(); + if (this.batch.Count == Config.DataBatchSize) this.FlushContents(); } continue; } @@ -159,7 +159,7 @@ public override unsafe void OnNext(StreamMessage batch) this.batch.payload.col[c] = this.finalResultSelector(this.currentKey, this.computeResult(this.currentState.state)); this.batch.hash.col[c] = 0; this.batch.Count++; - if (this.batch.Count == Config.DataBatchSize) FlushContents(); + if (this.batch.Count == Config.DataBatchSize) this.FlushContents(); } else { @@ -181,7 +181,7 @@ public override unsafe void OnNext(StreamMessage batch) this.batch.payload.col[c] = this.finalResultSelector(iter1entry.key, this.computeResult(iter1entry.value.state)); this.batch.hash.col[c] = 0; this.batch.Count++; - if (this.batch.Count == Config.DataBatchSize) FlushContents(); + if (this.batch.Count == Config.DataBatchSize) this.FlushContents(); } else { @@ -237,7 +237,7 @@ public override unsafe void OnNext(StreamMessage batch) this.batch.payload.col[c] = this.finalResultSelector(this.currentKey, this.computeResult(this.currentState.state)); this.batch.hash.col[c] = 0; this.batch.Count++; - if (this.batch.Count == Config.DataBatchSize) FlushContents(); + if (this.batch.Count == Config.DataBatchSize) this.FlushContents(); } this.currentState.timestamp = syncTime; @@ -265,7 +265,7 @@ public override unsafe void OnNext(StreamMessage batch) this.batch.payload.col[c] = this.finalResultSelector(this.currentKey, this.computeResult(this.currentState.state)); this.batch.hash.col[c] = 0; this.batch.Count++; - if (this.batch.Count == Config.DataBatchSize) FlushContents(); + if (this.batch.Count == Config.DataBatchSize) this.FlushContents(); } this.currentState.timestamp = syncTime; @@ -307,7 +307,7 @@ public void OnPunctuation(long syncTime) this.batch.payload.col[c] = this.finalResultSelector(this.currentKey, this.computeResult(this.currentState.state)); this.batch.hash.col[c] = 0; this.batch.Count++; - if (this.batch.Count == Config.DataBatchSize) FlushContents(); + if (this.batch.Count == Config.DataBatchSize) this.FlushContents(); } else { @@ -330,7 +330,7 @@ public void OnPunctuation(long syncTime) this.batch.payload.col[c] = this.finalResultSelector(iter1entry.key, this.computeResult(iter1entry.value.state)); this.batch.hash.col[c] = 0; this.batch.Count++; - if (this.batch.Count == Config.DataBatchSize) FlushContents(); + if (this.batch.Count == Config.DataBatchSize) this.FlushContents(); } else { @@ -379,6 +379,10 @@ protected override void UpdatePointers() } } - protected override void DisposeState() => this.batch.Free(); + protected override void DisposeState() + { + this.heldAggregates.Dispose(); + this.batch.Free(); + } } } diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/GroupedWindow/GroupedWindowStreamable.cs b/Sources/Core/Microsoft.StreamProcessing/Operators/GroupedWindow/GroupedWindowStreamable.cs index 1cab6c5e2..53fb6e3e8 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/GroupedWindow/GroupedWindowStreamable.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/GroupedWindow/GroupedWindowStreamable.cs @@ -14,7 +14,7 @@ internal sealed class GroupedWindowStreamable { private static readonly SafeConcurrentDictionary> cachedPipes - = new SafeConcurrentDictionary>(); + = new(); private readonly StreamProperties sourceProps; internal Expression> KeySelector; @@ -25,7 +25,7 @@ private static readonly SafeConcurrentDictionary> cachedPipe public GroupedWindowStreamable(IStreamable source, IAggregate aggregate, Expression> keySelector, Expression> resultSelector) : base(source, source.Properties.Group(keySelector).Snapshot(aggregate).Ungroup(resultSelector)) { - Contract.Requires(source != null); + ArgumentNullException.ThrowIfNull(source); this.Aggregate = aggregate; this.sourceProps = source.Properties; @@ -33,11 +33,11 @@ public GroupedWindowStreamable(IStreamable source, IAggregate CreatePipe(IStreamObserver observer) - => this.Properties.IsColumnar ? GetPipe(observer) : new GroupedWindowPipe(this, observer); + => this.Properties.IsColumnar ? this.GetPipe(observer) : new GroupedWindowPipe(this, observer); protected override bool CanGenerateColumnar() { diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/GroupedWindow/GroupedWindowTransformer.cs b/Sources/Core/Microsoft.StreamProcessing/Operators/GroupedWindow/GroupedWindowTransformer.cs index 2c3bd2dde..8a987925c 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/GroupedWindow/GroupedWindowTransformer.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/GroupedWindow/GroupedWindowTransformer.cs @@ -62,8 +62,8 @@ private GroupedWindowTemplate(string className) : base(className) { } internal static Tuple Generate( GroupedWindowStreamable stream) { - Contract.Requires(stream != null); - Contract.Ensures(Contract.Result>() == null || typeof(IStreamObserver).GetTypeInfo().IsAssignableFrom(Contract.Result>().Item1)); + ArgumentNullException.ThrowIfNull(stream); + Contract.Ensures(Contract.Result>() == null || typeof(IStreamObserver).IsAssignableFrom(Contract.Result>().Item1)); string errorMessages = null; try @@ -282,20 +282,19 @@ internal static Tuple Generate).GetTypeInfo().Assembly); + assemblyReferences.Add(typeof(IStreamable<,>).Assembly); assemblyReferences.Add(Transformer.GeneratedStreamMessageAssembly()); assemblyReferences.Add(Transformer.GeneratedStreamMessageAssembly()); assemblyReferences.Add(Transformer.GeneratedMemoryPoolAssembly()); - var assembly = Transformer.CompileSourceCode(expandedCode, assemblyReferences, out errorMessages); - var t = assembly.GetType(template.className); - if (t.GetTypeInfo().IsGenericType) + var t = Transformer.CompileSourceCode(expandedCode, assemblyReferences, a => a.GetType(template.className), out errorMessages); + if (t.IsGenericType) { var list = typeof(TKey).GetAnonymousTypes(); list.AddRange(typeof(TInput).GetAnonymousTypes()); list.AddRange(typeof(TState).GetAnonymousTypes()); list.AddRange(typeof(TOutput).GetAnonymousTypes()); - return Tuple.Create(t.MakeGenericType(list.ToArray()), errorMessages); + return Tuple.Create(t.MakeGenericType([.. list]), errorMessages); } else { diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/LeftAntiSemiJoin/LeftAntiSemiJoinPipe.cs b/Sources/Core/Microsoft.StreamProcessing/Operators/LeftAntiSemiJoin/LeftAntiSemiJoinPipe.cs index c45477543..a83576972 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/LeftAntiSemiJoin/LeftAntiSemiJoinPipe.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/LeftAntiSemiJoin/LeftAntiSemiJoinPipe.cs @@ -35,7 +35,7 @@ internal sealed class LeftAntiSemiJoinPipe : BinaryPipe [DataMember] - private FastMap leftIntervalMap = new FastMap(); + private FastMap leftIntervalMap = new(); /// /// Stores left start edges at @@ -43,7 +43,7 @@ internal sealed class LeftAntiSemiJoinPipe : BinaryPipe [DataMember] - private FastMap leftEdgeMap = new FastMap(); + private FastMap leftEdgeMap = new(); /// /// Stores left end edges at some point in the future, i.e. after . @@ -56,13 +56,13 @@ internal sealed class LeftAntiSemiJoinPipe : BinaryPipe /// [DataMember] - private FastMap rightMap = new FastMap(); + private FastMap rightMap = new(); /// /// Stores right end edges for , excluding interval endpoints /// [DataMember] - private FastStack rightEndEdges = new FastStack(); + private FastStack rightEndEdges = new(); /// /// Stores right endpoints at some point in the future, i.e. after , originating @@ -152,9 +152,9 @@ protected override void ProcessBothBatches(StreamMessage leftBatch, { if (this.nextLeftTime <= this.nextRightTime) { - UpdateTime(this.nextLeftTime); + this.UpdateTime(this.nextLeftTime); - ProcessLeftEvent( + this.ProcessLeftEvent( this.nextLeftTime, leftBatch.vother.col[leftBatch.iter], ref leftBatch.key.col[leftBatch.iter], @@ -174,9 +174,9 @@ protected override void ProcessBothBatches(StreamMessage leftBatch, } else { - UpdateTime(this.nextRightTime); + this.UpdateTime(this.nextRightTime); - ProcessRightEvent( + this.ProcessRightEvent( this.nextRightTime, rightBatch.vother.col[rightBatch.iter], ref rightBatch.key.col[rightBatch.iter], @@ -216,9 +216,9 @@ protected override void ProcessLeftBatch(StreamMessage batch, out b return; } - UpdateTime(this.nextLeftTime); + this.UpdateTime(this.nextLeftTime); - ProcessLeftEvent( + this.ProcessLeftEvent( this.nextLeftTime, batch.vother.col[batch.iter], ref batch.key.col[batch.iter], @@ -249,9 +249,9 @@ protected override void ProcessRightBatch(StreamMessage batch, out return; } - UpdateTime(this.nextRightTime); + this.UpdateTime(this.nextRightTime); - ProcessRightEvent( + this.ProcessRightEvent( this.nextRightTime, batch.vother.col[batch.iter], ref batch.key.col[batch.iter], @@ -277,9 +277,9 @@ private void UpdateTime(long time) { if (time != this.currTime) { - LeaveTime(); + this.LeaveTime(); this.currTime = time; - ReachTime(); + this.ReachTime(); } } @@ -294,7 +294,7 @@ private void ProcessLeftEvent(long start, long end, ref TKey key, TLeft payload, var map = isInterval ? this.leftIntervalMap : this.leftEdgeMap; if (isProcessable) { - if (FindOnRight(ref key, hash, out _)) + if (this.FindOnRight(ref key, hash, out _)) { // Row joins with something on right, so not currently visible. int index = map.Insert(hash); @@ -312,7 +312,7 @@ private void ProcessLeftEvent(long start, long end, ref TKey key, TLeft payload, if (isFullyOutputtable) { // Will never join because right has advanced beyond endtime, so output interval. - AddToBatch(start, end, ref key, ref payload, hash); + this.AddToBatch(start, end, ref key, ref payload, hash); } else { @@ -320,7 +320,7 @@ private void ProcessLeftEvent(long start, long end, ref TKey key, TLeft payload, int index = map.Insert(hash); map.Values[index].Populate(start, start, end, ref key, ref payload); - AddToBatch(start, StreamEvent.InfinitySyncTime, ref key, ref payload, hash); + this.AddToBatch(start, StreamEvent.InfinitySyncTime, ref key, ref payload, hash); if (isInterval) { this.leftEndPointHeap.Insert(end, index); @@ -337,7 +337,7 @@ private void ProcessLeftEvent(long start, long end, ref TKey key, TLeft payload, } else if (end == StreamEvent.PunctuationOtherTime) { - AddPunctuationToBatch(start); + this.AddPunctuationToBatch(start); } else { @@ -347,13 +347,13 @@ private void ProcessLeftEvent(long start, long end, ref TKey key, TLeft payload, while (leftEvents.Next(out int index)) { var temp = this.leftEdgeMap.Values[index]; - if (AreSame(end, StreamEvent.InfinitySyncTime, ref key, ref payload, ref temp)) + if (this.AreSame(end, StreamEvent.InfinitySyncTime, ref key, ref payload, ref temp)) { long currentStart = this.leftEdgeMap.Values[index].CurrentStart; if (currentStart != NotActive) { // Matching left start edge is currently visible, so output end edge. - AddToBatch(start, currentStart, ref key, ref payload, hash); + this.AddToBatch(start, currentStart, ref key, ref payload, hash); } leftEvents.Remove(); @@ -369,7 +369,7 @@ private void ProcessRightEvent(long start, long end, ref TKey key, int hash) if (start < end) { // Row is a start edge or interval. - if (FindOnRight(ref key, hash, out int index)) + if (this.FindOnRight(ref key, hash, out int index)) { // Corresponding key already exists in map, so any joining on left and already not active. this.rightMap.Values[index].Count++; @@ -379,7 +379,7 @@ private void ProcessRightEvent(long start, long end, ref TKey key, int hash) // First instance of this key, so insert and make any joining left entries not active. index = this.rightMap.Insert(hash); this.rightMap.Values[index].Initialize(ref key); - MakeMatchingLeftInvisible(start, ref key, hash); + this.MakeMatchingLeftInvisible(start, ref key, hash); } if (end != StreamEvent.InfinitySyncTime) @@ -390,7 +390,7 @@ private void ProcessRightEvent(long start, long end, ref TKey key, int hash) } else if (end == StreamEvent.PunctuationOtherTime) { - AddPunctuationToBatch(start); + this.AddPunctuationToBatch(start); } else { @@ -412,7 +412,7 @@ private void LeaveTime() hash = this.rightEndEdges.Values[i].Hash; var keyTemp = this.rightEndEdges.Values[i].Key; - if (FindOnRight(ref keyTemp, hash, out int index)) + if (this.FindOnRight(ref keyTemp, hash, out int index)) { int count = this.rightMap.Values[index].Count - 1; if (count > 0) @@ -420,7 +420,7 @@ private void LeaveTime() else { var key = this.rightMap.Values[index]; - MakeMatchingLeftVisible(this.currTime, ref key.Key, hash); + this.MakeMatchingLeftVisible(this.currTime, ref key.Key, hash); this.rightMap.Remove(index); } } @@ -434,7 +434,7 @@ private void LeaveTime() { var leftIntervalItem = this.leftIntervalMap.Values[index]; long end = leftIntervalItem.End; - if (FindOnRight(ref this.leftIntervalMap.Values[index].Key, hash, out _)) + if (this.FindOnRight(ref this.leftIntervalMap.Values[index].Key, hash, out _)) { leftEvents.MakeVisible(); this.leftEndPointHeap.Insert(end, index); @@ -445,7 +445,7 @@ private void LeaveTime() bool isFullyOutputtable = this.nextRightTime >= end; if (isFullyOutputtable) { - AddToBatch( + this.AddToBatch( this.currTime, end, ref leftIntervalItem.Key, @@ -458,7 +458,7 @@ private void LeaveTime() { leftEvents.MakeVisible(); this.leftIntervalMap.Values[index].CurrentStart = this.currTime; - AddToBatch( + this.AddToBatch( this.currTime, StreamEvent.InfinitySyncTime, ref leftIntervalItem.Key, @@ -474,12 +474,12 @@ private void LeaveTime() leftEvents = this.leftEdgeMap.TraverseInvisible(); while (leftEvents.Next(out int index, out hash)) { - if (!FindOnRight(ref this.leftEdgeMap.Values[index].Key, hash, out _)) + if (!this.FindOnRight(ref this.leftEdgeMap.Values[index].Key, hash, out _)) { // Row does not join, so output start edge. var leftEdgeItem = this.leftEdgeMap.Values[index]; this.leftEdgeMap.Values[index].CurrentStart = this.currTime; - AddToBatch( + this.AddToBatch( this.currTime, StreamEvent.InfinitySyncTime, ref leftEdgeItem.Key, @@ -516,7 +516,7 @@ private void ReachTime() if (currentStart != NotActive) { // Matching left start edge is currently visible, so output end edge. - AddToBatch( + this.AddToBatch( leftTime, currentStart, ref leftIntervalItem.Key, @@ -540,7 +540,7 @@ private void ReachTime() else { var key = this.rightMap.Values[rightIndex].Key; - MakeMatchingLeftVisible(rightTime, ref key, this.rightMap.GetHash(rightIndex)); + this.MakeMatchingLeftVisible(rightTime, ref key, this.rightMap.GetHash(rightIndex)); this.rightMap.Remove(rightIndex); } @@ -582,7 +582,7 @@ private void MakeMatchingLeftInvisible(long time, ref TKey key, int hash) { // Output end edge. var leftIntervalItem = this.leftIntervalMap.Values[index]; - AddToBatch( + this.AddToBatch( time, leftIntervalItem.CurrentStart, ref leftIntervalItem.Key, @@ -602,7 +602,7 @@ private void MakeMatchingLeftInvisible(long time, ref TKey key, int hash) { // Output end edge. var leftEdgeItem = this.leftEdgeMap.Values[index]; - AddToBatch( + this.AddToBatch( time, leftEdgeItem.CurrentStart, ref leftEdgeItem.Key, @@ -631,7 +631,7 @@ private void MakeMatchingLeftVisible(long time, ref TKey key, int hash) if (isFullyOutputtable) { // Output interval. - AddToBatch( + this.AddToBatch( time, end, ref leftIntervalItem.Key, @@ -644,7 +644,7 @@ private void MakeMatchingLeftVisible(long time, ref TKey key, int hash) else { // Output start edge. - AddToBatch( + this.AddToBatch( time, StreamEvent.InfinitySyncTime, ref leftIntervalItem.Key, @@ -665,7 +665,7 @@ private void MakeMatchingLeftVisible(long time, ref TKey key, int hash) if (this.keyComparerEquals(key, leftEdgeItem.Key)) { // Output start edge. - AddToBatch( + this.AddToBatch( time, StreamEvent.InfinitySyncTime, ref leftEdgeItem.Key, @@ -693,7 +693,7 @@ private void AddPunctuationToBatch(long start) this.output.hash.col[index] = 0; this.output.bitvector.col[index >> 6] |= 1L << (index & 0x3f); - if (this.output.Count == Config.DataBatchSize) FlushContents(); + if (this.output.Count == Config.DataBatchSize) this.FlushContents(); } } @@ -712,7 +712,7 @@ private void AddToBatch(long start, long end, ref TKey key, ref TLeft payload, i this.output[index] = payload; this.output.hash.col[index] = hash; - if (this.output.Count == Config.DataBatchSize) FlushContents(); + if (this.output.Count == Config.DataBatchSize) this.FlushContents(); } [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -756,7 +756,7 @@ public void Populate(long start, long currentStart, long end, ref TKey key, ref this.Payload = payload; } - public override string ToString() + public override readonly string ToString() => "[Start=" + this.Start + ", CurrentStart=" + this.CurrentStart + ", End=" + this.End + ", Key='" + this.Key + "', Payload='" + this.Payload + "']"; } @@ -775,7 +775,7 @@ public void Initialize(ref TKey key) this.Count = 1; } - public override string ToString() => "[Key='" + this.Key + "', Count=" + this.Count + "]"; + public override readonly string ToString() => "[Key='" + this.Key + "', Count=" + this.Count + "]"; } [DataContract] @@ -793,7 +793,7 @@ public void Populate(ref TKey key, int hash) this.Hash = hash; } - public override string ToString() => "[Key='" + this.Key + "', Hash=" + this.Hash + "]"; + public override readonly string ToString() => "[Key='" + this.Key + "', Hash=" + this.Hash + "]"; } } } diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/LeftAntiSemiJoin/LeftAntiSemiJoinStreamable.cs b/Sources/Core/Microsoft.StreamProcessing/Operators/LeftAntiSemiJoin/LeftAntiSemiJoinStreamable.cs index b1bfa99d1..f78fd1e3d 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/LeftAntiSemiJoin/LeftAntiSemiJoinStreamable.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/LeftAntiSemiJoin/LeftAntiSemiJoinStreamable.cs @@ -11,7 +11,7 @@ namespace Microsoft.StreamProcessing internal sealed class LeftAntiSemiJoinStreamable : BinaryStreamable { private static readonly SafeConcurrentDictionary> cachedPipes - = new SafeConcurrentDictionary>(); + = new(); [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes", Justification = "Expressions are immutable")] public readonly IEqualityComparerExpression LeftComparer; @@ -19,12 +19,12 @@ private static readonly SafeConcurrentDictionary> cachedPipe public LeftAntiSemiJoinStreamable(IStreamable left, IStreamable right) : base(left.Properties.LASJ(right.Properties), left, right) { - Contract.Requires(left != null); - Contract.Requires(right != null); + ArgumentNullException.ThrowIfNull(left); + ArgumentNullException.ThrowIfNull(right); this.LeftComparer = left.Properties.PayloadEqualityComparer; - Initialize(); + this.Initialize(); } protected override IBinaryObserver CreatePipe(IStreamObserver observer) @@ -33,7 +33,7 @@ protected override IBinaryObserver CreatePipe(IStrea if (part == null) { return this.properties.IsColumnar - ? GetPipe(observer, this.Left.Properties.IsConstantDuration, this.Right.Properties.IsConstantDuration) + ? this.GetPipe(observer, this.Left.Properties.IsConstantDuration, this.Right.Properties.IsConstantDuration) : new LeftAntiSemiJoinPipe(this, observer); } diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/LeftAntiSemiJoin/LeftAntiSemiJoinTemplate.cs b/Sources/Core/Microsoft.StreamProcessing/Operators/LeftAntiSemiJoin/LeftAntiSemiJoinTemplate.cs index 158c4ba9d..35d19df31 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/LeftAntiSemiJoin/LeftAntiSemiJoinTemplate.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/LeftAntiSemiJoin/LeftAntiSemiJoinTemplate.cs @@ -706,7 +706,7 @@ private void GetOutputBatch() this.Write(".Initialize();\r\n"); } this.Write(" }\r\n\r\n"); - if (!noLeftFields && !this.leftType.GetTypeInfo().IsValueType) { + if (!noLeftFields && !this.leftType.IsValueType) { this.Write(" [DataContract]\r\n private struct "); this.Write(this.ToStringHelper.ToStringWithCulture(ActiveEventType)); this.Write("\r\n {\r\n "); diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/LeftAntiSemiJoin/LeftAntiSemiJoinTemplate.tt b/Sources/Core/Microsoft.StreamProcessing/Operators/LeftAntiSemiJoin/LeftAntiSemiJoinTemplate.tt index 0188ca4a6..ad68dbe09 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/LeftAntiSemiJoin/LeftAntiSemiJoinTemplate.tt +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/LeftAntiSemiJoin/LeftAntiSemiJoinTemplate.tt @@ -807,7 +807,7 @@ internal sealed class <#= className #><#= genericParameters #> : BinaryPipe<<#= <# } #> } -<# if (!noLeftFields && !this.leftType.GetTypeInfo().IsValueType) { #> +<# if (!noLeftFields && !this.leftType.IsValueType) { #> [DataContract] private struct <#= ActiveEventType #> { diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/LeftAntiSemiJoin/LeftAntiSemiJoinTransformer.cs b/Sources/Core/Microsoft.StreamProcessing/Operators/LeftAntiSemiJoin/LeftAntiSemiJoinTransformer.cs index 655d581fb..d8f0a8dd0 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/LeftAntiSemiJoin/LeftAntiSemiJoinTransformer.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/LeftAntiSemiJoin/LeftAntiSemiJoinTransformer.cs @@ -38,8 +38,8 @@ private LeftAntiSemiJoinTemplate(string className, Type keyType, Type leftType, /// internal static Tuple Generate(LeftAntiSemiJoinStreamable stream) { - Contract.Requires(stream != null); - Contract.Ensures(Contract.Result>() == null || typeof(BinaryPipe).GetTypeInfo().IsAssignableFrom(Contract.Result>().Item1)); + ArgumentNullException.ThrowIfNull(stream); + Contract.Ensures(Contract.Result>() == null || typeof(BinaryPipe).IsAssignableFrom(Contract.Result>().Item1)); var template = new LeftAntiSemiJoinTemplate($"GeneratedLeftAntiSemiJoin_{LASJSequenceNumber++}", typeof(TKey), typeof(TLeft), typeof(TRight)); @@ -57,7 +57,7 @@ internal static Tuple Generate(LeftAntiSemiJo #endregion #region Left Comparer - template.ActiveEventType = template.leftType.GetTypeInfo().IsValueType ? template.TLeft : "Active_Event"; + template.ActiveEventType = template.leftType.IsValueType ? template.TLeft : "Active_Event"; template.noLeftFields = leftMessageRepresentation.noFields; var leftComparer = stream.LeftComparer.GetEqualsExpr(); diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/LeftAntiSemiJoin/PartitionedLeftAntiSemiJoinPipe.cs b/Sources/Core/Microsoft.StreamProcessing/Operators/LeftAntiSemiJoin/PartitionedLeftAntiSemiJoinPipe.cs index ee6025c5d..44955fdae 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/LeftAntiSemiJoin/PartitionedLeftAntiSemiJoinPipe.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/LeftAntiSemiJoin/PartitionedLeftAntiSemiJoinPipe.cs @@ -31,20 +31,20 @@ internal sealed class PartitionedLeftAntiSemiJoinPipe leftComparerEquals; [DataMember] - private FastDictionary2> leftQueue = new FastDictionary2>(); + private FastDictionary2> leftQueue = new(); [DataMember] - private FastDictionary2> rightQueue = new FastDictionary2>(); + private FastDictionary2> rightQueue = new(); [DataMember] - private HashSet processQueue = new HashSet(); + private HashSet processQueue = []; [DataMember] - private HashSet seenKeys = new HashSet(); + private HashSet seenKeys = []; [DataMember] - private HashSet cleanKeys = new HashSet(); + private HashSet cleanKeys = []; [DataMember] private StreamMessage output; [DataMember] - private FastDictionary partitionData = new FastDictionary(); + private FastDictionary partitionData = new(); [DataMember] private long lastLeftCTI = long.MinValue; [DataMember] @@ -92,8 +92,8 @@ protected override void ProduceBinaryQueryPlan(PlanNode left, PlanNode right) private void NewPartition(TPartitionKey pKey) { - this.leftQueue.Insert(pKey, new PooledElasticCircularBuffer()); - this.rightQueue.Insert(pKey, new PooledElasticCircularBuffer()); + this.leftQueue.Insert(pKey, []); + this.rightQueue.Insert(pKey, []); if (!this.partitionData.Lookup(pKey, out int index)) this.partitionData.Insert(ref index, pKey, new PartitionEntry(this)); } @@ -104,14 +104,15 @@ protected override void DisposeState() iter = FastDictionary.IteratorStart; while (this.leftQueue.Iterate(ref iter)) this.leftQueue.entries[iter].value.Dispose(); iter = FastDictionary.IteratorStart; - while (this.leftQueue.Iterate(ref iter)) this.rightQueue.entries[iter].value.Dispose(); + while (this.rightQueue.Iterate(ref iter)) this.rightQueue.entries[iter].value.Dispose(); + this.partitionData.Dispose(); this.output.Free(); } protected override void ProcessBothBatches(StreamMessage leftBatch, StreamMessage rightBatch, out bool leftBatchDone, out bool rightBatchDone, out bool leftBatchFree, out bool rightBatchFree) { - ProcessLeftBatch(leftBatch, out leftBatchDone, out leftBatchFree); - ProcessRightBatch(rightBatch, out rightBatchDone, out rightBatchFree); + this.ProcessLeftBatch(leftBatch, out leftBatchDone, out leftBatchFree); + this.ProcessRightBatch(rightBatch, out rightBatchDone, out rightBatchFree); } protected override void ProcessLeftBatch(StreamMessage batch, out bool leftBatchDone, out bool leftBatchFree) @@ -140,7 +141,7 @@ protected override void ProcessLeftBatch(StreamMessage batch, out b var partitionKey = this.getPartitionKey(batch.key.col[i]); if (first || !partitionKey.Equals(previous)) { - if (this.seenKeys.Add(partitionKey)) NewPartition(partitionKey); + if (this.seenKeys.Add(partitionKey)) this.NewPartition(partitionKey); this.leftQueue.Lookup(partitionKey, out int index); queue = this.leftQueue.entries[index].value; this.processQueue.Add(partitionKey); @@ -158,7 +159,7 @@ protected override void ProcessLeftBatch(StreamMessage batch, out b previous = partitionKey; } - ProcessPendingEntries(); + this.ProcessPendingEntries(); } protected override void ProcessRightBatch(StreamMessage batch, out bool rightBatchDone, out bool rightBatchFree) @@ -187,7 +188,7 @@ protected override void ProcessRightBatch(StreamMessage batch, out var partitionKey = this.getPartitionKey(batch.key.col[i]); if (first || !partitionKey.Equals(previous)) { - if (this.seenKeys.Add(partitionKey)) NewPartition(partitionKey); + if (this.seenKeys.Add(partitionKey)) this.NewPartition(partitionKey); this.rightQueue.Lookup(partitionKey, out int index); queue = this.rightQueue.entries[index].value; this.processQueue.Add(partitionKey); @@ -204,7 +205,7 @@ protected override void ProcessRightBatch(StreamMessage batch, out previous = partitionKey; } - ProcessPendingEntries(); + this.ProcessPendingEntries(); } [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -233,11 +234,11 @@ private void ProcessPendingEntries() if (leftEntry.Sync <= rightEntry.Sync) { - UpdateTime(partition, partition.nextLeftTime); + this.UpdateTime(partition, partition.nextLeftTime); if (leftEntry.Other != long.MinValue) { - ProcessLeftEvent( + this.ProcessLeftEvent( partition, leftEntry.Sync, leftEntry.Other, @@ -247,7 +248,7 @@ private void ProcessPendingEntries() } else if (partition.currTime > old) { - AddToBatch( + this.AddToBatch( partition.currTime, long.MinValue, ref leftEntry.Key, @@ -259,11 +260,11 @@ private void ProcessPendingEntries() } else { - UpdateTime(partition, partition.nextRightTime); + this.UpdateTime(partition, partition.nextRightTime); if (rightEntry.Other != long.MinValue) { - ProcessRightEvent( + this.ProcessRightEvent( partition, rightEntry.Sync, rightEntry.Other, @@ -273,7 +274,7 @@ private void ProcessPendingEntries() else if (partition.currTime > old) { var l = default(TLeft); - AddToBatch( + this.AddToBatch( partition.currTime, long.MinValue, ref rightEntry.Key, @@ -293,15 +294,15 @@ private void ProcessPendingEntries() // If we have not yet reached the lesser of the two sides (in this case, right), and we don't // have input from that side, reach that time now. This can happen with low watermarks. if (partition.currTime < partition.nextRightTime) - UpdateTime(partition, partition.nextRightTime); + this.UpdateTime(partition, partition.nextRightTime); break; } - UpdateTime(partition, leftEntry.Sync); + this.UpdateTime(partition, leftEntry.Sync); if (leftEntry.Other != long.MinValue) { - ProcessLeftEvent( + this.ProcessLeftEvent( partition, leftEntry.Sync, leftEntry.Other, @@ -311,7 +312,7 @@ private void ProcessPendingEntries() } else if (partition.currTime > old) { - AddToBatch( + this.AddToBatch( partition.currTime, long.MinValue, ref leftEntry.Key, @@ -330,15 +331,15 @@ private void ProcessPendingEntries() // If we have not yet reached the lesser of the two sides (in this case, left), and we don't // have input from that side, reach that time now. This can happen with low watermarks. if (partition.currTime < partition.nextLeftTime) - UpdateTime(partition, partition.nextLeftTime); + this.UpdateTime(partition, partition.nextLeftTime); break; } - UpdateTime(partition, rightEntry.Sync); + this.UpdateTime(partition, rightEntry.Sync); if (rightEntry.Other != long.MinValue) { - ProcessRightEvent( + this.ProcessRightEvent( partition, rightEntry.Sync, rightEntry.Other, @@ -348,7 +349,7 @@ private void ProcessPendingEntries() else if (partition.currTime > old) { var l = default(TLeft); - AddToBatch( + this.AddToBatch( partition.currTime, long.MinValue, ref rightEntry.Key, @@ -365,7 +366,7 @@ private void ProcessPendingEntries() if (partition.nextRightTime < this.lastRightCTI) partition.nextRightTime = this.lastRightCTI; - UpdateTime(partition, Math.Min(this.lastLeftCTI, this.lastRightCTI)); + this.UpdateTime(partition, Math.Min(this.lastLeftCTI, this.lastRightCTI)); if (partition.IsClean()) this.cleanKeys.Add(pKey); break; @@ -376,7 +377,7 @@ private void ProcessPendingEntries() if (this.emitCTI) { var earliest = Math.Min(this.lastLeftCTI, this.lastRightCTI); - AddLowWatermarkToBatch(earliest); + this.AddLowWatermarkToBatch(earliest); this.emitCTI = false; foreach (var p in this.cleanKeys) { @@ -399,9 +400,9 @@ private void UpdateTime(PartitionEntry partition, long time) { if (time > partition.currTime) { - LeaveTime(partition); + this.LeaveTime(partition); partition.currTime = time; - ReachTime(partition); + this.ReachTime(partition); } } @@ -417,7 +418,7 @@ private void ProcessLeftEvent(PartitionEntry partition, long start, long end, re var leph = partition.leftEndPointHeap; if (isProcessable) { - if (FindOnRight(partition, ref key, hash, out _)) + if (this.FindOnRight(partition, ref key, hash, out _)) { // Row joins with something on right, so not currently visible. int index = map.Insert(hash); @@ -431,14 +432,14 @@ private void ProcessLeftEvent(PartitionEntry partition, long start, long end, re if (isFullyOutputtable) { // Will never join because right has advanced beyond endtime, so output interval. - AddToBatch(start, end, ref key, ref payload, hash); + this.AddToBatch(start, end, ref key, ref payload, hash); } else { // Output start edge. int index = map.Insert(hash); map.Values[index].Populate(start, start, end, ref key, ref payload); - AddToBatch(start, StreamEvent.InfinitySyncTime, ref key, ref payload, hash); + this.AddToBatch(start, StreamEvent.InfinitySyncTime, ref key, ref payload, hash); if (isInterval) leph.Insert(end, index); } } @@ -459,13 +460,13 @@ private void ProcessLeftEvent(PartitionEntry partition, long start, long end, re var leftEvents = lem.Find(hash); while (leftEvents.Next(out int index)) { - if (AreSame(end, StreamEvent.InfinitySyncTime, ref key, ref payload, ref lem.Values[index])) + if (this.AreSame(end, StreamEvent.InfinitySyncTime, ref key, ref payload, ref lem.Values[index])) { long currentStart = lem.Values[index].CurrentStart; if (currentStart != NotActive) { // Matching left start edge is currently visible, so output end edge. - AddToBatch(start, currentStart, ref key, ref payload, hash); + this.AddToBatch(start, currentStart, ref key, ref payload, hash); } leftEvents.Remove(); @@ -482,7 +483,7 @@ private void ProcessRightEvent(PartitionEntry partition, long start, long end, r { // Row is a start edge or interval. var rm = partition.rightMap; - if (FindOnRight(partition, ref key, hash, out int index)) + if (this.FindOnRight(partition, ref key, hash, out int index)) { // Corresponding key already exists in map, so any joining on left and already not active. rm.Values[index].Count++; @@ -492,7 +493,7 @@ private void ProcessRightEvent(PartitionEntry partition, long start, long end, r // First instance of this key, so insert and make any joining left entries not active. index = rm.Insert(hash); rm.Values[index].Initialize(ref key); - MakeMatchingLeftInvisible(partition, start, ref key, hash); + this.MakeMatchingLeftInvisible(partition, start, ref key, hash); } if (end != StreamEvent.InfinitySyncTime) @@ -526,7 +527,7 @@ private void LeaveTime(PartitionEntry partition) for (int i = 0; i < ree.Count; i++) { hash = ree.Values[i].Hash; - if (FindOnRight(partition, ref ree.Values[i].Key, hash, out int index)) + if (this.FindOnRight(partition, ref ree.Values[i].Key, hash, out int index)) { int count = rm.Values[index].Count - 1; if (count > 0) @@ -535,7 +536,7 @@ private void LeaveTime(PartitionEntry partition) } else { - MakeMatchingLeftVisible(partition, partition.currTime, ref rm.Values[index].Key, hash); + this.MakeMatchingLeftVisible(partition, partition.currTime, ref rm.Values[index].Key, hash); rm.Remove(index); } } @@ -548,7 +549,7 @@ private void LeaveTime(PartitionEntry partition) while (leftEvents.Next(out int index, out hash)) { long end = lim.Values[index].End; - if (FindOnRight(partition, ref lim.Values[index].Key, hash, out _)) + if (this.FindOnRight(partition, ref lim.Values[index].Key, hash, out _)) { leftEvents.MakeVisible(); leph.Insert(end, index); @@ -559,7 +560,7 @@ private void LeaveTime(PartitionEntry partition) bool isFullyOutputtable = partition.nextRightTime >= end; if (isFullyOutputtable) { - AddToBatch( + this.AddToBatch( partition.currTime, end, ref lim.Values[index].Key, @@ -571,7 +572,7 @@ private void LeaveTime(PartitionEntry partition) { leftEvents.MakeVisible(); lim.Values[index].CurrentStart = partition.currTime; - AddToBatch( + this.AddToBatch( partition.currTime, StreamEvent.InfinitySyncTime, ref lim.Values[index].Key, @@ -587,11 +588,11 @@ private void LeaveTime(PartitionEntry partition) leftEvents = lem.TraverseInvisible(); while (leftEvents.Next(out int index, out hash)) { - if (!FindOnRight(partition, ref lem.Values[index].Key, hash, out _)) + if (!this.FindOnRight(partition, ref lem.Values[index].Key, hash, out _)) { // Row does not join, so output start edge. lem.Values[index].CurrentStart = partition.currTime; - AddToBatch( + this.AddToBatch( partition.currTime, StreamEvent.InfinitySyncTime, ref lem.Values[index].Key, @@ -627,7 +628,7 @@ private void ReachTime(PartitionEntry partition) if (currentStart != NotActive) { // Matching left start edge is currently visible, so output end edge. - AddToBatch( + this.AddToBatch( leftTime, currentStart, ref lim.Values[leftIndex].Key, @@ -650,7 +651,7 @@ private void ReachTime(PartitionEntry partition) } else { - MakeMatchingLeftVisible(partition, rightTime, ref rm.Values[rightIndex].Key, rm.GetHash(rightIndex)); + this.MakeMatchingLeftVisible(partition, rightTime, ref rm.Values[rightIndex].Key, rm.GetHash(rightIndex)); rm.Remove(rightIndex); } @@ -690,7 +691,7 @@ private void MakeMatchingLeftInvisible(PartitionEntry partition, long time, ref if (this.keyComparerEquals(key, lim.Values[index].Key)) { // Output end edge. - AddToBatch( + this.AddToBatch( time, lim.Values[index].CurrentStart, ref lim.Values[index].Key, @@ -709,7 +710,7 @@ private void MakeMatchingLeftInvisible(PartitionEntry partition, long time, ref if (this.keyComparerEquals(key, lem.Values[index].Key)) { // Output end edge. - AddToBatch( + this.AddToBatch( time, lem.Values[index].CurrentStart, ref lem.Values[index].Key, @@ -738,7 +739,7 @@ private void MakeMatchingLeftVisible(PartitionEntry partition, long time, ref TK if (isFullyOutputtable) { // Output interval. - AddToBatch( + this.AddToBatch( time, end, ref lim.Values[index].Key, @@ -751,7 +752,7 @@ private void MakeMatchingLeftVisible(PartitionEntry partition, long time, ref TK else { // Output start edge. - AddToBatch( + this.AddToBatch( time, StreamEvent.InfinitySyncTime, ref lim.Values[index].Key, @@ -771,7 +772,7 @@ private void MakeMatchingLeftVisible(PartitionEntry partition, long time, ref TK if (this.keyComparerEquals(key, lem.Values[index].Key)) { // Output start edge. - AddToBatch( + this.AddToBatch( time, StreamEvent.InfinitySyncTime, ref lem.Values[index].Key, @@ -799,7 +800,7 @@ private void AddLowWatermarkToBatch(long start) this.output.hash.col[index] = 0; this.output.bitvector.col[index >> 6] |= 1L << (index & 0x3f); - if (this.output.Count == Config.DataBatchSize) FlushContents(); + if (this.output.Count == Config.DataBatchSize) this.FlushContents(); } } @@ -819,7 +820,7 @@ private void AddToBatch(long start, long end, ref TKey key, ref TLeft payload, i this.output.hash.col[index] = hash; if (end == long.MinValue) this.output.bitvector.col[index >> 6] |= 1L << (index & 0x3f); - if (this.output.Count == Config.DataBatchSize) FlushContents(); + if (this.output.Count == Config.DataBatchSize) this.FlushContents(); } [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -927,7 +928,7 @@ public void Populate(long start, long currentStart, long end, ref TKey key, ref this.Payload = payload; } - public override string ToString() + public override readonly string ToString() => "[Start=" + this.Start + ", CurrentStart=" + this.CurrentStart + ", End=" + this.End + ", Key='" + this.Key + "', Payload='" + this.Payload + "']"; } @@ -946,7 +947,7 @@ public void Initialize(ref TKey key) this.Count = 1; } - public override string ToString() + public override readonly string ToString() => "[Key='" + this.Key + "', Count=" + this.Count + "]"; } @@ -965,7 +966,7 @@ public void Populate(ref TKey key, int hash) this.Hash = hash; } - public override string ToString() + public override readonly string ToString() => "[Key='" + this.Key + "', Hash=" + this.Hash + "]"; } @@ -1026,7 +1027,7 @@ private sealed class PartitionEntry /// When the interval is not joined, it is "invisible". /// [DataMember] - public FastMap leftIntervalMap = new FastMap(); + public FastMap leftIntervalMap = new(); /// /// Stores left start edges at @@ -1034,7 +1035,7 @@ private sealed class PartitionEntry /// When the interval is not joined, it is "invisible". /// [DataMember] - public FastMap leftEdgeMap = new FastMap(); + public FastMap leftEdgeMap = new(); /// /// Stores left end edges at some point in the future, i.e. after . @@ -1047,13 +1048,13 @@ private sealed class PartitionEntry /// Stores the right events present for this partition at /// [DataMember] - public FastMap rightMap = new FastMap(); + public FastMap rightMap = new(); /// /// Stores right end edges for , excluding interval endpoints /// [DataMember] - public FastStack rightEndEdges = new FastStack(); + public FastStack rightEndEdges = new(); /// /// Stores right endpoints at some point in the future, i.e. after , originating diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/MapReduce/Map2ReduceStreamable.cs b/Sources/Core/Microsoft.StreamProcessing/Operators/MapReduce/Map2ReduceStreamable.cs index 737b9129f..159236f27 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/MapReduce/Map2ReduceStreamable.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/MapReduce/Map2ReduceStreamable.cs @@ -65,9 +65,9 @@ internal Map2ReduceStreamable( resultSelector, reduceOptions)) { - Contract.Requires(sourceLeft1 != null); - Contract.Requires(sourceLeft2 != null); - Contract.Requires(reducer != null); + ArgumentNullException.ThrowIfNull(sourceLeft1); + ArgumentNullException.ThrowIfNull(sourceLeft2); + ArgumentNullException.ThrowIfNull(reducer); this.sourceLeft1 = sourceLeft1; this.sourceLeft2 = sourceLeft2; @@ -298,9 +298,9 @@ internal Map2ReduceStreamable( resultSelector, reduceOptions)) { - Contract.Requires(sourceLeft1 != null); - Contract.Requires(sourceLeft2 != null); - Contract.Requires(reducer != null); + ArgumentNullException.ThrowIfNull(sourceLeft1); + ArgumentNullException.ThrowIfNull(sourceLeft2); + ArgumentNullException.ThrowIfNull(reducer); this.sourceLeft1 = sourceLeft1; this.sourceLeft2 = sourceLeft2; diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/MapReduce/Map2ReduceStreamable.tt b/Sources/Core/Microsoft.StreamProcessing/Operators/MapReduce/Map2ReduceStreamable.tt index 246a97a67..664bbbd1e 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/MapReduce/Map2ReduceStreamable.tt +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/MapReduce/Map2ReduceStreamable.tt @@ -78,9 +78,9 @@ namespace Microsoft.StreamProcessing resultSelector, reduceOptions)) { - Contract.Requires(sourceLeft1 != null); - Contract.Requires(sourceLeft2 != null); - Contract.Requires(reducer != null); + ArgumentNullException.ThrowIfNull(sourceLeft1); + ArgumentNullException.ThrowIfNull(sourceLeft2); + ArgumentNullException.ThrowIfNull(reducer); this.sourceLeft1 = sourceLeft1; this.sourceLeft2 = sourceLeft2; diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/MapReduce/MapDefinition.cs b/Sources/Core/Microsoft.StreamProcessing/Operators/MapReduce/MapDefinition.cs index 5373f1a88..31c0de904 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/MapReduce/MapDefinition.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/MapReduce/MapDefinition.cs @@ -34,10 +34,10 @@ public IStreamable CreateStreamable( Func, TReduceInput>, IStreamable, TBind>> reducer, Expression, TBind, TOutput>> resultSelector) { - Contract.Assume(sourceLeft != null); + Contract.Assume(this.sourceLeft != null); - var sourceL = sourceLeft; - var sourceR = sourceRight; + var sourceL = this.sourceLeft; + var sourceR = this.sourceRight; Expression> resultSelector2 = (k, b) => CallInliner.Call(resultSelector, new GroupSelectorInput(k), b); @@ -47,26 +47,26 @@ public IStreamable CreateStreamable( return new MapReduceStreamable( sourceL, sourceR, - mapper, - keySelector, + this.mapper, + this.keySelector, reducer, inlinedResultSelector, - leftAsymmetric); + this.leftAsymmetric); } public IStreamable CreateStreamable() { - Contract.Assume(sourceLeft != null); + Contract.Assume(this.sourceLeft != null); - var sourceL = sourceLeft; - var sourceR = sourceRight; + var sourceL = this.sourceLeft; + var sourceR = this.sourceRight; return new MapReduceStreamable( sourceL, sourceR, - mapper, - keySelector, - leftAsymmetric); + this.mapper, + this.keySelector, + this.leftAsymmetric); } /* Create a streamable for a 2-input reducer, with two 2-input mappers */ @@ -78,11 +78,11 @@ public IStreamable CreateStreamable, TBind, TOutput>> resultSelector, OperationalHint reduceOptions) { - Contract.Assume(sourceLeft != null); + Contract.Assume(this.sourceLeft != null); var mapDefinitionRight = (MapDefinition)imapDefinitionRight; - var sourceL1 = sourceLeft; - var sourceR1 = sourceRight; + var sourceL1 = this.sourceLeft; + var sourceR1 = this.sourceRight; var sourceL2 = mapDefinitionRight.sourceLeft; var sourceR2 = mapDefinitionRight.sourceRight; @@ -94,15 +94,15 @@ public IStreamable CreateStreamable( sourceL1, sourceR1, - mapper, - keySelector, + this.mapper, + this.keySelector, sourceL2, sourceR2, mapDefinitionRight.mapper, mapDefinitionRight.keySelector, reducer, inlinedResultSelector, - leftAsymmetric, + this.leftAsymmetric, mapDefinitionRight.leftAsymmetric, reduceOptions); } } @@ -133,10 +133,10 @@ public IStreamable CreateStreamable( Func, IStreamable> reducer, Expression, TBind, TOutput>> resultSelector) { - Contract.Assume(sourceLeft != null); + Contract.Assume(this.sourceLeft != null); - var sourceL = sourceLeft; - var sourceR = sourceRight; + var sourceL = this.sourceLeft; + var sourceR = this.sourceRight; Expression> resultSelector2 = (k, b) => CallInliner.Call(resultSelector, new GroupSelectorInput(k), b); @@ -145,26 +145,26 @@ public IStreamable CreateStreamable( return new MapReduceStreamable( sourceL, sourceR, - mapper, - keySelector, + this.mapper, + this.keySelector, reducer, inlinedResultSelector, - leftAsymmetric); + this.leftAsymmetric); } public IStreamable CreateStreamable() { - Contract.Assume(sourceLeft != null); + Contract.Assume(this.sourceLeft != null); - var sourceL = sourceLeft; - var sourceR = sourceRight; + var sourceL = this.sourceLeft; + var sourceR = this.sourceRight; return new MapReduceStreamable( sourceL, sourceR, - mapper, - keySelector, - leftAsymmetric); + this.mapper, + this.keySelector, + this.leftAsymmetric); } /* Create a streamable for a 2-input reducer, with two 2-input mappers */ @@ -176,11 +176,11 @@ public IStreamable CreateStreamable, TBind, TOutput>> resultSelector, OperationalHint reduceOptions) { - Contract.Assume(sourceLeft != null); + Contract.Assume(this.sourceLeft != null); var mapDefinitionRight = (MapDefinition)imapDefinitionRight; - var sourceL1 = sourceLeft; - var sourceR1 = sourceRight; + var sourceL1 = this.sourceLeft; + var sourceR1 = this.sourceRight; var sourceL2 = mapDefinitionRight.sourceLeft; var sourceR2 = mapDefinitionRight.sourceRight; @@ -192,15 +192,15 @@ public IStreamable CreateStreamable( sourceL1, sourceR1, - mapper, - keySelector, + this.mapper, + this.keySelector, sourceL2, sourceR2, mapDefinitionRight.mapper, mapDefinitionRight.keySelector, reducer, inlinedResultSelector, - leftAsymmetric, + this.leftAsymmetric, mapDefinitionRight.leftAsymmetric, reduceOptions); } } diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/MapReduce/MapReduceStreamable.cs b/Sources/Core/Microsoft.StreamProcessing/Operators/MapReduce/MapReduceStreamable.cs index 93384a4ec..7f5df71d5 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/MapReduce/MapReduceStreamable.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/MapReduce/MapReduceStreamable.cs @@ -33,7 +33,7 @@ internal MapReduceStreamable( sourceLeft.Properties.MapReduce (sourceRight?.Properties, mapper, keySelector, reducer, resultSelector)) { - Contract.Requires(sourceLeft != null); + ArgumentNullException.ThrowIfNull(sourceLeft); this.sourceLeft = sourceLeft; this.sourceRight = sourceRight; @@ -225,7 +225,7 @@ internal MapReduceStreamable( sourceLeft.Properties.MapReduce (sourceRight?.Properties, mapper, keySelector, reducer, resultSelector)) { - Contract.Requires(sourceLeft != null); + ArgumentNullException.ThrowIfNull(sourceLeft); this.sourceLeft = sourceLeft; this.sourceRight = sourceRight; diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/MapReduce/MapReduceStreamable.tt b/Sources/Core/Microsoft.StreamProcessing/Operators/MapReduce/MapReduceStreamable.tt index eecb7f06e..743aab264 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/MapReduce/MapReduceStreamable.tt +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/MapReduce/MapReduceStreamable.tt @@ -46,7 +46,7 @@ namespace Microsoft.StreamProcessing sourceLeft.Properties.MapReduce (sourceRight?.Properties, mapper, keySelector, reducer, resultSelector)) { - Contract.Requires(sourceLeft != null); + ArgumentNullException.ThrowIfNull(sourceLeft); this.sourceLeft = sourceLeft; this.sourceRight = sourceRight; diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/MapReduce/MultiUnionStreamable.cs b/Sources/Core/Microsoft.StreamProcessing/Operators/MapReduce/MultiUnionStreamable.cs index b16111b50..6bfbb43d6 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/MapReduce/MultiUnionStreamable.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/MapReduce/MultiUnionStreamable.cs @@ -17,9 +17,9 @@ internal sealed class MultiUnionStreamable : Streamable[] sources, bool register = true, bool guaranteedDisjoint = false) : base(sources.Skip(1).Select(o => o.Properties).Aggregate(sources[0].Properties, (r, p) => r.Union(p))) { - Invariant.IsNotNull(sources, "sources"); - Invariant.IsPositive(sources.Length, "sources.Length"); - Invariant.IsNotNull(sources[0], "sources[0]"); + ArgumentNullException.ThrowIfNull(sources); + ArgumentOutOfRangeException.ThrowIfNegativeOrZero(sources.Length, "sources.Length"); + ArgumentNullException.ThrowIfNull(sources[0], "sources[0]"); this.Sources = sources; this.registerScheduler = register; diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/Multicast/BinaryMulticastStreamable.cs b/Sources/Core/Microsoft.StreamProcessing/Operators/Multicast/BinaryMulticastStreamable.cs index 06d19f01a..aab588648 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/Multicast/BinaryMulticastStreamable.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/Multicast/BinaryMulticastStreamable.cs @@ -17,7 +17,7 @@ public BinaryMulticastStreamable(IStreamable sourceLeft, IStr Func, IStreamable, IStreamable> selector) : base(sourceLeft.Properties.Derive(sourceRight.Properties, selector)) { - Contract.Requires(sourceLeft != null); + ArgumentNullException.ThrowIfNull(sourceLeft); this.sourceLeft = sourceLeft; this.sourceRight = sourceRight; diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/Multicast/ConnectableStreamableBase.cs b/Sources/Core/Microsoft.StreamProcessing/Operators/Multicast/ConnectableStreamableBase.cs index 51fcc78cb..f7b5eb3e7 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/Multicast/ConnectableStreamableBase.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/Multicast/ConnectableStreamableBase.cs @@ -33,7 +33,7 @@ internal abstract class ConnectableStreamableBase : Streamable properties) : base(properties) { - Contract.Requires(properties != null); + ArgumentNullException.ThrowIfNull(properties); this.pool = MemoryManager.GetMemoryPool(properties.IsColumnar); this.ClassId = Guid.NewGuid(); diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/Multicast/DependentStreamable.cs b/Sources/Core/Microsoft.StreamProcessing/Operators/Multicast/DependentStreamable.cs index 5af88e3f5..9091d8048 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/Multicast/DependentStreamable.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/Multicast/DependentStreamable.cs @@ -5,12 +5,13 @@ using System; using System.Collections.Generic; using System.Diagnostics.Contracts; +using System.Threading; namespace Microsoft.StreamProcessing { internal sealed class NWayMulticast { - private readonly object subscriptionLock = new object(); + private readonly Lock subscriptionLock = new(); private ConnectableStreamable connectableStream; private readonly IStreamable source; private readonly int outputCount; @@ -19,7 +20,7 @@ internal sealed class NWayMulticast private NWayMulticast(IStreamable source, int outputCount) { - Contract.Requires(source != null); + ArgumentNullException.ThrowIfNull(source); Contract.Requires(outputCount > 0); this.source = source; @@ -39,7 +40,7 @@ private IStreamable[] GenerateStreamableArray() throw new InvalidOperationException("Cannot generate a streamable array more than once."); } - this.toSubscribe = new HashSet(); + this.toSubscribe = []; var output = new IStreamable[this.outputCount]; for (int i = 0; i < this.outputCount; i++) @@ -51,25 +52,23 @@ private IStreamable[] GenerateStreamableArray() private IDisposable Subscribe(IStreamObserver observer, int index) { + using Lock.Scope _ = this.subscriptionLock.EnterScope(); IDisposable child; - lock (this.subscriptionLock) + if (this.toSubscribe.Add(index)) { - if (this.toSubscribe.Add(index)) - { - child = new ChildDisposable(this.connectableStream.Subscribe(observer), this.crew, index); - } - else - { - throw new InvalidOperationException("Cannot subscribe to the same child streamable more than once."); - } + child = new ChildDisposable(this.connectableStream.Subscribe(observer), this.crew, index); + } + else + { + throw new InvalidOperationException("Cannot subscribe to the same child streamable more than once."); + } - if (this.toSubscribe.Count == this.outputCount) - { - this.crew.SetListDisposable(this.connectableStream.Connect()); - this.crew = new DisposableManager(this.outputCount); - this.connectableStream = new ConnectableStreamable(this.source); - this.toSubscribe.Clear(); - } + if (this.toSubscribe.Count == this.outputCount) + { + this.crew.SetListDisposable(this.connectableStream.Connect()); + this.crew = new(this.outputCount); + this.connectableStream = new(this.source); + this.toSubscribe.Clear(); } return child; } @@ -85,8 +84,8 @@ public DependentStreamable( int index) : base(source.Properties) { - Contract.Requires(source != null); - Contract.Requires(leader != null); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(leader); Contract.Requires(index >= 0); this.leader = leader; @@ -99,13 +98,13 @@ public override IDisposable Subscribe(IStreamObserver o private sealed class DisposableManager { - private readonly object disposeLock = new object(); + private readonly Lock disposeLock = new(); private IDisposable last; private readonly HashSet toDispose; public DisposableManager(int count) { - this.toDispose = new HashSet(); + this.toDispose = []; for (int i = 0; i < count; i++) { this.toDispose.Add(i); @@ -116,34 +115,21 @@ public DisposableManager(int count) public void MarkAsDisposed(int index) { - lock (this.disposeLock) + using Lock.Scope _ = this.disposeLock.EnterScope(); + this.toDispose.Remove(index); + if (this.toDispose.Count == 0) { - this.toDispose.Remove(index); - if (this.toDispose.Count == 0) - { - this.last.Dispose(); - } + this.last.Dispose(); } } } - private sealed class ChildDisposable : IDisposable + private sealed class ChildDisposable(IDisposable inner, DisposableManager crew, int index) : IDisposable { - private readonly IDisposable inner; - private readonly DisposableManager crew; - private readonly int index; - - public ChildDisposable(IDisposable inner, DisposableManager crew, int index) - { - this.inner = inner; - this.crew = crew; - this.index = index; - } - public void Dispose() { - this.inner.Dispose(); - this.crew.MarkAsDisposed(this.index); + inner.Dispose(); + crew.MarkAsDisposed(index); } } } diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/Multicast/MulticastStreamable.cs b/Sources/Core/Microsoft.StreamProcessing/Operators/Multicast/MulticastStreamable.cs index 1fa8ccad1..8401c0d6f 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/Multicast/MulticastStreamable.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/Multicast/MulticastStreamable.cs @@ -15,8 +15,8 @@ internal sealed class MulticastStreamable : Streamable source, Func, IStreamable> selector) : base(source.Properties.Derive(selector)) { - Contract.Requires(source != null); - Contract.Requires(selector != null); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(selector); this.source = source; this.selector = selector; diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/Partition/PartitionPlanNode.cs b/Sources/Core/Microsoft.StreamProcessing/Operators/Partition/PartitionPlanNode.cs index f2123e4e6..156039743 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/Partition/PartitionPlanNode.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/Partition/PartitionPlanNode.cs @@ -46,7 +46,7 @@ internal PartitionPlanNode( internal override void PrintConciseSummary(System.Text.StringBuilder builder, int indentLevel) { - PrintConciseGeneralState(builder, indentLevel); + this.PrintConciseGeneralState(builder, indentLevel); builder.AppendLine(new string('\t', indentLevel + 1) + "Previous: "); this.Previous.PrintConciseSummary(builder, indentLevel + 2); } diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/Partition/PartitionStreamable.cs b/Sources/Core/Microsoft.StreamProcessing/Operators/Partition/PartitionStreamable.cs index 80d63eead..e9475b9d4 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/Partition/PartitionStreamable.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/Partition/PartitionStreamable.cs @@ -20,8 +20,8 @@ public PartitionStreamable( IStreamable source, Expression> keySelector, long partitionLag) : base(source.Properties.Partition(keySelector)) { - Contract.Requires(source != null); - Contract.Requires(keySelector != null); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(keySelector); this.Source = source; this.KeySelector = keySelector; diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/PointAtEnd/PartitionedPointAtEndPipe.cs b/Sources/Core/Microsoft.StreamProcessing/Operators/PointAtEnd/PartitionedPointAtEndPipe.cs index f8d8d860c..282deed90 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/PointAtEnd/PartitionedPointAtEndPipe.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/PointAtEnd/PartitionedPointAtEndPipe.cs @@ -19,11 +19,11 @@ internal sealed class PartitionedPointAtEndPipe : private StreamMessage output; [DataMember] - private FastDictionary lastSyncTime = new FastDictionary(); + private FastDictionary lastSyncTime = new(); [DataMember] - private FastDictionary endPointHeapDictionary = new FastDictionary(); + private FastDictionary endPointHeapDictionary = new(); [DataMember] - private FastDictionary> intervalMapDictionary = new FastDictionary>(); + private FastDictionary> intervalMapDictionary = new(); [Obsolete("Used only by serialization. Do not call directly.")] public PartitionedPointAtEndPipe() { } @@ -46,7 +46,7 @@ public override void ProduceQueryPlan(PlanNode previous) private void ReachTime(long timestamp) { int index = FastDictionary.IteratorStart; - while (this.lastSyncTime.Iterate(ref index)) ReachTime(index, timestamp); + while (this.lastSyncTime.Iterate(ref index)) this.ReachTime(index, timestamp); } private void ReachTime(int pIndex, long timestamp) @@ -62,7 +62,7 @@ private void ReachTime(int pIndex, long timestamp) this.output[ind] = intervalMap.Values[index].Payload; this.output.hash.col[ind] = intervalMap.Values[index].Hash; - if (this.output.Count == Config.DataBatchSize) FlushContents(); + if (this.output.Count == Config.DataBatchSize) this.FlushContents(); intervalMap.Remove(index); } @@ -91,8 +91,8 @@ public override unsafe void OnNext(StreamMessage batch) if ((bv[i >> 6] & (1L << (i & 0x3f))) == 0) { var partition = this.getPartitionKey(batch.key.col[i]); - if (!this.lastSyncTime.Lookup(partition, out int timeIndex)) timeIndex = AllocatePartition(partition, batch.vsync.col[i]); - else if (batch.vsync.col[i] > this.lastSyncTime.entries[timeIndex].value) ReachTime(timeIndex, batch.vsync.col[i]); + if (!this.lastSyncTime.Lookup(partition, out int timeIndex)) timeIndex = this.AllocatePartition(partition, batch.vsync.col[i]); + else if (batch.vsync.col[i] > this.lastSyncTime.entries[timeIndex].value) this.ReachTime(timeIndex, batch.vsync.col[i]); if (batch.vother.col[i] == StreamEvent.InfinitySyncTime) continue; else if (batch.vother.col[i] < batch.vsync.col[i]) // End edge @@ -104,7 +104,7 @@ public override unsafe void OnNext(StreamMessage batch) this.output[ind] = batch[i]; this.output.hash.col[ind] = batch.hash.col[i]; - if (this.output.Count == Config.DataBatchSize) FlushContents(); + if (this.output.Count == Config.DataBatchSize) this.FlushContents(); } else // Interval { @@ -118,7 +118,7 @@ public override unsafe void OnNext(StreamMessage batch) } else if (batch.vother.col[i] == PartitionedStreamEvent.LowWatermarkOtherTime) { - ReachTime(batch.vsync.col[i]); + this.ReachTime(batch.vsync.col[i]); int ind = this.output.Count++; this.output.vsync.col[ind] = batch.vsync.col[i]; @@ -128,13 +128,13 @@ public override unsafe void OnNext(StreamMessage batch) this.output.hash.col[ind] = 0; this.output.bitvector.col[ind >> 6] |= (1L << (ind & 0x3f)); - if (this.output.Count == Config.DataBatchSize) FlushContents(); + if (this.output.Count == Config.DataBatchSize) this.FlushContents(); } else if (batch.vother.col[i] == PartitionedStreamEvent.PunctuationOtherTime) { var partition = this.getPartitionKey(batch.key.col[i]); - if (!this.lastSyncTime.Lookup(partition, out int timeIndex)) timeIndex = AllocatePartition(partition, batch.vsync.col[i]); - else if (batch.vsync.col[i] > this.lastSyncTime.entries[timeIndex].value) ReachTime(timeIndex, batch.vsync.col[i]); + if (!this.lastSyncTime.Lookup(partition, out int timeIndex)) timeIndex = this.AllocatePartition(partition, batch.vsync.col[i]); + else if (batch.vsync.col[i] > this.lastSyncTime.entries[timeIndex].value) this.ReachTime(timeIndex, batch.vsync.col[i]); int ind = this.output.Count++; this.output.vsync.col[ind] = batch.vsync.col[i]; @@ -144,7 +144,7 @@ public override unsafe void OnNext(StreamMessage batch) this.output.hash.col[ind] = batch.hash.col[i]; this.output.bitvector.col[ind >> 6] |= (1L << (ind & 0x3f)); - if (this.output.Count == Config.DataBatchSize) FlushContents(); + if (this.output.Count == Config.DataBatchSize) this.FlushContents(); } } } @@ -160,7 +160,13 @@ protected override void FlushContents() this.output.Allocate(); } - protected override void DisposeState() => this.output.Free(); + protected override void DisposeState() + { + this.lastSyncTime.Dispose(); + this.endPointHeapDictionary.Dispose(); + this.intervalMapDictionary.Dispose(); + this.output.Free(); + } public override int CurrentlyBufferedOutputCount => this.output.Count; @@ -192,7 +198,7 @@ public void Populate(TKey key, TPayload payload, int hash) this.Hash = hash; } - public override string ToString() => "Key='" + this.Key + "', Payload='" + this.Payload; + public override readonly string ToString() => "Key='" + this.Key + "', Payload='" + this.Payload; } } } \ No newline at end of file diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/PointAtEnd/PointAtEndPipe.cs b/Sources/Core/Microsoft.StreamProcessing/Operators/PointAtEnd/PointAtEndPipe.cs index 03a1cdc8f..9f3883af3 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/PointAtEnd/PointAtEndPipe.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/PointAtEnd/PointAtEndPipe.cs @@ -20,9 +20,9 @@ internal sealed class PointAtEndPipe : UnaryPipe intervalMap = new FastMap(); + private FastMap intervalMap = new(); [Obsolete("Used only by serialization. Do not call directly.")] public PointAtEndPipe() { } @@ -53,7 +53,7 @@ private void ReachTime(long timestamp) this.output[ind] = this.intervalMap.Values[index].Payload; this.output.hash.col[ind] = this.intervalMap.Values[index].Hash; - if (this.output.Count == Config.DataBatchSize) FlushContents(); + if (this.output.Count == Config.DataBatchSize) this.FlushContents(); this.intervalMap.Remove(index); } @@ -71,7 +71,7 @@ public override unsafe void OnNext(StreamMessage batch) { if ((bv[i >> 6] & (1L << (i & 0x3f))) == 0) { - if (batch.vsync.col[i] > this.lastSyncTime) ReachTime(batch.vsync.col[i]); + if (batch.vsync.col[i] > this.lastSyncTime) this.ReachTime(batch.vsync.col[i]); if (batch.vother.col[i] == StreamEvent.InfinitySyncTime) { @@ -86,7 +86,7 @@ public override unsafe void OnNext(StreamMessage batch) this.output[ind] = batch[i]; this.output.hash.col[ind] = batch.hash.col[i]; - if (this.output.Count == Config.DataBatchSize) FlushContents(); + if (this.output.Count == Config.DataBatchSize) this.FlushContents(); } else { @@ -97,7 +97,7 @@ public override unsafe void OnNext(StreamMessage batch) } else if (batch.vother.col[i] == StreamEvent.PunctuationOtherTime) { - ReachTime(batch.vsync.col[i]); + this.ReachTime(batch.vsync.col[i]); int ind = this.output.Count++; this.output.vsync.col[ind] = batch.vsync.col[i]; @@ -107,7 +107,7 @@ public override unsafe void OnNext(StreamMessage batch) this.output.hash.col[ind] = batch.hash.col[i]; this.output.bitvector.col[ind >> 6] |= (1L << (ind & 0x3f)); - if (this.output.Count == Config.DataBatchSize) FlushContents(); + if (this.output.Count == Config.DataBatchSize) this.FlushContents(); } } } @@ -146,7 +146,7 @@ public void Populate(TKey key, TPayload payload, int hash) this.Hash = hash; } - public override string ToString() => "Key='" + this.Key + "', Payload='" + this.Payload; + public override readonly string ToString() => "Key='" + this.Key + "', Payload='" + this.Payload; } } diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/PointAtEnd/PointAtEndStreamable.cs b/Sources/Core/Microsoft.StreamProcessing/Operators/PointAtEnd/PointAtEndStreamable.cs index 9dffd6eaa..ed62e96d9 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/PointAtEnd/PointAtEndStreamable.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/PointAtEnd/PointAtEndStreamable.cs @@ -11,14 +11,14 @@ namespace Microsoft.StreamProcessing internal sealed class PointAtEndStreamable : UnaryStreamable { private static readonly SafeConcurrentDictionary> cachedPipes - = new SafeConcurrentDictionary>(); + = new(); public PointAtEndStreamable(IStreamable source) : base(source, source.Properties.PointAtEnd()) { - Contract.Requires(source != null); + ArgumentNullException.ThrowIfNull(source); - Initialize(); + this.Initialize(); } internal override IStreamObserver CreatePipe(IStreamObserver observer) @@ -32,7 +32,7 @@ internal override IStreamObserver CreatePipe(IStreamObserver(this, observer); } var outputType = typeof(PartitionedPointAtEndPipe<,,>).MakeGenericType( diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/PointAtEnd/PointAtEndTransformer.cs b/Sources/Core/Microsoft.StreamProcessing/Operators/PointAtEnd/PointAtEndTransformer.cs index 3eb62f29f..268e6df33 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/PointAtEnd/PointAtEndTransformer.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/PointAtEnd/PointAtEndTransformer.cs @@ -3,6 +3,9 @@ // Licensed under the MIT License // ********************************************************************* using System; +#if CODEGEN_TIMING +using System.Diagnostics; +#endif using System.Diagnostics.Contracts; using System.Reflection; @@ -27,8 +30,8 @@ private PointAtEndTemplate(string className, Type keyType, Type payloadType) /// internal static Tuple Generate(PointAtEndStreamable stream) { - Contract.Requires(stream != null); - Contract.Ensures(Contract.Result>() == null || typeof(UnaryPipe).GetTypeInfo().IsAssignableFrom(Contract.Result>().Item1)); + ArgumentNullException.ThrowIfNull(stream); + Contract.Ensures(Contract.Result>() == null || typeof(UnaryPipe).IsAssignableFrom(Contract.Result>().Item1)); #if CODEGEN_TIMING Stopwatch sw = new Stopwatch(); diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/QuantizeLifetime/PartitionedQuantizeLifetimePipe.cs b/Sources/Core/Microsoft.StreamProcessing/Operators/QuantizeLifetime/PartitionedQuantizeLifetimePipe.cs index f9f73eecd..57fe0a551 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/QuantizeLifetime/PartitionedQuantizeLifetimePipe.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/QuantizeLifetime/PartitionedQuantizeLifetimePipe.cs @@ -29,7 +29,7 @@ internal sealed class PartitionedQuantizeLifetimePipe output; [DataMember] - private FastDictionary partitionData = new FastDictionary(); + private FastDictionary partitionData = new(); [Obsolete("Used only by serialization. Do not call directly.")] public PartitionedQuantizeLifetimePipe() { } @@ -64,7 +64,7 @@ private int AllocatePartition(TPartitionKey pKey) private void ReachTime(long timestamp) { int index = FastDictionary.IteratorStart; - while (this.partitionData.Iterate(ref index)) ReachTime(index, timestamp); + while (this.partitionData.Iterate(ref index)) this.ReachTime(index, timestamp); } private void ReachTime(int pIndex, long timestamp) @@ -80,7 +80,7 @@ private void ReachTime(int pIndex, long timestamp) this.output[ind] = intervalMap.Values[index].Payload; this.output.hash.col[ind] = intervalMap.Values[index].Hash; - if (this.output.Count == Config.DataBatchSize) FlushContents(); + if (this.output.Count == Config.DataBatchSize) this.FlushContents(); intervalMap.Remove(index); } @@ -101,8 +101,8 @@ public override unsafe void OnNext(StreamMessage batch) if ((bv[i >> 6] & (1L << (i & 0x3f))) == 0) { var partition = this.getPartitionKey(batch.key.col[i]); - if (!this.partitionData.Lookup(partition, out int timeIndex)) timeIndex = AllocatePartition(partition); - else if (batch.vsync.col[i] > this.partitionData.entries[timeIndex].value.lastSyncTime) ReachTime(batch.vsync.col[i]); + if (!this.partitionData.Lookup(partition, out int timeIndex)) timeIndex = this.AllocatePartition(partition); + else if (batch.vsync.col[i] > this.partitionData.entries[timeIndex].value.lastSyncTime) this.ReachTime(batch.vsync.col[i]); if (batch.vother.col[i] == StreamEvent.InfinitySyncTime) // Start edge { @@ -113,7 +113,7 @@ public override unsafe void OnNext(StreamMessage batch) this.output[ind] = batch[i]; this.output.hash.col[ind] = batch.hash.col[i]; - if (this.output.Count == Config.DataBatchSize) FlushContents(); + if (this.output.Count == Config.DataBatchSize) this.FlushContents(); } else if (batch.vother.col[i] > batch.vsync.col[i]) // Interval { @@ -125,7 +125,7 @@ public override unsafe void OnNext(StreamMessage batch) this.output[ind] = batch[i]; this.output.hash.col[ind] = batch.hash.col[i]; - if (this.output.Count == Config.DataBatchSize) FlushContents(); + if (this.output.Count == Config.DataBatchSize) this.FlushContents(); } else // End edge { @@ -140,7 +140,7 @@ public override unsafe void OnNext(StreamMessage batch) } else if (batch.vother.col[i] == PartitionedStreamEvent.LowWatermarkOtherTime) { - ReachTime(batch.vsync.col[i]); + this.ReachTime(batch.vsync.col[i]); int ind = this.output.Count++; this.output.vsync.col[ind] = vsync[i] - ((vsync[i] - this.offset) % this.progress + this.progress) % this.progress; @@ -150,13 +150,13 @@ public override unsafe void OnNext(StreamMessage batch) this.output.hash.col[ind] = 0; this.output.bitvector.col[ind >> 6] |= 1L << (ind & 0x3f); - if (this.output.Count == Config.DataBatchSize) FlushContents(); + if (this.output.Count == Config.DataBatchSize) this.FlushContents(); } else if (batch.vother.col[i] == PartitionedStreamEvent.PunctuationOtherTime) { var partition = this.getPartitionKey(batch.key.col[i]); - if (!this.partitionData.Lookup(partition, out int timeIndex)) timeIndex = AllocatePartition(partition); - ReachTime(timeIndex, batch.vsync.col[i]); + if (!this.partitionData.Lookup(partition, out int timeIndex)) timeIndex = this.AllocatePartition(partition); + this.ReachTime(timeIndex, batch.vsync.col[i]); int ind = this.output.Count++; this.output.vsync.col[ind] = vsync[i] - ((vsync[i] - this.offset) % this.progress + this.progress) % this.progress; @@ -166,7 +166,7 @@ public override unsafe void OnNext(StreamMessage batch) this.output.hash.col[ind] = batch.hash.col[i]; this.output.bitvector.col[ind >> 6] |= (1L << (ind & 0x3f)); - if (this.output.Count == Config.DataBatchSize) FlushContents(); + if (this.output.Count == Config.DataBatchSize) this.FlushContents(); } } } @@ -182,7 +182,11 @@ protected override void FlushContents() this.output.Allocate(); } - protected override void DisposeState() => this.output.Free(); + protected override void DisposeState() + { + this.partitionData.Dispose(); + this.output.Free(); + } public override int CurrentlyBufferedOutputCount => this.output.Count; @@ -217,7 +221,7 @@ public void Populate(TKey key, TPayload payload, int hash, long other) this.Other = other; } - public override string ToString() => "Key='" + this.Key + "', Payload='" + this.Payload; + public override readonly string ToString() => "Key='" + this.Key + "', Payload='" + this.Payload; } [DataContract] @@ -226,9 +230,9 @@ private sealed class PartitionEntry [DataMember] public long lastSyncTime = long.MinValue; [DataMember] - public EndPointHeap endPointHeap = new EndPointHeap(); + public EndPointHeap endPointHeap = new(); [DataMember] - public FastMap intervalMap = new FastMap(); + public FastMap intervalMap = new(); } } diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/QuantizeLifetime/QuantizeLifetimePipe.cs b/Sources/Core/Microsoft.StreamProcessing/Operators/QuantizeLifetime/QuantizeLifetimePipe.cs index 1dceedbd3..2773bab49 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/QuantizeLifetime/QuantizeLifetimePipe.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/QuantizeLifetime/QuantizeLifetimePipe.cs @@ -30,9 +30,9 @@ internal sealed class QuantizeLifetimePipe : UnaryPipe intervalMap = new FastMap(); + private FastMap intervalMap = new(); [Obsolete("Used only by serialization. Do not call directly.")] public QuantizeLifetimePipe() { } @@ -68,7 +68,7 @@ private void ReachTime(long timestamp) this.output[ind] = this.intervalMap.Values[index].Payload; this.output.hash.col[ind] = this.intervalMap.Values[index].Hash; - if (this.output.Count == Config.DataBatchSize) FlushContents(); + if (this.output.Count == Config.DataBatchSize) this.FlushContents(); this.intervalMap.Remove(index); } @@ -88,7 +88,7 @@ public override unsafe void OnNext(StreamMessage batch) { if ((bv[i >> 6] & (1L << (i & 0x3f))) == 0) { - if (vsync[i] > this.lastSyncTime) ReachTime(vsync[i]); + if (vsync[i] > this.lastSyncTime) this.ReachTime(vsync[i]); if (vother[i] == StreamEvent.InfinitySyncTime) // Start edge { @@ -98,7 +98,7 @@ public override unsafe void OnNext(StreamMessage batch) this.output.key.col[ind] = batch.key.col[i]; this.output.payload.col[ind] = batch.payload.col[i]; this.output.hash.col[ind] = batch.hash.col[i]; - if (this.output.Count == Config.DataBatchSize) FlushContents(); + if (this.output.Count == Config.DataBatchSize) this.FlushContents(); } else if (vother[i] > vsync[i]) // Interval { @@ -109,7 +109,7 @@ public override unsafe void OnNext(StreamMessage batch) this.output.key.col[ind] = batch.key.col[i]; this.output[ind] = batch[i]; this.output.hash.col[ind] = batch.hash.col[i]; - if (this.output.Count == Config.DataBatchSize) FlushContents(); + if (this.output.Count == Config.DataBatchSize) this.FlushContents(); } else // End edge { @@ -121,7 +121,7 @@ public override unsafe void OnNext(StreamMessage batch) } else if (vother[i] == long.MinValue) // Punctuation { - if (vsync[i] > this.lastSyncTime) ReachTime(vsync[i]); + if (vsync[i] > this.lastSyncTime) this.ReachTime(vsync[i]); int ind = this.output.Count++; this.output.vsync.col[ind] = vsync[i] - ((vsync[i] - this.offset) % this.progress + this.progress) % this.progress; @@ -130,7 +130,7 @@ public override unsafe void OnNext(StreamMessage batch) this.output.payload.col[ind] = default; this.output.hash.col[ind] = batch.hash.col[i]; this.output.bitvector.col[ind >> 6] |= (1L << (ind & 0x3f)); - if (this.output.Count == Config.DataBatchSize) FlushContents(); + if (this.output.Count == Config.DataBatchSize) this.FlushContents(); } } } @@ -172,7 +172,7 @@ public void Populate(TKey key, TPayload payload, int hash, long other) this.Other = other; } - public override string ToString() => "Key='" + this.Key + "', Payload='" + this.Payload; + public override readonly string ToString() => "Key='" + this.Key + "', Payload='" + this.Payload; } } diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/QuantizeLifetime/QuantizeLifetimeStreamable.cs b/Sources/Core/Microsoft.StreamProcessing/Operators/QuantizeLifetime/QuantizeLifetimeStreamable.cs index 9c7d02e0f..3e9e92952 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/QuantizeLifetime/QuantizeLifetimeStreamable.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/QuantizeLifetime/QuantizeLifetimeStreamable.cs @@ -10,7 +10,7 @@ namespace Microsoft.StreamProcessing internal sealed class QuantizeLifetimeStreamable : UnaryStreamable { private static readonly SafeConcurrentDictionary> cachedPipes - = new SafeConcurrentDictionary>(); + = new(); private readonly long width; private readonly long skip; @@ -29,7 +29,7 @@ public QuantizeLifetimeStreamable(IStreamable source, long width this.progress = progress; this.offset = offset; - Initialize(); + this.Initialize(); } protected override bool CanGenerateColumnar() => typeof(TPayload).CanRepresentAsColumnar(); @@ -43,7 +43,7 @@ internal override IStreamObserver CreatePipe(IStreamObserver(this, observer, this.width, this.skip, this.progress, this.offset); } var outputType = typeof(PartitionedQuantizeLifetimePipe<,,>).MakeGenericType( diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/QuantizeLifetime/QuantizeLifetimeTransformer.cs b/Sources/Core/Microsoft.StreamProcessing/Operators/QuantizeLifetime/QuantizeLifetimeTransformer.cs index 1f7a43511..de7ad621c 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/QuantizeLifetime/QuantizeLifetimeTransformer.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/QuantizeLifetime/QuantizeLifetimeTransformer.cs @@ -3,6 +3,9 @@ // Licensed under the MIT License // ********************************************************************* using System; +#if CODEGEN_TIMING +using System.Diagnostics; +#endif using System.Diagnostics.Contracts; using System.Reflection; @@ -17,8 +20,8 @@ private QuantizeLifetimeTemplate(string className, Type keyType, Type payloadTyp internal static Tuple Generate(QuantizeLifetimeStreamable stream) { - Contract.Requires(stream != null); - Contract.Ensures(Contract.Result>() == null || typeof(UnaryPipe).GetTypeInfo().IsAssignableFrom(Contract.Result>().Item1)); + ArgumentNullException.ThrowIfNull(stream); + Contract.Ensures(Contract.Result>() == null || typeof(UnaryPipe).IsAssignableFrom(Contract.Result>().Item1)); #if CODEGEN_TIMING Stopwatch sw = new Stopwatch(); diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/RowToColumn/RowToColumnStreamable.cs b/Sources/Core/Microsoft.StreamProcessing/Operators/RowToColumn/RowToColumnStreamable.cs index 11f79d0c0..bbd5a6129 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/RowToColumn/RowToColumnStreamable.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/RowToColumn/RowToColumnStreamable.cs @@ -11,17 +11,17 @@ namespace Microsoft.StreamProcessing internal sealed class RowToColumnStreamable : UnaryStreamable { private static readonly SafeConcurrentDictionary> cachedPipes - = new SafeConcurrentDictionary>(); + = new(); public RowToColumnStreamable(IStreamable source) : base(source, source.Properties.ToColumnar()) { - Contract.Requires(source != null); + ArgumentNullException.ThrowIfNull(source); } internal override IStreamObserver CreatePipe(IStreamObserver observer) { - return GetPipe(observer); + return this.GetPipe(observer); } private UnaryPipe GetPipe(IStreamObserver observer) diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/RowToColumn/RowToColumnTransformer.cs b/Sources/Core/Microsoft.StreamProcessing/Operators/RowToColumn/RowToColumnTransformer.cs index ef9ca9b89..e42d26323 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/RowToColumn/RowToColumnTransformer.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/RowToColumn/RowToColumnTransformer.cs @@ -19,9 +19,9 @@ public RowToColumnTemplate(string className, Type keyType, Type payloadType) internal static Tuple Generate(RowToColumnStreamable stream) { - Contract.Requires(stream != null); + ArgumentNullException.ThrowIfNull(stream); Contract.Ensures(Contract.Result>() != null); - Contract.Ensures(typeof(UnaryPipe).GetTypeInfo().IsAssignableFrom(Contract.Result>().Item1)); + Contract.Ensures(typeof(UnaryPipe).IsAssignableFrom(Contract.Result>().Item1)); var keyType = typeof(TKey); var payloadType = typeof(TPayload); @@ -31,15 +31,13 @@ internal static Tuple Generate(RowToColumnStreamab var expandedCode = template.TransformText(); var assemblyReferences = Transformer.AssemblyReferencesNeededFor(keyType, payloadType); - assemblyReferences.Add(typeof(IStreamable<,>).GetTypeInfo().Assembly); + assemblyReferences.Add(typeof(IStreamable<,>).Assembly); assemblyReferences.Add(Transformer.GeneratedStreamMessageAssembly()); assemblyReferences.Add(Transformer.GeneratedMemoryPoolAssembly()); generatedClassName = generatedClassName.AddNumberOfNecessaryGenericArguments(keyType, payloadType); - var a = Transformer.CompileSourceCode(expandedCode, assemblyReferences, out string errorMessages); - - var t = a.GetType(generatedClassName); + var t = Transformer.CompileSourceCode(expandedCode, assemblyReferences, a=> a.GetType(generatedClassName), out string errorMessages); return Tuple.Create(t.InstantiateAsNecessary(typeof(TKey), typeof(TPayload)), errorMessages); } } diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/Select/SelectStreamable.cs b/Sources/Core/Microsoft.StreamProcessing/Operators/Select/SelectStreamable.cs index 63301089b..3a02fb72f 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/Select/SelectStreamable.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/Select/SelectStreamable.cs @@ -12,7 +12,7 @@ namespace Microsoft.StreamProcessing internal sealed class SelectStreamable : UnaryStreamable { private static readonly SafeConcurrentDictionary> cachedPipes - = new SafeConcurrentDictionary>(); + = new(); public Type KeyType { get; } = typeof(TKey); public Type PayloadType { get; } = typeof(TPayload); @@ -24,19 +24,19 @@ private static readonly SafeConcurrentDictionary> cachedPipe public SelectStreamable(IStreamable source, LambdaExpression selector, bool hasStartEdge = false, bool hasKey = false) : base(source, source.Properties.Select(selector, hasStartEdge, hasKey)) { - Contract.Requires(source != null); - Contract.Requires(selector != null); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(selector); this.Selector = selector; this.HasStartEdge = hasStartEdge; this.HasKey = hasKey; - Initialize(); + this.Initialize(); } internal override IStreamObserver CreatePipe(IStreamObserver observer) { - if (this.Source.Properties.IsColumnar) return GetPipe(observer); + if (this.Source.Properties.IsColumnar) return this.GetPipe(observer); if (!this.HasStartEdge && !this.HasKey) return new SelectPipe(this, observer); diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/Select/SelectTransformer.cs b/Sources/Core/Microsoft.StreamProcessing/Operators/Select/SelectTransformer.cs index a55184937..608aca1bf 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/Select/SelectTransformer.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/Select/SelectTransformer.cs @@ -67,7 +67,7 @@ private SelectTemplate(string className, Type keyType, Type payloadType, Type re public static Tuple Generate(SelectStreamable stream) { - Contract.Ensures(Contract.Result>() == null || typeof(UnaryPipe).GetTypeInfo().IsAssignableFrom(Contract.Result>().Item1)); + Contract.Ensures(Contract.Result>() == null || typeof(UnaryPipe).IsAssignableFrom(Contract.Result>().Item1)); string generatedClassName; string errorMessages = null; @@ -156,8 +156,7 @@ public static Tuple Generate(SelectStream assemblyReferences.Add(Transformer.GeneratedMemoryPoolAssembly()); assemblyReferences.AddRange(Transformer.AssemblyReferencesNeededFor(stream.Selector)); - var a = Transformer.CompileSourceCode(expandedCode, assemblyReferences, out errorMessages); - var t = a.GetType(generatedClassName); + var t = Transformer.CompileSourceCode(expandedCode, assemblyReferences, a => a.GetType(generatedClassName), out errorMessages); t = t.InstantiateAsNecessary(typeof(TKey), typeof(TPayload), typeof(TResult)); return Tuple.Create(t, errorMessages); } diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/SelectMany/SelectManyPipe.cs b/Sources/Core/Microsoft.StreamProcessing/Operators/SelectMany/SelectManyPipe.cs index 63c751902..701e0379c 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/SelectMany/SelectManyPipe.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/SelectMany/SelectManyPipe.cs @@ -88,7 +88,7 @@ public override unsafe void OnNext(StreamMessage batch) if (this.iter == Config.DataBatchSize) { - FlushContents(); + this.FlushContents(); this.batch.iter = batch.iter; dest_vsync = this.batch.vsync.col; dest_vother = this.batch.vother.col; @@ -110,7 +110,7 @@ public override unsafe void OnNext(StreamMessage batch) if (this.iter == Config.DataBatchSize) { - FlushContents(); + this.FlushContents(); this.batch.iter = batch.iter; dest_vsync = this.batch.vsync.col; dest_vother = this.batch.vother.col; @@ -216,7 +216,7 @@ public override unsafe void OnNext(StreamMessage batch) if (this.iter == Config.DataBatchSize) { - FlushContents(); + this.FlushContents(); this.batch.iter = batch.iter; dest_vsync = this.batch.vsync.col; dest_vother = this.batch.vother.col; @@ -238,7 +238,7 @@ public override unsafe void OnNext(StreamMessage batch) if (this.iter == Config.DataBatchSize) { - FlushContents(); + this.FlushContents(); this.batch.iter = batch.iter; dest_vsync = this.batch.vsync.col; dest_vother = this.batch.vother.col; @@ -344,7 +344,7 @@ public override unsafe void OnNext(StreamMessage batch) if (this.iter == Config.DataBatchSize) { - FlushContents(); + this.FlushContents(); this.batch.iter = batch.iter; dest_vsync = this.batch.vsync.col; dest_vother = this.batch.vother.col; @@ -366,7 +366,7 @@ public override unsafe void OnNext(StreamMessage batch) if (this.iter == Config.DataBatchSize) { - FlushContents(); + this.FlushContents(); this.batch.iter = batch.iter; dest_vsync = this.batch.vsync.col; dest_vother = this.batch.vother.col; @@ -472,7 +472,7 @@ public override unsafe void OnNext(StreamMessage batch) if (this.iter == Config.DataBatchSize) { - FlushContents(); + this.FlushContents(); this.batch.iter = batch.iter; dest_vsync = this.batch.vsync.col; dest_vother = this.batch.vother.col; @@ -494,7 +494,7 @@ public override unsafe void OnNext(StreamMessage batch) if (this.iter == Config.DataBatchSize) { - FlushContents(); + this.FlushContents(); this.batch.iter = batch.iter; dest_vsync = this.batch.vsync.col; dest_vother = this.batch.vother.col; diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/SelectMany/SelectManyStreamable.cs b/Sources/Core/Microsoft.StreamProcessing/Operators/SelectMany/SelectManyStreamable.cs index 23c0eab8a..4e1a65000 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/SelectMany/SelectManyStreamable.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/SelectMany/SelectManyStreamable.cs @@ -12,7 +12,7 @@ namespace Microsoft.StreamProcessing internal sealed class SelectManyStreamable : UnaryStreamable { private static readonly SafeConcurrentDictionary> cachedPipes - = new SafeConcurrentDictionary>(); + = new(); public readonly LambdaExpression Selector; internal readonly bool HasStartEdge; @@ -21,20 +21,20 @@ private static readonly SafeConcurrentDictionary> cachedPipe public SelectManyStreamable(IStreamable source, LambdaExpression selector, bool hasStartEdge = false, bool hasKey = false) : base(source, source.Properties.SelectMany(selector)) { - Contract.Requires(source != null); - Contract.Requires(selector != null); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(selector); this.Selector = selector; this.HasStartEdge = hasStartEdge; this.HasKey = hasKey; - Initialize(); + this.Initialize(); } internal override IStreamObserver CreatePipe(IStreamObserver observer) { if (this.Source.Properties.IsColumnar) - return GetPipe(observer); + return this.GetPipe(observer); if (!this.HasStartEdge && !this.HasKey) return new SelectManyPipe(this, observer); diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/SelectMany/SelectManyTransformer.cs b/Sources/Core/Microsoft.StreamProcessing/Operators/SelectMany/SelectManyTransformer.cs index 8332e3f9b..b5161f482 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/SelectMany/SelectManyTransformer.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/SelectMany/SelectManyTransformer.cs @@ -55,7 +55,7 @@ private SelectManyTemplate(string className, Type keyType, Type payloadType, Typ public static Tuple Generate(SelectManyStreamable stream) { - Contract.Ensures(Contract.Result>() == null || typeof(UnaryPipe).GetTypeInfo().IsAssignableFrom(Contract.Result>().Item1)); + Contract.Ensures(Contract.Result>() == null || typeof(UnaryPipe).IsAssignableFrom(Contract.Result>().Item1)); string generatedClassName; string expandedCode; @@ -165,14 +165,13 @@ public static Tuple Generate(SelectManySt expandedCode = template.TransformText(); var assemblyReferences = Transformer.AssemblyReferencesNeededFor(typeof(TKey), typeof(TPayload), typeof(TResult)); - assemblyReferences.Add(typeof(IStreamable<,>).GetTypeInfo().Assembly); + assemblyReferences.Add(typeof(IStreamable<,>).Assembly); assemblyReferences.Add(Transformer.GeneratedStreamMessageAssembly()); assemblyReferences.Add(Transformer.GeneratedStreamMessageAssembly()); assemblyReferences.Add(Transformer.GeneratedMemoryPoolAssembly()); assemblyReferences.AddRange(Transformer.AssemblyReferencesNeededFor(stream.Selector)); - var a = Transformer.CompileSourceCode(expandedCode, assemblyReferences, out errorMessages); - var t = a.GetType(generatedClassName); + var t = Transformer.CompileSourceCode(expandedCode, assemblyReferences, a => a.GetType(generatedClassName), out errorMessages); t = t.InstantiateAsNecessary(typeof(TKey), typeof(TPayload), typeof(TResult)); return Tuple.Create(t, errorMessages); } diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/SessionWindow/PartitionedSessionWindowPipe.cs b/Sources/Core/Microsoft.StreamProcessing/Operators/SessionWindow/PartitionedSessionWindowPipe.cs index 1fdf85f03..43834b4d1 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/SessionWindow/PartitionedSessionWindowPipe.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/SessionWindow/PartitionedSessionWindowPipe.cs @@ -26,13 +26,13 @@ internal sealed class PartitionedSessionWindowPipe output; - private Dictionary> orderedKeysDictionary = new Dictionary>(); + private Dictionary> orderedKeysDictionary = []; [DataMember] - private FastDictionary2 windowEndTimeDictionary = new FastDictionary2(); + private FastDictionary2 windowEndTimeDictionary = new(); [DataMember] - private FastDictionary2 lastDataTimeDictionary = new FastDictionary2(); + private FastDictionary2 lastDataTimeDictionary = new(); [DataMember] - private FastDictionary2> stateDictionary = new FastDictionary2>(); + private FastDictionary2> stateDictionary = new(); [Obsolete("Used only by serialization. Do not call directly.")] public PartitionedSessionWindowPipe() { } @@ -56,7 +56,7 @@ public override void ProduceQueryPlan(PlanNode previous) private void ReachTime(long timestamp) { - foreach (var pKey in this.orderedKeysDictionary.Keys) ReachTime(-1, timestamp, pKey); + foreach (var pKey in this.orderedKeysDictionary.Keys) this.ReachTime(-1, timestamp, pKey); } private void ReachTime(int pIndex, long timestamp, TPartitionKey pKey) @@ -86,7 +86,7 @@ private void ReachTime(int pIndex, long timestamp, TPartitionKey pKey) if (timestamp >= threshhold) { var queue = this.stateDictionary.entries[cIndex].value; - while (queue.Any()) + while (queue.Count != 0) { var active = queue.Dequeue(); @@ -97,7 +97,7 @@ private void ReachTime(int pIndex, long timestamp, TPartitionKey pKey) this.output[ind] = active.Payload; this.output.hash.col[ind] = active.Hash; - if (this.output.Count == Config.DataBatchSize) FlushContents(); + if (this.output.Count == Config.DataBatchSize) this.FlushContents(); } if (timestamp < this.lastDataTimeDictionary.entries[cIndex].value + this.sessionTimeout) this.windowEndTimeDictionary.entries[cIndex].value = StreamEvent.MaxSyncTime; @@ -138,20 +138,20 @@ public override unsafe void OnNext(StreamMessage batch) var partition = this.getPartitionKey(batch.key.col[i]); if (vsync[i] > vother[i]) // We have an end edge { - ReachTime(-1, vsync[i], partition); + this.ReachTime(-1, vsync[i], partition); } else { // Check to see if the key is already being tracked if (!this.lastDataTimeDictionary.Lookup(batch.key.col[i], out int keyIndex)) - keyIndex = AllocatePartition(batch.key.col[i], partition); - ReachTime(keyIndex, vsync[i], partition); + keyIndex = this.AllocatePartition(batch.key.col[i], partition); + this.ReachTime(keyIndex, vsync[i], partition); // Check to see if advancing time removed the key if (!this.lastDataTimeDictionary.Lookup(batch.key.col[i], out keyIndex)) - keyIndex = AllocatePartition(batch.key.col[i], partition); + keyIndex = this.AllocatePartition(batch.key.col[i], partition); - if (!this.stateDictionary.entries[keyIndex].value.Any()) + if (this.stateDictionary.entries[keyIndex].value.Count == 0) this.orderedKeysDictionary[partition].AddLast(new LinkedListNode(batch.key.col[i])); else { @@ -182,12 +182,12 @@ public override unsafe void OnNext(StreamMessage batch) this.output[ind] = batch.payload.col[i]; this.output.hash.col[ind] = hash[i]; - if (this.output.Count == Config.DataBatchSize) FlushContents(); + if (this.output.Count == Config.DataBatchSize) this.FlushContents(); } } else if (vother[i] == PartitionedStreamEvent.LowWatermarkOtherTime) { - ReachTime(vsync[i]); + this.ReachTime(vsync[i]); int ind = this.output.Count++; this.output.vsync.col[ind] = vsync[i]; @@ -197,17 +197,17 @@ public override unsafe void OnNext(StreamMessage batch) this.output.hash.col[ind] = 0; this.output.bitvector.col[ind >> 6] |= (1L << (ind & 0x3f)); - if (this.output.Count == Config.DataBatchSize) FlushContents(); + if (this.output.Count == Config.DataBatchSize) this.FlushContents(); } else if (vother[i] == PartitionedStreamEvent.PunctuationOtherTime) { var partition = this.getPartitionKey(batch.key.col[i]); if (!this.lastDataTimeDictionary.Lookup(batch.key.col[i], out int keyIndex)) { - keyIndex = AllocatePartition(batch.key.col[i], partition); + keyIndex = this.AllocatePartition(batch.key.col[i], partition); } - ReachTime(-1, vsync[i], partition); + this.ReachTime(-1, vsync[i], partition); int ind = this.output.Count++; this.output.vsync.col[ind] = vsync[i]; @@ -217,7 +217,7 @@ public override unsafe void OnNext(StreamMessage batch) this.output.hash.col[ind] = hash[i]; this.output.bitvector.col[ind >> 6] |= (1L << (ind & 0x3f)); - if (this.output.Count == Config.DataBatchSize) FlushContents(); + if (this.output.Count == Config.DataBatchSize) this.FlushContents(); } } } @@ -253,7 +253,7 @@ protected override void UpdatePointers() var temp = new List>(); while (this.lastDataTimeDictionary.Iterate(ref iter)) { - if (this.stateDictionary.entries[iter].value.Any()) + if (this.stateDictionary.entries[iter].value.Count != 0) { temp.Add(Tuple.Create( this.lastDataTimeDictionary.entries[iter].key, @@ -293,7 +293,7 @@ private struct ActiveEvent [DataMember] public long Sync; - public override string ToString() => "Key='" + this.Key + "', Payload='" + this.Payload; + public override readonly string ToString() => "Key='" + this.Key + "', Payload='" + this.Payload; } } } \ No newline at end of file diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/SessionWindow/SessionWindowPipe.cs b/Sources/Core/Microsoft.StreamProcessing/Operators/SessionWindow/SessionWindowPipe.cs index 57d64ee88..8f1657190 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/SessionWindow/SessionWindowPipe.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/SessionWindow/SessionWindowPipe.cs @@ -25,13 +25,13 @@ internal sealed class SessionWindowPipe : UnaryPipe output; - private LinkedList orderedKeys = new LinkedList(); + private LinkedList orderedKeys = new(); [DataMember] - private FastDictionary2 windowEndTimeDictionary = new FastDictionary2(); + private FastDictionary2 windowEndTimeDictionary = new(); [DataMember] - private FastDictionary2 lastDataTimeDictionary = new FastDictionary2(); + private FastDictionary2 lastDataTimeDictionary = new(); [DataMember] - private FastDictionary2> stateDictionary = new FastDictionary2>(); + private FastDictionary2> stateDictionary = new(); [Obsolete("Used only by serialization. Do not call directly.")] public SessionWindowPipe() { } @@ -78,7 +78,7 @@ private void ReachTime(int pIndex, long timestamp) if (timestamp >= threshold) { var queue = this.stateDictionary.entries[cIndex].value; - while (queue.Any()) + while (queue.Count != 0) { var active = queue.Dequeue(); @@ -89,7 +89,7 @@ private void ReachTime(int pIndex, long timestamp) this.output[ind] = active.Payload; this.output.hash.col[ind] = active.Hash; - if (this.output.Count == Config.DataBatchSize) FlushContents(); + if (this.output.Count == Config.DataBatchSize) this.FlushContents(); } if (timestamp < this.lastDataTimeDictionary.entries[cIndex].value + this.sessionTimeout) this.windowEndTimeDictionary.entries[cIndex].value = StreamEvent.MaxSyncTime; @@ -129,20 +129,20 @@ public override unsafe void OnNext(StreamMessage batch) { if (vsync[i] > vother[i]) // We have an end edge { - ReachTime(-1, vsync[i]); + this.ReachTime(-1, vsync[i]); } else { // Check to see if the key is already being tracked if (!this.lastDataTimeDictionary.Lookup(batch.key.col[i], out int keyIndex)) - keyIndex = AllocatePartition(batch.key.col[i]); - ReachTime(keyIndex, vsync[i]); + keyIndex = this.AllocatePartition(batch.key.col[i]); + this.ReachTime(keyIndex, vsync[i]); // Check to see if advancing time removed the key if (!this.lastDataTimeDictionary.Lookup(batch.key.col[i], out keyIndex)) - keyIndex = AllocatePartition(batch.key.col[i]); + keyIndex = this.AllocatePartition(batch.key.col[i]); - if (!this.stateDictionary.entries[keyIndex].value.Any()) + if (this.stateDictionary.entries[keyIndex].value.Count == 0) this.orderedKeys.AddLast(new LinkedListNode(batch.key.col[i])); else { @@ -172,12 +172,12 @@ public override unsafe void OnNext(StreamMessage batch) this.output[ind] = batch.payload.col[i]; this.output.hash.col[ind] = hash[i]; - if (this.output.Count == Config.DataBatchSize) FlushContents(); + if (this.output.Count == Config.DataBatchSize) this.FlushContents(); } } else if (vother[i] == long.MinValue) { - ReachTime(-1, vsync[i]); + this.ReachTime(-1, vsync[i]); int ind = this.output.Count++; this.output.vsync.col[ind] = vsync[i]; @@ -187,7 +187,7 @@ public override unsafe void OnNext(StreamMessage batch) this.output.hash.col[ind] = hash[i]; this.output.bitvector.col[ind >> 6] |= (1L << (ind & 0x3f)); - if (this.output.Count == Config.DataBatchSize) FlushContents(); + if (this.output.Count == Config.DataBatchSize) this.FlushContents(); } } } @@ -223,7 +223,7 @@ protected override void UpdatePointers() var temp = new List>(); while (this.lastDataTimeDictionary.Iterate(ref iter)) { - if (this.stateDictionary.entries[iter].value.Any()) + if (this.stateDictionary.entries[iter].value.Count != 0) { temp.Add(Tuple.Create( this.windowEndTimeDictionary.entries[iter].key, @@ -254,7 +254,7 @@ private struct ActiveEvent [DataMember] public long Sync; - public override string ToString() => "Key='" + this.Key + "', Payload='" + this.Payload; + public override readonly string ToString() => "Key='" + this.Key + "', Payload='" + this.Payload; } } } \ No newline at end of file diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/SessionWindow/SessionWindowPipeStateless.cs b/Sources/Core/Microsoft.StreamProcessing/Operators/SessionWindow/SessionWindowPipeStateless.cs index 0d15f0d9e..a4b95e1a3 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/SessionWindow/SessionWindowPipeStateless.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/SessionWindow/SessionWindowPipeStateless.cs @@ -23,7 +23,7 @@ internal sealed class SessionWindowPipeStateless : UnaryPipe> batches = new Queue>(); + private Queue> batches = new(); [DataMember] private int windowStartIdx = 0; @@ -74,18 +74,18 @@ public override unsafe void OnNext(StreamMessage batch) if (vsync[i] > vother[i]) // We have an end edge { bv[i >> 6] |= (1L << (i & 0x3f)); - ReachTime(vsync[i], false); + this.ReachTime(vsync[i], false); } else { - ReachTime(vsync[i], true); + this.ReachTime(vsync[i], true); this.lastDataTime = vsync[i]; } } else if (vother[i] == long.MinValue) { - ReachTime(vsync[i], false); + this.ReachTime(vsync[i], false); } } } @@ -122,7 +122,7 @@ private unsafe void ReachTime(long timestamp, bool isData) if (timestamp >= threshold) { StreamMessage batch; - while (this.batches.Any()) + while (this.batches.Count != 0) { batch = this.batches.Peek(); diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/SessionWindow/SessionWindowStreamable.cs b/Sources/Core/Microsoft.StreamProcessing/Operators/SessionWindow/SessionWindowStreamable.cs index 4b444a73d..564105672 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/SessionWindow/SessionWindowStreamable.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/SessionWindow/SessionWindowStreamable.cs @@ -11,7 +11,7 @@ namespace Microsoft.StreamProcessing internal sealed class SessionWindowStreamable : UnaryStreamable { private static readonly SafeConcurrentDictionary> cachedPipes - = new SafeConcurrentDictionary>(); + = new(); private readonly long sessionTimeout; private readonly long maximumDuration; @@ -24,7 +24,7 @@ public SessionWindowStreamable(IStreamable source, long sessionT this.sessionTimeout = sessionTimeout; this.maximumDuration = maximumDuration; - Initialize(); + this.Initialize(); } internal override IStreamObserver CreatePipe(IStreamObserver observer) @@ -32,7 +32,7 @@ internal override IStreamObserver CreatePipe(IStreamObserver(this, observer, this.sessionTimeout, this.maximumDuration); else diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/SessionWindow/SessionWindowTransformer.cs b/Sources/Core/Microsoft.StreamProcessing/Operators/SessionWindow/SessionWindowTransformer.cs index 62d7136fb..8393237c2 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/SessionWindow/SessionWindowTransformer.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/SessionWindow/SessionWindowTransformer.cs @@ -3,6 +3,9 @@ // Licensed under the MIT License // ********************************************************************* using System; +#if CODEGEN_TIMING +using System.Diagnostics; +#endif using System.Diagnostics.Contracts; using System.Reflection; @@ -27,8 +30,8 @@ private SessionWindowTemplate(string className, Type keyType, Type payloadType) /// internal static Tuple Generate(SessionWindowStreamable stream) { - Contract.Requires(stream != null); - Contract.Ensures(Contract.Result>() == null || typeof(UnaryPipe).GetTypeInfo().IsAssignableFrom(Contract.Result>().Item1)); + ArgumentNullException.ThrowIfNull(stream); + Contract.Ensures(Contract.Result>() == null || typeof(UnaryPipe).IsAssignableFrom(Contract.Result>().Item1)); #if CODEGEN_TIMING Stopwatch sw = new Stopwatch(); diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/Shuffle/ShufflePipe.cs b/Sources/Core/Microsoft.StreamProcessing/Operators/Shuffle/ShufflePipe.cs index f96d0328c..8023e7de8 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/Shuffle/ShufflePipe.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/Shuffle/ShufflePipe.cs @@ -56,7 +56,7 @@ public PartitionedShuffleNestedPipe( this.errorMessages = stream.ErrorMessages; this.l1Pool = MemoryManager.GetMemoryPool, TSource>(stream.Properties.IsColumnar); - this.Observers = new List, TSource>>(); + this.Observers = []; this.batches = new StreamMessage, TSource>[totalBranchesL2]; for (int i = 0; i < totalBranchesL2; i++) @@ -71,7 +71,7 @@ public PartitionedShuffleNestedPipe( public override void OnFlush() { - FlushContents(); + this.FlushContents(); for (int j = 0; j < this.totalBranchesL2; j++) { this.Observers[j].OnFlush(); @@ -363,7 +363,7 @@ public ShuffleNestedPipe( this.errorMessages = stream.ErrorMessages; this.l1Pool = MemoryManager.GetMemoryPool, TSource>(stream.Properties.IsColumnar); - this.Observers = new List, TSource>>(); + this.Observers = []; this.batches = new StreamMessage, TSource>[totalBranchesL2]; for (int i = 0; i < totalBranchesL2; i++) @@ -378,7 +378,7 @@ public ShuffleNestedPipe( public override void OnFlush() { - FlushContents(); + this.FlushContents(); for (int j = 0; j < this.totalBranchesL2; j++) { this.Observers[j].OnFlush(); @@ -652,7 +652,7 @@ public ShufflePipe( this.errorMessages = stream.ErrorMessages; this.l1Pool = MemoryManager.GetMemoryPool(stream.Properties.IsColumnar); - this.Observers = new List>(); + this.Observers = []; this.batches = new StreamMessage[totalBranchesL2]; for (int i = 0; i < totalBranchesL2; i++) @@ -667,7 +667,7 @@ public ShufflePipe( public override void OnFlush() { - FlushContents(); + this.FlushContents(); for (int j = 0; j < this.totalBranchesL2; j++) { this.Observers[j].OnFlush(); @@ -926,7 +926,7 @@ public ShuffleSameKeyPipe( this.errorMessages = stream.ErrorMessages; this.l1Pool = MemoryManager.GetMemoryPool(stream.Properties.IsColumnar); - this.Observers = new List>(); + this.Observers = []; this.batches = new StreamMessage[totalBranchesL2]; for (int i = 0; i < totalBranchesL2; i++) @@ -941,7 +941,7 @@ public ShuffleSameKeyPipe( public override void OnFlush() { - FlushContents(); + this.FlushContents(); for (int j = 0; j < this.totalBranchesL2; j++) { this.Observers[j].OnFlush(); diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/Shuffle/ShuffleStreamable.cs b/Sources/Core/Microsoft.StreamProcessing/Operators/Shuffle/ShuffleStreamable.cs index 9075041ac..3911903f0 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/Shuffle/ShuffleStreamable.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/Shuffle/ShuffleStreamable.cs @@ -12,7 +12,7 @@ namespace Microsoft.StreamProcessing internal sealed class ShuffleNestedStreamable : Streamable, TSource> { private static readonly SafeConcurrentDictionary> cachedPipes - = new SafeConcurrentDictionary>(); + = new(); [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes", Justification = "Used to avoid creating redundant readonly property.")] public readonly Expression> KeySelector; @@ -30,20 +30,20 @@ public ShuffleNestedStreamable( int shuffleId) : base(source.Properties.GroupNested(keySelector)) { - Contract.Requires(source != null); - Contract.Requires(keySelector != null); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(keySelector); Contract.Requires(totalBranchesL2 > 0); - Source = source; - KeySelector = keySelector; + this.Source = source; + this.KeySelector = keySelector; this.totalBranchesL2 = totalBranchesL2; this.shuffleId = shuffleId; - powerOf2 = ((totalBranchesL2 & (totalBranchesL2 - 1)) == 0); + this.powerOf2 = ((totalBranchesL2 & (totalBranchesL2 - 1)) == 0); if (totalBranchesL2 <= 1) { - singleThreadedShuffler = new GroupNestedStreamable(source, keySelector); - this.properties = singleThreadedShuffler.Properties; + this.singleThreadedShuffler = new GroupNestedStreamable(source, keySelector); + this.properties = this.singleThreadedShuffler.Properties; } } @@ -52,35 +52,35 @@ public ShuffleNestedStreamable( public override IDisposable Subscribe(IStreamObserver, TSource> observer) { - if (totalBranchesL2 <= 1) + if (this.totalBranchesL2 <= 1) { - return singleThreadedShuffler.Subscribe(observer); + return this.singleThreadedShuffler.Subscribe(observer); } - numBranches++; - if (pipe == null) + this.numBranches++; + if (this.pipe == null) { - if (this.Properties.IsColumnar && CanGenerateColumnar()) pipe = GetPipe(observer, totalBranchesL2, shuffleId); - else pipe = CreatePipe(observer); + if (this.Properties.IsColumnar && this.CanGenerateColumnar()) this.pipe = this.GetPipe(observer, this.totalBranchesL2, this.shuffleId); + else this.pipe = this.CreatePipe(observer); } var o = observer; - pipe.AddObserver(o); + this.pipe.AddObserver(o); var d = o as IDisposable; - if (numBranches < totalBranchesL2) + if (this.numBranches < this.totalBranchesL2) { return d ?? Utility.EmptyDisposable; } else { // Reset status for next set of subscribe calls - var oldpipe = pipe; - pipe = null; - numBranches = 0; + var oldpipe = this.pipe; + this.pipe = null; + this.numBranches = 0; return d == null - ? Source.Subscribe(oldpipe) - : Utility.CreateDisposable(Source.Subscribe(oldpipe), d); + ? this.Source.Subscribe(oldpipe) + : Utility.CreateDisposable(this.Source.Subscribe(oldpipe), d); } } @@ -88,8 +88,8 @@ private IStreamObserverAndNestedGroupedStreamObservable, TSource> observer) { if (typeof(TOuterKey).GetPartitionType() == null) - return new ShuffleNestedPipe(this, observer, totalBranchesL2, shuffleId); - return new PartitionedShuffleNestedPipe(this, observer, totalBranchesL2, shuffleId); + return new ShuffleNestedPipe(this, observer, this.totalBranchesL2, this.shuffleId); + return new PartitionedShuffleNestedPipe(this, observer, this.totalBranchesL2, this.shuffleId); } private bool CanGenerateColumnar() @@ -102,7 +102,7 @@ private bool CanGenerateColumnar() if (typeOfTOuterKey.GetPartitionType() != null) return false; if (typeOfTInnerKey.GetPartitionType() != null) return false; - var keyEqComparer = Properties.KeyEqualityComparer; + var keyEqComparer = this.Properties.KeyEqualityComparer; string inlinedHashCodeComputation; if (keyEqComparer is CompoundGroupKeyEqualityComparer comparer) { @@ -114,16 +114,16 @@ private bool CanGenerateColumnar() inlinedHashCodeComputation = keyEqComparer.GetGetHashCodeExpr().Inline("key"); } - var lookupKey = CacheKey.Create(KeySelector.ToString(), inlinedHashCodeComputation, powerOf2); + var lookupKey = CacheKey.Create(this.KeySelector.ToString(), inlinedHashCodeComputation, this.powerOf2); var generatedPipeType = cachedPipes.GetOrAdd(lookupKey, key => ShuffleTemplate.Generate(this.KeySelector, inlinedHashCodeComputation, true, this.powerOf2)); - errorMessages = generatedPipeType.Item2; + this.errorMessages = generatedPipeType.Item2; return generatedPipeType.Item1 != null; } private IStreamObserverAndNestedGroupedStreamObservable GetPipe(IStreamObserver, TSource> observer, int totalBranchesL2, int shuffleId) { - var keyEqComparer = Properties.KeyEqualityComparer; + var keyEqComparer = this.Properties.KeyEqualityComparer; string inlinedHashCodeComputation; if (keyEqComparer is CompoundGroupKeyEqualityComparer comparer) { @@ -135,7 +135,7 @@ private IStreamObserverAndNestedGroupedStreamObservable ShuffleTemplate.Generate(this.KeySelector, inlinedHashCodeComputation, true, this.powerOf2)); Func planNode = ((PlanNode p, IQueryObject o) => new GroupPlanNode( @@ -160,7 +160,7 @@ private IStreamObserverAndNestedGroupedStreamObservable : Streamable { private static readonly SafeConcurrentDictionary> cachedPipes - = new SafeConcurrentDictionary>(); + = new(); [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes", Justification = "Used to avoid creating redundant readonly property.")] public readonly Expression> KeySelector; @@ -178,20 +178,20 @@ public ShuffleStreamable( int shuffleId) : base(source.Properties.Group(keySelector)) { - Contract.Requires(source != null); - Contract.Requires(keySelector != null); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(keySelector); Contract.Requires(totalBranchesL2 > 0); - Source = source; - KeySelector = keySelector; + this.Source = source; + this.KeySelector = keySelector; this.totalBranchesL2 = totalBranchesL2; this.shuffleId = shuffleId; - powerOf2 = ((totalBranchesL2 & (totalBranchesL2 - 1)) == 0); + this.powerOf2 = ((totalBranchesL2 & (totalBranchesL2 - 1)) == 0); if (totalBranchesL2 <= 1) { - singleThreadedShuffler = new GroupStreamable(source, keySelector); - this.properties = singleThreadedShuffler.Properties; + this.singleThreadedShuffler = new GroupStreamable(source, keySelector); + this.properties = this.singleThreadedShuffler.Properties; } } @@ -200,42 +200,42 @@ public ShuffleStreamable( public override IDisposable Subscribe(IStreamObserver observer) { - if (totalBranchesL2 <= 1) + if (this.totalBranchesL2 <= 1) { - return singleThreadedShuffler.Subscribe(observer); + return this.singleThreadedShuffler.Subscribe(observer); } - numBranches++; - if (pipe == null) + this.numBranches++; + if (this.pipe == null) { - if (this.Properties.IsColumnar && CanGenerateColumnar()) pipe = GetPipe(observer, totalBranchesL2, shuffleId); - else pipe = CreatePipe(observer); + if (this.Properties.IsColumnar && this.CanGenerateColumnar()) this.pipe = this.GetPipe(observer, this.totalBranchesL2, this.shuffleId); + else this.pipe = this.CreatePipe(observer); } var o = observer; - pipe.AddObserver(o); + this.pipe.AddObserver(o); var d = o as IDisposable; - if (numBranches < totalBranchesL2) + if (this.numBranches < this.totalBranchesL2) { return d ?? Utility.EmptyDisposable; } else { // Reset status for next set of subscribe calls - var oldpipe = pipe; - pipe = null; - numBranches = 0; + var oldpipe = this.pipe; + this.pipe = null; + this.numBranches = 0; return d == null - ? Source.Subscribe(oldpipe) - : Utility.CreateDisposable(Source.Subscribe(oldpipe), d); + ? this.Source.Subscribe(oldpipe) + : Utility.CreateDisposable(this.Source.Subscribe(oldpipe), d); } } private IStreamObserverAndGroupedStreamObservable CreatePipe( IStreamObserver observer) { - return new ShufflePipe(this, observer, totalBranchesL2, shuffleId); + return new ShufflePipe(this, observer, this.totalBranchesL2, this.shuffleId); } private bool CanGenerateColumnar() @@ -248,7 +248,7 @@ private bool CanGenerateColumnar() if (typeOfTOuterKey.GetPartitionType() != null) return false; if (typeOfTInnerKey.GetPartitionType() != null) return false; - var keyEqComparer = Properties.KeyEqualityComparer; + var keyEqComparer = this.Properties.KeyEqualityComparer; string inlinedHashCodeComputation; if (keyEqComparer is CompoundGroupKeyEqualityComparer comparer) { @@ -260,16 +260,16 @@ private bool CanGenerateColumnar() inlinedHashCodeComputation = keyEqComparer.GetGetHashCodeExpr().Inline("key"); } - var lookupKey = CacheKey.Create(KeySelector.ToString(), inlinedHashCodeComputation, powerOf2); + var lookupKey = CacheKey.Create(this.KeySelector.ToString(), inlinedHashCodeComputation, this.powerOf2); var generatedPipeType = cachedPipes.GetOrAdd(lookupKey, key => ShuffleTemplate.Generate(this.KeySelector, inlinedHashCodeComputation, false, this.powerOf2)); - errorMessages = generatedPipeType.Item2; + this.errorMessages = generatedPipeType.Item2; return generatedPipeType.Item1 != null; } private IStreamObserverAndGroupedStreamObservable GetPipe(IStreamObserver observer, int totalBranchesL2, int shuffleId) { - var keyEqComparer = Properties.KeyEqualityComparer; + var keyEqComparer = this.Properties.KeyEqualityComparer; string inlinedHashCodeComputation; if (keyEqComparer is CompoundGroupKeyEqualityComparer comparer) { @@ -281,7 +281,7 @@ private IStreamObserverAndGroupedStreamObservable inlinedHashCodeComputation = keyEqComparer.GetGetHashCodeExpr().Inline("key"); } - var lookupKey = CacheKey.Create(KeySelector.ToString(), inlinedHashCodeComputation, powerOf2); + var lookupKey = CacheKey.Create(this.KeySelector.ToString(), inlinedHashCodeComputation, this.powerOf2); var generatedPipeType = cachedPipes.GetOrAdd(lookupKey, key => ShuffleTemplate.Generate(this.KeySelector, inlinedHashCodeComputation, false, this.powerOf2)); Func planNode = ((PlanNode p, IQueryObject o) => new GroupPlanNode( @@ -306,7 +306,7 @@ private IStreamObserverAndGroupedStreamObservable internal sealed class ShuffleSameKeyStreamable : Streamable { private static readonly SafeConcurrentDictionary> cachedPipes - = new SafeConcurrentDictionary>(); + = new(); [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes", Justification = "Used to avoid creating redundant readonly property.")] public readonly IStreamable Source; @@ -321,13 +321,13 @@ public ShuffleSameKeyStreamable( int shuffleId) : base(source.Properties) { - Contract.Requires(source != null); + ArgumentNullException.ThrowIfNull(source); Contract.Requires(totalBranchesL2 > 0); - Source = source; + this.Source = source; this.totalBranchesL2 = totalBranchesL2; this.shuffleId = shuffleId; - powerOf2 = ((totalBranchesL2 & (totalBranchesL2 - 1)) == 0); + this.powerOf2 = ((totalBranchesL2 & (totalBranchesL2 - 1)) == 0); } @@ -336,42 +336,42 @@ public ShuffleSameKeyStreamable( public override IDisposable Subscribe(IStreamObserver observer) { - if (totalBranchesL2 <= 1) + if (this.totalBranchesL2 <= 1) { - return Source.Subscribe(observer); + return this.Source.Subscribe(observer); } - numBranches++; - if (pipe == null) + this.numBranches++; + if (this.pipe == null) { - if (this.Properties.IsColumnar && CanGenerateColumnar()) pipe = GetPipe(observer, totalBranchesL2, shuffleId); - else pipe = CreatePipe(observer); + if (this.Properties.IsColumnar && this.CanGenerateColumnar()) this.pipe = this.GetPipe(observer, this.totalBranchesL2, this.shuffleId); + else this.pipe = this.CreatePipe(observer); } var o = observer; - pipe.AddObserver(o); + this.pipe.AddObserver(o); var d = o as IDisposable; - if (numBranches < totalBranchesL2) + if (this.numBranches < this.totalBranchesL2) { return d ?? Utility.EmptyDisposable; } else { // Reset status for next set of subscribe calls - var oldpipe = pipe; - pipe = null; - numBranches = 0; + var oldpipe = this.pipe; + this.pipe = null; + this.numBranches = 0; return d == null - ? Source.Subscribe(oldpipe) - : Utility.CreateDisposable(Source.Subscribe(oldpipe), d); + ? this.Source.Subscribe(oldpipe) + : Utility.CreateDisposable(this.Source.Subscribe(oldpipe), d); } } private IStreamObserverAndSameKeyGroupedStreamObservable CreatePipe( IStreamObserver observer) { - return new ShuffleSameKeyPipe(this, observer, totalBranchesL2, shuffleId); + return new ShuffleSameKeyPipe(this, observer, this.totalBranchesL2, this.shuffleId); } private bool CanGenerateColumnar() @@ -384,7 +384,7 @@ private bool CanGenerateColumnar() if (typeOfTOuterKey.GetPartitionType() != null) return false; if (typeOfTInnerKey.GetPartitionType() != null) return false; - var keyEqComparer = Properties.KeyEqualityComparer; + var keyEqComparer = this.Properties.KeyEqualityComparer; string inlinedHashCodeComputation; if (keyEqComparer is CompoundGroupKeyEqualityComparer comparer) { @@ -396,16 +396,16 @@ private bool CanGenerateColumnar() inlinedHashCodeComputation = keyEqComparer.GetGetHashCodeExpr().Inline("key"); } - var lookupKey = CacheKey.Create(inlinedHashCodeComputation, powerOf2); + var lookupKey = CacheKey.Create(inlinedHashCodeComputation, this.powerOf2); var generatedPipeType = cachedPipes.GetOrAdd(lookupKey, key => ShuffleTemplate.Generate(null, inlinedHashCodeComputation, false, this.powerOf2)); - errorMessages = generatedPipeType.Item2; + this.errorMessages = generatedPipeType.Item2; return generatedPipeType.Item1 != null; } private IStreamObserverAndSameKeyGroupedStreamObservable GetPipe(IStreamObserver observer, int totalBranchesL2, int shuffleId) { - var keyEqComparer = Properties.KeyEqualityComparer; + var keyEqComparer = this.Properties.KeyEqualityComparer; string inlinedHashCodeComputation; if (keyEqComparer is CompoundGroupKeyEqualityComparer comparer) { @@ -417,7 +417,7 @@ private IStreamObserverAndSameKeyGroupedStreamObservable ShuffleTemplate.Generate(null, inlinedHashCodeComputation, false, this.powerOf2)); Func planNode = ((PlanNode p, IQueryObject o) => new GroupPlanNode( diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/Shuffle/ShuffleStreamable.tt b/Sources/Core/Microsoft.StreamProcessing/Operators/Shuffle/ShuffleStreamable.tt index c9d5eb604..c7d69a990 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/Shuffle/ShuffleStreamable.tt +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/Shuffle/ShuffleStreamable.tt @@ -55,9 +55,9 @@ else { #> : base(source.Properties) <# } #> { - Contract.Requires(source != null); + ArgumentNullException.ThrowIfNull(source); <# if (i < 2) { #> - Contract.Requires(keySelector != null); + ArgumentNullException.ThrowIfNull(keySelector); <# } #> Contract.Requires(totalBranchesL2 > 0); diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/Shuffle/ShuffleTransformer.cs b/Sources/Core/Microsoft.StreamProcessing/Operators/Shuffle/ShuffleTransformer.cs index 43370cb0c..670a4e579 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/Shuffle/ShuffleTransformer.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/Shuffle/ShuffleTransformer.cs @@ -40,10 +40,10 @@ public ShuffleTemplate( string inlinedHashCodeComputation, bool nested, bool powerOf2) : base(className) { - Contract.Requires(className != null); - Contract.Requires(outerKeyType != null); - Contract.Requires(sourceType != null); - Contract.Requires(innerKeyType != null); + ArgumentNullException.ThrowIfNull(className); + ArgumentNullException.ThrowIfNull(outerKeyType); + ArgumentNullException.ThrowIfNull(sourceType); + ArgumentNullException.ThrowIfNull(innerKeyType); this.inlinedHashCodeComputation = inlinedHashCodeComputation; this.isFirstLevelGroup = !nested; @@ -126,7 +126,7 @@ public static Tuple Generate( var expandedCode = template.TransformText(); var assemblyReferences = Transformer.AssemblyReferencesNeededFor(typeOfTOuterKey, typeOfTSource, typeOfTInnerKey); - assemblyReferences.Add(typeof(IStreamable<,>).GetTypeInfo().Assembly); + assemblyReferences.Add(typeof(IStreamable<,>).Assembly); assemblyReferences.Add(Transformer.GeneratedStreamMessageAssembly()); if (nested) { @@ -140,15 +140,13 @@ public static Tuple Generate( } assemblyReferences.AddRange(Transformer.AssemblyReferencesNeededFor(keySelector)); - var a = Transformer.CompileSourceCode(expandedCode, assemblyReferences, out errorMessages); + generatedClassName = generatedClassName.AddNumberOfNecessaryGenericArguments(typeOfTOuterKey, typeOfTSource, typeOfTInnerKey); + var t = Transformer.CompileSourceCode(expandedCode, assemblyReferences, a => a.GetType(generatedClassName), out errorMessages); if (typeOfTInnerKey.IsAnonymousTypeName()) { - if (errorMessages == null) errorMessages = string.Empty; + errorMessages ??= string.Empty; errorMessages += "\nCodegen Warning: The inner key type for Shuffle is anonymous, causing the use of Activator.CreateInstance in an inner loop. This will lead to poor performance.\n"; } - - generatedClassName = generatedClassName.AddNumberOfNecessaryGenericArguments(typeOfTOuterKey, typeOfTSource, typeOfTInnerKey); - var t = a.GetType(generatedClassName); return Tuple.Create(t.InstantiateAsNecessary(typeOfTOuterKey, typeOfTSource, typeOfTInnerKey), errorMessages); } catch diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/Shufflecast/ShufflecastPipe.cs b/Sources/Core/Microsoft.StreamProcessing/Operators/Shufflecast/ShufflecastPipe.cs index 5ed3ef894..3c696354f 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/Shufflecast/ShufflecastPipe.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/Shufflecast/ShufflecastPipe.cs @@ -47,7 +47,7 @@ public ShufflecastPipe( this.l1Pool = MemoryManager.GetMemoryPool(stream.Properties.IsColumnar); this.l1Pool.GetBV(out this.resetBV); for (int i = 0; i < this.resetBV.col.Length; i++) this.resetBV.col[i] = ~0; - this.Observers = new List>(); + this.Observers = []; } public void AddObserver(IStreamObserver observer) => this.Observers.Add(observer); @@ -93,7 +93,7 @@ public unsafe void OnNext(StreamMessage batch) { if (batch.vother.col[i] < 0) { - AddPunctuationOrLowWatermarkToAllBatches( + this.AddPunctuationOrLowWatermarkToAllBatches( batches, batch.vsync.col[i], batch.vother.col[i], batch.key.col[i], batch.hash.col[i]); } @@ -114,7 +114,7 @@ public unsafe void OnNext(StreamMessage batch) { if (batch.vother.col[i] < 0) { - AddPunctuationOrLowWatermarkToAllBatches( + this.AddPunctuationOrLowWatermarkToAllBatches( batches, batch.vsync.col[i], batch.vother.col[i], batch.key.col[i], batch.hash.col[i]); } @@ -136,7 +136,7 @@ public unsafe void OnNext(StreamMessage batch) { if (batch.vother.col[i] < 0) { - AddPunctuationOrLowWatermarkToAllBatches( + this.AddPunctuationOrLowWatermarkToAllBatches( batches, batch.vsync.col[i], batch.vother.col[i], batch.key.col[i], batch.hash.col[i]); } diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/Shufflecast/ShufflecastStreamable.cs b/Sources/Core/Microsoft.StreamProcessing/Operators/Shufflecast/ShufflecastStreamable.cs index 6ad7ee93e..d71989599 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/Shufflecast/ShufflecastStreamable.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/Shufflecast/ShufflecastStreamable.cs @@ -24,7 +24,7 @@ public ShufflecastStreamable( Expression> destinationSelector = null) : base(source.Properties) { - Contract.Requires(source != null); + ArgumentNullException.ThrowIfNull(source); Contract.Requires(totalBranchesL2 > 0); this.Source = source; @@ -50,7 +50,7 @@ public override IDisposable Subscribe(IStreamObserver observ this.numBranches++; if (this.pipe == null) { - this.pipe = CreatePipe(observer); + this.pipe = this.CreatePipe(observer); } var o = observer; this.pipe.AddObserver(o); diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/SnapshotWindow/AggregateTempateClasses.cs b/Sources/Core/Microsoft.StreamProcessing/Operators/SnapshotWindow/AggregateTempateClasses.cs index 1bbf7a97a..42e32607a 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/SnapshotWindow/AggregateTempateClasses.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/SnapshotWindow/AggregateTempateClasses.cs @@ -42,8 +42,8 @@ protected AggregateTemplate(string className) : base(className) { } public static Tuple Generate(SnapshotWindowStreamable stream, AggregatePipeType pipeType) { - Contract.Requires(stream != null); - Contract.Ensures(Contract.Result>() == null || typeof(IStreamObserver).GetTypeInfo().IsAssignableFrom(Contract.Result>().Item1)); + ArgumentNullException.ThrowIfNull(stream); + Contract.Ensures(Contract.Result>() == null || typeof(IStreamObserver).IsAssignableFrom(Contract.Result>().Item1)); var container = stream.Properties.QueryContainer; string generatedClassName = string.Format("Aggregate_{0}", sequenceNumber++); @@ -88,7 +88,7 @@ public static Tuple Generate(Snapsh template.outputFields = new ColumnarRepresentation(outputType).AllFields; - assemblyReferences = new List(); + assemblyReferences = []; #region Key Comparer IEqualityComparerExpression keyComparer; @@ -241,20 +241,19 @@ public static Tuple Generate(Snapsh expandedCode = template.TransformText(); assemblyReferences.AddRange(Transformer.AssemblyReferencesNeededFor(typeof(TKey), typeof(TInput), typeof(TState), typeof(TOutput), typeof(FastDictionaryGenerator), typeof(SortedDictionary<,>))); - assemblyReferences.Add(typeof(IStreamable<,>).GetTypeInfo().Assembly); + assemblyReferences.Add(typeof(IStreamable<,>).Assembly); assemblyReferences.Add(Transformer.GeneratedStreamMessageAssembly()); assemblyReferences.Add(Transformer.GeneratedStreamMessageAssembly()); assemblyReferences.Add(Transformer.GeneratedMemoryPoolAssembly()); - if (container != null) assemblyReferences.AddRange(container.CollectedGeneratedTypes.Select(o => o.GetTypeInfo().Assembly)); + if (container != null) assemblyReferences.AddRange(container.CollectedGeneratedTypes.Select(o => o.Assembly)); - var a = Transformer.CompileSourceCode(expandedCode, assemblyReferences, out errorMessages); + var t = Transformer.CompileSourceCode(expandedCode, assemblyReferences, a => a.GetType(generatedClassName), out errorMessages); if (keyType.IsAnonymousType()) { - if (errorMessages == null) errorMessages = string.Empty; + errorMessages ??= string.Empty; errorMessages += "\nCodegen Warning: The key type for an aggregate is an anonymous type (or contains an anonymous type), preventing the inlining of the key equality and hashcode functions. This may lead to poor performance.\n"; } - var t = a.GetType(generatedClassName); - if (t.GetTypeInfo().IsGenericType) + if (t.IsGenericType) { var list = typeof(TKey).GetAnonymousTypes(); list.AddRange(typeof(TInput).GetAnonymousTypes()); @@ -280,7 +279,7 @@ public static Tuple Generate(Snapsh /// private static Expression/*?*/ Transform(NewExpression newExpression, Type outputBatchType) { - Contract.Requires(newExpression != null); + ArgumentNullException.ThrowIfNull(newExpression); Contract.Assume(newExpression != null && newExpression.Type.IsAnonymousType()); Contract.Assume(newExpression.Arguments != null); @@ -290,7 +289,7 @@ public static Tuple Generate(Snapsh var assignments = new List(); var indexVariable = Expression.Variable(typeof(int), "c"); var batch = Expression.Variable(outputBatchType, "batch"); - var outputFields = outputBatchType.GetTypeInfo().GetFields(); + var outputFields = outputBatchType.GetFields(); if (outputFields == null || outputFields.Length == 0) return null; // can this really happen? for (int i = 0; i < newExpression.Arguments.Count; i++) { @@ -302,7 +301,7 @@ public static Tuple Generate(Snapsh if (columnBatchField == null) return null; // this also should be an error, shouldn't be able to happen. var columnBatch = Expression.MakeMemberAccess(batch, columnBatchField); var columnBatchType = typeof(ColumnBatch<>).MakeGenericType(destinationField.PropertyType); - var arrayInColumnBatch = Expression.MakeMemberAccess(columnBatch, columnBatchType.GetTypeInfo().GetField("col")); + var arrayInColumnBatch = Expression.MakeMemberAccess(columnBatch, columnBatchType.GetField("col")); var lhs = Expression.ArrayAccess(arrayInColumnBatch, indexVariable); var assign = Expression.Assign(lhs, argument); assignments.Add(assign); diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/SnapshotWindow/Hopping/PartitionedSnapshotWindowHoppingPipe.cs b/Sources/Core/Microsoft.StreamProcessing/Operators/SnapshotWindow/Hopping/PartitionedSnapshotWindowHoppingPipe.cs index 7f8bd7ab9..b4c837b8a 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/SnapshotWindow/Hopping/PartitionedSnapshotWindowHoppingPipe.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/SnapshotWindow/Hopping/PartitionedSnapshotWindowHoppingPipe.cs @@ -20,7 +20,7 @@ namespace Microsoft.StreamProcessing [DataContract] internal sealed class PartitionedSnapshotWindowHoppingPipe : UnaryPipe { - private static readonly bool hasDisposableState = typeof(IDisposable).GetTypeInfo().IsAssignableFrom(typeof(TState)); + private static readonly bool hasDisposableState = typeof(IDisposable).IsAssignableFrom(typeof(TState)); private readonly int hopsPerDuration; private readonly MemoryPool pool; private readonly DataStructurePool>> ecqEntryPool; @@ -55,7 +55,7 @@ internal sealed class PartitionedSnapshotWindowHoppingPipe> aggregateByKey; [DataMember] - private FastDictionary2 partitionData = new FastDictionary2(); + private FastDictionary2 partitionData = new(); private readonly Func getPartitionKey = GetPartitionExtractor(); @@ -92,7 +92,7 @@ public PartitionedSnapshotWindowHoppingPipe( this.aggregateByKey = comparer.CreateFastDictionary2Generator>(1, this.keyComparerEquals, this.keyComparerGetHashCode, stream.Properties.QueryContainer).Invoke(); var stateDictGenerator = comparer.CreateFastDictionaryGenerator>(1, this.keyComparerEquals, this.keyComparerGetHashCode, stream.Properties.QueryContainer); - this.ecqEntryPool = new DataStructurePool>>(() => stateDictGenerator.Invoke()); + this.ecqEntryPool = new DataStructurePool>>(stateDictGenerator.Invoke); this.hopsPerDuration = (int)(stream.Source.Properties.ConstantDurationLength.Value / stream.Source.Properties.ConstantHopLength) + 1; } @@ -120,7 +120,7 @@ public override unsafe void OnNext(StreamMessage batch) { if (col_vother[i] == PartitionedStreamEvent.LowWatermarkOtherTime) { - OnLowWatermark(col_vsync[i]); + this.OnLowWatermark(col_vsync[i]); int c = this.batch.Count; this.batch.vsync.col[c] = col_vsync[i]; @@ -129,7 +129,7 @@ public override unsafe void OnNext(StreamMessage batch) this.batch.hash.col[c] = 0; this.batch.bitvector.col[c >> 6] |= 1L << (c & 0x3f); this.batch.Count++; - if (this.batch.Count == Config.DataBatchSize) FlushContents(); + if (this.batch.Count == Config.DataBatchSize) this.FlushContents(); } else if (col_vother[i] == PartitionedStreamEvent.PunctuationOtherTime) { @@ -139,7 +139,7 @@ public override unsafe void OnNext(StreamMessage batch) if (!this.partitionData.Lookup(p, out int partitionIndex)) this.partitionData.Insert(p, partitionEntry = new PartitionEntry { lastSyncTime = col_vsync[i], ecq = new CircularBuffer(this.hopsPerDuration) }); else partitionEntry = this.partitionData.entries[partitionIndex].value; - OnPunctuation(partitionEntry, col_vsync[i]); + this.OnPunctuation(partitionEntry, col_vsync[i]); int c = this.batch.Count; this.batch.vsync.col[c] = col_vsync[i]; @@ -148,7 +148,7 @@ public override unsafe void OnNext(StreamMessage batch) this.batch.hash.col[c] = this.keyComparerGetHashCode(colkey[i]); this.batch.bitvector.col[c >> 6] |= 1L << (c & 0x3f); this.batch.Count++; - if (this.batch.Count == Config.DataBatchSize) FlushContents(); + if (this.batch.Count == Config.DataBatchSize) this.FlushContents(); } continue; } @@ -161,7 +161,7 @@ public override unsafe void OnNext(StreamMessage batch) // Handle time moving forward if (!this.partitionData.Lookup(partition, out int pIndex)) this.partitionData.Insert(partition, entry = new PartitionEntry { lastSyncTime = syncTime, ecq = new CircularBuffer(this.hopsPerDuration) }); - else if (syncTime > (entry = this.partitionData.entries[pIndex].value).lastSyncTime) AdvanceTime(entry, syncTime); + else if (syncTime > (entry = this.partitionData.entries[pIndex].value).lastSyncTime) this.AdvanceTime(entry, syncTime); // Need to retrieve the key from the dictionary if (!this.aggregateByKey.Lookup(colkey[i], col_hash[i], out int aggindex)) @@ -197,7 +197,7 @@ public override unsafe void OnNext(StreamMessage batch) if (this.batch.Count == Config.DataBatchSize) { this.batch.iter = batch.iter; - FlushContents(); + this.FlushContents(); this.batch.iter = batch.iter; } } @@ -285,7 +285,7 @@ public void OnLowWatermark(long syncTime) var partition = this.partitionData.entries[iter].value; if (syncTime > partition.lastSyncTime) { - OnPunctuation(partition, syncTime); + this.OnPunctuation(partition, syncTime); bool partitionHasValidOutstandingState = false; if (partition.ecq != null) @@ -313,7 +313,7 @@ public void OnLowWatermark(long syncTime) private void OnPunctuation(PartitionEntry partition, long syncTime) { - if (syncTime > partition.lastSyncTime) AdvanceTime(partition, syncTime); + if (syncTime > partition.lastSyncTime) this.AdvanceTime(partition, syncTime); } private void AdvanceTime(PartitionEntry partition, long syncTime) @@ -332,7 +332,7 @@ private void AdvanceTime(PartitionEntry partition, long syncTime) this.batch.key.col[c] = iter1entry.key; this.batch.hash.col[c] = this.keyComparerGetHashCode(iter1entry.key); this.batch.Count++; - if (this.batch.Count == Config.DataBatchSize) FlushContents(); + if (this.batch.Count == Config.DataBatchSize) this.FlushContents(); } else this.aggregateByKey.Remove(iter1entry.key); @@ -364,7 +364,7 @@ private void AdvanceTime(PartitionEntry partition, long syncTime) this.batch.key.col[c] = ecqState.states.entries[iter].key; this.batch.hash.col[c] = this.keyComparerGetHashCode(ecqState.states.entries[iter].key); this.batch.Count++; - if (this.batch.Count == Config.DataBatchSize) FlushContents(); + if (this.batch.Count == Config.DataBatchSize) this.FlushContents(); } // Update aggregate @@ -386,7 +386,7 @@ private void AdvanceTime(PartitionEntry partition, long syncTime) this.batch.key.col[c] = ecqState.states.entries[iter].key; this.batch.hash.col[c] = this.keyComparerGetHashCode(ecqState.states.entries[iter].key); this.batch.Count++; - if (this.batch.Count == Config.DataBatchSize) FlushContents(); + if (this.batch.Count == Config.DataBatchSize) this.FlushContents(); } else this.aggregateByKey.Remove(ecqState.states.entries[iter].key); @@ -466,7 +466,7 @@ private sealed class PartitionEntry [DataMember] public CircularBuffer ecq; [DataMember] - public HashSet heldAggregates = new HashSet(); + public HashSet heldAggregates = []; [DataMember] public long lastSyncTime = long.MinValue; } diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/SnapshotWindow/Hopping/PartitionedSnapshotWindowHoppingPipeSimple.cs b/Sources/Core/Microsoft.StreamProcessing/Operators/SnapshotWindow/Hopping/PartitionedSnapshotWindowHoppingPipeSimple.cs index 5621a4e6d..25e2bd321 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/SnapshotWindow/Hopping/PartitionedSnapshotWindowHoppingPipeSimple.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/SnapshotWindow/Hopping/PartitionedSnapshotWindowHoppingPipeSimple.cs @@ -19,7 +19,7 @@ namespace Microsoft.StreamProcessing [DataContract] internal sealed class PartitionedSnapshotWindowHoppingPipeSimple : UnaryPipe, TInput, TOutput> { - private static readonly bool hasDisposableState = typeof(IDisposable).GetTypeInfo().IsAssignableFrom(typeof(TState)); + private static readonly bool hasDisposableState = typeof(IDisposable).IsAssignableFrom(typeof(TState)); private readonly int hopsPerDuration; private readonly MemoryPool, TOutput> pool; private readonly string errorMessages; @@ -45,7 +45,7 @@ internal sealed class PartitionedSnapshotWindowHoppingPipeSimple, TOutput> batch; [DataMember] - private FastDictionary2 partitionData = new FastDictionary2(); + private FastDictionary2 partitionData = new(); [Obsolete("Used only by serialization. Do not call directly.")] public PartitionedSnapshotWindowHoppingPipeSimple() { } @@ -98,7 +98,7 @@ public override unsafe void OnNext(StreamMessage, TI { if (col_vother[i] == PartitionedStreamEvent.LowWatermarkOtherTime) { - OnLowWatermark(col_vsync[i]); + this.OnLowWatermark(col_vsync[i]); int c = this.batch.Count; this.batch.vsync.col[c] = col_vsync[i]; @@ -107,7 +107,7 @@ public override unsafe void OnNext(StreamMessage, TI this.batch.hash.col[c] = 0; this.batch.bitvector.col[c >> 6] |= 1L << (c & 0x3f); this.batch.Count++; - if (this.batch.Count == Config.DataBatchSize) FlushContents(); + if (this.batch.Count == Config.DataBatchSize) this.FlushContents(); } else if (col_vother[i] == PartitionedStreamEvent.PunctuationOtherTime) { @@ -116,7 +116,7 @@ public override unsafe void OnNext(StreamMessage, TI if (!this.partitionData.Lookup(p, out int partitionIndex)) this.partitionData.Insert(p, partitionEntry = new PartitionEntry { lastSyncTime = col_vsync[i], currentKey = colkey[i], currentHash = col_hash[i], ecq = new CircularBuffer>(this.hopsPerDuration) }); else partitionEntry = this.partitionData.entries[partitionIndex].value; - OnPunctuation(partitionEntry, col_vsync[i]); + this.OnPunctuation(partitionEntry, col_vsync[i]); int c = this.batch.Count; this.batch.vsync.col[c] = col_vsync[i]; @@ -125,7 +125,7 @@ public override unsafe void OnNext(StreamMessage, TI this.batch.hash.col[c] = partitionEntry.currentHash; this.batch.bitvector.col[c >> 6] |= 1L << (c & 0x3f); this.batch.Count++; - if (this.batch.Count == Config.DataBatchSize) FlushContents(); + if (this.batch.Count == Config.DataBatchSize) this.FlushContents(); } continue; } @@ -138,7 +138,7 @@ public override unsafe void OnNext(StreamMessage, TI // Handle time moving forward if (!this.partitionData.Lookup(partition, out int pIndex)) this.partitionData.Insert(partition, entry = new PartitionEntry { lastSyncTime = syncTime, currentKey = colkey[i], currentHash = col_hash[i], ecq = new CircularBuffer>(this.hopsPerDuration) }); - else if (syncTime > (entry = this.partitionData.entries[pIndex].value).lastSyncTime) AdvanceTime(entry, syncTime); + else if (syncTime > (entry = this.partitionData.entries[pIndex].value).lastSyncTime) this.AdvanceTime(entry, syncTime); if (entry.currentState == null) { @@ -165,7 +165,7 @@ public override unsafe void OnNext(StreamMessage, TI if (this.batch.Count == Config.DataBatchSize) { this.batch.iter = batch.iter; - FlushContents(); + this.FlushContents(); this.batch.iter = batch.iter; } } @@ -226,7 +226,7 @@ public void OnLowWatermark(long syncTime) var partition = this.partitionData.entries[iter].value; if (syncTime > partition.lastSyncTime) { - OnPunctuation(partition, syncTime); + this.OnPunctuation(partition, syncTime); bool partitionHasValidOutstandingState = false; if (partition.ecq != null) { @@ -248,7 +248,7 @@ public void OnLowWatermark(long syncTime) private void OnPunctuation(PartitionEntry partition, long syncTime) { - if (syncTime > partition.lastSyncTime) AdvanceTime(partition, syncTime); + if (syncTime > partition.lastSyncTime) this.AdvanceTime(partition, syncTime); } private void AdvanceTime(PartitionEntry partition, long syncTime) @@ -265,7 +265,7 @@ private void AdvanceTime(PartitionEntry partition, long syncTime) this.batch.key.col[c] = partition.currentKey; this.batch.hash.col[c] = partition.currentHash; this.batch.Count++; - if (this.batch.Count == Config.DataBatchSize) FlushContents(); + if (this.batch.Count == Config.DataBatchSize) this.FlushContents(); } partition.held = false; } @@ -284,7 +284,7 @@ private void AdvanceTime(PartitionEntry partition, long syncTime) this.batch.key.col[c] = partition.currentKey; this.batch.hash.col[c] = partition.currentHash; this.batch.Count++; - if (this.batch.Count == Config.DataBatchSize) FlushContents(); + if (this.batch.Count == Config.DataBatchSize) this.FlushContents(); } // Update aggregate @@ -304,7 +304,7 @@ private void AdvanceTime(PartitionEntry partition, long syncTime) this.batch.key.col[c] = partition.currentKey; this.batch.hash.col[c] = partition.currentHash; this.batch.Count++; - if (this.batch.Count == Config.DataBatchSize) FlushContents(); + if (this.batch.Count == Config.DataBatchSize) this.FlushContents(); } else { diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/SnapshotWindow/Hopping/SnapshotWindowHoppingPipe.cs b/Sources/Core/Microsoft.StreamProcessing/Operators/SnapshotWindow/Hopping/SnapshotWindowHoppingPipe.cs index 057c502ce..f08a7e113 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/SnapshotWindow/Hopping/SnapshotWindowHoppingPipe.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/SnapshotWindow/Hopping/SnapshotWindowHoppingPipe.cs @@ -20,7 +20,7 @@ namespace Microsoft.StreamProcessing [DataContract] internal sealed class SnapshotWindowHoppingPipe : UnaryPipe { - private static readonly bool hasDisposableState = typeof(IDisposable).GetTypeInfo().IsAssignableFrom(typeof(TState)); + private static readonly bool hasDisposableState = typeof(IDisposable).IsAssignableFrom(typeof(TState)); private readonly MemoryPool pool; private readonly DataStructurePool>> ecqEntryPool; private readonly string errorMessages; @@ -54,7 +54,7 @@ internal sealed class SnapshotWindowHoppingPipe : [DataMember] private FastDictionary2> aggregateByKey; [DataMember] - private HashSet heldAggregates = new HashSet(); + private HashSet heldAggregates = []; [DataMember] private CircularBuffer ecq; [DataMember] @@ -95,7 +95,7 @@ public SnapshotWindowHoppingPipe( this.aggregateByKey = comparer.CreateFastDictionary2Generator>(1, this.keyComparerEquals, this.keyComparerGetHashCode, stream.Properties.QueryContainer).Invoke(); this.ecq = new CircularBuffer(hopsPerDuration); var stateDictGenerator = comparer.CreateFastDictionaryGenerator>(1, this.keyComparerEquals, this.keyComparerGetHashCode, stream.Properties.QueryContainer); - this.ecqEntryPool = new DataStructurePool>>(() => stateDictGenerator.Invoke()); + this.ecqEntryPool = new DataStructurePool>>(stateDictGenerator.Invoke); } public override void ProduceQueryPlan(PlanNode previous) @@ -123,7 +123,7 @@ public override unsafe void OnNext(StreamMessage batch) if (col_vother[i] == StreamEvent.PunctuationOtherTime) { // We have found a row that corresponds to punctuation - OnPunctuation(col_vsync[i]); + this.OnPunctuation(col_vsync[i]); int c = this.batch.Count; this.batch.vsync.col[c] = col_vsync[i]; @@ -132,7 +132,7 @@ public override unsafe void OnNext(StreamMessage batch) this.batch.hash.col[c] = 0; this.batch.bitvector.col[c >> 6] |= 1L << (c & 0x3f); this.batch.Count++; - if (this.batch.Count == Config.DataBatchSize) FlushContents(); + if (this.batch.Count == Config.DataBatchSize) this.FlushContents(); } continue; } @@ -140,7 +140,7 @@ public override unsafe void OnNext(StreamMessage batch) var syncTime = col_vsync[i]; // Handle time moving forward - if (syncTime > this.lastSyncTime) AdvanceTime(syncTime); + if (syncTime > this.lastSyncTime) this.AdvanceTime(syncTime); // Need to retrieve the key from the dictionary HeldState heldState; @@ -174,7 +174,7 @@ public override unsafe void OnNext(StreamMessage batch) this.batch.key.col[c] = colkey[i]; this.batch.hash.col[c] = this.keyComparerGetHashCode(colkey[i]); this.batch.Count++; - if (this.batch.Count == Config.DataBatchSize) FlushContents(); + if (this.batch.Count == Config.DataBatchSize) this.FlushContents(); } heldState.timestamp = syncTime; } @@ -251,7 +251,7 @@ public override unsafe void OnNext(StreamMessage batch) public void OnPunctuation(long syncTime) { // Handle time moving forward - if (syncTime > this.lastSyncTime) AdvanceTime(syncTime); + if (syncTime > this.lastSyncTime) this.AdvanceTime(syncTime); } private void AdvanceTime(long syncTime) @@ -270,7 +270,7 @@ private void AdvanceTime(long syncTime) this.batch.key.col[c] = iter1entry.key; this.batch.hash.col[c] = this.keyComparerGetHashCode(iter1entry.key); this.batch.Count++; - if (this.batch.Count == Config.DataBatchSize) FlushContents(); + if (this.batch.Count == Config.DataBatchSize) this.FlushContents(); } else this.aggregateByKey.Remove(iter1entry.key); @@ -300,7 +300,7 @@ private void AdvanceTime(long syncTime) this.batch.key.col[c] = ecqState.states.entries[iter].key; this.batch.hash.col[c] = this.keyComparerGetHashCode(ecqState.states.entries[iter].key); this.batch.Count++; - if (this.batch.Count == Config.DataBatchSize) FlushContents(); + if (this.batch.Count == Config.DataBatchSize) this.FlushContents(); } // Update aggregate @@ -322,7 +322,7 @@ private void AdvanceTime(long syncTime) this.batch.key.col[c] = ecqState.states.entries[iter].key; this.batch.hash.col[c] = this.keyComparerGetHashCode(ecqState.states.entries[iter].key); this.batch.Count++; - if (this.batch.Count == Config.DataBatchSize) FlushContents(); + if (this.batch.Count == Config.DataBatchSize) this.FlushContents(); } else this.aggregateByKey.Remove(ecqState.states.entries[iter].key); diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/SnapshotWindow/Hopping/SnapshotWindowHoppingPipeSimple.cs b/Sources/Core/Microsoft.StreamProcessing/Operators/SnapshotWindow/Hopping/SnapshotWindowHoppingPipeSimple.cs index 661c17194..55a42e456 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/SnapshotWindow/Hopping/SnapshotWindowHoppingPipeSimple.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/SnapshotWindow/Hopping/SnapshotWindowHoppingPipeSimple.cs @@ -18,7 +18,7 @@ namespace Microsoft.StreamProcessing [DataContract] internal sealed class SnapshotWindowHoppingPipeSimple : UnaryPipe { - private static readonly bool hasDisposableState = typeof(IDisposable).GetTypeInfo().IsAssignableFrom(typeof(TState)); + private static readonly bool hasDisposableState = typeof(IDisposable).IsAssignableFrom(typeof(TState)); private readonly MemoryPool pool; private readonly string errorMessages; @@ -106,7 +106,7 @@ public override unsafe void OnNext(StreamMessage batch) if (col_vother[i] == StreamEvent.PunctuationOtherTime) { // We have found a row that corresponds to punctuation - OnPunctuation(col_vsync[i]); + this.OnPunctuation(col_vsync[i]); int c = this.batch.Count; this.batch.vsync.col[c] = col_vsync[i]; @@ -115,7 +115,7 @@ public override unsafe void OnNext(StreamMessage batch) this.batch.hash.col[c] = 0; this.batch.bitvector.col[c >> 6] |= 1L << (c & 0x3f); this.batch.Count++; - if (this.batch.Count == Config.DataBatchSize) FlushContents(); + if (this.batch.Count == Config.DataBatchSize) this.FlushContents(); } continue; } @@ -123,7 +123,7 @@ public override unsafe void OnNext(StreamMessage batch) var syncTime = col_vsync[i]; // Handle time moving forward - if (syncTime > this.lastSyncTime) AdvanceTime(syncTime); + if (syncTime > this.lastSyncTime) this.AdvanceTime(syncTime); if (this.currentState == null) { @@ -147,7 +147,7 @@ public override unsafe void OnNext(StreamMessage batch) this.batch.key.col[c] = Empty.Default; this.batch.hash.col[c] = 0; this.batch.Count++; - if (this.batch.Count == Config.DataBatchSize) FlushContents(); + if (this.batch.Count == Config.DataBatchSize) this.FlushContents(); } this.currentState.timestamp = syncTime; @@ -200,7 +200,7 @@ public override unsafe void OnNext(StreamMessage batch) public void OnPunctuation(long syncTime) { // Handle time moving forward - if (syncTime > this.lastSyncTime) AdvanceTime(syncTime); + if (syncTime > this.lastSyncTime) this.AdvanceTime(syncTime); } private void AdvanceTime(long syncTime) @@ -217,7 +217,7 @@ private void AdvanceTime(long syncTime) this.batch.key.col[c] = Empty.Default; this.batch.hash.col[c] = 0; this.batch.Count++; - if (this.batch.Count == Config.DataBatchSize) FlushContents(); + if (this.batch.Count == Config.DataBatchSize) this.FlushContents(); } this.held = false; @@ -237,7 +237,7 @@ private void AdvanceTime(long syncTime) this.batch.key.col[c] = Empty.Default; this.batch.hash.col[c] = 0; this.batch.Count++; - if (this.batch.Count == Config.DataBatchSize) FlushContents(); + if (this.batch.Count == Config.DataBatchSize) this.FlushContents(); } // Update aggregate @@ -257,7 +257,7 @@ private void AdvanceTime(long syncTime) this.batch.key.col[c] = Empty.Default; this.batch.hash.col[c] = 0; this.batch.Count++; - if (this.batch.Count == Config.DataBatchSize) FlushContents(); + if (this.batch.Count == Config.DataBatchSize) this.FlushContents(); } else { diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/SnapshotWindow/PriorityQueue/PartitionedSnapshotWindowPriorityQueuePipe.cs b/Sources/Core/Microsoft.StreamProcessing/Operators/SnapshotWindow/PriorityQueue/PartitionedSnapshotWindowPriorityQueuePipe.cs index cca149633..abc9dcb58 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/SnapshotWindow/PriorityQueue/PartitionedSnapshotWindowPriorityQueuePipe.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/SnapshotWindow/PriorityQueue/PartitionedSnapshotWindowPriorityQueuePipe.cs @@ -20,7 +20,7 @@ namespace Microsoft.StreamProcessing [DataContract] internal sealed class PartitionedSnapshotWindowPriorityQueuePipe : UnaryPipe { - private static readonly bool hasDisposableState = typeof(IDisposable).GetTypeInfo().IsAssignableFrom(typeof(TState)); + private static readonly bool hasDisposableState = typeof(IDisposable).IsAssignableFrom(typeof(TState)); private readonly MemoryPool pool; private readonly DataStructurePool>> ecqEntryPool; private readonly string errorMessages; @@ -54,7 +54,7 @@ internal sealed class PartitionedSnapshotWindowPriorityQueuePipe> aggregateByKey; [DataMember] - private FastDictionary2 partitionData = new FastDictionary2(); + private FastDictionary2 partitionData = new(); private readonly Func getPartitionKey = GetPartitionExtractor(); @@ -92,7 +92,7 @@ public PartitionedSnapshotWindowPriorityQueuePipe( var generator = comparer.CreateFastDictionary2Generator>(1, this.keyComparerEquals, this.keyComparerGetHashCode, stream.Properties.QueryContainer); this.aggregateByKey = generator.Invoke(); var stateDictGenerator = comparer.CreateFastDictionaryGenerator>(1, this.keyComparerEquals, this.keyComparerGetHashCode, stream.Properties.QueryContainer); - this.ecqEntryPool = new DataStructurePool>>(() => stateDictGenerator.Invoke()); + this.ecqEntryPool = new DataStructurePool>>(stateDictGenerator.Invoke); } public override void ProduceQueryPlan(PlanNode previous) @@ -119,7 +119,7 @@ public override unsafe void OnNext(StreamMessage batch) { if (col_vother[i] == PartitionedStreamEvent.LowWatermarkOtherTime) { - OnLowWatermark(col_vsync[i]); + this.OnLowWatermark(col_vsync[i]); int c = this.batch.Count; this.batch.vsync.col[c] = col_vsync[i]; @@ -128,7 +128,7 @@ public override unsafe void OnNext(StreamMessage batch) this.batch.hash.col[c] = 0; this.batch.bitvector.col[c >> 6] |= 1L << (c & 0x3f); this.batch.Count++; - if (this.batch.Count == Config.DataBatchSize) FlushContents(); + if (this.batch.Count == Config.DataBatchSize) this.FlushContents(); } else if (col_vother[i] == PartitionedStreamEvent.PunctuationOtherTime) { @@ -138,7 +138,7 @@ public override unsafe void OnNext(StreamMessage batch) if (!this.partitionData.Lookup(p, out int partitionIndex)) this.partitionData.Insert(p, (partitionEntry = new PartitionEntry { lastSyncTime = col_vsync[i] })); else partitionEntry = this.partitionData.entries[partitionIndex].value; - OnPunctuation(partitionEntry, col_vsync[i]); + this.OnPunctuation(partitionEntry, col_vsync[i]); int c = this.batch.Count; this.batch.vsync.col[c] = col_vsync[i]; @@ -147,7 +147,7 @@ public override unsafe void OnNext(StreamMessage batch) this.batch.hash.col[c] = this.keyComparerGetHashCode(colkey[i]); this.batch.bitvector.col[c >> 6] |= 1L << (c & 0x3f); this.batch.Count++; - if (this.batch.Count == Config.DataBatchSize) FlushContents(); + if (this.batch.Count == Config.DataBatchSize) this.FlushContents(); } continue; } @@ -159,7 +159,7 @@ public override unsafe void OnNext(StreamMessage batch) // Handle time moving forward if (!this.partitionData.Lookup(partition, out int pIndex)) this.partitionData.Insert(partition, (entry = new PartitionEntry { lastSyncTime = syncTime })); - else if (syncTime > (entry = this.partitionData.entries[pIndex].value).lastSyncTime) AdvanceTime(entry, syncTime); + else if (syncTime > (entry = this.partitionData.entries[pIndex].value).lastSyncTime) this.AdvanceTime(entry, syncTime); // Need to retrieve the key from the dictionary HeldState heldState; @@ -194,7 +194,7 @@ public override unsafe void OnNext(StreamMessage batch) this.batch.key.col[c] = colkey[i]; this.batch.hash.col[c] = this.keyComparerGetHashCode(colkey[i]); this.batch.Count++; - if (this.batch.Count == Config.DataBatchSize) FlushContents(); + if (this.batch.Count == Config.DataBatchSize) this.FlushContents(); } heldState.timestamp = syncTime; } @@ -265,7 +265,7 @@ public void OnLowWatermark(long syncTime) var partition = this.partitionData.entries[iter].value; if (syncTime > partition.lastSyncTime) { - OnPunctuation(partition, syncTime); + this.OnPunctuation(partition, syncTime); bool partitionHasValidOutstandingState = false; if (partition.ecq != null) @@ -293,7 +293,7 @@ public void OnLowWatermark(long syncTime) private void OnPunctuation(PartitionEntry partition, long syncTime) { - if (syncTime > partition.lastSyncTime) AdvanceTime(partition, syncTime); + if (syncTime > partition.lastSyncTime) this.AdvanceTime(partition, syncTime); } private void AdvanceTime(PartitionEntry partition, long syncTime) @@ -313,7 +313,7 @@ private void AdvanceTime(PartitionEntry partition, long syncTime) this.batch.key.col[c] = iter1entry.key; this.batch.hash.col[c] = this.keyComparerGetHashCode(iter1entry.key); this.batch.Count++; - if (this.batch.Count == Config.DataBatchSize) FlushContents(); + if (this.batch.Count == Config.DataBatchSize) this.FlushContents(); } else this.aggregateByKey.Remove(iter1entry.key); @@ -343,7 +343,7 @@ private void AdvanceTime(PartitionEntry partition, long syncTime) this.batch.key.col[c] = ecqState.entries[iter].key; this.batch.hash.col[c] = this.keyComparerGetHashCode(ecqState.entries[iter].key); this.batch.Count++; - if (this.batch.Count == Config.DataBatchSize) FlushContents(); + if (this.batch.Count == Config.DataBatchSize) this.FlushContents(); } // Update aggregate @@ -365,7 +365,7 @@ private void AdvanceTime(PartitionEntry partition, long syncTime) this.batch.key.col[c] = ecqState.entries[iter].key; this.batch.hash.col[c] = this.keyComparerGetHashCode(ecqState.entries[iter].key); this.batch.Count++; - if (this.batch.Count == Config.DataBatchSize) FlushContents(); + if (this.batch.Count == Config.DataBatchSize) this.FlushContents(); } else this.aggregateByKey.Remove(ecqState.entries[iter].key); @@ -434,9 +434,9 @@ protected override void DisposeState() private sealed class PartitionEntry { [DataMember] - public HashSet heldAggregates = new HashSet(); + public HashSet heldAggregates = []; [DataMember] - public SortedDictionary>> ecq = new SortedDictionary>>(); + public SortedDictionary>> ecq = []; [DataMember] public long lastSyncTime = long.MinValue; } diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/SnapshotWindow/PriorityQueue/PartitionedSnapshotWindowPriorityQueuePipeSimple.cs b/Sources/Core/Microsoft.StreamProcessing/Operators/SnapshotWindow/PriorityQueue/PartitionedSnapshotWindowPriorityQueuePipeSimple.cs index bd51b2b16..b3fa2a8f6 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/SnapshotWindow/PriorityQueue/PartitionedSnapshotWindowPriorityQueuePipeSimple.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/SnapshotWindow/PriorityQueue/PartitionedSnapshotWindowPriorityQueuePipeSimple.cs @@ -19,7 +19,7 @@ namespace Microsoft.StreamProcessing [DataContract] internal sealed class PartitionedSnapshotWindowPriorityQueuePipeSimple : UnaryPipe, TInput, TOutput> { - private static readonly bool hasDisposableState = typeof(IDisposable).GetTypeInfo().IsAssignableFrom(typeof(TState)); + private static readonly bool hasDisposableState = typeof(IDisposable).IsAssignableFrom(typeof(TState)); private readonly MemoryPool, TOutput> pool; private readonly string errorMessages; @@ -44,7 +44,7 @@ internal sealed class PartitionedSnapshotWindowPriorityQueuePipeSimple, TOutput> batch; [DataMember] - private FastDictionary2 partitionData = new FastDictionary2(); + private FastDictionary2 partitionData = new(); [Obsolete("Used only by serialization. Do not call directly.")] public PartitionedSnapshotWindowPriorityQueuePipeSimple() { } @@ -96,7 +96,7 @@ public override unsafe void OnNext(StreamMessage, TI { if (col_vother[i] == PartitionedStreamEvent.LowWatermarkOtherTime) { - OnLowWatermark(col_vsync[i]); + this.OnLowWatermark(col_vsync[i]); int c = this.batch.Count; this.batch.vsync.col[c] = col_vsync[i]; @@ -105,7 +105,7 @@ public override unsafe void OnNext(StreamMessage, TI this.batch.hash.col[c] = 0; this.batch.bitvector.col[c >> 6] |= 1L << (c & 0x3f); this.batch.Count++; - if (this.batch.Count == Config.DataBatchSize) FlushContents(); + if (this.batch.Count == Config.DataBatchSize) this.FlushContents(); } else if (col_vother[i] == PartitionedStreamEvent.PunctuationOtherTime) { @@ -115,7 +115,7 @@ public override unsafe void OnNext(StreamMessage, TI if (!this.partitionData.Lookup(p, out int partitionIndex)) this.partitionData.Insert(p, (partitionEntry = new PartitionEntry { lastSyncTime = col_vsync[i], currentKey = colkey[i], currentHash = col_hash[i] })); else partitionEntry = this.partitionData.entries[partitionIndex].value; - OnPunctuation(partitionEntry, col_vsync[i]); + this.OnPunctuation(partitionEntry, col_vsync[i]); int c = this.batch.Count; this.batch.vsync.col[c] = col_vsync[i]; @@ -124,7 +124,7 @@ public override unsafe void OnNext(StreamMessage, TI this.batch.hash.col[c] = partitionEntry.currentHash; this.batch.bitvector.col[c >> 6] |= 1L << (c & 0x3f); this.batch.Count++; - if (this.batch.Count == Config.DataBatchSize) FlushContents(); + if (this.batch.Count == Config.DataBatchSize) this.FlushContents(); } continue; } @@ -136,7 +136,7 @@ public override unsafe void OnNext(StreamMessage, TI // Handle time moving forward if (!this.partitionData.Lookup(partition, out int pIndex)) this.partitionData.Insert(partition, (entry = new PartitionEntry { lastSyncTime = syncTime, currentKey = colkey[i], currentHash = col_hash[i] })); - else if (syncTime > (entry = this.partitionData.entries[pIndex].value).lastSyncTime) AdvanceTime(entry, syncTime); + else if (syncTime > (entry = this.partitionData.entries[pIndex].value).lastSyncTime) this.AdvanceTime(entry, syncTime); if (entry.currentState == null) { @@ -162,7 +162,7 @@ public override unsafe void OnNext(StreamMessage, TI if (this.batch.Count == Config.DataBatchSize) { this.batch.iter = batch.iter; - FlushContents(); + this.FlushContents(); this.batch.iter = batch.iter; } } @@ -222,7 +222,7 @@ public void OnLowWatermark(long syncTime) var partition = this.partitionData.entries[iter].value; if (syncTime > partition.lastSyncTime) { - OnPunctuation(partition, syncTime); + this.OnPunctuation(partition, syncTime); bool partitionHasValidOutstandingState = false; if (partition.ecq != null) { @@ -244,7 +244,7 @@ public void OnLowWatermark(long syncTime) private void OnPunctuation(PartitionEntry partition, long syncTime) { - if (syncTime > partition.lastSyncTime) AdvanceTime(partition, syncTime); + if (syncTime > partition.lastSyncTime) this.AdvanceTime(partition, syncTime); } private void AdvanceTime(PartitionEntry partition, long syncTime) @@ -261,7 +261,7 @@ private void AdvanceTime(PartitionEntry partition, long syncTime) this.batch.key.col[c] = partition.currentKey; this.batch.hash.col[c] = partition.currentHash; this.batch.Count++; - if (this.batch.Count == Config.DataBatchSize) FlushContents(); + if (this.batch.Count == Config.DataBatchSize) this.FlushContents(); } partition.held = false; } @@ -280,7 +280,7 @@ private void AdvanceTime(PartitionEntry partition, long syncTime) this.batch.key.col[c] = partition.currentKey; this.batch.hash.col[c] = partition.currentHash; this.batch.Count++; - if (this.batch.Count == Config.DataBatchSize) FlushContents(); + if (this.batch.Count == Config.DataBatchSize) this.FlushContents(); } // Update aggregate @@ -300,7 +300,7 @@ private void AdvanceTime(PartitionEntry partition, long syncTime) this.batch.key.col[c] = partition.currentKey; this.batch.hash.col[c] = partition.currentHash; this.batch.Count++; - if (this.batch.Count == Config.DataBatchSize) FlushContents(); + if (this.batch.Count == Config.DataBatchSize) this.FlushContents(); } else { @@ -360,7 +360,7 @@ protected override void DisposeState() private sealed class PartitionEntry { [DataMember] - public SortedDictionary> ecq = new SortedDictionary>(); + public SortedDictionary> ecq = []; [DataMember] public long lastSyncTime = long.MinValue; diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/SnapshotWindow/PriorityQueue/SnapshotWindowPriorityQueuePipe.cs b/Sources/Core/Microsoft.StreamProcessing/Operators/SnapshotWindow/PriorityQueue/SnapshotWindowPriorityQueuePipe.cs index 31de19c5c..9376a8b86 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/SnapshotWindow/PriorityQueue/SnapshotWindowPriorityQueuePipe.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/SnapshotWindow/PriorityQueue/SnapshotWindowPriorityQueuePipe.cs @@ -20,7 +20,7 @@ namespace Microsoft.StreamProcessing [DataContract] internal sealed class SnapshotWindowPriorityQueuePipe : UnaryPipe { - private static readonly bool hasDisposableState = typeof(IDisposable).GetTypeInfo().IsAssignableFrom(typeof(TState)); + private static readonly bool hasDisposableState = typeof(IDisposable).IsAssignableFrom(typeof(TState)); private readonly MemoryPool pool; private readonly DataStructurePool>> ecqEntryPool; private readonly string errorMessages; @@ -54,9 +54,9 @@ internal sealed class SnapshotWindowPriorityQueuePipe> aggregateByKey; [DataMember] - private HashSet heldAggregates = new HashSet(); + private HashSet heldAggregates = []; [DataMember] - private SortedDictionary>> ecq = new SortedDictionary>>(); + private SortedDictionary>> ecq = []; [DataMember] private long lastSyncTime = long.MinValue; @@ -93,7 +93,7 @@ public SnapshotWindowPriorityQueuePipe( this.aggregateByKey = comparer.CreateFastDictionary2Generator>(1, this.keyComparerEquals, this.keyComparerGetHashCode, stream.Properties.QueryContainer).Invoke(); var stateDictGenerator = comparer.CreateFastDictionaryGenerator>(1, this.keyComparerEquals, this.keyComparerGetHashCode, stream.Properties.QueryContainer); - this.ecqEntryPool = new DataStructurePool>>(() => stateDictGenerator.Invoke()); + this.ecqEntryPool = new DataStructurePool>>(stateDictGenerator.Invoke); } public override void ProduceQueryPlan(PlanNode previous) @@ -121,7 +121,7 @@ public override unsafe void OnNext(StreamMessage batch) if (col_vother[i] == StreamEvent.PunctuationOtherTime) { // We have found a row that corresponds to punctuation - OnPunctuation(col_vsync[i]); + this.OnPunctuation(col_vsync[i]); int c = this.batch.Count; this.batch.vsync.col[c] = col_vsync[i]; @@ -130,7 +130,7 @@ public override unsafe void OnNext(StreamMessage batch) this.batch.hash.col[c] = 0; this.batch.bitvector.col[c >> 6] |= 1L << (c & 0x3f); this.batch.Count++; - if (this.batch.Count == Config.DataBatchSize) FlushContents(); + if (this.batch.Count == Config.DataBatchSize) this.FlushContents(); } continue; } @@ -138,7 +138,7 @@ public override unsafe void OnNext(StreamMessage batch) var syncTime = col_vsync[i]; // Handle time moving forward - if (syncTime > this.lastSyncTime) AdvanceTime(syncTime); + if (syncTime > this.lastSyncTime) this.AdvanceTime(syncTime); // Need to retrieve the key from the dictionary HeldState heldState; @@ -175,7 +175,7 @@ public override unsafe void OnNext(StreamMessage batch) if (this.batch.Count == Config.DataBatchSize) { this.batch.iter = batch.iter; - FlushContents(); + this.FlushContents(); this.batch.iter = batch.iter; } } @@ -245,7 +245,7 @@ public override unsafe void OnNext(StreamMessage batch) public void OnPunctuation(long syncTime) { // Handle time moving forward - if (syncTime > this.lastSyncTime) AdvanceTime(syncTime); + if (syncTime > this.lastSyncTime) this.AdvanceTime(syncTime); } private void AdvanceTime(long syncTime) @@ -264,7 +264,7 @@ private void AdvanceTime(long syncTime) this.batch.key.col[c] = iter1entry.key; this.batch.hash.col[c] = this.keyComparerGetHashCode(iter1entry.key); this.batch.Count++; - if (this.batch.Count == Config.DataBatchSize) FlushContents(); + if (this.batch.Count == Config.DataBatchSize) this.FlushContents(); } else this.aggregateByKey.Remove(iter1entry.key); @@ -294,7 +294,7 @@ private void AdvanceTime(long syncTime) this.batch.key.col[c] = ecqState.entries[iter].key; this.batch.hash.col[c] = this.keyComparerGetHashCode(ecqState.entries[iter].key); this.batch.Count++; - if (this.batch.Count == Config.DataBatchSize) FlushContents(); + if (this.batch.Count == Config.DataBatchSize) this.FlushContents(); } // Update aggregate @@ -316,7 +316,7 @@ private void AdvanceTime(long syncTime) this.batch.key.col[c] = ecqState.entries[iter].key; this.batch.hash.col[c] = this.keyComparerGetHashCode(ecqState.entries[iter].key); this.batch.Count++; - if (this.batch.Count == Config.DataBatchSize) FlushContents(); + if (this.batch.Count == Config.DataBatchSize) this.FlushContents(); } else this.aggregateByKey.Remove(ecqState.entries[iter].key); diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/SnapshotWindow/PriorityQueue/SnapshotWindowPriorityQueuePipeSimple.cs b/Sources/Core/Microsoft.StreamProcessing/Operators/SnapshotWindow/PriorityQueue/SnapshotWindowPriorityQueuePipeSimple.cs index cf82f67aa..5bda4c2ba 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/SnapshotWindow/PriorityQueue/SnapshotWindowPriorityQueuePipeSimple.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/SnapshotWindow/PriorityQueue/SnapshotWindowPriorityQueuePipeSimple.cs @@ -19,7 +19,7 @@ namespace Microsoft.StreamProcessing [DataContract] internal sealed class SnapshotWindowPriorityQueuePipeSimple : UnaryPipe { - private static readonly bool hasDisposableState = typeof(IDisposable).GetTypeInfo().IsAssignableFrom(typeof(TState)); + private static readonly bool hasDisposableState = typeof(IDisposable).IsAssignableFrom(typeof(TState)); private readonly MemoryPool pool; private readonly string errorMessages; @@ -44,7 +44,7 @@ internal sealed class SnapshotWindowPriorityQueuePipeSimple batch; [DataMember] - private SortedDictionary> ecq = new SortedDictionary>(); + private SortedDictionary> ecq = []; [DataMember] private long lastSyncTime = long.MinValue; [DataMember] @@ -102,7 +102,7 @@ public override unsafe void OnNext(StreamMessage batch) if (col_vother[i] == StreamEvent.PunctuationOtherTime) { // We have found a row that corresponds to punctuation - OnPunctuation(col_vsync[i]); + this.OnPunctuation(col_vsync[i]); int c = this.batch.Count; this.batch.vsync.col[c] = col_vsync[i]; @@ -112,7 +112,7 @@ public override unsafe void OnNext(StreamMessage batch) this.batch.hash.col[c] = 0; this.batch.bitvector.col[c >> 6] |= 1L << (c & 0x3f); this.batch.Count++; - if (this.batch.Count == Config.DataBatchSize) FlushContents(); + if (this.batch.Count == Config.DataBatchSize) this.FlushContents(); } continue; } @@ -120,7 +120,7 @@ public override unsafe void OnNext(StreamMessage batch) var syncTime = col_vsync[i]; // Handle time moving forward - if (syncTime > this.lastSyncTime) AdvanceTime(syncTime); + if (syncTime > this.lastSyncTime) this.AdvanceTime(syncTime); if (this.currentState == null) { @@ -143,7 +143,7 @@ public override unsafe void OnNext(StreamMessage batch) this.batch.key.col[c] = Empty.Default; this.batch.hash.col[c] = 0; this.batch.Count++; - if (this.batch.Count == Config.DataBatchSize) FlushContents(); + if (this.batch.Count == Config.DataBatchSize) this.FlushContents(); } this.currentState.timestamp = syncTime; @@ -194,7 +194,7 @@ public override unsafe void OnNext(StreamMessage batch) public void OnPunctuation(long syncTime) { // Handle time moving forward - if (syncTime > this.lastSyncTime) AdvanceTime(syncTime); + if (syncTime > this.lastSyncTime) this.AdvanceTime(syncTime); } private void AdvanceTime(long syncTime) @@ -211,7 +211,7 @@ private void AdvanceTime(long syncTime) this.batch.key.col[c] = Empty.Default; this.batch.hash.col[c] = 0; this.batch.Count++; - if (this.batch.Count == Config.DataBatchSize) FlushContents(); + if (this.batch.Count == Config.DataBatchSize) this.FlushContents(); } this.held = false; @@ -231,7 +231,7 @@ private void AdvanceTime(long syncTime) this.batch.key.col[c] = Empty.Default; this.batch.hash.col[c] = 0; this.batch.Count++; - if (this.batch.Count == Config.DataBatchSize) FlushContents(); + if (this.batch.Count == Config.DataBatchSize) this.FlushContents(); } // Update aggregate @@ -251,7 +251,7 @@ private void AdvanceTime(long syncTime) this.batch.key.col[c] = Empty.Default; this.batch.hash.col[c] = 0; this.batch.Count++; - if (this.batch.Count == Config.DataBatchSize) FlushContents(); + if (this.batch.Count == Config.DataBatchSize) this.FlushContents(); } else { diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/SnapshotWindow/Sliding/PartitionedSnapshotWindowSlidingPipe.cs b/Sources/Core/Microsoft.StreamProcessing/Operators/SnapshotWindow/Sliding/PartitionedSnapshotWindowSlidingPipe.cs index 145da4400..fba92b131 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/SnapshotWindow/Sliding/PartitionedSnapshotWindowSlidingPipe.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/SnapshotWindow/Sliding/PartitionedSnapshotWindowSlidingPipe.cs @@ -20,7 +20,7 @@ namespace Microsoft.StreamProcessing [DataContract] internal sealed class PartitionedSnapshotWindowSlidingPipe : UnaryPipe { - private static readonly bool hasDisposableState = typeof(IDisposable).GetTypeInfo().IsAssignableFrom(typeof(TState)); + private static readonly bool hasDisposableState = typeof(IDisposable).IsAssignableFrom(typeof(TState)); private readonly MemoryPool pool; private readonly DataStructurePool>> ecqEntryPool; private readonly string errorMessages; @@ -54,7 +54,7 @@ internal sealed class PartitionedSnapshotWindowSlidingPipe> aggregateByKey; [DataMember] - private FastDictionary2 partitionData = new FastDictionary2(); + private FastDictionary2 partitionData = new(); private readonly Func getPartitionKey = GetPartitionExtractor(); @@ -91,7 +91,7 @@ public PartitionedSnapshotWindowSlidingPipe( this.aggregateByKey = comparer.CreateFastDictionary2Generator>(1, this.keyComparerEquals, this.keyComparerGetHashCode, stream.Properties.QueryContainer).Invoke(); var stateDictGenerator = comparer.CreateFastDictionaryGenerator>(1, this.keyComparerEquals, this.keyComparerGetHashCode, stream.Properties.QueryContainer); - this.ecqEntryPool = new DataStructurePool>>(() => stateDictGenerator.Invoke()); + this.ecqEntryPool = new DataStructurePool>>(stateDictGenerator.Invoke); } public override void ProduceQueryPlan(PlanNode previous) @@ -118,7 +118,7 @@ public override unsafe void OnNext(StreamMessage batch) { if (col_vother[i] == PartitionedStreamEvent.LowWatermarkOtherTime) { - OnLowWatermark(col_vsync[i]); + this.OnLowWatermark(col_vsync[i]); int c = this.batch.Count; this.batch.vsync.col[c] = col_vsync[i]; @@ -127,7 +127,7 @@ public override unsafe void OnNext(StreamMessage batch) this.batch.hash.col[c] = 0; this.batch.bitvector.col[c >> 6] |= 1L << (c & 0x3f); this.batch.Count++; - if (this.batch.Count == Config.DataBatchSize) FlushContents(); + if (this.batch.Count == Config.DataBatchSize) this.FlushContents(); } else if (col_vother[i] == PartitionedStreamEvent.PunctuationOtherTime) { @@ -137,7 +137,7 @@ public override unsafe void OnNext(StreamMessage batch) if (!this.partitionData.Lookup(p, out int partitionIndex)) this.partitionData.Insert(p, partitionEntry = new PartitionEntry { lastSyncTime = col_vsync[i] }); else partitionEntry = this.partitionData.entries[partitionIndex].value; - OnPunctuation(partitionEntry, col_vsync[i]); + this.OnPunctuation(partitionEntry, col_vsync[i]); int c = this.batch.Count; this.batch.vsync.col[c] = col_vsync[i]; @@ -146,7 +146,7 @@ public override unsafe void OnNext(StreamMessage batch) this.batch.hash.col[c] = this.keyComparerGetHashCode(colkey[i]); this.batch.bitvector.col[c >> 6] |= 1L << (c & 0x3f); this.batch.Count++; - if (this.batch.Count == Config.DataBatchSize) FlushContents(); + if (this.batch.Count == Config.DataBatchSize) this.FlushContents(); } continue; } @@ -159,7 +159,7 @@ public override unsafe void OnNext(StreamMessage batch) // Handle time moving forward if (!this.partitionData.Lookup(partition, out int pIndex)) this.partitionData.Insert(partition, entry = new PartitionEntry { lastSyncTime = syncTime }); - else if (syncTime > (entry = this.partitionData.entries[pIndex].value).lastSyncTime) AdvanceTime(entry, syncTime); + else if (syncTime > (entry = this.partitionData.entries[pIndex].value).lastSyncTime) this.AdvanceTime(entry, syncTime); // Need to retrieve the key from the dictionary if (!this.aggregateByKey.Lookup(colkey[i], col_hash[i], out int aggindex)) @@ -195,7 +195,7 @@ public override unsafe void OnNext(StreamMessage batch) if (this.batch.Count == Config.DataBatchSize) { this.batch.iter = batch.iter; - FlushContents(); + this.FlushContents(); this.batch.iter = batch.iter; } } @@ -283,7 +283,7 @@ public void OnLowWatermark(long syncTime) var partition = this.partitionData.entries[iter].value; if (syncTime > partition.lastSyncTime) { - OnPunctuation(partition, syncTime); + this.OnPunctuation(partition, syncTime); bool partitionHasValidOutstandingState = false; if (partition.ecq != null) @@ -311,7 +311,7 @@ public void OnLowWatermark(long syncTime) private void OnPunctuation(PartitionEntry partition, long syncTime) { - if (syncTime > partition.lastSyncTime) AdvanceTime(partition, syncTime); + if (syncTime > partition.lastSyncTime) this.AdvanceTime(partition, syncTime); } private void AdvanceTime(PartitionEntry partition, long syncTime) @@ -330,7 +330,7 @@ private void AdvanceTime(PartitionEntry partition, long syncTime) this.batch.key.col[c] = iter1entry.key; this.batch.hash.col[c] = this.keyComparerGetHashCode(iter1entry.key); this.batch.Count++; - if (this.batch.Count == Config.DataBatchSize) FlushContents(); + if (this.batch.Count == Config.DataBatchSize) this.FlushContents(); } else this.aggregateByKey.Remove(iter1entry.key); @@ -362,7 +362,7 @@ private void AdvanceTime(PartitionEntry partition, long syncTime) this.batch.key.col[c] = ecqState.states.entries[iter].key; this.batch.hash.col[c] = this.keyComparerGetHashCode(ecqState.states.entries[iter].key); this.batch.Count++; - if (this.batch.Count == Config.DataBatchSize) FlushContents(); + if (this.batch.Count == Config.DataBatchSize) this.FlushContents(); } // Update aggregate @@ -384,7 +384,7 @@ private void AdvanceTime(PartitionEntry partition, long syncTime) this.batch.key.col[c] = ecqState.states.entries[iter].key; this.batch.hash.col[c] = this.keyComparerGetHashCode(ecqState.states.entries[iter].key); this.batch.Count++; - if (this.batch.Count == Config.DataBatchSize) FlushContents(); + if (this.batch.Count == Config.DataBatchSize) this.FlushContents(); } else this.aggregateByKey.Remove(ecqState.states.entries[iter].key); @@ -462,9 +462,9 @@ private sealed class EcqState private sealed class PartitionEntry { [DataMember] - public ElasticCircularBuffer ecq = new ElasticCircularBuffer(); + public ElasticCircularBuffer ecq = []; [DataMember] - public HashSet heldAggregates = new HashSet(); + public HashSet heldAggregates = []; [DataMember] public long lastSyncTime = long.MinValue; } diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/SnapshotWindow/Sliding/PartitionedSnapshotWindowSlidingPipeSimple.cs b/Sources/Core/Microsoft.StreamProcessing/Operators/SnapshotWindow/Sliding/PartitionedSnapshotWindowSlidingPipeSimple.cs index 2af3ccb17..29dbf18ac 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/SnapshotWindow/Sliding/PartitionedSnapshotWindowSlidingPipeSimple.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/SnapshotWindow/Sliding/PartitionedSnapshotWindowSlidingPipeSimple.cs @@ -19,7 +19,7 @@ namespace Microsoft.StreamProcessing [DataContract] internal sealed class PartitionedSnapshotWindowSlidingPipeSimple : UnaryPipe, TInput, TOutput> { - private static readonly bool hasDisposableState = typeof(IDisposable).GetTypeInfo().IsAssignableFrom(typeof(TState)); + private static readonly bool hasDisposableState = typeof(IDisposable).IsAssignableFrom(typeof(TState)); private readonly MemoryPool, TOutput> pool; private readonly string errorMessages; @@ -44,7 +44,7 @@ internal sealed class PartitionedSnapshotWindowSlidingPipeSimple, TOutput> batch; [DataMember] - private FastDictionary2 partitionData = new FastDictionary2(); + private FastDictionary2 partitionData = new(); [Obsolete("Used only by serialization. Do not call directly.")] public PartitionedSnapshotWindowSlidingPipeSimple() { } @@ -96,7 +96,7 @@ public override unsafe void OnNext(StreamMessage, TI { if (col_vother[i] == PartitionedStreamEvent.LowWatermarkOtherTime) { - OnLowWatermark(col_vsync[i]); + this.OnLowWatermark(col_vsync[i]); int c = this.batch.Count; this.batch.vsync.col[c] = col_vsync[i]; @@ -105,7 +105,7 @@ public override unsafe void OnNext(StreamMessage, TI this.batch.hash.col[c] = 0; this.batch.bitvector.col[c >> 6] |= 1L << (c & 0x3f); this.batch.Count++; - if (this.batch.Count == Config.DataBatchSize) FlushContents(); + if (this.batch.Count == Config.DataBatchSize) this.FlushContents(); } else if (col_vother[i] == PartitionedStreamEvent.PunctuationOtherTime) { @@ -115,7 +115,7 @@ public override unsafe void OnNext(StreamMessage, TI if (!this.partitionData.Lookup(p, out int partitionIndex)) this.partitionData.Insert(p, partitionEntry = new PartitionEntry { lastSyncTime = col_vsync[i], currentKey = colkey[i], currentHash = col_hash[i] }); else partitionEntry = this.partitionData.entries[partitionIndex].value; - OnPunctuation(partitionEntry, col_vsync[i]); + this.OnPunctuation(partitionEntry, col_vsync[i]); int c = this.batch.Count; this.batch.vsync.col[c] = col_vsync[i]; @@ -124,7 +124,7 @@ public override unsafe void OnNext(StreamMessage, TI this.batch.hash.col[c] = partitionEntry.currentHash; this.batch.bitvector.col[c >> 6] |= 1L << (c & 0x3f); this.batch.Count++; - if (this.batch.Count == Config.DataBatchSize) FlushContents(); + if (this.batch.Count == Config.DataBatchSize) this.FlushContents(); } continue; } @@ -137,7 +137,7 @@ public override unsafe void OnNext(StreamMessage, TI // Handle time moving forward if (!this.partitionData.Lookup(partition, out int pIndex)) this.partitionData.Insert(partition, entry = new PartitionEntry { lastSyncTime = syncTime, currentKey = colkey[i], currentHash = col_hash[i] }); - else if (syncTime > (entry = this.partitionData.entries[pIndex].value).lastSyncTime) AdvanceTime(entry, syncTime); + else if (syncTime > (entry = this.partitionData.entries[pIndex].value).lastSyncTime) this.AdvanceTime(entry, syncTime); if (entry.currentState == null) { @@ -164,7 +164,7 @@ public override unsafe void OnNext(StreamMessage, TI if (this.batch.Count == Config.DataBatchSize) { this.batch.iter = batch.iter; - FlushContents(); + this.FlushContents(); this.batch.iter = batch.iter; } } @@ -225,7 +225,7 @@ public void OnLowWatermark(long syncTime) var partition = this.partitionData.entries[iter].value; if (syncTime > partition.lastSyncTime) { - OnPunctuation(partition, syncTime); + this.OnPunctuation(partition, syncTime); bool partitionHasValidOutstandingState = false; if (partition.ecq != null) @@ -248,7 +248,7 @@ public void OnLowWatermark(long syncTime) private void OnPunctuation(PartitionEntry partition, long syncTime) { - if (syncTime > partition.lastSyncTime) AdvanceTime(partition, syncTime); + if (syncTime > partition.lastSyncTime) this.AdvanceTime(partition, syncTime); } private void AdvanceTime(PartitionEntry partition, long syncTime) @@ -265,7 +265,7 @@ private void AdvanceTime(PartitionEntry partition, long syncTime) this.batch.key.col[c] = partition.currentKey; this.batch.hash.col[c] = partition.currentHash; this.batch.Count++; - if (this.batch.Count == Config.DataBatchSize) FlushContents(); + if (this.batch.Count == Config.DataBatchSize) this.FlushContents(); } partition.held = false; } @@ -284,7 +284,7 @@ private void AdvanceTime(PartitionEntry partition, long syncTime) this.batch.key.col[c] = partition.currentKey; this.batch.hash.col[c] = partition.currentHash; this.batch.Count++; - if (this.batch.Count == Config.DataBatchSize) FlushContents(); + if (this.batch.Count == Config.DataBatchSize) this.FlushContents(); } // Update aggregate @@ -304,7 +304,7 @@ private void AdvanceTime(PartitionEntry partition, long syncTime) this.batch.key.col[c] = partition.currentKey; this.batch.hash.col[c] = partition.currentHash; this.batch.Count++; - if (this.batch.Count == Config.DataBatchSize) FlushContents(); + if (this.batch.Count == Config.DataBatchSize) this.FlushContents(); } else { @@ -361,7 +361,7 @@ protected override void DisposeState() private sealed class PartitionEntry { [DataMember] - public ElasticCircularBuffer> ecq = new ElasticCircularBuffer>(); + public ElasticCircularBuffer> ecq = []; [DataMember] public long lastSyncTime = long.MinValue; diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/SnapshotWindow/Sliding/SnapshotWindowSlidingPipe.cs b/Sources/Core/Microsoft.StreamProcessing/Operators/SnapshotWindow/Sliding/SnapshotWindowSlidingPipe.cs index 39b912ca1..1cfbd2a0f 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/SnapshotWindow/Sliding/SnapshotWindowSlidingPipe.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/SnapshotWindow/Sliding/SnapshotWindowSlidingPipe.cs @@ -20,7 +20,7 @@ namespace Microsoft.StreamProcessing [DataContract] internal sealed class SnapshotWindowSlidingPipe : UnaryPipe { - private static readonly bool hasDisposableState = typeof(IDisposable).GetTypeInfo().IsAssignableFrom(typeof(TState)); + private static readonly bool hasDisposableState = typeof(IDisposable).IsAssignableFrom(typeof(TState)); private readonly MemoryPool pool; private readonly DataStructurePool>> ecqEntryPool; private readonly string errorMessages; @@ -54,7 +54,7 @@ internal sealed class SnapshotWindowSlidingPipe : [DataMember] private FastDictionary2> aggregateByKey; [DataMember] - private HashSet heldAggregates = new HashSet(); + private HashSet heldAggregates = []; [DataMember] private ElasticCircularBuffer ecq; [DataMember] @@ -92,9 +92,9 @@ public SnapshotWindowSlidingPipe( this.batch.Allocate(); this.aggregateByKey = comparer.CreateFastDictionary2Generator>(1, this.keyComparerEquals, this.keyComparerGetHashCode, stream.Properties.QueryContainer).Invoke(); - this.ecq = new ElasticCircularBuffer(); + this.ecq = []; var stateDictGenerator = comparer.CreateFastDictionaryGenerator>(1, this.keyComparerEquals, this.keyComparerGetHashCode, stream.Properties.QueryContainer); - this.ecqEntryPool = new DataStructurePool>>(() => stateDictGenerator.Invoke()); + this.ecqEntryPool = new DataStructurePool>>(stateDictGenerator.Invoke); } public override void ProduceQueryPlan(PlanNode previous) @@ -122,7 +122,7 @@ public override unsafe void OnNext(StreamMessage batch) if (col_vother[i] == StreamEvent.PunctuationOtherTime) { // We have found a row that corresponds to punctuation - OnPunctuation(col_vsync[i]); + this.OnPunctuation(col_vsync[i]); int c = this.batch.Count; this.batch.vsync.col[c] = col_vsync[i]; @@ -131,7 +131,7 @@ public override unsafe void OnNext(StreamMessage batch) this.batch.hash.col[c] = 0; this.batch.bitvector.col[c >> 6] |= 1L << (c & 0x3f); this.batch.Count++; - if (this.batch.Count == Config.DataBatchSize) FlushContents(); + if (this.batch.Count == Config.DataBatchSize) this.FlushContents(); } continue; } @@ -139,7 +139,7 @@ public override unsafe void OnNext(StreamMessage batch) var syncTime = col_vsync[i]; // Handle time moving forward - if (syncTime > this.lastSyncTime) AdvanceTime(syncTime); + if (syncTime > this.lastSyncTime) this.AdvanceTime(syncTime); // Need to retrieve the key from the dictionary HeldState heldState; @@ -173,7 +173,7 @@ public override unsafe void OnNext(StreamMessage batch) this.batch.key.col[c] = colkey[i]; this.batch.hash.col[c] = this.keyComparerGetHashCode(colkey[i]); this.batch.Count++; - if (this.batch.Count == Config.DataBatchSize) FlushContents(); + if (this.batch.Count == Config.DataBatchSize) this.FlushContents(); } heldState.timestamp = syncTime; } @@ -250,7 +250,7 @@ public override unsafe void OnNext(StreamMessage batch) public void OnPunctuation(long syncTime) { // Handle time moving forward - if (syncTime > this.lastSyncTime) AdvanceTime(syncTime); + if (syncTime > this.lastSyncTime) this.AdvanceTime(syncTime); } private void AdvanceTime(long syncTime) @@ -269,7 +269,7 @@ private void AdvanceTime(long syncTime) this.batch.key.col[c] = iter1entry.key; this.batch.hash.col[c] = this.keyComparerGetHashCode(iter1entry.key); this.batch.Count++; - if (this.batch.Count == Config.DataBatchSize) FlushContents(); + if (this.batch.Count == Config.DataBatchSize) this.FlushContents(); } else this.aggregateByKey.Remove(iter1entry.key); @@ -299,7 +299,7 @@ private void AdvanceTime(long syncTime) this.batch.key.col[c] = ecqState.states.entries[iter].key; this.batch.hash.col[c] = this.keyComparerGetHashCode(ecqState.states.entries[iter].key); this.batch.Count++; - if (this.batch.Count == Config.DataBatchSize) FlushContents(); + if (this.batch.Count == Config.DataBatchSize) this.FlushContents(); } // Update aggregate @@ -321,7 +321,7 @@ private void AdvanceTime(long syncTime) this.batch.key.col[c] = ecqState.states.entries[iter].key; this.batch.hash.col[c] = this.keyComparerGetHashCode(ecqState.states.entries[iter].key); this.batch.Count++; - if (this.batch.Count == Config.DataBatchSize) FlushContents(); + if (this.batch.Count == Config.DataBatchSize) this.FlushContents(); } else this.aggregateByKey.Remove(ecqState.states.entries[iter].key); diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/SnapshotWindow/Sliding/SnapshotWindowSlidingPipeSimple.cs b/Sources/Core/Microsoft.StreamProcessing/Operators/SnapshotWindow/Sliding/SnapshotWindowSlidingPipeSimple.cs index 36fd57556..a1f4f5d46 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/SnapshotWindow/Sliding/SnapshotWindowSlidingPipeSimple.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/SnapshotWindow/Sliding/SnapshotWindowSlidingPipeSimple.cs @@ -18,7 +18,7 @@ namespace Microsoft.StreamProcessing [DataContract] internal sealed class SnapshotWindowSlidingPipeSimple : UnaryPipe { - private static readonly bool hasDisposableState = typeof(IDisposable).GetTypeInfo().IsAssignableFrom(typeof(TState)); + private static readonly bool hasDisposableState = typeof(IDisposable).IsAssignableFrom(typeof(TState)); private readonly MemoryPool pool; private readonly string errorMessages; @@ -78,7 +78,7 @@ public SnapshotWindowSlidingPipeSimple( this.pool.Get(out this.batch); this.batch.Allocate(); - this.ecq = new ElasticCircularBuffer>(); + this.ecq = []; } public override void ProduceQueryPlan(PlanNode previous) @@ -105,7 +105,7 @@ public override unsafe void OnNext(StreamMessage batch) if (col_vother[i] == StreamEvent.PunctuationOtherTime) { // We have found a row that corresponds to punctuation - OnPunctuation(col_vsync[i]); + this.OnPunctuation(col_vsync[i]); int c = this.batch.Count; this.batch.vsync.col[c] = col_vsync[i]; @@ -114,7 +114,7 @@ public override unsafe void OnNext(StreamMessage batch) this.batch.hash.col[c] = 0; this.batch.bitvector.col[c >> 6] |= 1L << (c & 0x3f); this.batch.Count++; - if (this.batch.Count == Config.DataBatchSize) FlushContents(); + if (this.batch.Count == Config.DataBatchSize) this.FlushContents(); } continue; } @@ -122,7 +122,7 @@ public override unsafe void OnNext(StreamMessage batch) var syncTime = col_vsync[i]; // Handle time moving forward - if (syncTime > this.lastSyncTime) AdvanceTime(syncTime); + if (syncTime > this.lastSyncTime) this.AdvanceTime(syncTime); if (this.currentState == null) { @@ -146,7 +146,7 @@ public override unsafe void OnNext(StreamMessage batch) this.batch.key.col[c] = Empty.Default; this.batch.hash.col[c] = 0; this.batch.Count++; - if (this.batch.Count == Config.DataBatchSize) FlushContents(); + if (this.batch.Count == Config.DataBatchSize) this.FlushContents(); } this.currentState.timestamp = syncTime; @@ -199,7 +199,7 @@ public override unsafe void OnNext(StreamMessage batch) public void OnPunctuation(long syncTime) { // Handle time moving forward - if (syncTime > this.lastSyncTime) AdvanceTime(syncTime); + if (syncTime > this.lastSyncTime) this.AdvanceTime(syncTime); } private void AdvanceTime(long syncTime) @@ -216,7 +216,7 @@ private void AdvanceTime(long syncTime) this.batch.key.col[c] = Empty.Default; this.batch.hash.col[c] = 0; this.batch.Count++; - if (this.batch.Count == Config.DataBatchSize) FlushContents(); + if (this.batch.Count == Config.DataBatchSize) this.FlushContents(); } this.held = false; @@ -236,7 +236,7 @@ private void AdvanceTime(long syncTime) this.batch.key.col[c] = Empty.Default; this.batch.hash.col[c] = 0; this.batch.Count++; - if (this.batch.Count == Config.DataBatchSize) FlushContents(); + if (this.batch.Count == Config.DataBatchSize) this.FlushContents(); } // Update aggregate @@ -256,7 +256,7 @@ private void AdvanceTime(long syncTime) this.batch.key.col[c] = Empty.Default; this.batch.hash.col[c] = 0; this.batch.Count++; - if (this.batch.Count == Config.DataBatchSize) FlushContents(); + if (this.batch.Count == Config.DataBatchSize) this.FlushContents(); } else { diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/SnapshotWindow/SnapshotWindowStreamable.cs b/Sources/Core/Microsoft.StreamProcessing/Operators/SnapshotWindow/SnapshotWindowStreamable.cs index 6d2e0e78f..8df83e754 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/SnapshotWindow/SnapshotWindowStreamable.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/SnapshotWindow/SnapshotWindowStreamable.cs @@ -68,7 +68,7 @@ internal sealed class SnapshotWindowStreamable : UnaryStreamable { private static readonly SafeConcurrentDictionary> cachedPipes - = new SafeConcurrentDictionary>(); + = new(); private readonly StreamProperties sourceProps; private readonly AggregatePipeType apt; @@ -78,7 +78,7 @@ private static readonly SafeConcurrentDictionary> cachedPipe public SnapshotWindowStreamable(IStreamable source, IAggregate aggregate) : base(source, source.Properties.Snapshot(aggregate)) { - Contract.Requires(source != null); + ArgumentNullException.ThrowIfNull(source); this.Aggregate = aggregate; this.sourceProps = source.Properties; @@ -97,7 +97,7 @@ public SnapshotWindowStreamable(IStreamable source, IAggregate a) @@ -115,15 +115,15 @@ internal override IStreamObserver CreatePipe(IStreamObserver CreateStartEdge(IStreamObserver planNode = ((PlanNode p, IQueryObject o) => new SnapshotWindowPlanNode( p, o, typeof(TKey), typeof(TInput), typeof(TOutput), this.apt, this.Aggregate, true, tuple.Item2)); var instance = Activator.CreateInstance(tuple.Item1, this, observer, planNode, this.Aggregate); @@ -182,7 +182,7 @@ internal IStreamObserver CreateTumbling(IStreamObserver planNode = ((PlanNode p, IQueryObject o) => new SnapshotWindowPlanNode( p, o, typeof(TKey), typeof(TInput), typeof(TOutput), this.apt, this.Aggregate, true, tuple.Item2)); var instance = Activator.CreateInstance(tuple.Item1, this, observer, planNode, this.Aggregate, this.sourceProps.ConstantDurationLength.Value); @@ -230,7 +230,7 @@ internal IStreamObserver CreateHopping(IStreamObserver planNode = ((PlanNode p, IQueryObject o) => new SnapshotWindowPlanNode( p, o, typeof(TKey), typeof(TInput), typeof(TOutput), this.apt, this.Aggregate, true, tuple.Item2)); var instance = Activator.CreateInstance(tuple.Item1, this, observer, planNode, this.Aggregate); @@ -278,7 +278,7 @@ internal IStreamObserver CreateSliding(IStreamObserver planNode = ((PlanNode p, IQueryObject o) => new SnapshotWindowPlanNode( p, o, typeof(TKey), typeof(TInput), typeof(TOutput), this.apt, this.Aggregate, true, tuple.Item2)); var instance = Activator.CreateInstance(tuple.Item1, this, observer, planNode, this.Aggregate); @@ -326,7 +326,7 @@ internal IStreamObserver CreatePQ(IStreamObserver o { if (this.Properties.IsColumnar) { - var tuple = GetPipe(); + var tuple = this.GetPipe(); Func planNode = ((PlanNode p, IQueryObject o) => new SnapshotWindowPlanNode( p, o, typeof(TKey), typeof(TInput), typeof(TOutput), this.apt, this.Aggregate, true, tuple.Item2)); var instance = Activator.CreateInstance(tuple.Item1, this, observer, planNode, this.Aggregate); diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/SnapshotWindow/StartEdge/PartitionedSnapshotWindowStartEdgePipe.cs b/Sources/Core/Microsoft.StreamProcessing/Operators/SnapshotWindow/StartEdge/PartitionedSnapshotWindowStartEdgePipe.cs index 1f4923159..371280d50 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/SnapshotWindow/StartEdge/PartitionedSnapshotWindowStartEdgePipe.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/SnapshotWindow/StartEdge/PartitionedSnapshotWindowStartEdgePipe.cs @@ -19,7 +19,7 @@ namespace Microsoft.StreamProcessing [DataContract] internal sealed class PartitionedSnapshotWindowStartEdgePipe : UnaryPipe { - private static readonly bool hasDisposableState = typeof(IDisposable).GetTypeInfo().IsAssignableFrom(typeof(TState)); + private static readonly bool hasDisposableState = typeof(IDisposable).IsAssignableFrom(typeof(TState)); private readonly MemoryPool pool; private readonly string errorMessages; @@ -46,7 +46,7 @@ internal sealed class PartitionedSnapshotWindowStartEdgePipe> aggregateByKey; [DataMember] - private FastDictionary2 partitionData = new FastDictionary2(); + private FastDictionary2 partitionData = new(); private readonly Func getPartitionKey = GetPartitionExtractor(); @@ -105,7 +105,7 @@ public override unsafe void OnNext(StreamMessage batch) { if (col_vother[i] == PartitionedStreamEvent.LowWatermarkOtherTime) { - OnLowWatermark(col_vsync[i]); + this.OnLowWatermark(col_vsync[i]); int c = this.batch.Count; this.batch.vsync.col[c] = col_vsync[i]; @@ -114,7 +114,7 @@ public override unsafe void OnNext(StreamMessage batch) this.batch.hash.col[c] = 0; this.batch.bitvector.col[c >> 6] |= 1L << (c & 0x3f); this.batch.Count++; - if (this.batch.Count == Config.DataBatchSize) FlushContents(); + if (this.batch.Count == Config.DataBatchSize) this.FlushContents(); } else if (col_vother[i] == PartitionedStreamEvent.PunctuationOtherTime) { @@ -124,7 +124,7 @@ public override unsafe void OnNext(StreamMessage batch) if (!this.partitionData.Lookup(p, out int partitionIndex)) this.partitionData.Insert(p, partitionEntry = new PartitionEntry { lastSyncTime = col_vsync[i] }); else partitionEntry = this.partitionData.entries[partitionIndex].value; - OnPunctuation(partitionEntry, col_vsync[i]); + this.OnPunctuation(partitionEntry, col_vsync[i]); int c = this.batch.Count; this.batch.vsync.col[c] = col_vsync[i]; @@ -133,7 +133,7 @@ public override unsafe void OnNext(StreamMessage batch) this.batch.hash.col[c] = this.keyComparerGetHashCode(colkey[i]); this.batch.bitvector.col[c >> 6] |= 1L << (c & 0x3f); this.batch.Count++; - if (this.batch.Count == Config.DataBatchSize) FlushContents(); + if (this.batch.Count == Config.DataBatchSize) this.FlushContents(); } continue; } @@ -161,7 +161,7 @@ public override unsafe void OnNext(StreamMessage batch) this.batch.key.col[c] = iter1entry.key; this.batch.hash.col[c] = this.keyComparerGetHashCode(iter1entry.key); this.batch.Count++; - if (this.batch.Count == Config.DataBatchSize) FlushContents(); + if (this.batch.Count == Config.DataBatchSize) this.FlushContents(); } } @@ -201,7 +201,7 @@ public override unsafe void OnNext(StreamMessage batch) this.batch.key.col[c] = colkey[i]; this.batch.hash.col[c] = this.keyComparerGetHashCode(colkey[i]); this.batch.Count++; - if (this.batch.Count == Config.DataBatchSize) FlushContents(); + if (this.batch.Count == Config.DataBatchSize) this.FlushContents(); heldState.timestamp = syncTime; } } @@ -231,7 +231,7 @@ public void OnLowWatermark(long syncTime) var partition = this.partitionData.entries[iter].value; if (syncTime > partition.lastSyncTime) { - OnPunctuation(partition, syncTime); + this.OnPunctuation(partition, syncTime); // We can safely remove the partition, since its aggregation is still stored in aggregateByKey deprecated.Add(this.partitionData.entries[iter].key); @@ -255,7 +255,7 @@ private void OnPunctuation(PartitionEntry partition, long syncTime) this.batch.key.col[c] = iter1entry.key; this.batch.hash.col[c] = this.keyComparerGetHashCode(iter1entry.key); this.batch.Count++; - if (this.batch.Count == Config.DataBatchSize) FlushContents(); + if (this.batch.Count == Config.DataBatchSize) this.FlushContents(); } // Time has moved forward, clear the held aggregates @@ -294,7 +294,7 @@ protected override void DisposeState() private sealed class PartitionEntry { [DataMember] - public HashSet heldAggregates = new HashSet(); + public HashSet heldAggregates = []; [DataMember] public long lastSyncTime = long.MinValue; } diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/SnapshotWindow/StartEdge/PartitionedSnapshotWindowStartEdgePipeSimple.cs b/Sources/Core/Microsoft.StreamProcessing/Operators/SnapshotWindow/StartEdge/PartitionedSnapshotWindowStartEdgePipeSimple.cs index 8f5787394..a008a1d93 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/SnapshotWindow/StartEdge/PartitionedSnapshotWindowStartEdgePipeSimple.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/SnapshotWindow/StartEdge/PartitionedSnapshotWindowStartEdgePipeSimple.cs @@ -19,7 +19,7 @@ namespace Microsoft.StreamProcessing [DataContract] internal sealed class PartitionedSnapshotWindowStartEdgePipeSimple : UnaryPipe, TInput, TOutput> { - private static readonly bool hasDisposableState = typeof(IDisposable).GetTypeInfo().IsAssignableFrom(typeof(TState)); + private static readonly bool hasDisposableState = typeof(IDisposable).IsAssignableFrom(typeof(TState)); private readonly MemoryPool, TOutput> pool; private readonly string errorMessages; @@ -38,7 +38,7 @@ internal sealed class PartitionedSnapshotWindowStartEdgePipeSimple, TOutput> batch; [DataMember] - private FastDictionary2 partitionData = new FastDictionary2(); + private FastDictionary2 partitionData = new(); [Obsolete("Used only by serialization. Do not call directly.")] public PartitionedSnapshotWindowStartEdgePipeSimple() { } @@ -86,7 +86,7 @@ public override unsafe void OnNext(StreamMessage, TI { if (col_vother[i] == PartitionedStreamEvent.LowWatermarkOtherTime) { - OnLowWatermark(col_vsync[i]); + this.OnLowWatermark(col_vsync[i]); int c = this.batch.Count; this.batch.vsync.col[c] = col_vsync[i]; @@ -95,7 +95,7 @@ public override unsafe void OnNext(StreamMessage, TI this.batch.hash.col[c] = 0; this.batch.bitvector.col[c >> 6] |= 1L << (c & 0x3f); this.batch.Count++; - if (this.batch.Count == Config.DataBatchSize) FlushContents(); + if (this.batch.Count == Config.DataBatchSize) this.FlushContents(); } else if (col_vother[i] == PartitionedStreamEvent.PunctuationOtherTime) { @@ -105,7 +105,7 @@ public override unsafe void OnNext(StreamMessage, TI if (!this.partitionData.Lookup(p, out int partitionIndex)) this.partitionData.Insert(p, (partitionEntry = new PartitionEntry { lastSyncTime = col_vsync[i], currentKey = colkey[i], currentHash = col_hash[i] })); else partitionEntry = this.partitionData.entries[partitionIndex].value; - OnPunctuation(partitionEntry, col_vsync[i]); + this.OnPunctuation(partitionEntry, col_vsync[i]); int c = this.batch.Count; this.batch.vsync.col[c] = col_vsync[i]; @@ -114,7 +114,7 @@ public override unsafe void OnNext(StreamMessage, TI this.batch.hash.col[c] = partitionEntry.currentHash; this.batch.bitvector.col[c >> 6] |= 1L << (c & 0x3f); this.batch.Count++; - if (this.batch.Count == Config.DataBatchSize) FlushContents(); + if (this.batch.Count == Config.DataBatchSize) this.FlushContents(); } continue; } @@ -139,7 +139,7 @@ public override unsafe void OnNext(StreamMessage, TI this.batch.key.col[c] = entry.currentKey; this.batch.hash.col[c] = entry.currentHash; this.batch.Count++; - if (this.batch.Count == Config.DataBatchSize) FlushContents(); + if (this.batch.Count == Config.DataBatchSize) this.FlushContents(); entry.held = false; } @@ -164,7 +164,7 @@ public override unsafe void OnNext(StreamMessage, TI this.batch.key.col[c] = entry.currentKey; this.batch.hash.col[c] = entry.currentHash; this.batch.Count++; - if (this.batch.Count == Config.DataBatchSize) FlushContents(); + if (this.batch.Count == Config.DataBatchSize) this.FlushContents(); entry.currentState.timestamp = syncTime; entry.held = true; @@ -191,7 +191,7 @@ public void OnLowWatermark(long syncTime) var partition = this.partitionData.entries[iter].value; if (syncTime > partition.lastSyncTime) { - OnPunctuation(partition, syncTime); + this.OnPunctuation(partition, syncTime); if (partition.currentState == null) deprecated.Add(this.partitionData.entries[iter].key); } @@ -213,7 +213,7 @@ private void OnPunctuation(PartitionEntry partition, long syncTime) this.batch.key.col[c] = partition.currentKey; this.batch.hash.col[c] = partition.currentHash; this.batch.Count++; - if (this.batch.Count == Config.DataBatchSize) FlushContents(); + if (this.batch.Count == Config.DataBatchSize) this.FlushContents(); partition.held = false; } diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/SnapshotWindow/StartEdge/SnapshotWindowStartEdgePipe.cs b/Sources/Core/Microsoft.StreamProcessing/Operators/SnapshotWindow/StartEdge/SnapshotWindowStartEdgePipe.cs index 3da156a68..ecf6be7d5 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/SnapshotWindow/StartEdge/SnapshotWindowStartEdgePipe.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/SnapshotWindow/StartEdge/SnapshotWindowStartEdgePipe.cs @@ -19,7 +19,7 @@ namespace Microsoft.StreamProcessing [DataContract] internal sealed class SnapshotWindowStartEdgePipe : UnaryPipe { - private static readonly bool hasDisposableState = typeof(IDisposable).GetTypeInfo().IsAssignableFrom(typeof(TState)); + private static readonly bool hasDisposableState = typeof(IDisposable).IsAssignableFrom(typeof(TState)); private readonly MemoryPool pool; private readonly string errorMessages; @@ -46,7 +46,7 @@ internal sealed class SnapshotWindowStartEdgePipe [DataMember] private FastDictionary2> aggregateByKey; [DataMember] - private HashSet heldAggregates = new HashSet(); + private HashSet heldAggregates = []; [DataMember] private long lastSyncTime = long.MinValue; @@ -103,7 +103,7 @@ public override unsafe void OnNext(StreamMessage batch) if (col_vother[i] == StreamEvent.PunctuationOtherTime) { // We have found a row that corresponds to punctuation - OnPunctuation(col_vsync[i]); + this.OnPunctuation(col_vsync[i]); int c = this.batch.Count; this.batch.vsync.col[c] = col_vsync[i]; @@ -112,7 +112,7 @@ public override unsafe void OnNext(StreamMessage batch) this.batch.hash.col[c] = 0; this.batch.bitvector.col[c >> 6] |= 1L << (c & 0x3f); this.batch.Count++; - if (this.batch.Count == Config.DataBatchSize) FlushContents(); + if (this.batch.Count == Config.DataBatchSize) this.FlushContents(); } continue; } @@ -133,7 +133,7 @@ public override unsafe void OnNext(StreamMessage batch) this.batch.key.col[c] = iter1entry.key; this.batch.hash.col[c] = this.keyComparerGetHashCode(iter1entry.key); this.batch.Count++; - if (this.batch.Count == Config.DataBatchSize) FlushContents(); + if (this.batch.Count == Config.DataBatchSize) this.FlushContents(); } this.heldAggregates.Clear(); @@ -171,7 +171,7 @@ public override unsafe void OnNext(StreamMessage batch) this.batch.key.col[c] = colkey[i]; this.batch.hash.col[c] = this.keyComparerGetHashCode(colkey[i]); this.batch.Count++; - if (this.batch.Count == Config.DataBatchSize) FlushContents(); + if (this.batch.Count == Config.DataBatchSize) this.FlushContents(); heldState.timestamp = syncTime; } } @@ -206,7 +206,7 @@ public void OnPunctuation(long syncTime) this.batch.key.col[c] = iter1entry.key; this.batch.hash.col[c] = this.keyComparerGetHashCode(iter1entry.key); this.batch.Count++; - if (this.batch.Count == Config.DataBatchSize) FlushContents(); + if (this.batch.Count == Config.DataBatchSize) this.FlushContents(); } // Time has moved forward, clear the held aggregates diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/SnapshotWindow/StartEdge/SnapshotWindowStartEdgePipeSimple.cs b/Sources/Core/Microsoft.StreamProcessing/Operators/SnapshotWindow/StartEdge/SnapshotWindowStartEdgePipeSimple.cs index 14fc77556..4d09ea49e 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/SnapshotWindow/StartEdge/SnapshotWindowStartEdgePipeSimple.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/SnapshotWindow/StartEdge/SnapshotWindowStartEdgePipeSimple.cs @@ -18,7 +18,7 @@ namespace Microsoft.StreamProcessing [DataContract] internal sealed class SnapshotWindowStartEdgePipeSimple : UnaryPipe { - private static readonly bool hasDisposableState = typeof(IDisposable).GetTypeInfo().IsAssignableFrom(typeof(TState)); + private static readonly bool hasDisposableState = typeof(IDisposable).IsAssignableFrom(typeof(TState)); private readonly MemoryPool pool; private readonly string errorMessages; @@ -86,7 +86,7 @@ public override unsafe void OnNext(StreamMessage batch) if (col_vother[i] == StreamEvent.PunctuationOtherTime) { // We have found a row that corresponds to punctuation - OnPunctuation(col_vsync[i]); + this.OnPunctuation(col_vsync[i]); int c = this.batch.Count; this.batch.vsync.col[c] = col_vsync[i]; @@ -95,7 +95,7 @@ public override unsafe void OnNext(StreamMessage batch) this.batch.hash.col[c] = 0; this.batch.bitvector.col[c >> 6] |= 1L << (c & 0x3f); this.batch.Count++; - if (this.batch.Count == Config.DataBatchSize) FlushContents(); + if (this.batch.Count == Config.DataBatchSize) this.FlushContents(); } continue; } @@ -114,7 +114,7 @@ public override unsafe void OnNext(StreamMessage batch) this.batch.key.col[c] = Empty.Default; this.batch.hash.col[c] = 0; this.batch.Count++; - if (this.batch.Count == Config.DataBatchSize) FlushContents(); + if (this.batch.Count == Config.DataBatchSize) this.FlushContents(); this.held = false; } @@ -139,7 +139,7 @@ public override unsafe void OnNext(StreamMessage batch) this.batch.key.col[c] = Empty.Default; this.batch.hash.col[c] = 0; this.batch.Count++; - if (this.batch.Count == Config.DataBatchSize) FlushContents(); + if (this.batch.Count == Config.DataBatchSize) this.FlushContents(); this.currentState.timestamp = syncTime; this.held = true; @@ -169,7 +169,7 @@ public void OnPunctuation(long syncTime) this.batch.key.col[c] = Empty.Default; this.batch.hash.col[c] = 0; this.batch.Count++; - if (this.batch.Count == Config.DataBatchSize) FlushContents(); + if (this.batch.Count == Config.DataBatchSize) this.FlushContents(); this.held = false; } diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/SnapshotWindow/Tumbling/PartitionedSnapshotWindowTumblingPipe.cs b/Sources/Core/Microsoft.StreamProcessing/Operators/SnapshotWindow/Tumbling/PartitionedSnapshotWindowTumblingPipe.cs index b1ba2a43e..45525efaf 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/SnapshotWindow/Tumbling/PartitionedSnapshotWindowTumblingPipe.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/SnapshotWindow/Tumbling/PartitionedSnapshotWindowTumblingPipe.cs @@ -19,7 +19,7 @@ namespace Microsoft.StreamProcessing [DataContract] internal sealed class PartitionedSnapshotWindowTumblingPipe : UnaryPipe { - private static readonly bool hasDisposableState = typeof(IDisposable).GetTypeInfo().IsAssignableFrom(typeof(TState)); + private static readonly bool hasDisposableState = typeof(IDisposable).IsAssignableFrom(typeof(TState)); private readonly MemoryPool pool; private readonly string errorMessages; private readonly IAggregate aggregate; @@ -46,7 +46,7 @@ internal sealed class PartitionedSnapshotWindowTumblingPipe batch; [DataMember] - private FastDictionary2 partitionData = new FastDictionary2(); + private FastDictionary2 partitionData = new(); private readonly Func getPartitionKey = GetPartitionExtractor(); private readonly Func> dictionaryGenerator; @@ -104,7 +104,7 @@ public override unsafe void OnNext(StreamMessage batch) { if (col_vother[i] == PartitionedStreamEvent.LowWatermarkOtherTime) { - OnLowWatermark(col_vsync[i]); + this.OnLowWatermark(col_vsync[i]); int c = this.batch.Count; this.batch.vsync.col[c] = col_vsync[i]; @@ -113,7 +113,7 @@ public override unsafe void OnNext(StreamMessage batch) this.batch.hash.col[c] = 0; this.batch.bitvector.col[c >> 6] |= 1L << (c & 0x3f); this.batch.Count++; - if (this.batch.Count == Config.DataBatchSize) FlushContents(); + if (this.batch.Count == Config.DataBatchSize) this.FlushContents(); } else if (col_vother[i] == PartitionedStreamEvent.PunctuationOtherTime) { @@ -131,7 +131,7 @@ public override unsafe void OnNext(StreamMessage batch) partitionEntry = this.partitionData.entries[partitionKeyIndex].value; emitPunctuation = partitionEntry.lastSyncTime < col_vsync[i]; } - OnPunctuation(partitionEntry, col_vsync[i]); + this.OnPunctuation(partitionEntry, col_vsync[i]); if (emitPunctuation) { @@ -142,7 +142,7 @@ public override unsafe void OnNext(StreamMessage batch) this.batch.hash.col[c] = col_hash[i]; this.batch.bitvector.col[c >> 6] |= 1L << (c & 0x3f); this.batch.Count++; - if (this.batch.Count == Config.DataBatchSize) FlushContents(); + if (this.batch.Count == Config.DataBatchSize) this.FlushContents(); } } continue; @@ -169,7 +169,7 @@ public override unsafe void OnNext(StreamMessage batch) this.batch.key.col[c] = iter1entry.key; this.batch.hash.col[c] = this.keyComparerGetHashCode(iter1entry.key); this.batch.Count++; - if (this.batch.Count == Config.DataBatchSize) FlushContents(); + if (this.batch.Count == Config.DataBatchSize) this.FlushContents(); if (hasDisposableState) { @@ -206,7 +206,7 @@ public void OnLowWatermark(long syncTime) var partition = this.partitionData.entries[iter].value; if (syncTime > partition.lastSyncTime) { - OnPunctuation(partition, syncTime); + this.OnPunctuation(partition, syncTime); deprecated.Add(this.partitionData.entries[iter].key); } } @@ -230,7 +230,7 @@ private void OnPunctuation(PartitionEntry partition, long syncTime) this.batch.key.col[c] = iter1entry.key; this.batch.hash.col[c] = this.keyComparerGetHashCode(iter1entry.key); this.batch.Count++; - if (this.batch.Count == Config.DataBatchSize) FlushContents(); + if (this.batch.Count == Config.DataBatchSize) this.FlushContents(); if (hasDisposableState) { diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/SnapshotWindow/Tumbling/PartitionedSnapshotWindowTumblingPipeSimple.cs b/Sources/Core/Microsoft.StreamProcessing/Operators/SnapshotWindow/Tumbling/PartitionedSnapshotWindowTumblingPipeSimple.cs index 976e37502..2f03edb6e 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/SnapshotWindow/Tumbling/PartitionedSnapshotWindowTumblingPipeSimple.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/SnapshotWindow/Tumbling/PartitionedSnapshotWindowTumblingPipeSimple.cs @@ -19,7 +19,7 @@ namespace Microsoft.StreamProcessing [DataContract] internal sealed class PartitionedSnapshotWindowTumblingPipeSimple : UnaryPipe, TInput, TOutput> { - private static readonly bool hasDisposableState = typeof(IDisposable).GetTypeInfo().IsAssignableFrom(typeof(TState)); + private static readonly bool hasDisposableState = typeof(IDisposable).IsAssignableFrom(typeof(TState)); private readonly MemoryPool, TOutput> pool; private readonly string errorMessages; private readonly IAggregate aggregate; @@ -40,7 +40,7 @@ internal sealed class PartitionedSnapshotWindowTumblingPipeSimple, TOutput> batch; [DataMember] - private FastDictionary2 partitionData = new FastDictionary2(); + private FastDictionary2 partitionData = new(); [Obsolete("Used only by serialization. Do not call directly.")] public PartitionedSnapshotWindowTumblingPipeSimple() { } @@ -88,7 +88,7 @@ public override unsafe void OnNext(StreamMessage, TI { if (col_vother[i] == PartitionedStreamEvent.LowWatermarkOtherTime) { - OnLowWatermark(col_vsync[i]); + this.OnLowWatermark(col_vsync[i]); int c = this.batch.Count; this.batch.vsync.col[c] = col_vsync[i]; @@ -97,7 +97,7 @@ public override unsafe void OnNext(StreamMessage, TI this.batch.hash.col[c] = 0; this.batch.bitvector.col[c >> 6] |= 1L << (c & 0x3f); this.batch.Count++; - if (this.batch.Count == Config.DataBatchSize) FlushContents(); + if (this.batch.Count == Config.DataBatchSize) this.FlushContents(); } else if (col_vother[i] == PartitionedStreamEvent.PunctuationOtherTime) { @@ -115,7 +115,7 @@ public override unsafe void OnNext(StreamMessage, TI partitionEntry = this.partitionData.entries[partitionKeyIndex].value; emitPunctuation = partitionEntry.lastSyncTime < col_vsync[i]; } - OnPunctuation(partitionEntry, col_vsync[i]); + this.OnPunctuation(partitionEntry, col_vsync[i]); if (emitPunctuation) { @@ -126,7 +126,7 @@ public override unsafe void OnNext(StreamMessage, TI this.batch.hash.col[c] = col_hash[i]; this.batch.bitvector.col[c >> 6] |= 1L << (c & 0x3f); this.batch.Count++; - if (this.batch.Count == Config.DataBatchSize) FlushContents(); + if (this.batch.Count == Config.DataBatchSize) this.FlushContents(); } } continue; @@ -151,7 +151,7 @@ public override unsafe void OnNext(StreamMessage, TI this.batch.key.col[c] = colkey[i]; this.batch.hash.col[c] = col_hash[i]; this.batch.Count++; - if (this.batch.Count == Config.DataBatchSize) FlushContents(); + if (this.batch.Count == Config.DataBatchSize) this.FlushContents(); if (hasDisposableState) { @@ -206,7 +206,7 @@ public void OnLowWatermark(long syncTime) var partition = this.partitionData.entries[iter].value; if (syncTime > partition.lastSyncTime) { - OnPunctuation(partition, syncTime); + this.OnPunctuation(partition, syncTime); deprecated.Add(this.partitionData.entries[iter].key); } } @@ -227,7 +227,7 @@ private void OnPunctuation(PartitionEntry partition, long syncTime) this.batch.key.col[c] = partition.key; this.batch.hash.col[c] = partition.hash; this.batch.Count++; - if (this.batch.Count == Config.DataBatchSize) FlushContents(); + if (this.batch.Count == Config.DataBatchSize) this.FlushContents(); if (hasDisposableState) { diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/SnapshotWindow/Tumbling/SnapshotWindowTumblingPipe.cs b/Sources/Core/Microsoft.StreamProcessing/Operators/SnapshotWindow/Tumbling/SnapshotWindowTumblingPipe.cs index c0a947914..0bd57aa5f 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/SnapshotWindow/Tumbling/SnapshotWindowTumblingPipe.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/SnapshotWindow/Tumbling/SnapshotWindowTumblingPipe.cs @@ -18,7 +18,7 @@ namespace Microsoft.StreamProcessing [DataContract] internal sealed class SnapshotWindowTumblingPipe : UnaryPipe { - private static readonly bool hasDisposableState = typeof(IDisposable).GetTypeInfo().IsAssignableFrom(typeof(TState)); + private static readonly bool hasDisposableState = typeof(IDisposable).IsAssignableFrom(typeof(TState)); private readonly MemoryPool pool; private readonly string errorMessages; private readonly IAggregate aggregate; @@ -103,7 +103,7 @@ public override unsafe void OnNext(StreamMessage batch) if (col_vother[i] == StreamEvent.PunctuationOtherTime) { // We have found a row that corresponds to punctuation - OnPunctuation(col_vsync[i]); + this.OnPunctuation(col_vsync[i]); int c = this.batch.Count; this.batch.vsync.col[c] = col_vsync[i]; @@ -112,7 +112,7 @@ public override unsafe void OnNext(StreamMessage batch) this.batch.hash.col[c] = 0; this.batch.bitvector.col[c >> 6] |= 1L << (c & 0x3f); this.batch.Count++; - if (this.batch.Count == Config.DataBatchSize) FlushContents(); + if (this.batch.Count == Config.DataBatchSize) this.FlushContents(); } continue; } @@ -132,10 +132,10 @@ public override unsafe void OnNext(StreamMessage batch) this.batch.key.col[c] = iter1entry.key; this.batch.hash.col[c] = this.keyComparerGetHashCode(iter1entry.key); this.batch.Count++; - if (this.batch.Count == Config.DataBatchSize) FlushContents(); + if (this.batch.Count == Config.DataBatchSize) this.FlushContents(); } - if (hasDisposableState) DisposeStateLocal(); + if (hasDisposableState) this.DisposeStateLocal(); this.heldAggregates.Clear(); // Since sync time changed, set lastSyncTime @@ -171,11 +171,11 @@ public void OnPunctuation(long syncTime) this.batch.key.col[c] = iter1entry.key; this.batch.hash.col[c] = this.keyComparerGetHashCode(iter1entry.key); this.batch.Count++; - if (this.batch.Count == Config.DataBatchSize) FlushContents(); + if (this.batch.Count == Config.DataBatchSize) this.FlushContents(); } // Time has moved forward, clear the held aggregates - if (hasDisposableState) DisposeStateLocal(); + if (hasDisposableState) this.DisposeStateLocal(); this.heldAggregates.Clear(); // Since sync time changed, set lastSyncTime @@ -198,15 +198,16 @@ protected override void FlushContents() private void DisposeStateLocal() { - int index = FastDictionary2.IteratorStart; + int index = FastDictionary.IteratorStart; while (this.heldAggregates.Iterate(ref index)) (this.heldAggregates.entries[index].value as IDisposable).Dispose(); } protected override void DisposeState() { + if (hasDisposableState) this.DisposeStateLocal(); + this.heldAggregates.Dispose(); this.batch.Free(); - if (hasDisposableState) DisposeStateLocal(); } } } diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/SnapshotWindow/Tumbling/SnapshotWindowTumblingPipeSimple.cs b/Sources/Core/Microsoft.StreamProcessing/Operators/SnapshotWindow/Tumbling/SnapshotWindowTumblingPipeSimple.cs index 7c78ace2e..5997bb9cf 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/SnapshotWindow/Tumbling/SnapshotWindowTumblingPipeSimple.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/SnapshotWindow/Tumbling/SnapshotWindowTumblingPipeSimple.cs @@ -19,7 +19,7 @@ namespace Microsoft.StreamProcessing [DataContract] internal sealed class SnapshotWindowTumblingPipeSimple : UnaryPipe { - private static readonly bool hasDisposableState = typeof(IDisposable).GetTypeInfo().IsAssignableFrom(typeof(TState)); + private static readonly bool hasDisposableState = typeof(IDisposable).IsAssignableFrom(typeof(TState)); private readonly MemoryPool pool; private readonly string errorMessages; private readonly IAggregate aggregate; @@ -90,7 +90,7 @@ public override unsafe void OnNext(StreamMessage batch) if (col_vother[i] == StreamEvent.PunctuationOtherTime) { // We have found a row that corresponds to punctuation - OnPunctuation(col_vsync[i]); + this.OnPunctuation(col_vsync[i]); int c = this.batch.Count; this.batch.vsync.col[c] = col_vsync[i]; @@ -99,7 +99,7 @@ public override unsafe void OnNext(StreamMessage batch) this.batch.hash.col[c] = 0; this.batch.bitvector.col[c >> 6] |= 1L << (c & 0x3f); this.batch.Count++; - if (this.batch.Count == Config.DataBatchSize) FlushContents(); + if (this.batch.Count == Config.DataBatchSize) this.FlushContents(); } continue; } @@ -117,9 +117,9 @@ public override unsafe void OnNext(StreamMessage batch) this.batch.key.col[c] = Empty.Default; this.batch.hash.col[c] = 0; this.batch.Count++; - if (this.batch.Count == Config.DataBatchSize) FlushContents(); + if (this.batch.Count == Config.DataBatchSize) this.FlushContents(); - if (hasDisposableState) DisposeStateLocal(); + if (hasDisposableState) this.DisposeStateLocal(); this.currentState = null; } @@ -134,7 +134,7 @@ public override unsafe void OnNext(StreamMessage batch) if (syncTime > this.currentState.timestamp) { // Reset currentState - if (hasDisposableState) DisposeStateLocal(); + if (hasDisposableState) this.DisposeStateLocal(); this.currentState.state = this.initialState(); this.currentState.timestamp = syncTime; } @@ -162,9 +162,9 @@ public void OnPunctuation(long syncTime) this.batch.key.col[c] = Empty.Default; this.batch.hash.col[c] = 0; this.batch.Count++; - if (this.batch.Count == Config.DataBatchSize) FlushContents(); + if (this.batch.Count == Config.DataBatchSize) this.FlushContents(); - if (hasDisposableState) DisposeStateLocal(); + if (hasDisposableState) this.DisposeStateLocal(); this.currentState = null; } @@ -198,7 +198,7 @@ private void DisposeStateLocal() protected override void DisposeState() { this.batch.Free(); - if (hasDisposableState) DisposeStateLocal(); + if (hasDisposableState) this.DisposeStateLocal(); } } } diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/SprayGroupImport/SprayGroupImportPipe.cs b/Sources/Core/Microsoft.StreamProcessing/Operators/SprayGroupImport/SprayGroupImportPipe.cs index 174dbb335..8fc2baff0 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/SprayGroupImport/SprayGroupImportPipe.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/SprayGroupImport/SprayGroupImportPipe.cs @@ -47,7 +47,7 @@ public SynchronousGAPipe( this.l1_spray = 0; - this.Observers = new List>(); + this.Observers = []; this.pool = MemoryManager.GetMemoryPool(stream.Properties.IsColumnar); } diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/SprayGroupImport/SprayGroupImportStreamable.cs b/Sources/Core/Microsoft.StreamProcessing/Operators/SprayGroupImport/SprayGroupImportStreamable.cs index 4a975f263..d8546c8aa 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/SprayGroupImport/SprayGroupImportStreamable.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/SprayGroupImport/SprayGroupImportStreamable.cs @@ -27,7 +27,7 @@ public SprayGroupImportStreamable( IComparerExpression sprayComparer = null) : base(source.Properties.ToMulticore(true)) { - Contract.Requires(source != null); + ArgumentNullException.ThrowIfNull(source); this.totalBranches = totalBranches; this.Source = source; @@ -49,7 +49,7 @@ public override IDisposable Subscribe(IStreamObserver observer) this.numBranches++; if (this.pipe == null) { - this.pipe = CreatePipe(observer); + this.pipe = this.CreatePipe(observer); } var o = (!this.multicast) && (this.spraySortOrderComparer == null) diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/Stitch/PartitionedStitchPipe.cs b/Sources/Core/Microsoft.StreamProcessing/Operators/Stitch/PartitionedStitchPipe.cs index ad7b83ae9..969464f3b 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/Stitch/PartitionedStitchPipe.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/Stitch/PartitionedStitchPipe.cs @@ -29,20 +29,20 @@ internal sealed class PartitionedStitchPipe : Una [DataMember] private FastDictionary> CurrentTimeOpenEventBuffer = - new FastDictionary>(); + new(); private readonly Func> CurrentTimeOpenEventBufferGenerator; [DataMember] private int CurrentTimeOpenEventBufferIndex; [DataMember] private FastDictionary CurrentTimeOpenEventBufferTime = - new FastDictionary(); + new(); [DataMember] private int CurrentTimeOpenEventBufferTimeIndex; [DataMember] private FastDictionary now = - new FastDictionary(); + new(); [DataMember] private int nowIndex; @@ -52,7 +52,7 @@ internal sealed class PartitionedStitchPipe : Una // The VALUE version in this dictionary has the ORIGINAL, EARLY Start Time [DataMember] private FastDictionary>> OpenEvents = - new FastDictionary>>(); + new(); private readonly Func>> OpenEventsGenerator; [DataMember] private int OpenEventsIndex; @@ -62,7 +62,7 @@ internal sealed class PartitionedStitchPipe : Una // The End event moves an item from the OpenEvent to the ClosedEvent set [DataMember] private FastDictionary>>> ClosedEvents = - new FastDictionary>>>(); + new(); [DataMember] private int ClosedEventsIndex; @@ -85,13 +85,13 @@ public PartitionedStitchPipe(IStreamable stream, IStreamObserver var getHashCode = khpcomparer.GetGetHashCodeExpr().Compile(); var generator1 = khpcomparer.CreateFastDictionary2Generator>(1, equals, getHashCode, stream.Properties.QueryContainer); - this.dictPool = new DataStructurePool>>(() => generator1.Invoke()); + this.dictPool = new DataStructurePool>>(generator1.Invoke); var generator2 = khpcomparer.CreateFastDictionary2Generator(1, equals, getHashCode, stream.Properties.QueryContainer); - this.CurrentTimeOpenEventBufferGenerator = () => generator2.Invoke(); + this.CurrentTimeOpenEventBufferGenerator = generator2.Invoke; var generator3 = khpcomparer.CreateFastDictionary2Generator>(1, equals, getHashCode, stream.Properties.QueryContainer); - this.OpenEventsGenerator = () => generator3.Invoke(); + this.OpenEventsGenerator = generator3.Invoke; } [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -105,7 +105,7 @@ private static void InsertOrAppend(FastDictionary2> events, K k } else { - lst = new List(); + lst = []; events.Insert(key, lst); lst.Add(value); } @@ -172,7 +172,7 @@ public static ActiveEvent FromExt(ActiveEventExt item) return rv; } - public override string ToString() + public override readonly string ToString() => "[Start=" + this.Start + ", End=" + this.End + ", Key='" + this.Key + "', Payload='" + this.Payload + "']"; } @@ -185,7 +185,7 @@ private struct ActiveEventExt public TKey Key; public int Hash; - public override string ToString() + public override readonly string ToString() => "[OriginalStart=" + this.OriginalStart + ", Start=" + this.Start + ", End=" + this.End + ", Key='" + this.Key + "', Payload='" + this.Payload + "']"; } @@ -195,7 +195,7 @@ private struct KHP public TKey Key; public int Hash; - public override string ToString() + public override readonly string ToString() => "[Key='" + this.Key + "', Payload='" + this.Payload + "']"; } @@ -225,7 +225,7 @@ public override unsafe void OnNext(StreamMessage input) if ((src_bv[i >> 6] & (1L << (i & 0x3f))) == 0 || *vother < 0) { var partitionKey = this.getPartitionKey(input.key.col[i]); - if (!this.ClosedEvents.Lookup(partitionKey, out this.ClosedEventsIndex)) this.ClosedEvents.Insert(ref this.ClosedEventsIndex, partitionKey, new SortedDictionary>>()); + if (!this.ClosedEvents.Lookup(partitionKey, out this.ClosedEventsIndex)) this.ClosedEvents.Insert(ref this.ClosedEventsIndex, partitionKey, []); if (!this.OpenEvents.Lookup(partitionKey, out this.OpenEventsIndex)) this.OpenEvents.Insert(ref this.OpenEventsIndex, partitionKey, this.OpenEventsGenerator()); if (!this.now.Lookup(partitionKey, out this.nowIndex)) this.now.Insert(ref this.nowIndex, partitionKey, StreamEvent.MinSyncTime); if (!this.CurrentTimeOpenEventBufferTime.Lookup(partitionKey, out this.CurrentTimeOpenEventBufferTimeIndex)) this.CurrentTimeOpenEventBufferTime.Insert(ref this.CurrentTimeOpenEventBufferTimeIndex, partitionKey, StreamEvent.MinSyncTime); @@ -235,16 +235,16 @@ public override unsafe void OnNext(StreamMessage input) if (this.now.entries[this.nowIndex].value < sync) { this.now.entries[this.nowIndex].value = sync; - Purge(this.now.entries[this.nowIndex].value); + this.Purge(this.now.entries[this.nowIndex].value); } if (*vother == StreamEvent.InfinitySyncTime) { - ActOnStart(input.payload.col[i], input.key.col[i], *hash, *vsync); + this.ActOnStart(input.payload.col[i], input.key.col[i], *hash, *vsync); } else if (*vother == PartitionedStreamEvent.LowWatermarkOtherTime) { - PurgeGlobal(*vsync); + this.PurgeGlobal(*vsync); this.batch.vsync.col[this.outputCount] = *vsync; this.batch.vother.col[this.outputCount] = *vother; @@ -254,20 +254,20 @@ public override unsafe void OnNext(StreamMessage input) this.batch.bitvector.col[this.outputCount >> 6] |= 1L << (this.outputCount & 0x3f); this.outputCount++; - if (this.outputCount == Config.DataBatchSize) FlushContents(); + if (this.outputCount == Config.DataBatchSize) this.FlushContents(); } else if (*vother == PartitionedStreamEvent.PunctuationOtherTime) { - Purge(*vsync); + this.Purge(*vsync); } else if (*vsync < *vother) { - ActOnStart(input.payload.col[i], input.key.col[i], *hash, *vsync); - ActOnEnd(input.payload.col[i], input.key.col[i], *hash, *vsync, *vother); + this.ActOnStart(input.payload.col[i], input.key.col[i], *hash, *vsync); + this.ActOnEnd(input.payload.col[i], input.key.col[i], *hash, *vsync, *vother); } else { - ActOnEnd(input.payload.col[i], input.key.col[i], *hash, *vother, *vsync); + this.ActOnEnd(input.payload.col[i], input.key.col[i], *hash, *vother, *vsync); } } @@ -347,7 +347,7 @@ private void ActOnStart(TPayload payload, TKey key, int hash, long eventstart, b }; // brand new event! Issue a public version - Emit(ActiveEvent.FromExt(activeEventExt)); + this.Emit(ActiveEvent.FromExt(activeEventExt)); InsertOrAppend(this.OpenEvents.entries[this.OpenEventsIndex].value, lookupStart, activeEventExt); } } @@ -388,7 +388,7 @@ private void PurgeGlobal(long time) var partitionKey = this.ClosedEvents.entries[this.ClosedEventsIndex].key; this.CurrentTimeOpenEventBufferTime.Lookup(partitionKey, out this.CurrentTimeOpenEventBufferTimeIndex); this.CurrentTimeOpenEventBuffer.Lookup(partitionKey, out this.CurrentTimeOpenEventBufferIndex); - Purge(time); + this.Purge(time); } } @@ -402,7 +402,7 @@ private void Purge(long time) { var e = this.CurrentTimeOpenEventBuffer.entries[this.CurrentTimeOpenEventBufferIndex].value.entries[it].key; for (int i = 0; i < this.CurrentTimeOpenEventBuffer.entries[this.CurrentTimeOpenEventBufferIndex].value.entries[it].value; i++) - ActOnStart(e.Payload, e.Key, e.Hash, this.CurrentTimeOpenEventBufferTime.entries[this.CurrentTimeOpenEventBufferTimeIndex].value, true); + this.ActOnStart(e.Payload, e.Key, e.Hash, this.CurrentTimeOpenEventBufferTime.entries[this.CurrentTimeOpenEventBufferTimeIndex].value, true); } @@ -414,7 +414,7 @@ private void Purge(long time) var iterator = FastDictionary2.IteratorStart; while (closed.Value.Iterate(ref iterator)) { - foreach (var v in closed.Value.entries[iterator].value) Emit(v); + foreach (var v in closed.Value.entries[iterator].value) this.Emit(v); } closed.Value.Initialize(); this.ClosedEvents.entries[this.ClosedEventsIndex].value.Remove(closed.Key); @@ -448,7 +448,7 @@ private void Emit(ActiveEvent evt) dest_hash[this.outputCount] = evt.Hash; this.outputCount++; - if (this.outputCount == Config.DataBatchSize) FlushContents(); + if (this.outputCount == Config.DataBatchSize) this.FlushContents(); } public override int CurrentlyBufferedOutputCount => this.outputCount; diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/Stitch/StitchPipe.cs b/Sources/Core/Microsoft.StreamProcessing/Operators/Stitch/StitchPipe.cs index c2c867553..215fce49a 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/Stitch/StitchPipe.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/Stitch/StitchPipe.cs @@ -45,7 +45,7 @@ internal sealed class StitchPipe : UnaryPipe>> ClosedEvents = - new SortedDictionary>>(); + []; [Obsolete("Used only by serialization. Do not call directly.")] public StitchPipe() { } @@ -64,7 +64,7 @@ public StitchPipe(StitchStreamable stream, IStreamObserver>(1, equals, getHashCode, stream.Properties.QueryContainer); - this.dictPool = new DataStructurePool>>(() => generator.Invoke()); + this.dictPool = new DataStructurePool>>(generator.Invoke); this.outputCount = 0; this.CurrentTimeOpenEventBuffer = khpcomparer.CreateFastDictionary2Generator(1, equals, getHashCode, stream.Properties.QueryContainer).Invoke(); this.OpenEvents = khpcomparer.CreateFastDictionary2Generator>(1, equals, getHashCode, stream.Properties.QueryContainer).Invoke(); @@ -81,7 +81,7 @@ private static void InsertOrAppend(FastDictionary2> events, K k } else { - lst = new List(); + lst = []; events.Insert(key, lst); lst.Add(value); } @@ -148,7 +148,7 @@ public static ActiveEvent FromExt(ActiveEventExt item) return rv; } - public override string ToString() + public override readonly string ToString() => "[Start=" + this.Start + ", End=" + this.End + ", Key='" + this.Key + "', Payload='" + this.Payload + "']"; } @@ -161,7 +161,7 @@ private struct ActiveEventExt public TKey Key; public int Hash; - public override string ToString() + public override readonly string ToString() => "[OriginalStart=" + this.OriginalStart + ", Start=" + this.Start + ", End=" + this.End + ", Key='" + this.Key + "', Payload='" + this.Payload + "']"; } @@ -171,7 +171,7 @@ private struct KHP public TKey Key; public int Hash; - public override string ToString() + public override readonly string ToString() => "[Key='" + this.Key + "', Payload='" + this.Payload + "']"; } @@ -204,12 +204,12 @@ public override unsafe void OnNext(StreamMessage input) if (this.now < sync) { this.now = sync; - Purge(sync); + this.Purge(sync); } if (*vother == StreamEvent.InfinitySyncTime) { - ActOnStart(input[i], input.key.col[i], *hash, *vsync); + this.ActOnStart(input[i], input.key.col[i], *hash, *vsync); } else if (*vother == StreamEvent.PunctuationOtherTime) { @@ -221,16 +221,16 @@ public override unsafe void OnNext(StreamMessage input) this.batch.bitvector.col[this.outputCount >> 6] |= 1L << (this.outputCount & 0x3f); this.outputCount++; - if (this.outputCount == Config.DataBatchSize) FlushContents(); + if (this.outputCount == Config.DataBatchSize) this.FlushContents(); } else if (*vsync < *vother) { - ActOnStart(input[i], input.key.col[i], *hash, *vsync); - ActOnEnd(input[i], input.key.col[i], *hash, *vsync, *vother); + this.ActOnStart(input[i], input.key.col[i], *hash, *vsync); + this.ActOnEnd(input[i], input.key.col[i], *hash, *vsync, *vother); } else { - ActOnEnd(input[i], input.key.col[i], *hash, *vother, *vsync); + this.ActOnEnd(input[i], input.key.col[i], *hash, *vother, *vsync); } } @@ -309,7 +309,7 @@ private void ActOnStart(TPayload payload, TKey key, int hash, long eventstart, b }; // brand new event! Issue a public version - Emit(ActiveEvent.FromExt(activeEventExt)); + this.Emit(ActiveEvent.FromExt(activeEventExt)); InsertOrAppend(this.OpenEvents, lookupStart, activeEventExt); } @@ -353,7 +353,7 @@ internal void Purge(long time) var e = this.CurrentTimeOpenEventBuffer.entries[it]; for (int i = 0; i < e.value; i++) - ActOnStart(e.key.Payload, e.key.Key, e.key.Hash, this.CurrentTimeOpenEventBufferTime, true); + this.ActOnStart(e.key.Payload, e.key.Key, e.key.Hash, this.CurrentTimeOpenEventBufferTime, true); } @@ -365,7 +365,7 @@ internal void Purge(long time) var iterator = FastDictionary2.IteratorStart; while (closed.Value.Iterate(ref iterator)) { - foreach (var v in closed.Value.entries[iterator].value) Emit(v); + foreach (var v in closed.Value.entries[iterator].value) this.Emit(v); } closed.Value.Initialize(); this.ClosedEvents.Remove(closed.Key); @@ -402,7 +402,7 @@ private void Emit(ActiveEvent evt) this.outputCount++; tempOutputCount = this.outputCount; - if (tempOutputCount == Config.DataBatchSize) FlushContents(); + if (tempOutputCount == Config.DataBatchSize) this.FlushContents(); } public override int CurrentlyBufferedOutputCount => this.outputCount; diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/Stitch/StitchStreamable.cs b/Sources/Core/Microsoft.StreamProcessing/Operators/Stitch/StitchStreamable.cs index 7d06b6779..96de48c0d 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/Stitch/StitchStreamable.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/Stitch/StitchStreamable.cs @@ -10,7 +10,7 @@ namespace Microsoft.StreamProcessing internal sealed class StitchStreamable : UnaryStreamable { private static readonly SafeConcurrentDictionary> cachedPipes - = new SafeConcurrentDictionary>(); + = new(); public StitchStreamable(IStreamable source) : base(source, source.Properties) @@ -21,7 +21,7 @@ public StitchStreamable(IStreamable source) throw new InvalidOperationException($"Type of payload, '{typeof(TPayload).FullName}', to Stitch does not have a valid equality operator for columnar mode."); } - Initialize(); + this.Initialize(); } internal override IStreamObserver CreatePipe(IStreamObserver observer) @@ -30,7 +30,7 @@ internal override IStreamObserver CreatePipe(IStreamObserver(this, observer); } diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/Stitch/StitchTemplate.cs b/Sources/Core/Microsoft.StreamProcessing/Operators/Stitch/StitchTemplate.cs index 3d40a7a6c..6f7fb51ae 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/Stitch/StitchTemplate.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/Stitch/StitchTemplate.cs @@ -169,7 +169,7 @@ public override void ProduceQueryPlan(PlanNode previous) } "); - if (!noFields && !this.payloadType.GetTypeInfo().IsValueType) { + if (!noFields && !this.payloadType.IsValueType) { this.Write(" [DataContract]\r\n private struct "); this.Write(this.ToStringHelper.ToStringWithCulture(ActiveEventType)); this.Write("\r\n {\r\n "); @@ -414,21 +414,19 @@ protected override void FlushContents() "er.entries[it].key;\r\n for (int i = 0; i < CurrentTimeOpenEventBuf" + "fer.entries[it].value; i++)\r\n ActOnStartWithKHP(e, CurrentTim" + "eOpenEventBufferTime, true);\r\n\r\n }\r\n CurrentTimeOpenEventB" + - "uffer.Initialize();\r\n }\r\n\r\n foreach (var closed in ClosedEvents.Wh" + - "ere(k => k.Key < time).ToArray())\r\n {\r\n var iterator = FastDic" + - "tionary2<"); - this.Write(this.ToStringHelper.ToStringWithCulture(TPayload)); - this.Write(@", ActiveEvent>.IteratorStart; - while (closed.Value.Iterate(ref iterator)) - foreach (var v in closed.Value.entries[iterator].value) - Emit(v); - - closed.Value.Initialize(); - ClosedEvents.Remove(closed.Key); + "uffer.Initialize();\r\n }\r\n\r\n while (ClosedEvents.Count > 0)\r\n " + + " {\r\n long firstKey;\r\n using (var en = ClosedEvents.GetEnume" + + "rator())\r\n {\r\n if (!en.MoveNext())\r\n " + + "break;\r\n firstKey = en.Current.Key;\r\n }\r\n\r\n " + + "if (firstKey >= time)\r\n break;\r\n\r\n var closedDict = Clo" + + "sedEvents[firstKey];\r\n var iterator = FastDictionary2>.IteratorStart;\r\n while (closedDict.Iterate(ref iterator))\r\n " + + " {\r\n foreach (var v in closedDict.entries[iterator].value)" + + "\r\n Emit(v);\r\n }\r\n\r\n closedDict.Initialize" + + "();\r\n ClosedEvents.Remove(firstKey);\r\n dictPool.Return(close" + + "dDict);\r\n }\r\n }\r\n"); - dictPool.Return(closed.Value); - } - } + this.Write(@" // Optimally, this would be inline [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/Stitch/StitchTemplate.tt b/Sources/Core/Microsoft.StreamProcessing/Operators/Stitch/StitchTemplate.tt index 0f8dea22f..6a7427c27 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/Stitch/StitchTemplate.tt +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/Stitch/StitchTemplate.tt @@ -113,7 +113,7 @@ internal sealed class <#= className #><#= TKeyTPayloadGenericParameters #> : Una Observer.ProduceQueryPlan(queryPlanGenerator(previous, this)); } -<# if (!noFields && !this.payloadType.GetTypeInfo().IsValueType) { #> +<# if (!noFields && !this.payloadType.IsValueType) { #> [DataContract] private struct <#= ActiveEventType #> { @@ -444,17 +444,30 @@ internal sealed class <#= className #><#= TKeyTPayloadGenericParameters #> : Una CurrentTimeOpenEventBuffer.Initialize(); } - foreach (var closed in ClosedEvents.Where(k => k.Key < time).ToArray()) + while (ClosedEvents.Count > 0) { - var iterator = FastDictionary2<<#= TPayload #>, ActiveEvent>.IteratorStart; - while (closed.Value.Iterate(ref iterator)) - foreach (var v in closed.Value.entries[iterator].value) - Emit(v); + long firstKey; + using (var en = ClosedEvents.GetEnumerator()) + { + if (!en.MoveNext()) + break; + firstKey = en.Current.Key; + } + + if (firstKey >= time) + break; - closed.Value.Initialize(); - ClosedEvents.Remove(closed.Key); + var closedDict = ClosedEvents[firstKey]; + var iterator = FastDictionary2>.IteratorStart; + while (closedDict.Iterate(ref iterator)) + { + foreach (var v in closedDict.entries[iterator].value) + Emit(v); + } - dictPool.Return(closed.Value); + closedDict.Initialize(); + ClosedEvents.Remove(firstKey); + dictPool.Return(closedDict); } } diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/Stitch/StitchTransformer.cs b/Sources/Core/Microsoft.StreamProcessing/Operators/Stitch/StitchTransformer.cs index db1ca7411..512b3a817 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/Stitch/StitchTransformer.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/Stitch/StitchTransformer.cs @@ -33,8 +33,8 @@ private StitchTemplate(string className, Type keyType, Type payloadType) internal static Tuple Generate( StitchStreamable stream) { - Contract.Requires(stream != null); - Contract.Ensures(Contract.Result>() == null || typeof(UnaryPipe).GetTypeInfo().IsAssignableFrom(Contract.Result>().Item1)); + ArgumentNullException.ThrowIfNull(stream); + Contract.Ensures(Contract.Result>() == null || typeof(UnaryPipe).IsAssignableFrom(Contract.Result>().Item1)); var template = new StitchTemplate( $"GeneratedStitch_{StitchSequenceNumber++}", @@ -54,7 +54,7 @@ internal static Tuple Generate( #region Payload Equals { - template.ActiveEventType = typeof(TPayload).GetTypeInfo().IsValueType ? template.TPayload : "Active_Event"; + template.ActiveEventType = typeof(TPayload).IsValueType ? template.TPayload : "Active_Event"; var payloadComparer = stream.Properties.PayloadEqualityComparer.GetEqualsExpr(); template.payloadEquals = (left, right) => payloadComparer.Inline(left, right); diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/Ungroup/UngroupPipe.cs b/Sources/Core/Microsoft.StreamProcessing/Operators/Ungroup/UngroupPipe.cs index 4ea43ab53..1289c7b20 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/Ungroup/UngroupPipe.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/Ungroup/UngroupPipe.cs @@ -44,10 +44,10 @@ public PartitionedUngroupNestedPipe( public unsafe void OnNext(StreamMessage, TInnerResult> batch) { - outPool.Get(out StreamMessage tmp); + this.outPool.Get(out StreamMessage tmp); tmp.AllocatePayload(); - outPool.GetKey(out tmp.key); - tmp.hash = batch.hash.MakeWritable(outPool.intPool); + this.outPool.GetKey(out tmp.key); + tmp.hash = batch.hash.MakeWritable(this.outPool.intPool); var count = batch.Count; tmp.vsync = batch.vsync; @@ -73,7 +73,7 @@ public unsafe void OnNext(StreamMessage, continue; } destkey[i] = srckey[i].outerGroup; - tmp[i] = resultSelector(srckey[i].innerGroup, batch[i]); + tmp[i] = this.resultSelector(srckey[i].innerGroup, batch[i]); desthash[i] = this.outerHashCode(destkey[i]); } } @@ -81,7 +81,7 @@ public unsafe void OnNext(StreamMessage, tmp.Count = count; tmp.Seal(); - Observer.OnNext(tmp); + this.Observer.OnNext(tmp); batch.ReleasePayload(); batch.key.Return(); @@ -89,16 +89,16 @@ public unsafe void OnNext(StreamMessage, } public override void ProduceQueryPlan(PlanNode previous) - => Observer.ProduceQueryPlan(new UngroupPlanNode( + => this.Observer.ProduceQueryPlan(new UngroupPlanNode( previous, this, typeof(CompoundGroupKey), typeof(TOuterKey), typeof(TInnerResult), typeof(TResult), - resultSelectorExpr, + this.resultSelectorExpr, false, - errorMessages)); + this.errorMessages)); public override int CurrentlyBufferedOutputCount => 0; @@ -137,10 +137,10 @@ public UngroupNestedPipe( public unsafe void OnNext(StreamMessage, TInnerResult> batch) { - outPool.Get(out StreamMessage tmp); + this.outPool.Get(out StreamMessage tmp); tmp.AllocatePayload(); - outPool.GetKey(out tmp.key); - tmp.hash = batch.hash.MakeWritable(outPool.intPool); + this.outPool.GetKey(out tmp.key); + tmp.hash = batch.hash.MakeWritable(this.outPool.intPool); var count = batch.Count; tmp.vsync = batch.vsync; @@ -157,7 +157,7 @@ public unsafe void OnNext(StreamMessage, { if ((srcbv[i >> 6] & (1L << (i & 0x3f))) != 0) continue; destkey[i] = srckey[i].outerGroup; - tmp[i] = resultSelector(srckey[i].innerGroup, batch[i]); + tmp[i] = this.resultSelector(srckey[i].innerGroup, batch[i]); desthash[i] = this.outerHashCode(destkey[i]); } } @@ -165,7 +165,7 @@ public unsafe void OnNext(StreamMessage, tmp.Count = count; tmp.Seal(); - Observer.OnNext(tmp); + this.Observer.OnNext(tmp); batch.ReleasePayload(); batch.key.Return(); @@ -173,16 +173,16 @@ public unsafe void OnNext(StreamMessage, } public override void ProduceQueryPlan(PlanNode previous) - => Observer.ProduceQueryPlan(new UngroupPlanNode( + => this.Observer.ProduceQueryPlan(new UngroupPlanNode( previous, this, typeof(CompoundGroupKey), typeof(TOuterKey), typeof(TInnerResult), typeof(TResult), - resultSelectorExpr, + this.resultSelectorExpr, false, - errorMessages)); + this.errorMessages)); public override int CurrentlyBufferedOutputCount => 0; @@ -216,10 +216,10 @@ public UngroupPipe( public unsafe void OnNext(StreamMessage batch) { - outPool.Get(out StreamMessage tmp); + this.outPool.Get(out StreamMessage tmp); tmp.AllocatePayload(); - outPool.GetKey(out tmp.key); - tmp.hash = batch.hash.MakeWritable(outPool.intPool); + this.outPool.GetKey(out tmp.key); + tmp.hash = batch.hash.MakeWritable(this.outPool.intPool); var count = batch.Count; tmp.vsync = batch.vsync; @@ -240,14 +240,14 @@ public unsafe void OnNext(StreamMessage batch) { if ((srcbv[i >> 6] & (1L << (i & 0x3f))) != 0) continue; destkey[i] = unit; - tmp[i] = resultSelector(srckey[i], batch[i]); + tmp[i] = this.resultSelector(srckey[i], batch[i]); } } tmp.Count = count; tmp.Seal(); - Observer.OnNext(tmp); + this.Observer.OnNext(tmp); batch.ReleasePayload(); batch.key.Return(); @@ -255,16 +255,16 @@ public unsafe void OnNext(StreamMessage batch) } public override void ProduceQueryPlan(PlanNode previous) - => Observer.ProduceQueryPlan(new UngroupPlanNode( + => this.Observer.ProduceQueryPlan(new UngroupPlanNode( previous, this, typeof(TInnerKey), typeof(Empty), typeof(TInnerResult), typeof(TResult), - resultSelectorExpr, + this.resultSelectorExpr, false, - errorMessages)); + this.errorMessages)); public override int CurrentlyBufferedOutputCount => 0; diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/Ungroup/UngroupPlanNode.cs b/Sources/Core/Microsoft.StreamProcessing/Operators/Ungroup/UngroupPlanNode.cs index b7fdcb13e..db0adb7d6 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/Ungroup/UngroupPlanNode.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/Ungroup/UngroupPlanNode.cs @@ -58,7 +58,7 @@ internal UngroupPlanNode( internal override void PrintConciseSummary(System.Text.StringBuilder builder, int indentLevel) { - PrintConciseGeneralState(builder, indentLevel); + this.PrintConciseGeneralState(builder, indentLevel); builder.AppendLine(new string('\t', indentLevel + 1) + "Previous: "); this.Previous.PrintConciseSummary(builder, indentLevel + 2); } diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/Ungroup/UngroupStreamable.cs b/Sources/Core/Microsoft.StreamProcessing/Operators/Ungroup/UngroupStreamable.cs index 2c0ef72e2..0e9c591d7 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/Ungroup/UngroupStreamable.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/Ungroup/UngroupStreamable.cs @@ -13,7 +13,7 @@ namespace Microsoft.StreamProcessing internal sealed class UngroupStreamable : Streamable { private static readonly SafeConcurrentDictionary> cachedPipes - = new SafeConcurrentDictionary>(); + = new(); [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes", Justification="Used to avoid creating redundant readonly property.")] public readonly Expression> ResultSelector; @@ -25,8 +25,8 @@ public UngroupStreamable( Expression> resultSelector) : base(source.Properties.Ungroup(resultSelector)) { - Contract.Requires(source != null); - Contract.Requires(resultSelector != null); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(resultSelector); this.Source = source; this.ResultSelector = resultSelector; @@ -34,10 +34,10 @@ public UngroupStreamable( public override IDisposable Subscribe(IStreamObserver observer) { - if (this.Properties.IsColumnar && CanGenerateColumnar()) - return this.Source.Subscribe(GetPipe(observer)); + if (this.Properties.IsColumnar && this.CanGenerateColumnar()) + return this.Source.Subscribe(this.GetPipe(observer)); else - return this.Source.Subscribe(CreatePipe(observer)); + return this.Source.Subscribe(this.CreatePipe(observer)); } internal IStreamObserver, TInnerResult> CreatePipe( @@ -94,7 +94,7 @@ private IStreamObserver, TInnerResult> Ge internal sealed class UngroupStreamable : Streamable { private static readonly SafeConcurrentDictionary> cachedPipes - = new SafeConcurrentDictionary>(); + = new(); [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes", Justification="Used to avoid creating redundant readonly property.")] public readonly Expression> ResultSelector; @@ -105,8 +105,8 @@ public UngroupStreamable( Expression> resultSelector) : base(source.Properties.Ungroup(resultSelector)) { - Contract.Requires(source != null); - Contract.Requires(resultSelector != null); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(resultSelector); this.Source = source; this.ResultSelector = resultSelector; @@ -114,10 +114,10 @@ public UngroupStreamable( public override IDisposable Subscribe(IStreamObserver observer) { - if (this.Properties.IsColumnar && CanGenerateColumnar()) - return this.Source.Subscribe(GetPipe(observer)); + if (this.Properties.IsColumnar && this.CanGenerateColumnar()) + return this.Source.Subscribe(this.GetPipe(observer)); else - return this.Source.Subscribe(CreatePipe(observer)); + return this.Source.Subscribe(this.CreatePipe(observer)); } internal IStreamObserver CreatePipe( diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/Ungroup/UngroupStreamable.tt b/Sources/Core/Microsoft.StreamProcessing/Operators/Ungroup/UngroupStreamable.tt index f738d5031..a837db422 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/Ungroup/UngroupStreamable.tt +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/Ungroup/UngroupStreamable.tt @@ -37,8 +37,8 @@ namespace Microsoft.StreamProcessing Expression> resultSelector) : base(source.Properties.Ungroup(resultSelector)) { - Contract.Requires(source != null); - Contract.Requires(resultSelector != null); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(resultSelector); this.Source = source; this.ResultSelector = resultSelector; diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/Ungroup/UngroupTransform.cs b/Sources/Core/Microsoft.StreamProcessing/Operators/Ungroup/UngroupTransform.cs index 48dfc63fb..8438b6f51 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/Ungroup/UngroupTransform.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/Ungroup/UngroupTransform.cs @@ -29,11 +29,11 @@ private UngroupTemplate( Type innerResultType, Type resultType) : base(className) { - Contract.Requires(className != null); - Contract.Requires(outerKeyType != null); - Contract.Requires(innerKeyType != null); - Contract.Requires(innerResultType != null); - Contract.Requires(resultType != null); + ArgumentNullException.ThrowIfNull(className); + ArgumentNullException.ThrowIfNull(outerKeyType); + ArgumentNullException.ThrowIfNull(innerKeyType); + ArgumentNullException.ThrowIfNull(innerResultType); + ArgumentNullException.ThrowIfNull(resultType); this.outerKeyType = outerKeyType; this.innerKeyType = innerKeyType; @@ -96,7 +96,7 @@ internal static Tuple Generate(E private static Tuple GenerateInternal(Expression> resultSelector, bool isFirstLevelGroup) { Contract.Ensures(Contract.Result>() != null); - Contract.Ensures(typeof(Pipe).GetTypeInfo().IsAssignableFrom(Contract.Result>().Item1)); + Contract.Ensures(typeof(Pipe).IsAssignableFrom(Contract.Result>().Item1)); string errorMessages = null; try @@ -152,7 +152,7 @@ private static Tuple GenerateInternal).GetTypeInfo().Assembly); + assemblyReferences.Add(typeof(IStreamable<,>).Assembly); // input messages assemblyReferences.Add(Transformer.GeneratedStreamMessageAssembly, TInnerResult>()); @@ -166,11 +166,9 @@ private static Tuple GenerateInternal 0) generatedClassName = generatedClassName + "`" + numberOfGenericParameters.ToString(CultureInfo.InvariantCulture); - var t = a.GetType(generatedClassName); + var t = Transformer.CompileSourceCode(expandedCode, assemblyReferences, a => a.GetType(generatedClassName), out errorMessages); t = t.InstantiateAsNecessary(typeOfTOuterKey, typeOfTInnerKey, typeofTInnerResult, typeofTResult); return Tuple.Create(t, errorMessages); diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/Union/PartitionedUnionPipe.cs b/Sources/Core/Microsoft.StreamProcessing/Operators/Union/PartitionedUnionPipe.cs index d6e6e6ac5..d3affc996 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/Union/PartitionedUnionPipe.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/Union/PartitionedUnionPipe.cs @@ -18,23 +18,23 @@ internal sealed class PartitionedUnionPipe : Bina private readonly Func getPartitionKey = GetPartitionExtractor(); [DataMember] - private FastDictionary2> leftQueue = new FastDictionary2>(); + private FastDictionary2> leftQueue = new(); [DataMember] - private FastDictionary2> rightQueue = new FastDictionary2>(); + private FastDictionary2> rightQueue = new(); [DataMember] - private HashSet processQueue = new HashSet(); + private HashSet processQueue = []; [DataMember] - private HashSet seenKeys = new HashSet(); + private HashSet seenKeys = []; [DataMember] - private HashSet cleanKeys = new HashSet(); + private HashSet cleanKeys = []; [DataMember] private StreamMessage output; [DataMember] - private FastDictionary nextLeftTime = new FastDictionary(); + private FastDictionary nextLeftTime = new(); [DataMember] - private FastDictionary nextRightTime = new FastDictionary(); + private FastDictionary nextRightTime = new(); [DataMember] private long lastLeftCTI = long.MinValue; [DataMember] @@ -56,8 +56,8 @@ public PartitionedUnionPipe(IStreamable stream, IStreamObserver< private void NewPartition(TPartitionKey pKey) { - this.leftQueue.Insert(pKey, new PooledElasticCircularBuffer()); - this.rightQueue.Insert(pKey, new PooledElasticCircularBuffer()); + this.leftQueue.Insert(pKey, []); + this.rightQueue.Insert(pKey, []); if (!this.nextLeftTime.Lookup(pKey, out int left)) this.nextLeftTime.Insert(ref left, pKey, StreamEvent.MinSyncTime); if (!this.nextRightTime.Lookup(pKey, out int right)) this.nextRightTime.Insert(ref right, pKey, StreamEvent.MinSyncTime); @@ -65,8 +65,8 @@ private void NewPartition(TPartitionKey pKey) protected override void ProcessBothBatches(StreamMessage leftBatch, StreamMessage rightBatch, out bool leftBatchDone, out bool rightBatchDone, out bool leftBatchFree, out bool rightBatchFree) { - ProcessLeftBatch(leftBatch, out leftBatchDone, out leftBatchFree); - ProcessRightBatch(rightBatch, out rightBatchDone, out rightBatchFree); + this.ProcessLeftBatch(leftBatch, out leftBatchDone, out leftBatchFree); + this.ProcessRightBatch(rightBatch, out rightBatchDone, out rightBatchFree); } protected override void ProcessLeftBatch(StreamMessage batch, out bool leftBatchDone, out bool leftBatchFree) @@ -95,7 +95,7 @@ protected override void ProcessLeftBatch(StreamMessage batch, ou var partitionKey = this.getPartitionKey(batch.key.col[i]); if (first || !partitionKey.Equals(previous)) { - if (this.seenKeys.Add(partitionKey)) NewPartition(partitionKey); + if (this.seenKeys.Add(partitionKey)) this.NewPartition(partitionKey); this.leftQueue.Lookup(partitionKey, out int index); queue = this.leftQueue.entries[index].value; this.processQueue.Add(partitionKey); @@ -113,7 +113,7 @@ protected override void ProcessLeftBatch(StreamMessage batch, ou previous = partitionKey; } - ProcessPendingEntries(); + this.ProcessPendingEntries(); } protected override void ProcessRightBatch(StreamMessage batch, out bool rightBatchDone, out bool rightBatchFree) @@ -142,7 +142,7 @@ protected override void ProcessRightBatch(StreamMessage batch, o var partitionKey = this.getPartitionKey(batch.key.col[i]); if (first || !partitionKey.Equals(previous)) { - if (this.seenKeys.Add(partitionKey)) NewPartition(partitionKey); + if (this.seenKeys.Add(partitionKey)) this.NewPartition(partitionKey); this.rightQueue.Lookup(partitionKey, out int index); queue = this.rightQueue.entries[index].value; this.processQueue.Add(partitionKey); @@ -160,7 +160,7 @@ protected override void ProcessRightBatch(StreamMessage batch, o previous = partitionKey; } - ProcessPendingEntries(); + this.ProcessPendingEntries(); } [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -170,7 +170,9 @@ protected override void DisposeState() iter = FastDictionary.IteratorStart; while (this.leftQueue.Iterate(ref iter)) this.leftQueue.entries[iter].value.Dispose(); iter = FastDictionary.IteratorStart; - while (this.leftQueue.Iterate(ref iter)) this.rightQueue.entries[iter].value.Dispose(); + while (this.rightQueue.Iterate(ref iter)) this.rightQueue.entries[iter].value.Dispose(); + this.nextLeftTime.Dispose(); + this.nextRightTime.Dispose(); this.output.Free(); } @@ -206,21 +208,21 @@ private void ProcessPendingEntries() { case -1: // Output the left tuple - OutputCurrentTuple(leftEntry); + this.OutputCurrentTuple(leftEntry); leftWorking.TryDequeue(out leftEntry); break; case 0: // Output both tuples - OutputCurrentTuple(leftEntry); - OutputCurrentTuple(rightEntry); + this.OutputCurrentTuple(leftEntry); + this.OutputCurrentTuple(rightEntry); leftWorking.TryDequeue(out leftEntry); rightWorking.TryDequeue(out rightEntry); break; case 1: // Output the right tuple - OutputCurrentTuple(rightEntry); + this.OutputCurrentTuple(rightEntry); rightWorking.TryDequeue(out rightEntry); break; @@ -239,7 +241,7 @@ private void ProcessPendingEntries() if (leftEntry.Sync <= Math.Max(lastRightTime, this.lastRightCTI)) { // Output the left tuple - OutputCurrentTuple(leftEntry); + this.OutputCurrentTuple(leftEntry); leftWorking.TryDequeue(out leftEntry); } else @@ -260,7 +262,7 @@ private void ProcessPendingEntries() if (rightEntry.Sync <= Math.Max(lastLeftTime, this.lastLeftCTI)) { // Output the right tuple - OutputCurrentTuple(rightEntry); + this.OutputCurrentTuple(rightEntry); rightWorking.TryDequeue(out _); } else @@ -280,7 +282,7 @@ private void ProcessPendingEntries() if (this.emitCTI) { var earliest = Math.Min(this.lastLeftCTI, this.lastRightCTI); - AddLowWatermarkToBatch(earliest); + this.AddLowWatermarkToBatch(earliest); this.emitCTI = false; foreach (var p in this.cleanKeys) { @@ -313,7 +315,7 @@ private void AddLowWatermarkToBatch(long start) this.output.hash.col[index] = 0; this.output.bitvector.col[index >> 6] |= (1L << (index & 0x3f)); - if (this.output.Count == Config.DataBatchSize) FlushContents(); + if (this.output.Count == Config.DataBatchSize) this.FlushContents(); } } @@ -333,7 +335,7 @@ private void OutputCurrentTuple(Entry current) this.output.hash.col[index] = current.Hash; if (current.Other == long.MinValue) this.output.bitvector.col[index >> 6] |= (1L << (index & 0x3f)); - if (this.output.Count == Config.DataBatchSize) FlushContents(); + if (this.output.Count == Config.DataBatchSize) this.FlushContents(); } protected override void ProduceBinaryQueryPlan(PlanNode left, PlanNode right) diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/Union/UnionPipe.cs b/Sources/Core/Microsoft.StreamProcessing/Operators/Union/UnionPipe.cs index c0ef1fc7b..6c3d80b08 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/Union/UnionPipe.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/Union/UnionPipe.cs @@ -74,14 +74,14 @@ protected override void ProcessBothBatches(StreamMessage leftBat leftBatchDone = rightBatchDone = false; if (lastLeftTime <= this.nextRightTime) { - OutputBatch(leftBatch); + this.OutputBatch(leftBatch); leftBatchDone = true; leftBatchFree = false; } if (Config.DeterministicWithinTimestamp ? (lastRightTime < this.nextLeftTime) : (lastRightTime <= this.nextLeftTime)) { - OutputBatch(rightBatch); + this.OutputBatch(rightBatch); rightBatchDone = true; rightBatchFree = false; } @@ -93,7 +93,7 @@ protected override void ProcessBothBatches(StreamMessage leftBat { if (this.nextLeftTime <= this.nextRightTime) { - OutputCurrentTuple(leftBatch); + this.OutputCurrentTuple(leftBatch); leftBatch.iter++; @@ -108,7 +108,7 @@ protected override void ProcessBothBatches(StreamMessage leftBat } else { - OutputCurrentTuple(rightBatch); + this.OutputCurrentTuple(rightBatch); rightBatch.iter++; @@ -132,7 +132,7 @@ protected override void ProcessLeftBatch(StreamMessage batch, ou { if (batch.vsync.col[batch.Count - 1] <= this.nextRightTime) { - OutputBatch(batch); + this.OutputBatch(batch); isBatchDone = true; isBatchFree = false; return; @@ -155,7 +155,7 @@ protected override void ProcessLeftBatch(StreamMessage batch, ou return; } - OutputCurrentTuple(batch); + this.OutputCurrentTuple(batch); batch.iter++; } @@ -169,7 +169,7 @@ protected override void ProcessRightBatch(StreamMessage batch, o { if (Config.DeterministicWithinTimestamp ? (batch.vsync.col[batch.Count - 1] < this.nextLeftTime) : (batch.vsync.col[batch.Count - 1] <= this.nextLeftTime)) { - OutputBatch(batch); + this.OutputBatch(batch); isBatchDone = true; isBatchFree = false; return; @@ -192,7 +192,7 @@ protected override void ProcessRightBatch(StreamMessage batch, o return; } - OutputCurrentTuple(batch); + this.OutputCurrentTuple(batch); batch.iter++; } @@ -225,7 +225,7 @@ private void OutputCurrentTuple(StreamMessage batch) this.output.hash.col[index] = batch.hash.col[batch.iter]; if ((batch.bitvector.col[batch.iter >> 6] & (1L << (batch.iter & 0x3f))) != 0) this.output.bitvector.col[index >> 6] |= (1L << (index & 0x3f)); - if (this.output.Count == Config.DataBatchSize) FlushContents(); + if (this.output.Count == Config.DataBatchSize) this.FlushContents(); } [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -259,7 +259,7 @@ private void OutputBatch(StreamMessage batch) this.lastCTI = updatedCTI; - FlushContents(); + this.FlushContents(); this.Observer.OnNext(batch); } diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/Union/UnionStreamable.cs b/Sources/Core/Microsoft.StreamProcessing/Operators/Union/UnionStreamable.cs index aadc659f1..f73f28074 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/Union/UnionStreamable.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/Union/UnionStreamable.cs @@ -10,18 +10,18 @@ namespace Microsoft.StreamProcessing internal sealed class UnionStreamable : BinaryStreamable { private static readonly SafeConcurrentDictionary> cachedPipes - = new SafeConcurrentDictionary>(); + = new(); public UnionStreamable(IStreamable left, IStreamable right, bool registerInputs = false) : base(left.Properties.Union(right.Properties), left, right, registerInputs) - => Initialize(); + => this.Initialize(); protected override IBinaryObserver CreatePipe(IStreamObserver observer) { var part = typeof(TKey).GetPartitionType(); if (part == null) { - if (this.Left.Properties.IsColumnar && this.Right.Properties.IsColumnar) return GetPipe(observer); + if (this.Left.Properties.IsColumnar && this.Right.Properties.IsColumnar) return this.GetPipe(observer); else return new UnionPipe(this, observer); } diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/Union/UnionTransformer.cs b/Sources/Core/Microsoft.StreamProcessing/Operators/Union/UnionTransformer.cs index a5855d0d4..f9404f168 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/Union/UnionTransformer.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/Union/UnionTransformer.cs @@ -4,6 +4,9 @@ // ********************************************************************* using System; using System.Collections.Generic; +#if CODEGEN_TIMING +using System.Diagnostics; +#endif using System.Diagnostics.Contracts; using System.Reflection; @@ -32,8 +35,8 @@ private UnionTemplate(string className, Type keyType, Type payloadType) internal static Tuple GenerateUnionPipeClass( UnionStreamable stream) { - Contract.Requires(stream != null); - Contract.Ensures(Contract.Result>() == null || typeof(BinaryPipe).GetTypeInfo().IsAssignableFrom(Contract.Result>().Item1)); + ArgumentNullException.ThrowIfNull(stream); + Contract.Ensures(Contract.Result>() == null || typeof(BinaryPipe).IsAssignableFrom(Contract.Result>().Item1)); #if CODEGEN_TIMING Stopwatch sw = new Stopwatch(); diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/Where/MultiStringTransforms.cs b/Sources/Core/Microsoft.StreamProcessing/Operators/Where/MultiStringTransforms.cs index 671081067..23d1b5c7b 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/Where/MultiStringTransforms.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/Where/MultiStringTransforms.cs @@ -33,7 +33,7 @@ public static MultiStringTransformationResult Transform(Type t, Expression e) return new MultiStringTransformationResult { vectorOperation = string.Join("\n", vectorStatements), - wrapperTable = new Dictionary(), + wrapperTable = [], }; } var wrapperVisitor = new WrapperTransformer(t); @@ -78,8 +78,8 @@ protected override Expression VisitBinary(BinaryExpression node) { case ExpressionType.AndAlso: case ExpressionType.OrElse: - Visit(node.Left); - Visit(node.Right); + this.Visit(node.Left); + this.Visit(node.Right); return node; default: this.IsVectorizable = false; @@ -92,7 +92,7 @@ protected override Expression VisitUnary(UnaryExpression node) switch (node.NodeType) { case ExpressionType.Not: - Visit(node.Operand); + this.Visit(node.Operand); return node; default: this.IsVectorizable = false; @@ -149,7 +149,7 @@ public static bool IsStaticRegexMatch(MethodCallExpression methodCall, Type batc private sealed class Vectorize : ExpressionVisitor { private static int counter = 0; - public List vectorStatements = new List(); + public List vectorStatements = []; private string incomingBV = "batch.bitvector"; private bool inPlace = false; private string resultBV; @@ -177,14 +177,14 @@ protected override Expression VisitBinary(BinaryExpression node) { case ExpressionType.OrElse: this.inPlace = false; - Visit(node.Left); + this.Visit(node.Left); left_result = this.resultBV; var bv_i = "bv" + counter++; // var bv_i = invert(left_result) | incomingBV; this.vectorStatements.Add($"var {bv_i} = MultiString.InvertLeftThenOrWithRight({left_result}, {this.incomingBV}, this.pool.bitvectorPool);"); this.incomingBV = bv_i; - Visit(node.Right); + this.Visit(node.Right); // free bv_i this.vectorStatements.Add($"{bv_i}.ReturnClear();"); @@ -197,10 +197,10 @@ protected override Expression VisitBinary(BinaryExpression node) break; case ExpressionType.AndAlso: - Visit(node.Left); + this.Visit(node.Left); left_result = this.resultBV; this.incomingBV = this.resultBV; - Visit(node.Right); + this.Visit(node.Right); // free left_result this.vectorStatements.Add($"{left_result}.ReturnClear();"); @@ -296,7 +296,7 @@ private bool IsCallToStringMethodOnBatchField(MemberExpression memberBinding) protected override Expression VisitMethodCall(MethodCallExpression methodCall) { if (methodCall.Method.DeclaringType != typeof(string)) goto JustVisit; - if (!IsCallToStringMethodOnBatchField(methodCall.Object as MemberExpression)) goto JustVisit; + if (!this.IsCallToStringMethodOnBatchField(methodCall.Object as MemberExpression)) goto JustVisit; this.found = true; return methodCall; @@ -308,7 +308,7 @@ protected override Expression VisitMethodCall(MethodCallExpression methodCall) protected override Expression VisitMember(MemberExpression node) { if (!node.Member.DeclaringType.Equals(typeof(string))) goto JustVisit; - if (!IsCallToStringMethodOnBatchField(node.Expression as MemberExpression)) goto JustVisit; + if (!this.IsCallToStringMethodOnBatchField(node.Expression as MemberExpression)) goto JustVisit; this.found = true; return node; @@ -346,7 +346,7 @@ private static bool MultiStringHasVectorImplementation(string methodName) private class WrapperTransformer : ExpressionVisitor { private readonly Type batchType; - public Dictionary multiStringTable = new Dictionary(); + public Dictionary multiStringTable = []; public WrapperTransformer(Type t) => this.batchType = t; @@ -375,7 +375,7 @@ protected override Expression VisitMethodCall(MethodCallExpression node) this.multiStringTable.Add(field, wrapper); } - var wrapperMethod = typeof(MultiString.MultiStringWrapper).GetTypeInfo().GetMethod(method.Name, node.Arguments.Select(a => a.Type).ToArray()); + var wrapperMethod = typeof(MultiString.MultiStringWrapper).GetMethod(method.Name, node.Arguments.Select(a => a.Type).ToArray()); return Expression.Call(wrapper, wrapperMethod, node.Arguments); JustVisit: @@ -403,7 +403,7 @@ protected override Expression VisitMember(MemberExpression node) this.multiStringTable.Add(field, wrapper); } - var wrapperMembers = typeof(MultiString.MultiStringWrapper).GetTypeInfo().GetMember(node.Member.Name); + var wrapperMembers = typeof(MultiString.MultiStringWrapper).GetMember(node.Member.Name); Contract.Assume(wrapperMembers.Length > 0); var wrapperMember = wrapperMembers[0]; return Expression.MakeMemberAccess(wrapper, wrapperMember); diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/Where/WhereStreamable.cs b/Sources/Core/Microsoft.StreamProcessing/Operators/Where/WhereStreamable.cs index bc61f4b0f..da2846b6a 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/Where/WhereStreamable.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/Where/WhereStreamable.cs @@ -12,23 +12,23 @@ namespace Microsoft.StreamProcessing internal sealed class WhereStreamable : UnaryStreamable { private static readonly SafeConcurrentDictionary> cachedPipes - = new SafeConcurrentDictionary>(); + = new(); public readonly Expression> Predicate; public WhereStreamable(IStreamable source, Expression> predicate) : base(source, source.Properties.Where(predicate)) { - Contract.Requires(source != null); - Contract.Requires(predicate != null); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(predicate); this.Predicate = predicate; - Initialize(); + this.Initialize(); } internal override IStreamObserver CreatePipe(IStreamObserver observer) => this.Properties.IsColumnar - ? GetPipe(observer) + ? this.GetPipe(observer) : new WherePipe(this, observer); protected override bool CanGenerateColumnar() diff --git a/Sources/Core/Microsoft.StreamProcessing/Operators/Where/WhereTransformer.cs b/Sources/Core/Microsoft.StreamProcessing/Operators/Where/WhereTransformer.cs index 6c7e82645..be961331a 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Operators/Where/WhereTransformer.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Operators/Where/WhereTransformer.cs @@ -102,10 +102,9 @@ internal static Tuple Generate(WhereStreamable()); - assemblyReferences.Add(typeof(IStreamable<,>).GetTypeInfo().Assembly); + assemblyReferences.Add(typeof(IStreamable<,>).Assembly); - var a = Transformer.CompileSourceCode(expandedCode, assemblyReferences, out errorMessages); - var t = a.GetType(generatedClassName); + var t = Transformer.CompileSourceCode(expandedCode, assemblyReferences, a => a.GetType(generatedClassName), out errorMessages); t = t.InstantiateAsNecessary(typeof(TKey), typeof(TPayload)); return Tuple.Create(t, errorMessages); } diff --git a/Sources/Core/Microsoft.StreamProcessing/Pipes/BinaryPipe.cs b/Sources/Core/Microsoft.StreamProcessing/Pipes/BinaryPipe.cs index 2c5ef1f0e..5c5b277f3 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Pipes/BinaryPipe.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Pipes/BinaryPipe.cs @@ -48,18 +48,20 @@ public abstract class BinaryPipe : Pipe leftPlans = new Queue(); - private readonly Queue rightPlans = new Queue(); + private readonly Queue leftPlans = []; + private readonly Lock leftPlansLock = new(); + private readonly Queue rightPlans = []; + private readonly Lock rightPlansLock = new(); [DataMember] private int completedCount; [DataMember] - private ConcurrentQueue> leftQueue = new ConcurrentQueue>(); + private ConcurrentQueue> leftQueue = new(); [DataMember] - private ConcurrentQueue> rightQueue = new ConcurrentQueue>(); + private ConcurrentQueue> rightQueue = new(); /// /// Currently for internal use only - do not use directly. @@ -128,7 +130,7 @@ private void OnLeft(StreamMessage batch) } this.leftQueue.Enqueue(batch); - ProcessPendingBatches(); + this.ProcessPendingBatches(); } private void OnRight(StreamMessage batch) @@ -142,7 +144,7 @@ private void OnRight(StreamMessage batch) } this.rightQueue.Enqueue(batch); - ProcessPendingBatches(); + this.ProcessPendingBatches(); } /// @@ -152,16 +154,9 @@ public override void OnFlush() { // This will not deadlock, since it we can only be waiting another thread further along in the // query, and there cannot be cycles in the query. - Monitor.Enter(this.sync); - try - { - FlushContents(); - this.Observer.OnFlush(); - } - finally - { - Monitor.Exit(this.sync); - } + using Lock.Scope _ = this.sync.EnterScope(); + this.FlushContents(); + this.Observer.OnFlush(); } /// @@ -175,28 +170,24 @@ public override void OnCompleted() // Ensure we have no pending batches in case we cut off another thread that was about to do so. // TODO: add parameter to so implementers can finish processing data knowing there will be no // future batches, then the cleanup below should only catch bugs in implementers. - ProcessPendingBatches(); + this.ProcessPendingBatches(); // Not all binary pipes will have processed all batches, so make sure we don't leak. // This will not deadlock, since it we can only be waiting another thread further along in the // query, and there cannot be cycles in the query. - Monitor.Enter(this.sync); - try - { - base.OnCompleted(); + using Lock.Scope _ = this.sync.EnterScope(); + // Process any batches that were enqueued while another thread held the lock above. + // Call the lock-free core directly — we already hold the lock here. + this.ProcessPendingBatchesCore(); + base.OnCompleted(); - while (this.leftQueue.TryDequeue(out var leftBatch)) - { - leftBatch.Free(); - } - while (this.rightQueue.TryDequeue(out var rightBatch)) - { - rightBatch.Free(); - } + while (this.leftQueue.TryDequeue(out var leftBatch)) + { + leftBatch.Free(); } - finally + while (this.rightQueue.TryDequeue(out var rightBatch)) { - Monitor.Exit(this.sync); + rightBatch.Free(); } } } @@ -205,7 +196,7 @@ public override void OnCompleted() private void ProcessPendingBatches() { // Exit if another thread is already processing the pending batches - if (!Monitor.TryEnter(this.sync)) + if (!this.sync.TryEnter()) { return; } @@ -214,79 +205,76 @@ private void ProcessPendingBatches() // there is still processing to be done, we shouldn't release the lock. try { + this.ProcessPendingBatchesCore(); + } + finally + { + this.sync.Exit(); + } + } + + // Lock-free batch processing loop — caller must hold this.sync. + private void ProcessPendingBatchesCore() + { + while (true) + { + var process = this.state switch + { + ProcessState.WaitingForLeft => !this.leftQueue.IsEmpty, + ProcessState.WaitingForRight => !this.rightQueue.IsEmpty, + ProcessState.WaitingForAny => !this.leftQueue.IsEmpty || !this.rightQueue.IsEmpty, + _ => throw new InvalidOperationException(), + }; + if (!process) break; + + this.state = ProcessState.Processing; + while (true) { - bool process; - switch (this.state) + bool hasLeftBatch = this.leftQueue.TryPeek(out var leftBatch); + bool hasRightBatch = this.rightQueue.TryPeek(out var rightBatch); + bool leftBatchDone = false; + bool rightBatchDone = false; + bool leftBatchFree = true; + bool rightBatchFree = true; + + if (hasLeftBatch && hasRightBatch) + { + this.ProcessBothBatches(leftBatch, rightBatch, out leftBatchDone, out rightBatchDone, out leftBatchFree, out rightBatchFree); + } + else if (hasLeftBatch) + { + this.ProcessLeftBatch(leftBatch, out leftBatchDone, out leftBatchFree); + } + else if (hasRightBatch) { - case ProcessState.WaitingForLeft: - process = !this.leftQueue.IsEmpty; - break; - case ProcessState.WaitingForRight: - process = !this.rightQueue.IsEmpty; - break; - case ProcessState.WaitingForAny: - process = !this.leftQueue.IsEmpty || !this.rightQueue.IsEmpty; - break; - default: - throw new InvalidOperationException(); + this.ProcessRightBatch(rightBatch, out rightBatchDone, out rightBatchFree); + } + else + { + this.state = ProcessState.WaitingForAny; + break; } - if (!process) break; + if (leftBatchDone) + { + this.leftQueue.TryDequeue(out leftBatch); + if (leftBatchFree) leftBatch.Free(); + } - this.state = ProcessState.Processing; + if (rightBatchDone) + { + this.rightQueue.TryDequeue(out rightBatch); + if (rightBatchFree) rightBatch.Free(); + } - while (true) + if (!leftBatchDone && !rightBatchDone) { - bool hasLeftBatch = this.leftQueue.TryPeek(out var leftBatch); - bool hasRightBatch = this.rightQueue.TryPeek(out var rightBatch); - bool leftBatchDone = false; - bool rightBatchDone = false; - bool leftBatchFree = true; - bool rightBatchFree = true; - - if (hasLeftBatch && hasRightBatch) - { - ProcessBothBatches(leftBatch, rightBatch, out leftBatchDone, out rightBatchDone, out leftBatchFree, out rightBatchFree); - } - else if (hasLeftBatch) - { - ProcessLeftBatch(leftBatch, out leftBatchDone, out leftBatchFree); - } - else if (hasRightBatch) - { - ProcessRightBatch(rightBatch, out rightBatchDone, out rightBatchFree); - } - else - { - this.state = ProcessState.WaitingForAny; - break; - } - - if (leftBatchDone) - { - this.leftQueue.TryDequeue(out leftBatch); - if (leftBatchFree) leftBatch.Free(); - } - - if (rightBatchDone) - { - this.rightQueue.TryDequeue(out rightBatch); - if (rightBatchFree) rightBatch.Free(); - } - - if (!leftBatchDone && !rightBatchDone) - { - this.state = hasLeftBatch ? ProcessState.WaitingForRight : ProcessState.WaitingForLeft; - break; - } + this.state = hasLeftBatch ? ProcessState.WaitingForRight : ProcessState.WaitingForLeft; + break; } } } - finally - { - Monitor.Exit(this.sync); - } } /// @@ -369,7 +357,7 @@ private void CheckpointLeft(Stream stream) { case SerializationState.Open: this.serializationState = SerializationState.CheckpointLeft; - Checkpoint(stream); + this.Checkpoint(stream); break; case SerializationState.CheckpointRight: @@ -395,7 +383,7 @@ private void CheckpointRight(Stream stream) { case SerializationState.Open: this.serializationState = SerializationState.CheckpointRight; - Checkpoint(stream); + this.Checkpoint(stream); break; case SerializationState.CheckpointLeft: @@ -421,7 +409,7 @@ private void RestoreLeft(Stream stream) { case SerializationState.Open: this.serializationState = SerializationState.RestoreLeft; - Restore(stream); + this.Restore(stream); break; case SerializationState.RestoreRight: @@ -447,7 +435,7 @@ private void RestoreRight(Stream stream) { case SerializationState.Open: this.serializationState = SerializationState.RestoreRight; - Restore(stream); + this.Restore(stream); break; case SerializationState.RestoreLeft: @@ -478,24 +466,20 @@ public override void Reset() private void ReceiveLeftQueryPlan(PlanNode left) { this.leftPlans.Enqueue(left); - lock (this.rightPlans) + using Lock.Scope _ = this.rightPlansLock.EnterScope(); + if (this.rightPlans.Count > 0) { - if (this.rightPlans.Count > 0) - { - ProduceBinaryQueryPlan(this.leftPlans.Dequeue(), this.rightPlans.Dequeue()); - } + this.ProduceBinaryQueryPlan(this.leftPlans.Dequeue(), this.rightPlans.Dequeue()); } } private void ReceiveRightQueryPlan(PlanNode right) { this.rightPlans.Enqueue(right); - lock (this.leftPlans) + using Lock.Scope _ = this.leftPlansLock.EnterScope(); + if (this.leftPlans.Count > 0) { - if (this.leftPlans.Count > 0) - { - ProduceBinaryQueryPlan(this.leftPlans.Dequeue(), this.rightPlans.Dequeue()); - } + this.ProduceBinaryQueryPlan(this.leftPlans.Dequeue(), this.rightPlans.Dequeue()); } } diff --git a/Sources/Core/Microsoft.StreamProcessing/Pipes/BinaryPlanNode.cs b/Sources/Core/Microsoft.StreamProcessing/Pipes/BinaryPlanNode.cs index 8b3683a8b..ab11bc1a4 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Pipes/BinaryPlanNode.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Pipes/BinaryPlanNode.cs @@ -87,7 +87,7 @@ protected BinaryPlanNode( internal override void PrintConciseSummary(System.Text.StringBuilder builder, int indentLevel) { - PrintConciseGeneralState(builder, indentLevel); + this.PrintConciseGeneralState(builder, indentLevel); builder.AppendLine(new string('\t', indentLevel + 1) + "Left input: "); this.LeftPlanNode.PrintConciseSummary(builder, indentLevel + 2); builder.AppendLine(new string('\t', indentLevel + 1) + "Right input: "); @@ -140,7 +140,7 @@ internal JoinPlanNode( /// /// Returns the set of expressions employed by the current node to compute the join. /// - public Dictionary JoinExpressions { get; } = new Dictionary(); + public Dictionary JoinExpressions { get; } = []; } /// diff --git a/Sources/Core/Microsoft.StreamProcessing/Pipes/Checkpointable.cs b/Sources/Core/Microsoft.StreamProcessing/Pipes/Checkpointable.cs index bd69b71e2..a4b711ed3 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Pipes/Checkpointable.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Pipes/Checkpointable.cs @@ -41,40 +41,40 @@ protected Checkpointable(bool? isColumnar, QueryContainer container) { this.isColumnar = isColumnar; this.container = container; - this.schemaHashCode = new Lazy(GetSchemaHashCode); - this.serializerMethod = new Lazy(GetSerializerMethod); - this.deserializerMethod = new Lazy(GetDeserializerMethod); - this.schemaFields = new Lazy>(GetSchemaFields); - this.serializationFields = new Lazy>(GetSerializationFields); + this.schemaHashCode = new Lazy(this.GetSchemaHashCode); + this.serializerMethod = new Lazy(this.GetSerializerMethod); + this.deserializerMethod = new Lazy(this.GetDeserializerMethod); + this.schemaFields = new Lazy>(this.GetSchemaFields); + this.serializationFields = new Lazy>(this.GetSerializationFields); } private int GetSchemaHashCode() - => this.schemaFields.Value.Aggregate(GetType().ToString().StableHash(), (a, f) => a ^ (f.GetValue(this) ?? string.Empty).ToString().StableHash()); + => this.schemaFields.Value.Aggregate(this.GetType().ToString().StableHash(), (a, f) => a ^ (f.GetValue(this) ?? string.Empty).ToString().StableHash()); - private object Serializer => this.container?.GetOrCreateSerializer(GetType()); + private object Serializer => this.container?.GetOrCreateSerializer(this.GetType()); private MethodInfo GetSerializerMethod() - => this.Serializer.GetType().GetTypeInfo().GetMethod("Serialize", new Type[] { typeof(Stream), GetType() }); + => this.Serializer.GetType().GetMethod("Serialize", [typeof(Stream), this.GetType()]); private MethodInfo GetDeserializerMethod() - => this.Serializer.GetType().GetTypeInfo().GetMethod("Deserialize", new Type[] { typeof(Stream) }); + => this.Serializer.GetType().GetMethod("Deserialize", [typeof(Stream)]); private List GetSerializationFields() - => GetType().GetAllFields().Where(f => f.IsDefined(typeof(DataMemberAttribute))).ToList(); + => this.GetType().GetAllFields().Where(f => f.IsDefined(typeof(DataMemberAttribute))).ToList(); private List GetSchemaFields() - => GetType().GetAllFields().Where(f => f.IsDefined(typeof(SchemaSerializationAttribute))).ToList(); + => this.GetType().GetAllFields().Where(f => f.IsDefined(typeof(SchemaSerializationAttribute))).ToList(); private void Serialize(Stream stream) - => this.serializerMethod.Value.Invoke(this.Serializer, new object[] { stream, this }); + => this.serializerMethod.Value.Invoke(this.Serializer, [stream, this]); private void Deserialize(Stream stream) { - object newObject = this.deserializerMethod.Value.Invoke(this.Serializer, new object[] { stream }); + object newObject = this.deserializerMethod.Value.Invoke(this.Serializer, [stream]); foreach (var field in this.serializationFields.Value) field.SetValue(this, field.GetValue(newObject)); - UpdatePointers(); + this.UpdatePointers(); } /// @@ -83,8 +83,8 @@ private void Deserialize(Stream stream) [EditorBrowsable(EditorBrowsableState.Never)] public virtual void Checkpoint(Stream stream) { - CheckpointSchema(stream); - Serialize(stream); + this.CheckpointSchema(stream); + this.Serialize(stream); } /// @@ -99,8 +99,8 @@ public virtual void Checkpoint(Stream stream) [EditorBrowsable(EditorBrowsableState.Never)] public virtual void Restore(Stream stream) { - ValidateSchema(stream); - Deserialize(stream); + this.ValidateSchema(stream); + this.Deserialize(stream); } /// @@ -115,11 +115,15 @@ public virtual void Reset() { } [EditorBrowsable(EditorBrowsableState.Never)] protected void ValidateSchema(Stream stream) { - byte[] hashCodeBytes = new byte[sizeof(int)]; + Span hashCodeBytes = stackalloc byte[sizeof(int)]; try { - stream.ReadAllRequiredBytes(hashCodeBytes, 0, sizeof(int)); - int hashCode = BitConverter.ToInt32(hashCodeBytes, 0); + if (stream.ReadAllRequiredBytes(hashCodeBytes) != sizeof(int)) + { + throw new EndOfStreamException(); + } + + int hashCode = BitConverter.ToInt32(hashCodeBytes); if (this.schemaHashCode.Value != hashCode) { throw new StreamProcessingException("The input serialization state does not match the schema of the query."); diff --git a/Sources/Core/Microsoft.StreamProcessing/Pipes/Pipe.cs b/Sources/Core/Microsoft.StreamProcessing/Pipes/Pipe.cs index 9dbf4209f..3fa2bbfe6 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Pipes/Pipe.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Pipes/Pipe.cs @@ -53,8 +53,8 @@ protected Pipe() : base(false, null) { } protected Pipe(IStreamable stream, IStreamObserver observer) : base(stream.Properties.IsColumnar, stream.Properties.QueryContainer) { - Contract.Requires(stream != null); - Contract.Requires(observer != null); + ArgumentNullException.ThrowIfNull(stream); + ArgumentNullException.ThrowIfNull(observer); this.Observer = observer; this.id = Guid.NewGuid(); @@ -86,7 +86,7 @@ public override void Restore(Stream stream) [EditorBrowsable(EditorBrowsableState.Never)] public virtual void OnCompleted() { - Dispose(); + this.Dispose(); this.Observer.OnCompleted(); } @@ -96,7 +96,7 @@ public virtual void OnCompleted() [EditorBrowsable(EditorBrowsableState.Never)] public virtual void OnError(Exception exception) { - Dispose(); + this.Dispose(); this.Observer.OnError(exception); } @@ -108,7 +108,7 @@ public void Dispose() { if (!this.disposed) { - DisposeState(); + this.DisposeState(); this.disposed = true; } } @@ -125,7 +125,7 @@ protected virtual void DisposeState() { } [EditorBrowsable(EditorBrowsableState.Never)] public virtual void OnFlush() { - FlushContents(); + this.FlushContents(); this.Observer.OnFlush(); } diff --git a/Sources/Core/Microsoft.StreamProcessing/Pipes/UnaryPlanNode.cs b/Sources/Core/Microsoft.StreamProcessing/Pipes/UnaryPlanNode.cs index 581862cd4..a7c3b7a30 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Pipes/UnaryPlanNode.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Pipes/UnaryPlanNode.cs @@ -49,7 +49,7 @@ protected UnaryPlanNode( internal override void PrintConciseSummary(StringBuilder builder, int indentLevel) { - PrintConciseGeneralState(builder, indentLevel); + this.PrintConciseGeneralState(builder, indentLevel); builder.AppendLine(new string('\t', indentLevel + 1) + "Previous: "); this.PreviousPlanNode.PrintConciseSummary(builder, indentLevel + 2); } diff --git a/Sources/Core/Microsoft.StreamProcessing/PlanNode.cs b/Sources/Core/Microsoft.StreamProcessing/PlanNode.cs index 092fd2cc7..9ac2d8850 100644 --- a/Sources/Core/Microsoft.StreamProcessing/PlanNode.cs +++ b/Sources/Core/Microsoft.StreamProcessing/PlanNode.cs @@ -77,7 +77,7 @@ protected PlanNode(IQueryObject pipe, Type keyType, Type payloadType, bool isGen public override string ToString() { var builder = new StringBuilder(); - PrintConciseSummary(builder, 0); + this.PrintConciseSummary(builder, 0); return builder.ToString(); } @@ -139,7 +139,7 @@ internal IngressPlanNode(IIngressStreamObserver observer, Type keyType, Type pay internal override void PrintConciseSummary(StringBuilder builder, int indentLevel) { - PrintConciseGeneralState(builder, indentLevel); + this.PrintConciseGeneralState(builder, indentLevel); builder.AppendLine(new string('\t', indentLevel + 1) + "Name: " + this.observer.IngressSiteIdentifier); } diff --git a/Sources/Core/Microsoft.StreamProcessing/QueryContainer.cs b/Sources/Core/Microsoft.StreamProcessing/QueryContainer.cs index 4eb1d6c72..26306e81d 100644 --- a/Sources/Core/Microsoft.StreamProcessing/QueryContainer.cs +++ b/Sources/Core/Microsoft.StreamProcessing/QueryContainer.cs @@ -9,6 +9,7 @@ using System.IO; using System.Linq; using System.Reflection; +using System.Threading; using Microsoft.StreamProcessing.Serializer; namespace Microsoft.StreamProcessing @@ -18,7 +19,7 @@ namespace Microsoft.StreamProcessing /// public sealed class QueryContainer { - private readonly object sentinel = new object(); + private readonly Lock sentinel = new(); /// /// ISurrogate to be used in serialization in checkpoints and serialized StreamMessage @@ -26,18 +27,18 @@ public sealed class QueryContainer /// public ISurrogate Surrogate { get; } - private readonly HashSet ingressSites = new HashSet(); - private readonly HashSet egressSites = new HashSet(); + private readonly HashSet ingressSites = []; + private readonly HashSet egressSites = []; - private readonly Dictionary ingressPipes = new Dictionary(); - private readonly Dictionary egressPipes = new Dictionary(); + private readonly Dictionary ingressPipes = []; + private readonly Dictionary egressPipes = []; - private readonly ConcurrentDictionary, Type> sortedDictionaryTypes = new ConcurrentDictionary, Type>(); - private readonly ConcurrentDictionary, Type> fastDictionaryTypes = new ConcurrentDictionary, Type>(); - private readonly ConcurrentDictionary, Type> fastDictionary2Types = new ConcurrentDictionary, Type>(); - private readonly ConcurrentDictionary, Type> fastDictionary3Types = new ConcurrentDictionary, Type>(); + private readonly ConcurrentDictionary, Type> sortedDictionaryTypes = new(); + private readonly ConcurrentDictionary, Type> fastDictionaryTypes = new(); + private readonly ConcurrentDictionary, Type> fastDictionary2Types = new(); + private readonly ConcurrentDictionary, Type> fastDictionary3Types = new(); - private readonly ConcurrentDictionary serializers = new ConcurrentDictionary(); + private readonly ConcurrentDictionary serializers = new(); /// /// Creates a new instance of a query container for use in checkpointable queries. @@ -102,13 +103,13 @@ internal object GetOrCreateSerializer(Type type) { if (this.serializers.TryGetValue(type, out object serializer)) return serializer; var serializerStatic = typeof(StreamSerializer); - var method = serializerStatic.GetTypeInfo().GetMethod("Create", new Type[] { typeof(SerializerSettings) }).MakeGenericMethod(type); + var method = serializerStatic.GetMethod("Create", [typeof(SerializerSettings)]).MakeGenericMethod(type); var settings = new SerializerSettings() { KnownTypes = this.CollectedGeneratedTypes, Surrogate = this.Surrogate, }; - serializer = method.Invoke(/* static */ null, new object[] { settings }); + serializer = method.Invoke(/* static */ null, [settings]); this.serializers[type] = serializer; return serializer; } @@ -124,21 +125,19 @@ internal IEnumerable CollectedGeneratedTypes /// A Process object that represents an active, running query that can be checkpointed. public Process Restore(Stream inputStream = null) { - lock (this.sentinel) - { - // Restoration should not happen until after all streams have been both registered and subscribed - if (this.ingressSites.Count != this.ingressPipes.Count) throw new StreamProcessingException("Not all input data sources have been subscribed to."); - if (this.egressSites.Count != this.egressPipes.Count) throw new StreamProcessingException("Not all output data sources have been subscribed to."); + using var _ = this.sentinel.EnterScope(); + // Restoration should not happen until after all streams have been both registered and subscribed + if (this.ingressSites.Count != this.ingressPipes.Count) throw new StreamProcessingException("Not all input data sources have been subscribed to."); + if (this.egressSites.Count != this.egressPipes.Count) throw new StreamProcessingException("Not all output data sources have been subscribed to."); - var process = new Process(this.ingressPipes.Clone(), this.egressPipes.Clone()); + var process = new Process(this.ingressPipes.Clone(), this.egressPipes.Clone()); - process.Restore(inputStream); + process.Restore(inputStream); - this.ingressPipes.Clear(); - this.egressPipes.Clear(); + this.ingressPipes.Clear(); + this.egressPipes.Clear(); - return process; - } + return process; } } @@ -151,7 +150,7 @@ public sealed class Process private const int CheckpointVersionMinor = 0; private const int CheckpointVersionRevision = 0; - private readonly object sentinel = new object(); + private readonly Lock sentinel = new(); private readonly Dictionary IngressPipes; private Dictionary queryPlans; @@ -170,76 +169,80 @@ internal Process(Dictionary ingress, Dictionary< /// The stream to which the checkpoint is recorded. public void Checkpoint(Stream outputStream) { - Invariant.IsNotNull(outputStream, nameof(outputStream)); - lock (this.sentinel) + ArgumentNullException.ThrowIfNull(outputStream); + using var _ = this.sentinel.EnterScope(); + Span buffer = stackalloc byte[sizeof(int) * 3]; + BitConverter.TryWriteBytes(buffer, CheckpointVersionMajor); + BitConverter.TryWriteBytes(buffer[sizeof(int)..], CheckpointVersionMinor); + BitConverter.TryWriteBytes(buffer[(2 * sizeof(int))..], CheckpointVersionRevision); + outputStream.Write(buffer); + + try { - outputStream.Write(BitConverter.GetBytes(CheckpointVersionMajor), 0, sizeof(int)); - outputStream.Write(BitConverter.GetBytes(CheckpointVersionMinor), 0, sizeof(int)); - outputStream.Write(BitConverter.GetBytes(CheckpointVersionRevision), 0, sizeof(int)); - - try + foreach (var pipe in this.IngressPipes.Values) { - foreach (var pipe in this.IngressPipes.Values) - { - pipe.Checkpoint(outputStream); - } + pipe.Checkpoint(outputStream); } - catch (Exception) + } + catch (Exception) + { + foreach (var pipe in this.IngressPipes.Values) { - foreach (var pipe in this.IngressPipes.Values) - { - pipe.Reset(); - } - throw; + pipe.Reset(); } + throw; } } internal void Restore(Stream inputStream) { - lock (this.sentinel) + using var _ = this.sentinel.EnterScope(); + if (inputStream != null) { - if (inputStream != null) + Span buffer = stackalloc byte[sizeof(int) * 3]; + try { - byte[] buffer = new byte[sizeof(int)]; - inputStream.Read(buffer, 0, sizeof(int)); - int major = BitConverter.ToInt32(buffer, 0); - inputStream.Read(buffer, 0, sizeof(int)); - int minor = BitConverter.ToInt32(buffer, 0); - inputStream.Read(buffer, 0, sizeof(int)); - int revision = BitConverter.ToInt32(buffer, 0); - - if (major != CheckpointVersionMajor || minor != CheckpointVersionMinor || revision != CheckpointVersionRevision) - { - throw new StreamProcessingException( - string.Format( - CultureInfo.InvariantCulture, - "Version mismatch between the stream state and the engine. Expected: {0}.{1}.{2}, Found: {3}.{4}.{5}", - CheckpointVersionMajor, - CheckpointVersionMinor, - CheckpointVersionRevision, - major, - minor, - revision)); - } + inputStream.ReadExactly(buffer); + } + catch (EndOfStreamException e) + { + throw new StreamProcessingException("Failed to read checkpoint version information from the stream.", e); } - try + int major = BitConverter.ToInt32(buffer); + int minor = BitConverter.ToInt32(buffer[sizeof(int)..]); + int revision = BitConverter.ToInt32(buffer[(2 * sizeof(int))..]); + + if (major != CheckpointVersionMajor || minor != CheckpointVersionMinor || revision != CheckpointVersionRevision) { - foreach (var pipe in this.IngressPipes.Values) - { - pipe.Restore(inputStream); - } + throw new StreamProcessingException( + string.Format( + CultureInfo.InvariantCulture, + "Version mismatch between the stream state and the engine. Expected: {0}.{1}.{2}, Found: {3}.{4}.{5}", + CheckpointVersionMajor, + CheckpointVersionMinor, + CheckpointVersionRevision, + major, + minor, + revision)); } - catch (Exception) + } + + try + { + foreach (var pipe in this.IngressPipes.Values) { - foreach (var pipe in this.IngressPipes.Values) - { - pipe.Reset(); - } - throw; + pipe.Restore(inputStream); } } + catch (Exception) + { + foreach (var pipe in this.IngressPipes.Values) + { + pipe.Reset(); + } + throw; + } } /// @@ -247,23 +250,21 @@ internal void Restore(Stream inputStream) /// public void Flush() { - lock (this.sentinel) + using var _ = this.sentinel.EnterScope(); + try { - try + foreach (var pipe in this.IngressPipes.Values) { - foreach (var pipe in this.IngressPipes.Values) - { - pipe.OnFlush(); - } + pipe.OnFlush(); } - catch (Exception) + } + catch (Exception) + { + foreach (var pipe in this.IngressPipes.Values) { - foreach (var pipe in this.IngressPipes.Values) - { - pipe.Reset(); - } - throw; + pipe.Reset(); } + throw; } } @@ -298,7 +299,7 @@ public Dictionary QueryPlan { if (this.queryPlans == null) { - this.queryPlans = new Dictionary(); + this.queryPlans = []; foreach (var i in this.IngressPipes) { i.Value.ProduceQueryPlan(null); diff --git a/Sources/Core/Microsoft.StreamProcessing/Scheduler/NullScheduler.cs b/Sources/Core/Microsoft.StreamProcessing/Scheduler/NullScheduler.cs index 7e9d0467a..d8f9400e7 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Scheduler/NullScheduler.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Scheduler/NullScheduler.cs @@ -8,8 +8,6 @@ namespace Microsoft.StreamProcessing { internal sealed class NullScheduler : IInternalScheduler { - public NullScheduler() { } - public IStreamObserver RegisterStreamObserver(IStreamObserver o, Guid? classId = null) => o; public void Stop() { } diff --git a/Sources/Core/Microsoft.StreamProcessing/Scheduler/ProgressiveScheduler.cs b/Sources/Core/Microsoft.StreamProcessing/Scheduler/ProgressiveScheduler.cs index ca5c5e24e..d853576e9 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Scheduler/ProgressiveScheduler.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Scheduler/ProgressiveScheduler.cs @@ -24,47 +24,31 @@ internal enum MessageKind Flush } - internal struct QueuedMessage where T : StreamMessage + internal readonly struct QueuedMessage where T : StreamMessage { - public MessageKind Kind; - public T Message; + public MessageKind Kind { get; init; } + public T Message { get; init; } } - internal sealed class TaskEntry + internal sealed class TaskEntry(Guid classId, Action onNext, Action onCompleted, Action onFlush, Action onError) { - public TaskEntry(Guid classId, Action onNext, Action onCompleted, Action onFlush, Action onError) - { - this.ClassId = classId; - this.Priority = -1; - this.TaskCount = 0; - this.onNext = onNext; - this.onCompleted = onCompleted; - this.onFlush = onFlush; - this.onError = onError; - this.tasks = new ConcurrentQueue>(); - this.Status = TaskEntryStatus.Inactive; - this.Disposed = false; - this.Completed = false; - } - - public Guid ClassId; - public long Priority; - public int TaskCount; - public bool Disposed; - public bool Completed; - public TaskEntryStatus Status; - public Action onNext; - private Action onCompleted; - public Action onFlush; - public Action onError; - public ConcurrentQueue> tasks; + public Guid ClassId = classId; + public long Priority = -1; + public int TaskCount = 0; + public bool Disposed = false; + public bool Completed = false; + public TaskEntryStatus Status = TaskEntryStatus.Inactive; + public Action onNext = onNext; + public Action onFlush = onFlush; + public Action onError = onError; + public ConcurrentQueue> tasks = []; public void OnCompleted() { this.Completed = true; - this.onCompleted(); + onCompleted(); this.onNext = null; - this.onCompleted = null; + onCompleted = null; this.onFlush = null; this.onError = null; } @@ -83,7 +67,7 @@ internal sealed class OwnedThreadsScheduler : IInternalScheduler internal ConcurrentDictionary activeThreads; internal int pendingTaskCount; internal bool useCommonSprayPool = false; - internal object global = new object(); + internal object global = new(); internal bool affinitize; @@ -92,10 +76,10 @@ public OwnedThreadsScheduler(int numThreads, bool affinitize = false) this.pendingTaskCount = 0; this.affinitize = affinitize; this.pendingTasks = new SortedSet(new TaskEntryComparer()); - this.activeThreads = new ConcurrentDictionary(); - this.taskTable = new ConcurrentDictionary(); + this.activeThreads = []; + this.taskTable = []; - for (int i = 0; i < numThreads; i++) this.activeThreads.TryAdd(i, new ScheduledUnit(this, i)); + for (int i = 0; i < numThreads; i++) this.activeThreads.TryAdd(i, new(this, i)); this.MapArity = numThreads; } @@ -103,7 +87,7 @@ public OwnedThreadsScheduler(int numThreads, bool affinitize = false) public IStreamObserver RegisterStreamObserver(IStreamObserver o, Guid? classId = null) { // Check if already wrapped - if (o as WrapperStreamObserver != null) + if (o is WrapperStreamObserver) return o; var cid = o.ClassId; @@ -137,7 +121,7 @@ public ScheduledUnit(OwnedThreadsScheduler scheduler, int id) { this.scheduler = scheduler; this.stopped = false; - this.thread = new Thread(Run); + this.thread = new Thread(this.Run); this.thread.Start(id); } @@ -244,57 +228,48 @@ public void Run(object obj) } } - internal sealed class WrapperStreamObserver : IStreamObserver, IDisposable + internal sealed class WrapperStreamObserver(IStreamObserver observer, OwnedThreadsScheduler scheduler, TaskEntry entry) + : IStreamObserver, IDisposable { - private readonly IStreamObserver o; - private readonly OwnedThreadsScheduler scheduler; - private readonly TaskEntry te; private bool onCompletedSeen = false; - public WrapperStreamObserver(IStreamObserver o, OwnedThreadsScheduler scheduler, TaskEntry t) - { - this.o = o; - this.scheduler = scheduler; - this.te = t; - } - - public void OnError(Exception error) => this.o.OnError(error); + public void OnError(Exception error) => observer.OnError(error); - public void Checkpoint(System.IO.Stream stream) => this.o.Checkpoint(stream); + public void Checkpoint(System.IO.Stream stream) => observer.Checkpoint(stream); - public void Restore(System.IO.Stream stream) => this.o.Restore(stream); + public void Restore(System.IO.Stream stream) => observer.Restore(stream); - public void Reset() => this.o.Reset(); + public void Reset() => observer.Reset(); public void ProduceQueryPlan(PlanNode previous) => throw new NotImplementedException(); public void OnNext(StreamMessage message) { - if (this.te.Disposed) + if (entry.Disposed) { message.Free(); return; } - EnqueueMessage(MessageKind.DataBatch, message); + this.EnqueueMessage(MessageKind.DataBatch, message); } private void EnqueueMessage(MessageKind kind, StreamMessage message = null) { - this.te.tasks.Enqueue(new QueuedMessage { Kind = kind, Message = message }); - var newCount = Interlocked.Increment(ref this.te.TaskCount); + entry.tasks.Enqueue(new QueuedMessage { Kind = kind, Message = message }); + var newCount = Interlocked.Increment(ref entry.TaskCount); if (newCount == 1) { - lock (this.scheduler.global) + lock (scheduler.global) { - if (this.te.Status == TaskEntryStatus.Inactive) + if (entry.Status == TaskEntryStatus.Inactive) { // It's possible that a scheduler thread dequeues this event before this happens, // and hence does not see the correct priority for the TaskEvent. This is benign. - this.te.Priority = message?.MinTimestamp ?? StreamEvent.MaxSyncTime; - this.te.Status = TaskEntryStatus.HasWork; - this.scheduler.pendingTasks.Add(this.te); - if (this.scheduler.pendingTasks.Count == 1) Monitor.Pulse(this.scheduler.global); + entry.Priority = message?.MinTimestamp ?? StreamEvent.MaxSyncTime; + entry.Status = TaskEntryStatus.HasWork; + scheduler.pendingTasks.Add(entry); + if (scheduler.pendingTasks.Count == 1) Monitor.Pulse(scheduler.global); } } } @@ -303,28 +278,28 @@ private void EnqueueMessage(MessageKind kind, StreamMessage message = nu public void OnCompleted() { this.onCompletedSeen = true; - EnqueueMessage(MessageKind.Completed); + this.EnqueueMessage(MessageKind.Completed); } - public void OnFlush() => EnqueueMessage(MessageKind.Flush); + public void OnFlush() => this.EnqueueMessage(MessageKind.Flush); public Guid ClassId => throw new NotImplementedException(); - public int CurrentlyBufferedOutputCount => this.o.CurrentlyBufferedOutputCount; + public int CurrentlyBufferedOutputCount => observer.CurrentlyBufferedOutputCount; - public int CurrentlyBufferedInputCount => this.o.CurrentlyBufferedInputCount; + public int CurrentlyBufferedInputCount => observer.CurrentlyBufferedInputCount; public void Dispose() { - lock (this.scheduler.global) + lock (scheduler.global) { - this.te.Disposed = true; + entry.Disposed = true; } if (!this.onCompletedSeen) { this.onCompletedSeen = true; - OnCompleted(); + this.OnCompleted(); } } } diff --git a/Sources/Core/Microsoft.StreamProcessing/Serializer/Encoders/BinaryBase.cs b/Sources/Core/Microsoft.StreamProcessing/Serializer/Encoders/BinaryBase.cs index 769b8b309..cf4cb4e64 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Serializer/Encoders/BinaryBase.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Serializer/Encoders/BinaryBase.cs @@ -10,14 +10,12 @@ namespace Microsoft.StreamProcessing.Serializer { - internal abstract class BinaryBase + internal abstract class BinaryBase(Stream stream) { - protected Stream stream; + protected readonly Stream stream = stream ?? throw new ArgumentNullException(nameof(stream)); - private static readonly ConcurrentDictionary, object> columnPools = new ConcurrentDictionary, object>(); - private static readonly ConcurrentDictionary bitVectorPools = new ConcurrentDictionary(); - - protected BinaryBase(Stream stream) => this.stream = stream ?? throw new ArgumentNullException(nameof(stream)); + private static readonly ConcurrentDictionary, object> columnPools = []; + private static readonly ConcurrentDictionary bitVectorPools = []; protected static ColumnBatch AllocateColumnBatch(int size) { @@ -33,7 +31,7 @@ protected static ColumnBatch AllocateColumnBatch(int size) pool.Get(out var result); return result; } - return new ColumnBatch(size); + return new(size); } protected static T[] AllocateArray(int size) diff --git a/Sources/Core/Microsoft.StreamProcessing/Serializer/Encoders/BinaryDecoder.cs b/Sources/Core/Microsoft.StreamProcessing/Serializer/Encoders/BinaryDecoder.cs index 8392f8475..508c34c52 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Serializer/Encoders/BinaryDecoder.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Serializer/Encoders/BinaryDecoder.cs @@ -3,6 +3,7 @@ // Licensed under the MIT License // ********************************************************************* using System; +using System.Buffers; using System.IO; using System.Runtime.Serialization; using System.Text; @@ -11,10 +12,9 @@ namespace Microsoft.StreamProcessing.Serializer { - internal sealed partial class BinaryDecoder : BinaryBase + internal sealed partial class BinaryDecoder(Stream stream) + : BinaryBase(stream) { - public BinaryDecoder(Stream stream) : base(stream) { } - public bool DecodeBool() => this.stream.ReadByte() != 0; public byte DecodeByte() => (byte)this.stream.ReadByte(); @@ -110,19 +110,19 @@ public ulong DecodeULong() public float DecodeFloat() { - var value = new byte[4]; - ReadAllRequiredBytes(value); + Span value = stackalloc byte[4]; + this.ReadAllRequiredBytes(value); if (!BitConverter.IsLittleEndian) { - Array.Reverse(value); + value.Reverse(); } - return BitConverter.ToSingle(value, 0); + return BitConverter.ToSingle(value); } public double DecodeDouble() { - var value = new byte[8]; - ReadAllRequiredBytes(value); + Span value = stackalloc byte[8]; + this.ReadAllRequiredBytes(value); long longValue = value[0] | (long)value[1] << 0x8 | (long)value[2] << 0x10 @@ -136,20 +136,38 @@ public double DecodeDouble() public byte[] DecodeByteArray() { - int arraySize = DecodeInt(); + int arraySize = this.DecodeInt(); + if (arraySize == 0) + { + return []; + } var array = new byte[arraySize]; - if (arraySize > 0) ReadAllRequiredBytes(array); + this.ReadAllRequiredBytes(array); return array; } - public string DecodeString() => Encoding.UTF8.GetString(DecodeByteArray()); + public string DecodeString() + { + int byteCount = this.DecodeInt(); + if (byteCount == 0) return string.Empty; + var rented = ArrayPool.Shared.Rent(byteCount); + try + { + this.ReadAllRequiredBytes(rented.AsSpan(0, byteCount)); + return Encoding.UTF8.GetString(rented, 0, byteCount); + } + finally + { + ArrayPool.Shared.Return(rented); + } + } public int DecodeArrayChunk() { - int result = DecodeInt(); + int result = this.DecodeInt(); if (result < 0) { - DecodeLong(); + this.DecodeLong(); result = -result; } return result; @@ -157,40 +175,41 @@ public int DecodeArrayChunk() public Guid DecodeGuid() { - var array = new byte[16]; - ReadAllRequiredBytes(array); - return new Guid(array); + Span value = stackalloc byte[16]; + this.ReadAllRequiredBytes(value); + return new Guid(value); } - private void ReadAllRequiredBytes(byte[] array) + private void ReadAllRequiredBytes(Span span) { - int read = this.stream.ReadAllRequiredBytes(array, 0, array.Length); - if (read != array.Length) + int totalRead = 0; + while (totalRead < span.Length) { - throw new SerializationException( - $"Unexpected end of stream: '{array.Length - read}' bytes missing."); + int read = this.stream.Read(span[totalRead..]); + if (read == 0) + throw new SerializationException($"Unexpected end of stream: '{span.Length - totalRead}' bytes missing."); + totalRead += read; } } private int ReadIntFixed() { - var value = new byte[4]; - this.stream.ReadAllRequiredBytes(value, 0, value.Length); - int intValue = value[0] + Span value = stackalloc byte[4]; + this.ReadAllRequiredBytes(value); + return value[0] | value[1] << 0x8 | value[2] << 0x10 | value[3] << 0x18; - return intValue; } public unsafe T[] DecodeArray() where T : struct { - long sizeInBytes = DecodeLong(); + long sizeInBytes = this.DecodeLong(); int length = (int)(sizeInBytes / typeof(T).GetSizeOf()); var buffer = AllocateColumnBatch((int)sizeInBytes); var result = AllocateArray(length); - FromStream(result, length, buffer.col); + this.FromStream(result, length, buffer.col); buffer.Return(); return result; @@ -198,16 +217,16 @@ public unsafe T[] DecodeArray() where T : struct public ColumnBatch DecodeColumnBatch() where T : struct { - long sizeInBytes = DecodeLong(); + long sizeInBytes = this.DecodeLong(); int usedlength = (int)((sizeInBytes - sizeof(int)) / typeof(T).GetSizeOf()); - int length = ReadIntFixed(); + int length = this.ReadIntFixed(); var buffer = AllocateColumnBatch((int)(sizeInBytes - sizeof(int))); var result = AllocateColumnBatch(length); result.UsedLength = usedlength; - FromStream(result.col, result.UsedLength, buffer.col); + this.FromStream(result.col, result.UsedLength, buffer.col); buffer.Return(); return result; @@ -224,14 +243,14 @@ private void FromStream(T[] blob, int numElements, byte[] buffer) Buffer.BlockCopy(buffer, 0, blob, 0, buffer.Length); } - private static readonly Lazy> bytePool = new Lazy>(MemoryManager.GetDoublingArrayPool); - private static readonly Lazy charArrayPool = new Lazy(MemoryManager.GetCharArrayPool); + private static readonly Lazy> bytePool = new(MemoryManager.GetDoublingArrayPool); + private static readonly Lazy charArrayPool = new(MemoryManager.GetCharArrayPool); public CharArrayWrapper Decode_CharArrayWrapper() { - int header = DecodeInt(); - int usedLength = DecodeInt(); - int length = DecodeInt(); + int header = this.DecodeInt(); + int usedLength = this.DecodeInt(); + this.DecodeInt(); // unused length CharArrayWrapper result; if (usedLength == 0) @@ -242,12 +261,12 @@ public CharArrayWrapper Decode_CharArrayWrapper() if (header == 0) { var buffer = AllocateColumnBatch(result.UsedLength * sizeof(char)); - FromStream(result.charArray.content, result.UsedLength, buffer.col); + this.FromStream(result.charArray.content, result.UsedLength, buffer.col); buffer.Return(); } else { - var encodedSize = DecodeInt(); + var encodedSize = this.DecodeInt(); byte[] buffer; if (encodedSize > 0) @@ -265,7 +284,7 @@ public CharArrayWrapper Decode_CharArrayWrapper() public string[] DecodeStringArray() { - var cb = Decode_ColumnBatch_String(); + var cb = this.Decode_ColumnBatch_String(); string[] result = new string[cb.UsedLength]; cb.col.CopyTo(result, 0); cb.ReturnClear(); @@ -274,7 +293,7 @@ public string[] DecodeStringArray() public ColumnBatch Decode_ColumnBatch_String() { - var usedLength = ReadIntFixed(); + var usedLength = this.ReadIntFixed(); if (usedLength == 0) { var result = AllocateColumnBatch(Config.DataBatchSize); @@ -282,12 +301,12 @@ public ColumnBatch Decode_ColumnBatch_String() return result; } - int maxLength = ReadIntFixed(); + int maxLength = this.ReadIntFixed(); if (maxLength <= short.MaxValue) { - var lengths = DecodeColumnBatch(); - var caw = Decode_CharArrayWrapper(); + var lengths = this.DecodeColumnBatch(); + var caw = this.Decode_CharArrayWrapper(); var result = AllocateColumnBatch(Config.DataBatchSize); result.UsedLength = lengths.UsedLength; @@ -313,10 +332,10 @@ public ColumnBatch Decode_ColumnBatch_String() else { var result = AllocateColumnBatch(Config.DataBatchSize); - result.UsedLength = ReadIntFixed(); + result.UsedLength = this.ReadIntFixed(); for (int i = 0; i < result.UsedLength; i++) { - result.col[i] = DecodeString(); + result.col[i] = this.DecodeString(); } return result; } diff --git a/Sources/Core/Microsoft.StreamProcessing/Serializer/Encoders/BinaryEncoder.cs b/Sources/Core/Microsoft.StreamProcessing/Serializer/Encoders/BinaryEncoder.cs index dd944275e..83f4366fb 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Serializer/Encoders/BinaryEncoder.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Serializer/Encoders/BinaryEncoder.cs @@ -3,6 +3,7 @@ // Licensed under the MIT License // ********************************************************************* using System; +using System.Buffers; using System.IO; using System.Text; using Microsoft.StreamProcessing.Internal; @@ -10,10 +11,9 @@ namespace Microsoft.StreamProcessing.Serializer { - internal sealed partial class BinaryEncoder : BinaryBase + internal sealed partial class BinaryEncoder(Stream stream) + : BinaryBase(stream) { - public BinaryEncoder(Stream stream) : base(stream) { } - public void Encode(bool value) => this.stream.WriteByte(value ? (byte)1 : (byte)0); public void Encode(byte value) => this.stream.WriteByte(value); @@ -83,13 +83,10 @@ public void Encode(ulong value) public void Encode(float value) { - byte[] bytes = BitConverter.GetBytes(value); - if (!BitConverter.IsLittleEndian) - { - Array.Reverse(bytes); - } - - this.stream.Write(bytes, 0, bytes.Length); + Span bytes = stackalloc byte[4]; + BitConverter.TryWriteBytes(bytes, value); + if (!BitConverter.IsLittleEndian) bytes.Reverse(); + this.stream.Write(bytes); } public void Encode(double value) @@ -107,18 +104,46 @@ public void Encode(double value) public void Encode(byte[] value) { - if (value == null) throw new ArgumentNullException(nameof(value)); + ArgumentNullException.ThrowIfNull(value); - Encode(value.Length); + this.Encode(value.Length); if (value.Length > 0) this.stream.Write(value, 0, value.Length); } + public void Encode(ReadOnlySpan span) + { + int count = span.Length; + this.Encode(count); + if (count > 0) + { + this.stream.Write(span); + } + } + public void Encode(string value) - => Encode(Encoding.UTF8.GetBytes(value ?? throw new ArgumentNullException(nameof(value)))); + { + ArgumentNullException.ThrowIfNull(value); + int byteCount = Encoding.UTF8.GetByteCount(value); + var rented = ArrayPool.Shared.Rent(byteCount); + try + { + int written = Encoding.UTF8.GetBytes(value, rented); + this.Encode(rented.AsSpan(0, written)); + } + finally + { + ArrayPool.Shared.Return(rented); + } + } - public void EncodeArrayChunk(int size) => Encode(size); + public void EncodeArrayChunk(int size) => this.Encode(size); - public void Encode(Guid value) => this.stream.Write(value.ToByteArray(), 0, 16); + public void Encode(Guid value) + { + Span bytes = stackalloc byte[16]; + value.TryWriteBytes(bytes); + this.stream.Write(bytes); + } private void WriteIntFixed(int encodedValue) { @@ -131,22 +156,22 @@ private void WriteIntFixed(int encodedValue) public void Encode(T[] value) where T : struct { long sizeInBytes = value.Length * typeof(T).GetSizeOf(); - Encode(sizeInBytes); + this.Encode(sizeInBytes); var buffer = AllocateColumnBatch((int)sizeInBytes); - ToStream(value, value.Length, buffer.col); + this.ToStream(value, value.Length, buffer.col); buffer.Return(); } public void Encode(ColumnBatch value) where T : struct { long sizeInBytes = value.UsedLength * typeof(T).GetSizeOf() + sizeof(int); - Encode(sizeInBytes); + this.Encode(sizeInBytes); - WriteIntFixed(value.col.Length); + this.WriteIntFixed(value.col.Length); var buffer = AllocateColumnBatch(value.UsedLength * typeof(T).GetSizeOf()); - ToStream(value.col, value.UsedLength, buffer.col); + this.ToStream(value.col, value.UsedLength, buffer.col); buffer.Return(); } @@ -162,23 +187,23 @@ private void ToStream(T[] blob, int numElements, byte[] buffer) where T : str this.stream.Write(buffer, 0, buffer.Length); } - private static readonly Lazy> bytePool = new Lazy>(MemoryManager.GetDoublingArrayPool); + private static readonly Lazy> bytePool = new(MemoryManager.GetDoublingArrayPool); public unsafe void Encode(CharArrayWrapper value) { if (Config.SerializationCompressionLevel.HasFlag(SerializationCompressionLevel.CharArrayToUTF8)) - Encode(1); + this.Encode(1); else - Encode(0); // header for version number + this.Encode(0); // header for version number - Encode(value.UsedLength); - Encode(value.charArray.content.Length); + this.Encode(value.UsedLength); + this.Encode(value.charArray.content.Length); if (Config.SerializationCompressionLevel.HasFlag(SerializationCompressionLevel.CharArrayToUTF8)) { byte[] result; int encodedSize = Encoding.UTF8.GetByteCount(value.charArray.content, 0, value.UsedLength); - Encode(encodedSize); + this.Encode(encodedSize); if (encodedSize > 0) bytePool.Value.Get(out result, encodedSize); @@ -193,7 +218,7 @@ public unsafe void Encode(CharArrayWrapper value) else { var buffer = AllocateColumnBatch(value.UsedLength * sizeof(char)); - ToStream(value.charArray.content, value.UsedLength, buffer.col); + this.ToStream(value.charArray.content, value.UsedLength, buffer.col); buffer.Return(); } } @@ -206,7 +231,7 @@ public unsafe void Encode(string[] value) col = value }; - Encode(temp); + this.Encode(temp); } private static CharArrayPool charPool; @@ -224,7 +249,7 @@ public unsafe void Encode(ColumnBatch value) batchSize = Config.DataBatchSize; } - WriteIntFixed(value.UsedLength); + this.WriteIntFixed(value.UsedLength); if (value.UsedLength == 0) return; int totalChars = 0; @@ -238,7 +263,7 @@ public unsafe void Encode(ColumnBatch value) if (length > maxLength) maxLength = length; } } - WriteIntFixed(maxLength); + this.WriteIntFixed(maxLength); if (maxLength <= short.MaxValue) { @@ -272,19 +297,19 @@ public unsafe void Encode(ColumnBatch value) } } - Encode(lengths); + this.Encode(lengths); lengths.Return(); - Encode(caw); + this.Encode(caw); caw.Return(); } else { - WriteIntFixed(value.UsedLength); + this.WriteIntFixed(value.UsedLength); for (int i = 0; i < value.UsedLength; i++) { - Encode(value.col[i]); + this.Encode(value.col[i]); } } } diff --git a/Sources/Core/Microsoft.StreamProcessing/Serializer/GeneratedSubtypes/FastDictionaryGenerator.cs b/Sources/Core/Microsoft.StreamProcessing/Serializer/GeneratedSubtypes/FastDictionaryGenerator.cs index 4393bacc6..23808a528 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Serializer/GeneratedSubtypes/FastDictionaryGenerator.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Serializer/GeneratedSubtypes/FastDictionaryGenerator.cs @@ -13,9 +13,9 @@ namespace Microsoft.StreamProcessing.Internal internal static class FastDictionaryGenerator { private const string Prefix = "GeneratedFastDictionary_"; - private static readonly object sentinel = new object(); + private static readonly System.Threading.Lock sentinel = new(); private static int classCounter = 0; - private static readonly Dictionary, Type> generatorCache = new Dictionary, Type>(); + private static readonly Dictionary, Type> generatorCache = []; public static Func> CreateFastDictionaryGenerator( this IEqualityComparerExpression comparerExp, int capacity, Func equalsFunc, Func getHashCodeFunc, QueryContainer container) @@ -35,23 +35,22 @@ public static Func> CreateFastDictionaryGenerator(), out string errorMessages); - - temp = a.GetType(typeName + "`2"); - temp = temp.MakeGenericType(typeof(TKey), typeof(TValue)); - MethodInfo init = temp.GetTypeInfo().GetMethod("Initialize", BindingFlags.Static | BindingFlags.Public); - init.Invoke(null, new object[] { equalsFunc, getHashCodeFunc, capacity }); - generatorCache.Add(key, temp); - } - if (!container.TryGetFastDictionaryType(key, out Type other)) - container.RegisterFastDictionaryType(key, temp); - } + string typeName = Prefix + classCounter++; + var builderCode = new GeneratedFastDictionary(typeName, string.Empty).TransformText(); + temp = Transformer.CompileSourceCode(builderCode, [], a => a.GetType(typeName + "`2"), out string errorMessages); + + temp = temp.MakeGenericType(typeof(TKey), typeof(TValue)); + MethodInfo init = temp.GetMethod("Initialize", BindingFlags.Static | BindingFlags.Public); + init.Invoke(null, [ equalsFunc, getHashCodeFunc, capacity ]); + generatorCache.Add(key, temp); + } + if (!container.TryGetFastDictionaryType(key, out Type other)) + container.RegisterFastDictionaryType(key, temp); + return () => (FastDictionary)Activator.CreateInstance(temp); } @@ -59,9 +58,9 @@ public static Func> CreateFastDictionaryGenerator, Type> generatorCache = new Dictionary, Type>(); + private static readonly Dictionary, Type> generatorCache = []; public static Func> CreateFastDictionary2Generator( this IEqualityComparerExpression comparerExp, int capacity, Func equalsFunc, Func getHashCodeFunc, QueryContainer container) @@ -81,23 +80,22 @@ public static Func> CreateFastDictionary2Generator typeof(TKey), typeof(TValue)); Type temp; - lock (sentinel) + using var scope = sentinel.EnterScope(); + + if (!generatorCache.TryGetValue(key, out temp)) { - if (!generatorCache.TryGetValue(key, out temp)) - { - string typeName = Prefix + classCounter++; - var builderCode = new GeneratedFastDictionary(typeName, "2").TransformText(); - var a = Transformer.CompileSourceCode(builderCode, Array.Empty(), out string errorMessages); - - temp = a.GetType(typeName + "`2"); - temp = temp.MakeGenericType(typeof(TKey), typeof(TValue)); - MethodInfo init = temp.GetTypeInfo().GetMethod("Initialize", BindingFlags.Static | BindingFlags.Public); - init.Invoke(null, new object[] { equalsFunc, getHashCodeFunc, capacity }); - generatorCache.Add(key, temp); - } - if (!container.TryGetFastDictionary2Type(key, out Type other)) - container.RegisterFastDictionary2Type(key, temp); - } + string typeName = Prefix + classCounter++; + var builderCode = new GeneratedFastDictionary(typeName, "2").TransformText(); + temp = Transformer.CompileSourceCode(builderCode, [], a => a.GetType(typeName + "`2"), out string errorMessages); + + temp = temp.MakeGenericType(typeof(TKey), typeof(TValue)); + MethodInfo init = temp.GetMethod("Initialize", BindingFlags.Static | BindingFlags.Public); + init.Invoke(null, [ equalsFunc, getHashCodeFunc, capacity ]); + generatorCache.Add(key, temp); + } + if (!container.TryGetFastDictionary2Type(key, out Type other)) + container.RegisterFastDictionary2Type(key, temp); + return () => (FastDictionary2)Activator.CreateInstance(temp); } @@ -105,9 +103,9 @@ public static Func> CreateFastDictionary2Generator internal static class FastDictionaryGenerator3 { private const string Prefix = "GeneratedFastDictionary3_"; - private static readonly object sentinel = new object(); + private static readonly System.Threading.Lock sentinel = new(); private static int classCounter = 0; - private static readonly Dictionary, Type> generatorCache = new Dictionary, Type>(); + private static readonly Dictionary, Type> generatorCache = []; public static Func> CreateFastDictionary3Generator( this IEqualityComparerExpression comparerExp, int capacity, Func equalsFunc, Func getHashCodeFunc, QueryContainer container) @@ -127,23 +125,22 @@ public static Func> CreateFastDictionary3Generator typeof(TKey), typeof(TValue)); Type temp; - lock (sentinel) + using var scope = sentinel.EnterScope(); + + if (!generatorCache.TryGetValue(key, out temp)) { - if (!generatorCache.TryGetValue(key, out temp)) - { - string typeName = Prefix + classCounter++; - var builderCode = new GeneratedFastDictionary(typeName, "3").TransformText(); - var a = Transformer.CompileSourceCode(builderCode, Array.Empty(), out string errorMessages); - - temp = a.GetType(typeName + "`2"); - temp = temp.MakeGenericType(typeof(TKey), typeof(TValue)); - MethodInfo init = temp.GetTypeInfo().GetMethod("Initialize", BindingFlags.Static | BindingFlags.Public); - init.Invoke(null, new object[] { equalsFunc, getHashCodeFunc, capacity }); - generatorCache.Add(key, temp); - } - if (!container.TryGetFastDictionary3Type(key, out Type other)) - container.RegisterFastDictionary3Type(key, temp); - } + string typeName = Prefix + classCounter++; + var builderCode = new GeneratedFastDictionary(typeName, "3").TransformText(); + temp = Transformer.CompileSourceCode(builderCode, [], a => a.GetType(typeName + "`2"), out string errorMessages); + + temp = temp.MakeGenericType(typeof(TKey), typeof(TValue)); + MethodInfo init = temp.GetMethod("Initialize", BindingFlags.Static | BindingFlags.Public); + init.Invoke(null, [ equalsFunc, getHashCodeFunc, capacity ]); + generatorCache.Add(key, temp); + } + if (!container.TryGetFastDictionary3Type(key, out Type other)) + container.RegisterFastDictionary3Type(key, temp); + return () => (FastDictionary3)Activator.CreateInstance(temp); } diff --git a/Sources/Core/Microsoft.StreamProcessing/Serializer/GeneratedSubtypes/FastDictionaryGenerator.tt b/Sources/Core/Microsoft.StreamProcessing/Serializer/GeneratedSubtypes/FastDictionaryGenerator.tt index 263b8cad2..ddd2e341e 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Serializer/GeneratedSubtypes/FastDictionaryGenerator.tt +++ b/Sources/Core/Microsoft.StreamProcessing/Serializer/GeneratedSubtypes/FastDictionaryGenerator.tt @@ -1,5 +1,6 @@ <#@ template debug="false" hostspecific="false" language="C#" #> <#@ assembly name="System.Core" #> +<#@ assembly name="System.Runtime" #> <#@ import namespace="System.Linq" #> <#@ import namespace="System.Text" #> <#@ import namespace="System.Collections.Generic" #> @@ -23,9 +24,9 @@ foreach (var t in new[] {string.Empty, "2", "3"}) internal static class FastDictionaryGenerator<#= t #> { private const string Prefix = "GeneratedFastDictionary<#= t #>_"; - private static readonly object sentinel = new object(); + private static readonly System.Threading.Lock sentinel = new(); private static int classCounter = 0; - private static readonly Dictionary, Type> generatorCache = new Dictionary, Type>(); + private static readonly Dictionary, Type> generatorCache = []; public static Func> CreateFastDictionary<#= t #>Generator( this IEqualityComparerExpression comparerExp, int capacity, Func equalsFunc, Func getHashCodeFunc, QueryContainer container) @@ -45,23 +46,22 @@ foreach (var t in new[] {string.Empty, "2", "3"}) typeof(TKey), typeof(TValue)); Type temp; - lock (sentinel) + using var scope = sentinel.EnterScope(); + + if (!generatorCache.TryGetValue(key, out temp)) { - if (!generatorCache.TryGetValue(key, out temp)) - { - string typeName = Prefix + classCounter++; - var builderCode = new GeneratedFastDictionary(typeName, <#= string.IsNullOrEmpty(t) ? "string.Empty" : "\"" + t + "\"" #>).TransformText(); - var a = Transformer.CompileSourceCode(builderCode, Array.Empty(), out string errorMessages); + string typeName = Prefix + classCounter++; + var builderCode = new GeneratedFastDictionary(typeName, <#= string.IsNullOrEmpty(t) ? "string.Empty" : "\"" + t + "\"" #>).TransformText(); + temp = Transformer.CompileSourceCode(builderCode, [], a => a.GetType(typeName + "`2"), out string errorMessages); - temp = a.GetType(typeName + "`2"); - temp = temp.MakeGenericType(typeof(TKey), typeof(TValue)); - MethodInfo init = temp.GetTypeInfo().GetMethod("Initialize", BindingFlags.Static | BindingFlags.Public); - init.Invoke(null, new object[] { equalsFunc, getHashCodeFunc, capacity }); - generatorCache.Add(key, temp); - } - if (!container.TryGetFastDictionary<#= t #>Type(key, out Type other)) - container.RegisterFastDictionary<#= t #>Type(key, temp); - } + temp = temp.MakeGenericType(typeof(TKey), typeof(TValue)); + MethodInfo init = temp.GetMethod("Initialize", BindingFlags.Static | BindingFlags.Public); + init.Invoke(null, [ equalsFunc, getHashCodeFunc, capacity ]); + generatorCache.Add(key, temp); + } + if (!container.TryGetFastDictionary<#= t #>Type(key, out Type other)) + container.RegisterFastDictionary<#= t #>Type(key, temp); + return () => (FastDictionary<#= t #>)Activator.CreateInstance(temp); } diff --git a/Sources/Core/Microsoft.StreamProcessing/Serializer/GeneratedSubtypes/GeneratedFastDictionary.cs b/Sources/Core/Microsoft.StreamProcessing/Serializer/GeneratedSubtypes/GeneratedFastDictionary.cs index f0969be4e..47ce34995 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Serializer/GeneratedSubtypes/GeneratedFastDictionary.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Serializer/GeneratedSubtypes/GeneratedFastDictionary.cs @@ -34,13 +34,13 @@ public override string TransformText() [DataContract] public sealed class "); - this.Write(this.ToStringHelper.ToStringWithCulture(this.classname)); + this.Write(this.ToStringHelper.ToStringWithCulture(classname)); this.Write(" : FastDictionary"); - this.Write(this.ToStringHelper.ToStringWithCulture(this.dictType)); + this.Write(this.ToStringHelper.ToStringWithCulture(dictType)); this.Write("\r\n{\r\n private static Func equalsFunc;\r\n pri" + "vate static Func getHashCodeFunc;\r\n private static int defaultSize" + " = 10;\r\n\r\n public "); - this.Write(this.ToStringHelper.ToStringWithCulture(this.classname)); + this.Write(this.ToStringHelper.ToStringWithCulture(classname)); this.Write(@"() : base(defaultSize, equalsFunc ?? EqualityComparerExpression.DefaultEqualsFunction, getHashCodeFunc ?? EqualityComparerExpression.DefaultGetHashCodeFunction) { } public static void Initialize(Func equals, Func getHashCode, int size = 10) { diff --git a/Sources/Core/Microsoft.StreamProcessing/Serializer/GeneratedSubtypes/SortedDictionaryGenerator.cs b/Sources/Core/Microsoft.StreamProcessing/Serializer/GeneratedSubtypes/SortedDictionaryGenerator.cs index 4ff794c7b..fdc51dea5 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Serializer/GeneratedSubtypes/SortedDictionaryGenerator.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Serializer/GeneratedSubtypes/SortedDictionaryGenerator.cs @@ -8,14 +8,15 @@ using System.Linq; using System.Linq.Expressions; using System.Reflection; +using System.Threading; namespace Microsoft.StreamProcessing.Internal { internal static class SortedDictionaryGenerator { private const string Prefix = "GeneratedSortedDictionary"; - private static readonly object sentinel = new object(); - private static readonly Dictionary, Type> DictionaryTypes = new Dictionary, Type>(); + private static readonly Lock sentinel = new(); + private static readonly Dictionary, Type> DictionaryTypes = []; public static Expression>> CreateSortedDictionaryGenerator(this IComparerExpression comparerExp, QueryContainer container) { @@ -36,7 +37,7 @@ Expression, SortedDictionary>> template var key = Tuple.Create(expression + string.Concat(vars.Select(o => o.ToString(CultureInfo.InvariantCulture))), typeof(TKey), typeof(TValue)); Type temp; - lock (sentinel) + using (sentinel.EnterScope()) { if (!DictionaryTypes.TryGetValue(key, out temp)) { @@ -47,12 +48,11 @@ Expression, SortedDictionary>> template typeName = typeName.Replace("-", "_"); var builderCode = new GeneratedSortedDictionary(typeName).TransformText(); var assemblyReferences = Transformer.AssemblyReferencesNeededFor(typeof(SortedDictionary<,>)); - var a = Transformer.CompileSourceCode(builderCode, assemblyReferences, out string errorMessages); - temp = a.GetType(typeName + "`2"); + temp = Transformer.CompileSourceCode(builderCode, assemblyReferences, a => a.GetType(typeName + "`2"), out string errorMessages); temp = temp.MakeGenericType(typeof(TKey), typeof(TValue)); - var init = temp.GetTypeInfo().GetMethod("Initialize", BindingFlags.Static | BindingFlags.Public); - init.Invoke(null, new object[] { Comparer.Create(expr.Compile()) }); + var init = temp.GetMethod("Initialize", BindingFlags.Static | BindingFlags.Public); + init.Invoke(null, [Comparer.Create(expr.Compile())]); DictionaryTypes.Add(key, temp); } if (!container.TryGetSortedDictionaryType(key, out var other)) @@ -62,10 +62,8 @@ Expression, SortedDictionary>> template } } - internal partial class GeneratedSortedDictionary + internal partial class GeneratedSortedDictionary(string name) { - private readonly string name; - - public GeneratedSortedDictionary(string name) => this.name = name; + private readonly string name = name; } } diff --git a/Sources/Core/Microsoft.StreamProcessing/Serializer/SerializerSettings.cs b/Sources/Core/Microsoft.StreamProcessing/Serializer/SerializerSettings.cs index 0b19c425f..b6b61bb18 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Serializer/SerializerSettings.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Serializer/SerializerSettings.cs @@ -74,7 +74,7 @@ public bool Equals(SerializerSettings other) /// /// true if the specified is equal to this instance; otherwise, false. /// - public override bool Equals(object obj) => Equals(obj as SerializerSettings); + public override bool Equals(object obj) => this.Equals(obj as SerializerSettings); /// /// Returns a hash code for this instance. diff --git a/Sources/Core/Microsoft.StreamProcessing/Serializer/Serializers/ArraySerializer.cs b/Sources/Core/Microsoft.StreamProcessing/Serializer/Serializers/ArraySerializer.cs index f959a1220..e643aa93a 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Serializer/Serializers/ArraySerializer.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Serializer/Serializers/ArraySerializer.cs @@ -16,7 +16,7 @@ internal sealed class ArraySerializer : ObjectSerializerBase protected override Expression BuildSerializerSafe(Expression encoder, Expression value) { - var getLength = this.RuntimeType.GetTypeInfo().GetProperty("Length"); + var getLength = this.RuntimeType.GetProperty("Length"); if (getLength == null) { throw new SerializationException($"Runtime type '{this.RuntimeType}' is being serialized as array, but does not have 'Length' property."); @@ -51,7 +51,7 @@ protected override Expression BuildDeserializerSafe(Expression decoder) { var arrayType = this.RuntimeType; - var resize = typeof(Array).GetTypeInfo().GetMethod("Resize").MakeGenericMethod(arrayType.GetElementType()); + var resize = typeof(Array).GetMethod("Resize").MakeGenericMethod(arrayType.GetElementType()); var body = new List(); var result = Expression.Variable(arrayType, "result"); diff --git a/Sources/Core/Microsoft.StreamProcessing/Serializer/Serializers/ClassSerializer.cs b/Sources/Core/Microsoft.StreamProcessing/Serializer/Serializers/ClassSerializer.cs index 57f253942..a920f3f41 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Serializer/Serializers/ClassSerializer.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Serializer/Serializers/ClassSerializer.cs @@ -14,7 +14,7 @@ namespace Microsoft.StreamProcessing.Serializer.Serializers { internal abstract class ClassSerializer : ObjectSerializerBase { - protected readonly List fields = new List(); + protected readonly List fields = []; protected ClassSerializer(Type runtimeType) : base(runtimeType) { } @@ -49,11 +49,11 @@ protected override Expression BuildSerializerSafe(Expression encoder, Expression // For handling potential recursive types. this.cachedSerializer = (o, e) => { }; - this.cachedSerializer = GenerateCachedSerializer(); + this.cachedSerializer = this.GenerateCachedSerializer(); // For performance reasons we do not use a cached serializer // for the first encounter of the type in the schema tree. - return SerializeFields(encoder, value); + return this.SerializeFields(encoder, value); } protected override Expression BuildDeserializerSafe(Expression decoder) @@ -62,7 +62,7 @@ protected override Expression BuildDeserializerSafe(Expression decoder) // For handling potential recursive types. this.cachedDeserializer = d => default; - var deserializeLambda = GenerateCachedDeserializer(); + var deserializeLambda = this.GenerateCachedDeserializer(); this.cachedDeserializer = deserializeLambda.Compile(); return Expression.Invoke(deserializeLambda, decoder); @@ -78,7 +78,7 @@ private Expression> GenerateCachedDeserializer() { // Cannot create an object beforehand. Have to call a constructor with parameters. var properties = this.fields.Select(f => f.Schema.BuildDeserializer(decoderParam)); - var ctor = this.RuntimeType.GetTypeInfo() + var ctor = this.RuntimeType .GetConstructors() .Single(c => c.GetParameters().Select(p => p.ParameterType).SequenceEqual(this.fields.Select(f => f.Schema.RuntimeType))); body.Add(Expression.Assign(instance, Expression.New(ctor, properties))); @@ -100,7 +100,7 @@ private Action GenerateCachedSerializer() { var instanceParam = Expression.Parameter(this.RuntimeType, "instance"); var encoderParam = Expression.Parameter(typeof(BinaryEncoder), "encoder"); - var block = SerializeFields(encoderParam, instanceParam); + var block = this.SerializeFields(encoderParam, instanceParam); var lambda = Expression.Lambda>(block, instanceParam, encoderParam); return lambda.Compile(); } @@ -116,7 +116,7 @@ private Expression SerializeFields(Expression encoder, Expression value) } // Check for null. - if (!this.RuntimeType.GetTypeInfo().IsValueType) + if (!this.RuntimeType.IsValueType) { body.Add(Expression.IfThen( Expression.Equal(value, Expression.Constant(null)), diff --git a/Sources/Core/Microsoft.StreamProcessing/Serializer/Serializers/EnumerableSerializer.cs b/Sources/Core/Microsoft.StreamProcessing/Serializer/Serializers/EnumerableSerializer.cs index b39512952..9aace8dad 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Serializer/Serializers/EnumerableSerializer.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Serializer/Serializers/EnumerableSerializer.cs @@ -41,11 +41,11 @@ public static ObjectSerializerBase Create(Type collectionType, Type itemType, Ob /// The value. /// Expression, serializing an enumerable. protected override Expression BuildSerializerSafe(Expression encoder, Expression value) - => typeof(IList).GetTypeInfo().IsAssignableFrom(typeof(TCollection).GetTypeInfo()) - ? BuildSerializerForList(encoder, value) - : typeof(ICollection).GetTypeInfo().IsAssignableFrom(typeof(TCollection).GetTypeInfo()) - ? BuildSerializerForCollection(encoder, value) - : BuildSerializerForEnumerable(encoder, value); + => typeof(IList).IsAssignableFrom(typeof(TCollection)) + ? this.BuildSerializerForList(encoder, value) + : typeof(ICollection).IsAssignableFrom(typeof(TCollection)) + ? this.BuildSerializerForCollection(encoder, value) + : this.BuildSerializerForEnumerable(encoder, value); private Expression BuildSerializerForEnumerable(Expression encoder, Expression value) { @@ -151,13 +151,13 @@ private Expression BuildSerializerForList(Expression encoder, Expression value) } protected override Expression BuildDeserializerSafe(Expression decoder) - => typeof(ICollection).GetTypeInfo().IsAssignableFrom(typeof(TCollection).GetTypeInfo()) - ? BuildDeserializerForCollection(decoder) - : BuildDeserializerForEnumerable(decoder); + => typeof(ICollection).IsAssignableFrom(typeof(TCollection)) + ? this.BuildDeserializerForCollection(decoder) + : this.BuildDeserializerForEnumerable(decoder); private Expression BuildDeserializerForEnumerable(Expression decoder) { - var addElement = GetAddMethod(); + var addElement = this.GetAddMethod(); var result = Expression.Variable(typeof(TCollection), "result"); var index = Expression.Variable(typeof(int), "index"); @@ -180,7 +180,7 @@ private Expression BuildDeserializerForEnumerable(Expression decoder) Expression.Block( Expression.IfThen( Expression.GreaterThanOrEqual(counter, chunkSize), Expression.Break(chunkLoop)), - Expression.Call(result, addElement, new[] { this.itemSchema.BuildDeserializer(decoder) }), + Expression.Call(result, addElement, [this.itemSchema.BuildDeserializer(decoder)]), Expression.PreIncrementAssign(index), Expression.PreIncrementAssign(counter)), chunkLoop)), diff --git a/Sources/Core/Microsoft.StreamProcessing/Serializer/Serializers/MultidimensionalArraySerializer.cs b/Sources/Core/Microsoft.StreamProcessing/Serializer/Serializers/MultidimensionalArraySerializer.cs index 636b69382..cc4bb2e14 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Serializer/Serializers/MultidimensionalArraySerializer.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Serializer/Serializers/MultidimensionalArraySerializer.cs @@ -19,7 +19,7 @@ internal sealed class MultidimensionalArraySerializer : ObjectSerializerBase protected override Expression BuildSerializerSafe(Expression encoder, Expression value) { int rank = this.RuntimeType.GetArrayRank(); - return BuildSerializerImpl(new List(), encoder, value, 0, rank); + return this.BuildSerializerImpl([], encoder, value, 0, rank); } private Expression BuildSerializerImpl( @@ -33,9 +33,9 @@ private Expression BuildSerializerImpl( if (currentRank == maxRank) return this.ItemSchema.BuildSerializer(encoder, Expression.ArrayIndex(value, indexes)); - var getLength = this.RuntimeType.GetTypeInfo().GetMethod("GetLength"); + var getLength = this.RuntimeType.GetMethod("GetLength"); var length = Expression.Variable(typeof(int), "length"); - body.Add(Expression.Assign(length, Expression.Call(value, getLength, new Expression[] { Expression.Constant(currentRank) }))); + body.Add(Expression.Assign(length, Expression.Call(value, getLength, [Expression.Constant(currentRank)]))); body.Add(EncodeArrayChunkMethod.ReplaceParametersInBody(encoder, length)); var label = Expression.Label(); @@ -47,7 +47,7 @@ private Expression BuildSerializerImpl( Expression.Loop( Expression.Block( Expression.IfThen(Expression.GreaterThanOrEqual(counter, length), Expression.Break(label)), - BuildSerializerImpl(indexes, encoder, value, currentRank + 1, maxRank), + this.BuildSerializerImpl(indexes, encoder, value, currentRank + 1, maxRank), Expression.PreIncrementAssign(counter)), label)); @@ -66,19 +66,19 @@ protected override Expression BuildDeserializerSafe(Expression decoder) var jaggedType = GenerateJaggedType(this.RuntimeType); var deserialized = Expression.Variable(jaggedType, "deserialized"); - body.Add(Expression.Assign(deserialized, GenerateBuildJaggedDeserializer(decoder, jaggedType, 0, type.GetArrayRank()))); + body.Add(Expression.Assign(deserialized, this.GenerateBuildJaggedDeserializer(decoder, jaggedType, 0, type.GetArrayRank()))); var lengths = new List(); Expression currentObject = deserialized; for (int i = 0; i < type.GetArrayRank(); i++) { lengths.Add(Expression.Property(currentObject, "Count")); - currentObject = Expression.Property(currentObject, "Item", new Expression[] { ConstantZero }); + currentObject = Expression.Property(currentObject, "Item", [ConstantZero]); } var result = Expression.Variable(type, "result"); body.Add(Expression.Assign(result, Expression.NewArrayBounds(type.GetElementType(), lengths))); - body.Add(GenerateCopy(new List(), result, deserialized, 0, type.GetArrayRank())); + body.Add(this.GenerateCopy([], result, deserialized, 0, type.GetArrayRank())); body.Add(result); return Expression.Block(new[] { deserialized, result }, body); } @@ -130,15 +130,14 @@ private Expression GenerateBuildJaggedDeserializer(Expression decoder, Type valu Expression.Break(internalLoopLabel)), Expression.Call( result, - valueType.GetTypeInfo().GetMethod("Add"), - new[] - { - GenerateBuildJaggedDeserializer( + valueType.GetMethod("Add"), + [ + this.GenerateBuildJaggedDeserializer( decoder, - valueType.GetTypeInfo().GetGenericArguments()[0], + valueType.GetGenericArguments()[0], currentRank + 1, maxRank) - }), + ]), Expression.PreIncrementAssign(index), Expression.PreIncrementAssign(counter)), internalLoopLabel)), @@ -167,10 +166,10 @@ private Expression GenerateCopy(List indexes, Expression destination Expression.Loop( Expression.Block( Expression.IfThen(Expression.GreaterThanOrEqual(counter, length), Expression.Break(label)), - GenerateCopy( + this.GenerateCopy( indexes, destination, - Expression.Property(source, "Item", new Expression[] { counter }), + Expression.Property(source, "Item", [counter]), currentRank + 1, maxRank), Expression.PreIncrementAssign(counter)), diff --git a/Sources/Core/Microsoft.StreamProcessing/Serializer/Serializers/ObjectSerializerBase.cs b/Sources/Core/Microsoft.StreamProcessing/Serializer/Serializers/ObjectSerializerBase.cs index 6fe933876..d447c3f2c 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Serializer/Serializers/ObjectSerializerBase.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Serializer/Serializers/ObjectSerializerBase.cs @@ -18,12 +18,12 @@ internal abstract class ObjectSerializerBase protected ObjectSerializerBase(Type baseType) : base() => this.RuntimeType = baseType; public Expression BuildSerializer(Expression encoder, Expression value) - => BuildSerializerSafe( + => this.BuildSerializerSafe( encoder ?? throw new ArgumentNullException(nameof(encoder)), value ?? throw new ArgumentNullException(nameof(value))); public Expression BuildDeserializer(Expression decoder) - => BuildDeserializerSafe(decoder ?? throw new ArgumentNullException(nameof(decoder))); + => this.BuildDeserializerSafe(decoder ?? throw new ArgumentNullException(nameof(decoder))); protected abstract Expression BuildSerializerSafe(Expression encoder, Expression value); protected abstract Expression BuildDeserializerSafe(Expression decoder); diff --git a/Sources/Core/Microsoft.StreamProcessing/Serializer/Serializers/RecordFieldSerializer.cs b/Sources/Core/Microsoft.StreamProcessing/Serializer/Serializers/RecordFieldSerializer.cs index e403b1d96..b1fffbefc 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Serializer/Serializers/RecordFieldSerializer.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Serializer/Serializers/RecordFieldSerializer.cs @@ -22,11 +22,11 @@ public RecordFieldSerializer(ObjectSerializerBase schema, MyFieldInfo info) public Expression BuildSerializer(Expression encoder, Expression @object) { - if (encoder == null) throw new ArgumentNullException(nameof(encoder)); - if (@object == null) throw new ArgumentNullException(nameof(@object)); + ArgumentNullException.ThrowIfNull(encoder); + ArgumentNullException.ThrowIfNull(@object); - var member = GetMember(@object); - if (this.Schema.RuntimeType.GetTypeInfo().IsValueType || this.MemberInfo.isField) + var member = this.GetMember(@object); + if (this.Schema.RuntimeType.IsValueType || this.MemberInfo.isField) { return this.Schema.BuildSerializer(encoder, member); } @@ -34,17 +34,17 @@ public Expression BuildSerializer(Expression encoder, Expression @object) var tmp = Expression.Variable(this.Schema.RuntimeType, Guid.NewGuid().ToString()); var assignment = Expression.Assign(tmp, member); var serialized = this.Schema.BuildSerializer(encoder, tmp); - return Expression.Block(new[] { tmp }, new[] { assignment, serialized }); + return Expression.Block(new[] { tmp }, [assignment, serialized]); } public Expression BuildDeserializer(Expression decoder, Expression @object) { - if (decoder == null) throw new ArgumentNullException(nameof(decoder)); - if (@object == null) throw new ArgumentNullException(nameof(@object)); + ArgumentNullException.ThrowIfNull(decoder); + ArgumentNullException.ThrowIfNull(@object); var value = this.Schema.BuildDeserializer(decoder); - var member = GetMember(@object); - if (@object.Type.GetTypeInfo().IsValueType) + var member = this.GetMember(@object); + if (@object.Type.IsValueType) { var tmp = Expression.Variable(value.Type); return Expression.Block( diff --git a/Sources/Core/Microsoft.StreamProcessing/Serializer/Serializers/ReflectionSchemaBuilder.cs b/Sources/Core/Microsoft.StreamProcessing/Serializer/Serializers/ReflectionSchemaBuilder.cs index 5802f698f..b59b284fd 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Serializer/Serializers/ReflectionSchemaBuilder.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Serializer/Serializers/ReflectionSchemaBuilder.cs @@ -15,11 +15,11 @@ namespace Microsoft.StreamProcessing.Serializer.Serializers internal sealed class ReflectionSchemaBuilder { private static readonly ConcurrentDictionary> RuntimeTypeToSerializer = - new ConcurrentDictionary>(); + new(); private readonly SerializerSettings settings; private readonly HashSet knownTypes; - private readonly Dictionary seenTypes = new Dictionary(); + private readonly Dictionary seenTypes = []; static ReflectionSchemaBuilder() { @@ -43,27 +43,27 @@ static ReflectionSchemaBuilder() RuntimeTypeToSerializer[typeof(DateTimeOffset)] = () => PrimitiveSerializer.DateTimeOffset; RuntimeTypeToSerializer[typeof(Guid)] = () => PrimitiveSerializer.Guid; - RuntimeTypeToSerializer[typeof(char[])] = () => PrimitiveSerializer.CreateForArray(); + RuntimeTypeToSerializer[typeof(char[])] = PrimitiveSerializer.CreateForArray; RuntimeTypeToSerializer[typeof(byte[])] = () => PrimitiveSerializer.ByteArray; - RuntimeTypeToSerializer[typeof(short[])] = () => PrimitiveSerializer.CreateForArray(); - RuntimeTypeToSerializer[typeof(ushort[])] = () => PrimitiveSerializer.CreateForArray(); - RuntimeTypeToSerializer[typeof(int[])] = () => PrimitiveSerializer.CreateForArray(); - RuntimeTypeToSerializer[typeof(uint[])] = () => PrimitiveSerializer.CreateForArray(); - RuntimeTypeToSerializer[typeof(long[])] = () => PrimitiveSerializer.CreateForArray(); - RuntimeTypeToSerializer[typeof(ulong[])] = () => PrimitiveSerializer.CreateForArray(); - RuntimeTypeToSerializer[typeof(float[])] = () => PrimitiveSerializer.CreateForArray(); - RuntimeTypeToSerializer[typeof(double[])] = () => PrimitiveSerializer.CreateForArray(); + RuntimeTypeToSerializer[typeof(short[])] = PrimitiveSerializer.CreateForArray; + RuntimeTypeToSerializer[typeof(ushort[])] = PrimitiveSerializer.CreateForArray; + RuntimeTypeToSerializer[typeof(int[])] = PrimitiveSerializer.CreateForArray; + RuntimeTypeToSerializer[typeof(uint[])] = PrimitiveSerializer.CreateForArray; + RuntimeTypeToSerializer[typeof(long[])] = PrimitiveSerializer.CreateForArray; + RuntimeTypeToSerializer[typeof(ulong[])] = PrimitiveSerializer.CreateForArray; + RuntimeTypeToSerializer[typeof(float[])] = PrimitiveSerializer.CreateForArray; + RuntimeTypeToSerializer[typeof(double[])] = PrimitiveSerializer.CreateForArray; RuntimeTypeToSerializer[typeof(string[])] = () => PrimitiveSerializer.StringArray; - RuntimeTypeToSerializer[typeof(ColumnBatch)] = () => PrimitiveSerializer.CreateForColumnBatch(); - RuntimeTypeToSerializer[typeof(ColumnBatch)] = () => PrimitiveSerializer.CreateForColumnBatch(); - RuntimeTypeToSerializer[typeof(ColumnBatch)] = () => PrimitiveSerializer.CreateForColumnBatch(); - RuntimeTypeToSerializer[typeof(ColumnBatch)] = () => PrimitiveSerializer.CreateForColumnBatch(); - RuntimeTypeToSerializer[typeof(ColumnBatch)] = () => PrimitiveSerializer.CreateForColumnBatch(); - RuntimeTypeToSerializer[typeof(ColumnBatch)] = () => PrimitiveSerializer.CreateForColumnBatch(); - RuntimeTypeToSerializer[typeof(ColumnBatch)] = () => PrimitiveSerializer.CreateForColumnBatch(); - RuntimeTypeToSerializer[typeof(ColumnBatch)] = () => PrimitiveSerializer.CreateForColumnBatch(); - RuntimeTypeToSerializer[typeof(ColumnBatch)] = () => PrimitiveSerializer.CreateForColumnBatch(); + RuntimeTypeToSerializer[typeof(ColumnBatch)] = PrimitiveSerializer.CreateForColumnBatch; + RuntimeTypeToSerializer[typeof(ColumnBatch)] = PrimitiveSerializer.CreateForColumnBatch; + RuntimeTypeToSerializer[typeof(ColumnBatch)] = PrimitiveSerializer.CreateForColumnBatch; + RuntimeTypeToSerializer[typeof(ColumnBatch)] = PrimitiveSerializer.CreateForColumnBatch; + RuntimeTypeToSerializer[typeof(ColumnBatch)] = PrimitiveSerializer.CreateForColumnBatch; + RuntimeTypeToSerializer[typeof(ColumnBatch)] = PrimitiveSerializer.CreateForColumnBatch; + RuntimeTypeToSerializer[typeof(ColumnBatch)] = PrimitiveSerializer.CreateForColumnBatch; + RuntimeTypeToSerializer[typeof(ColumnBatch)] = PrimitiveSerializer.CreateForColumnBatch; + RuntimeTypeToSerializer[typeof(ColumnBatch)] = PrimitiveSerializer.CreateForColumnBatch; RuntimeTypeToSerializer[typeof(ColumnBatch)] = () => PrimitiveSerializer.StringColumnBatch; RuntimeTypeToSerializer[typeof(CharArrayWrapper)] = () => PrimitiveSerializer.CharArray; @@ -77,10 +77,10 @@ public ReflectionSchemaBuilder(SerializerSettings settings) public ObjectSerializerBase BuildSchema(Type type) { - if (type == null) throw new ArgumentNullException(nameof(type)); + ArgumentNullException.ThrowIfNull(type); this.knownTypes.UnionWith(type.GetAllKnownTypes() ?? new List()); - return CreateSchema(type, 0); + return this.CreateSchema(type, 0); } private ObjectSerializerBase CreateSchema(Type type, uint currentDepth) @@ -105,17 +105,17 @@ private ObjectSerializerBase CreateSchema(Type type, uint currentDepth) } return type.ValidateTypeForSerializer().CanContainNull() - ? CreateNullableSchema(type, currentDepth) - : CreateNotNullableSchema(type, currentDepth); + ? this.CreateNullableSchema(type, currentDepth) + : this.CreateNotNullableSchema(type, currentDepth); } private ObjectSerializerBase CreateNullableSchema(Type type, uint currentDepth) { - if (type.GetTypeInfo().IsInterface || type.GetTypeInfo().IsAbstract || HasApplicableKnownType(type)) - return new UnionSerializer(FindKnownTypes(type, currentDepth).ToList(), type); + if (type.IsInterface || type.IsAbstract || this.HasApplicableKnownType(type)) + return new UnionSerializer(this.FindKnownTypes(type, currentDepth).ToList(), type); var typeSchemas = new List(); - var notNullableSchema = CreateNotNullableSchema(Nullable.GetUnderlyingType(type) ?? type, currentDepth); + var notNullableSchema = this.CreateNotNullableSchema(Nullable.GetUnderlyingType(type) ?? type, currentDepth); typeSchemas.Add(notNullableSchema); @@ -127,24 +127,23 @@ private ObjectSerializerBase CreateNotNullableSchema(Type type, uint currentDept if (RuntimeTypeToSerializer.TryGetValue(type, out var p)) return p(); if (this.seenTypes.TryGetValue(type, out var schema)) return schema; - var typeInfo = type.GetTypeInfo(); - if (typeInfo.IsEnum) return BuildEnumTypeSchema(type); + if (type.IsEnum) return this.BuildEnumTypeSchema(type); // Array - if (type.IsArray || type == typeof(Array)) return BuildArrayTypeSchema(type, currentDepth); + if (type.IsArray || type == typeof(Array)) return this.BuildArrayTypeSchema(type, currentDepth); // Enumerable - var enumerableType = typeInfo + var enumerableType = type .GetInterfaces() - .SingleOrDefault(t => t.GetTypeInfo().IsGenericType && t.GetGenericTypeDefinition() == typeof(IEnumerable<>)); + .SingleOrDefault(t => t.IsGenericType && t.GetGenericTypeDefinition() == typeof(IEnumerable<>)); if (enumerableType != null) { - var itemType = enumerableType.GetTypeInfo().GetGenericArguments()[0]; - return EnumerableSerializer.Create(type, itemType, CreateSchema(itemType, currentDepth + 1)); + var itemType = enumerableType.GetGenericArguments()[0]; + return EnumerableSerializer.Create(type, itemType, this.CreateSchema(itemType, currentDepth + 1)); } // Others - if (typeInfo.IsClass || typeInfo.IsValueType) return BuildRecordTypeSchema(type, currentDepth); + if (type.IsClass || type.IsValueType) return this.BuildRecordTypeSchema(type, currentDepth); throw new SerializationException($"Type '{type}' is not supported."); } @@ -158,7 +157,7 @@ private ObjectSerializerBase BuildEnumTypeSchema(Type type) private ObjectSerializerBase BuildArrayTypeSchema(Type type, uint currentDepth) { - var elementSchema = CreateSchema(type.GetElementType(), currentDepth + 1); + var elementSchema = this.CreateSchema(type.GetElementType(), currentDepth + 1); return type == typeof(Array) || type.GetArrayRank() == 1 ? new ArraySerializer(elementSchema, type) @@ -173,7 +172,7 @@ private ObjectSerializerBase BuildRecordTypeSchema(Type type, uint currentDepth) var members = type.ResolveMembers(); foreach (var info in members) { - var fieldSchema = CreateSchema(info.Type, currentDepth + 1); + var fieldSchema = this.CreateSchema(info.Type, currentDepth + 1); var recordField = new RecordFieldSerializer(fieldSchema, info); record.AddField(recordField); @@ -191,7 +190,7 @@ private IEnumerable FindKnownTypes(Type type, uint current } if (!type.IsAbstract && !type.IsInterface && !this.knownTypes.Contains(type)) applicable.Add(type); - return applicable.Select(t => CreateNotNullableSchema(t, currentDepth)); + return applicable.Select(t => this.CreateNotNullableSchema(t, currentDepth)); } private bool HasApplicableKnownType(Type type) => this.knownTypes.Where(t => t.CanBeKnownTypeOf(type)).Any(); diff --git a/Sources/Core/Microsoft.StreamProcessing/Serializer/Serializers/SurrogateSerializer.cs b/Sources/Core/Microsoft.StreamProcessing/Serializer/Serializers/SurrogateSerializer.cs index 71584f7cd..6ef52da29 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Serializer/Serializers/SurrogateSerializer.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Serializer/Serializers/SurrogateSerializer.cs @@ -24,7 +24,7 @@ protected override Expression BuildSerializerSafe(Expression encoder, Expression { var surrogate = Expression.Constant(this.Surrogate); var stream = Expression.Field(encoder, "stream"); - return Expression.Call(surrogate, this.serialize, new[] { value, stream }); + return Expression.Call(surrogate, this.serialize, [value, stream]); } protected override Expression BuildDeserializerSafe(Expression decoder) diff --git a/Sources/Core/Microsoft.StreamProcessing/Serializer/Serializers/UnionSerializer.cs b/Sources/Core/Microsoft.StreamProcessing/Serializer/Serializers/UnionSerializer.cs index 964108dd3..aaacb8d18 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Serializer/Serializers/UnionSerializer.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Serializer/Serializers/UnionSerializer.cs @@ -37,7 +37,7 @@ protected override Expression BuildSerializerSafe(Expression encoder, Expression encoder, value.Type == otherRuntimeSchema.RuntimeType ? value - : (otherRuntimeSchema.RuntimeType.GetTypeInfo().IsValueType + : (otherRuntimeSchema.RuntimeType.IsValueType ? (Expression)Expression.Property(value, "Value") : Expression.TypeAs(value, otherRuntimeSchema.RuntimeType)))); } @@ -89,13 +89,13 @@ protected override Expression BuildDeserializerSafe(Expression decoder) elseBranch); elseBranch = conditions; } - return Expression.Block(new[] { resultParameter, unionTypeParameter }, new Expression[] { assignUnionType, conditions, resultParameter }); + return Expression.Block(new[] { resultParameter, unionTypeParameter }, [assignUnionType, conditions, resultParameter]); } private static int MoreSpecializedTypesFirst(Tuple s1, Tuple s2) { - if (s1.Item1.RuntimeType.GetTypeInfo().IsAssignableFrom(s2.Item1.RuntimeType)) return 1; - if (s2.Item1.RuntimeType.GetTypeInfo().IsAssignableFrom(s1.Item1.RuntimeType)) return -1; + if (s1.Item1.RuntimeType.IsAssignableFrom(s2.Item1.RuntimeType)) return 1; + if (s2.Item1.RuntimeType.IsAssignableFrom(s1.Item1.RuntimeType)) return -1; return s1.Item2.CompareTo(s2.Item2); } diff --git a/Sources/Core/Microsoft.StreamProcessing/Serializer/StateSerializer.cs b/Sources/Core/Microsoft.StreamProcessing/Serializer/StateSerializer.cs index 3d5cc2a85..b38e00402 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Serializer/StateSerializer.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Serializer/StateSerializer.cs @@ -22,8 +22,8 @@ public sealed class StateSerializer internal StateSerializer(ObjectSerializerBase schema) { this.schema = schema ?? throw new ArgumentNullException(nameof(schema)); - this.serialize = new Lazy>(GenerateSerializer); - this.deserialize = new Lazy>(GenerateDeserializer); + this.serialize = new Lazy>(this.GenerateSerializer); + this.deserialize = new Lazy>(this.GenerateDeserializer); } /// diff --git a/Sources/Core/Microsoft.StreamProcessing/Serializer/StreamSerializer.cs b/Sources/Core/Microsoft.StreamProcessing/Serializer/StreamSerializer.cs index 875fc09d3..51742ffce 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Serializer/StreamSerializer.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Serializer/StreamSerializer.cs @@ -14,7 +14,7 @@ namespace Microsoft.StreamProcessing.Serializer public static class StreamSerializer { private static readonly ConcurrentDictionary, object> TypedSerializers - = new ConcurrentDictionary, object>(); + = new(); /// /// Create instance of serializer for given object type @@ -36,7 +36,7 @@ private static readonly ConcurrentDictionary, ob /// public static StateSerializer Create(SerializerSettings settings) { - if (settings == null) throw new ArgumentNullException(nameof(settings)); + ArgumentNullException.ThrowIfNull(settings); var key = Tuple.Create(typeof(T), settings); lock (TypedSerializers) diff --git a/Sources/Core/Microsoft.StreamProcessing/Sharding/ShardedStreamCache.cs b/Sources/Core/Microsoft.StreamProcessing/Sharding/ShardedStreamCache.cs index 585cd9b91..22e6cb220 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Sharding/ShardedStreamCache.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Sharding/ShardedStreamCache.cs @@ -69,14 +69,14 @@ internal sealed class ShardedCacheObserver : IObserver>> elements; - private readonly AutoResetEvent done = new AutoResetEvent(false); + private readonly AutoResetEvent done = new(false); public ShardedCacheObserver(StreamCache cache, StreamProperties sourceProps) { this.cache = cache; this.sourceProps = sourceProps; - this.elements = new List>>(); + this.elements = []; } public void Dispose() @@ -129,6 +129,6 @@ public static class ShardedStreamableIO /// The sharded streamable to cache /// A cached sharded streamable public static ShardedStreamCache Cache(this IShardedStreamable source) - => new ShardedStreamCache(source); + => new(source); } } \ No newline at end of file diff --git a/Sources/Core/Microsoft.StreamProcessing/Sharding/ShardedStreamSerialization.cs b/Sources/Core/Microsoft.StreamProcessing/Sharding/ShardedStreamSerialization.cs index e6e5378ba..9bdc1df45 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Sharding/ShardedStreamSerialization.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Sharding/ShardedStreamSerialization.cs @@ -53,7 +53,7 @@ internal sealed class ShardedSerializerObserver : IObserver>> serializer; private readonly Stream destination; - private readonly AutoResetEvent done = new AutoResetEvent(false); + private readonly AutoResetEvent done = new(false); // TODO: This appears to be copied code from Binary egress - can we unify? public ShardedSerializerObserver(Stream destination, StreamProperties sourceProps, bool writePropertiesToStream = false) diff --git a/Sources/Core/Microsoft.StreamProcessing/StreamProcessing.nuspec b/Sources/Core/Microsoft.StreamProcessing/StreamProcessing.nuspec deleted file mode 100644 index b5e2ee8a6..000000000 --- a/Sources/Core/Microsoft.StreamProcessing/StreamProcessing.nuspec +++ /dev/null @@ -1,35 +0,0 @@ - - - - Trill - $version$ - Trill - Microsoft - https://github.com/Microsoft/Trill - https://github.com/Microsoft/Trill/blob/master/LICENSE - true - Trill is a high-performance one-pass in-memory streaming analytics engine - © Microsoft Corporation. All rights reserved. - en-US - Streaming Temporal Data - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/Sources/Core/Microsoft.StreamProcessing/StreamProperties/StreamProperties.cs b/Sources/Core/Microsoft.StreamProcessing/StreamProperties/StreamProperties.cs index 2d077f0fa..431122db0 100644 --- a/Sources/Core/Microsoft.StreamProcessing/StreamProperties/StreamProperties.cs +++ b/Sources/Core/Microsoft.StreamProcessing/StreamProperties/StreamProperties.cs @@ -39,8 +39,8 @@ internal class PropertySetter : IPropertySetter { internal static StreamProperties Default - => new StreamProperties( - Config.ForceRowBasedExecution ? false : true, + => new( + !Config.ForceRowBasedExecution, false, null, false, null, null, false, false, @@ -49,8 +49,8 @@ internal static StreamProperties Default EqualityComparerExpression.Default, null, null, - new Dictionary(), - new Dictionary(), + [], + [], null); internal static StreamProperties DefaultIngress(LambdaExpression startEdgeSelector, LambdaExpression endEdgeSelector) @@ -79,8 +79,8 @@ internal static StreamProperties DefaultIngress(LambdaExpression EqualityComparerExpression.Default, null, null, - new Dictionary(), - new Dictionary(), + [], + [], null); } @@ -262,7 +262,7 @@ internal StreamProperties(StreamProperties that) internal StreamProperties ToDecrementable() { - var result = Clone(); + var result = this.Clone(); result.IsConstantDuration = false; result.ConstantDurationLength = null; return result; @@ -270,28 +270,28 @@ internal StreamProperties ToDecrementable() internal StreamProperties ToColumnar() { - var result = Clone(); + var result = this.Clone(); result.IsColumnar = true; return result; } internal StreamProperties ToDelayedColumnar(Func predicate) { - var result = CloneDelayed(); + var result = this.CloneDelayed(); result.predicate = predicate; return result; } internal StreamProperties ToRowBased() { - var result = Clone(); + var result = this.Clone(); result.IsColumnar = false; return result; } internal StreamProperties ToConstantDuration(bool value, long? durationLength = null) { - var result = Clone(); + var result = this.Clone(); result.IsConstantDuration = value; result.ConstantDurationLength = durationLength; result.IsIntervalFree = false; @@ -301,14 +301,14 @@ internal StreamProperties ToConstantDuration(bool value, long? d internal StreamProperties SetQueryContainer(QueryContainer container) { - var result = Clone(); + var result = this.Clone(); result.QueryContainer = container; return result; } internal StreamProperties ToConstantHop(bool value, long? hopLength = null, long? hopOffset = null) { - var result = Clone(); + var result = this.Clone(); result.IsConstantHop = value; result.ConstantHopLength = hopLength; result.ConstantHopOffset = hopOffset; @@ -319,14 +319,14 @@ internal StreamProperties ToConstantHop(bool value, long? hopLen internal StreamProperties ToIntervalFree(bool value) { - var result = Clone(); + var result = this.Clone(); result.IsIntervalFree = value; return result; } internal StreamProperties ToSyncTimeSimultaneityFree(bool value) { - var result = Clone(); + var result = this.Clone(); result.IsSyncTimeSimultaneityFree = value; if (!value) result.IsEventOverlappingFree = false; return result; @@ -334,7 +334,7 @@ internal StreamProperties ToSyncTimeSimultaneityFree(bool value) internal StreamProperties ToEventOverlappingFree(bool value) { - var result = Clone(); + var result = this.Clone(); result.IsEventOverlappingFree = value; if (value) result.IsSyncTimeSimultaneityFree = true; return result; @@ -342,35 +342,35 @@ internal StreamProperties ToEventOverlappingFree(bool value) internal StreamProperties ToMulticore(bool value) { - var result = Clone(); + var result = this.Clone(); result.IsMulticore = value; return result; } internal StreamProperties ToPayloadEqualityComparer(IEqualityComparerExpression comparer) { - var result = Clone(); + var result = this.Clone(); result.PayloadEqualityComparer = comparer; return result; } internal StreamProperties ToPayloadComparer(IComparerExpression comparer) { - var result = Clone(); + var result = this.Clone(); result.PayloadComparer = comparer; return result; } internal StreamProperties ToKeyEqualityComparer(IEqualityComparerExpression comparer) { - var result = Clone(); + var result = this.Clone(); result.KeyEqualityComparer = comparer; return result; } internal StreamProperties ToEqualityComparer(Expression> streamSelector, IEqualityComparerExpression comparer) { - var result = Clone(); + var result = this.Clone(); result.EqualityComparerSelectorMap.Add(streamSelector, comparer); return result; } @@ -380,11 +380,11 @@ internal StreamProperties ToSnapshotSorted(bool isSnapshotSorted if (isSnapshotSorted) { Expression> sortFieldSelector = (e => e); - return ToSnapshotSorted(isSnapshotSorted, sortFieldSelector, packingScheme); + return this.ToSnapshotSorted(isSnapshotSorted, sortFieldSelector, packingScheme); } else { - var result = Clone(); + var result = this.Clone(); result.IsSnapshotSorted = false; result.PayloadComparer = null; result.KeyComparer = null; @@ -397,9 +397,9 @@ internal StreamProperties ToSnapshotSorted( bool isSnapshotSorted, Expression> sortFieldsSelector, Guid? packingScheme) { Contract.Requires(isSnapshotSorted == true); - Contract.Requires(sortFieldsSelector != null); + ArgumentNullException.ThrowIfNull(sortFieldsSelector); - var result = Clone(); + var result = this.Clone(); result.IsSnapshotSorted = isSnapshotSorted; // Remove pre-existing selector to replace with new version @@ -432,18 +432,18 @@ internal StreamProperties Derive rightProperties, Func, IStreamable, IStreamable> selector) { - Contract.Requires(selector != null); + ArgumentNullException.ThrowIfNull(selector); return selector(new NullStreamable(this), new NullStreamable(rightProperties)).Properties; } internal IEqualityComparerExpression FindEqualityComparer(Expression> keySelector) { - foreach (var kvp in this.EqualityComparerSelectorMap) + foreach ((Expression key, object value) in this.EqualityComparerSelectorMap) { - if (kvp.Key.ExpressionEquals(keySelector)) + if (key.ExpressionEquals(keySelector)) { - return kvp.Value as IEqualityComparerExpression; + return value as IEqualityComparerExpression; } } return null; @@ -451,9 +451,9 @@ internal IEqualityComparerExpression FindEqualityComparer(Expression internal IComparerExpression FindComparer(Expression> keySelector) { - foreach (var kvp in this.SortSelectorMap) + foreach (Expression key in this.SortSelectorMap.Keys) { - if (kvp.Key.ExpressionEquals(keySelector)) + if (key.ExpressionEquals(keySelector)) { return ComparerExpression.Default; } @@ -464,11 +464,11 @@ internal IComparerExpression FindComparer(Expression> k internal IComparerExpression GetSprayComparerExpression(Expression> keySelector) { - foreach (var kvp in this.SortSelectorMap) + foreach (Expression key in this.SortSelectorMap.Keys) { - if (kvp.Key.ExpressionEquals(keySelector)) + if (key.ExpressionEquals(keySelector)) { - var packSelector = kvp.Key as Expression>; + var packSelector = key as Expression>; return new ComparerExpression (Utility.CreateCompoundComparer(packSelector, ComparerExpression.Default.GetCompareExpr())); } @@ -479,9 +479,9 @@ internal IComparerExpression GetSprayComparerExpression(Expres internal bool CanSpray(Expression> keySelector) { - foreach (var kvp in this.SortSelectorMap) + foreach ((Expression key, Guid? value) in this.SortSelectorMap) { - if (kvp.Key.ExpressionEquals(keySelector) && (kvp.Value.HasValue)) + if (key.ExpressionEquals(keySelector) && value.HasValue) { return true; } @@ -513,15 +513,13 @@ internal bool CanSpray(StreamProperties internal StreamProperties Clone() - => new StreamProperties - (this.IsColumnar, this.IsConstantDuration, this.ConstantDurationLength, this.IsConstantHop, this.ConstantHopLength, this.ConstantHopOffset, this.IsIntervalFree, this.IsSyncTimeSimultaneityFree, this.IsSnapshotSorted, this.IsEventOverlappingFree, this.KeyEqualityComparer, this.PayloadEqualityComparer, this.KeyComparer, this.PayloadComparer, this.EqualityComparerSelectorMap.Clone(), this.SortSelectorMap.Clone(), this.QueryContainer); + => new (this.IsColumnar, this.IsConstantDuration, this.ConstantDurationLength, this.IsConstantHop, this.ConstantHopLength, this.ConstantHopOffset, this.IsIntervalFree, this.IsSyncTimeSimultaneityFree, this.IsSnapshotSorted, this.IsEventOverlappingFree, this.KeyEqualityComparer, this.PayloadEqualityComparer, this.KeyComparer, this.PayloadComparer, this.EqualityComparerSelectorMap.Clone(), this.SortSelectorMap.Clone(), this.QueryContainer); /// /// Clone /// internal StreamProperties CloneDelayed() - => new StreamProperties - (this.isColumnar, this.IsConstantDuration, this.ConstantDurationLength, this.IsConstantHop, this.ConstantHopLength, this.ConstantHopOffset, this.IsIntervalFree, this.IsSyncTimeSimultaneityFree, this.IsSnapshotSorted, this.IsEventOverlappingFree, this.KeyEqualityComparer, this.PayloadEqualityComparer, this.KeyComparer, this.PayloadComparer, this.EqualityComparerSelectorMap.Clone(), this.SortSelectorMap.Clone(), this.QueryContainer); + => new (this.isColumnar, this.IsConstantDuration, this.ConstantDurationLength, this.IsConstantHop, this.ConstantHopLength, this.ConstantHopOffset, this.IsIntervalFree, this.IsSyncTimeSimultaneityFree, this.IsSnapshotSorted, this.IsEventOverlappingFree, this.KeyEqualityComparer, this.PayloadEqualityComparer, this.KeyComparer, this.PayloadComparer, this.EqualityComparerSelectorMap.Clone(), this.SortSelectorMap.Clone(), this.QueryContainer); /// /// Clone @@ -529,8 +527,7 @@ internal StreamProperties CloneDelayed() internal StreamProperties CloneToNewKeyType( IEqualityComparerExpression newKeyEqualityComparer, IComparerExpression newKeyComparer) - => new StreamProperties - (this.IsColumnar, this.IsConstantDuration, this.ConstantDurationLength, this.IsConstantHop, this.ConstantHopLength, this.ConstantHopOffset, this.IsIntervalFree, this.IsSyncTimeSimultaneityFree, this.IsSnapshotSorted, this.IsEventOverlappingFree, + => new (this.IsColumnar, this.IsConstantDuration, this.ConstantDurationLength, this.IsConstantHop, this.ConstantHopLength, this.ConstantHopOffset, this.IsIntervalFree, this.IsSyncTimeSimultaneityFree, this.IsSnapshotSorted, this.IsEventOverlappingFree, newKeyEqualityComparer, this.PayloadEqualityComparer, newKeyComparer, this.PayloadComparer, this.EqualityComparerSelectorMap.Clone(), this.SortSelectorMap.Clone(), this.QueryContainer); @@ -540,8 +537,7 @@ internal StreamProperties CloneToNewKeyType( internal StreamProperties CloneToNewPayloadType( IEqualityComparerExpression newPayloadEqualityComparer, IComparerExpression newPayloadComparer) - => new StreamProperties - (this.IsColumnar, this.IsConstantDuration, this.ConstantDurationLength, this.IsConstantHop, this.ConstantHopLength, this.ConstantHopOffset, this.IsIntervalFree, this.IsSyncTimeSimultaneityFree, this.IsSnapshotSorted, this.IsEventOverlappingFree, this.KeyEqualityComparer, + => new (this.IsColumnar, this.IsConstantDuration, this.ConstantDurationLength, this.IsConstantHop, this.ConstantHopLength, this.ConstantHopOffset, this.IsIntervalFree, this.IsSyncTimeSimultaneityFree, this.IsSnapshotSorted, this.IsEventOverlappingFree, this.KeyEqualityComparer, newPayloadEqualityComparer, this.KeyComparer, newPayloadComparer, this.EqualityComparerSelectorMap.Clone(), this.SortSelectorMap.Clone(), this.QueryContainer); @@ -605,8 +601,8 @@ internal StreamProperties SelectMany(LambdaExpression se this.IsIntervalFree, false, this.IsSnapshotSorted, false, this.KeyEqualityComparer, EqualityComparerExpression.Default, this.KeyComparer, newPayloadComparer, - new Dictionary(), - new Dictionary(), + [], + [], this.QueryContainer); } @@ -627,10 +623,10 @@ internal StreamProperties, TPayload> Partition internal StreamProperties Group(Expression> keySelector) { - var innerEqualityComparer = FindEqualityComparer(keySelector); + var innerEqualityComparer = this.FindEqualityComparer(keySelector); if (innerEqualityComparer == null) innerEqualityComparer = EqualityComparerExpression.Default; - var innerKeyComparer = FindComparer(keySelector); + var innerKeyComparer = this.FindComparer(keySelector); return new StreamProperties(this.IsColumnar, this.IsConstantDuration, this.ConstantDurationLength, this.IsConstantHop, this.ConstantHopLength, this.ConstantHopOffset, this.IsIntervalFree, this.IsSyncTimeSimultaneityFree, this.IsSnapshotSorted, this.IsEventOverlappingFree, innerEqualityComparer, this.PayloadEqualityComparer, innerKeyComparer, this.PayloadComparer, this.EqualityComparerSelectorMap.Clone(), this.SortSelectorMap.Clone(), this.QueryContainer); @@ -642,7 +638,7 @@ internal StreamProperties Group(Expression, TPayload> GroupNested (Expression> keySelector) { - var innerEqualityComparer = FindEqualityComparer(keySelector); + var innerEqualityComparer = this.FindEqualityComparer(keySelector); var newKeyEqualityComparer = new CompoundGroupKeyEqualityComparer(this.KeyEqualityComparer, innerEqualityComparer); @@ -650,7 +646,7 @@ internal StreamProperties, TPayload> GroupNest IComparerExpression> newKeyComparer = null; if ((this.KeyComparer != null) || (typeof(TKey) == typeof(Empty))) { - var innerKeyComparer = FindComparer(keySelector); + var innerKeyComparer = this.FindComparer(keySelector); if (innerKeyComparer != null) { newKeyComparer = new CompoundGroupKeyComparer(this.KeyComparer, innerKeyComparer); @@ -659,9 +655,9 @@ internal StreamProperties, TPayload> GroupNest return new StreamProperties, TPayload>( this.IsColumnar - && (typeof(TInnerKey).GetTypeInfo().IsVisible || typeof(TInnerKey).IsAnonymousTypeName()) - && (typeof(TPayload).GetTypeInfo().IsVisible || typeof(TPayload).IsAnonymousTypeName()) - && (typeof(TKey).GetTypeInfo().IsVisible || typeof(TKey).IsAnonymousTypeName()), this.IsConstantDuration, this.ConstantDurationLength, this.IsConstantHop, this.ConstantHopLength, this.ConstantHopOffset, this.IsIntervalFree, this.IsSyncTimeSimultaneityFree, this.IsSnapshotSorted, this.IsEventOverlappingFree, + && (typeof(TInnerKey).IsVisible || typeof(TInnerKey).IsAnonymousTypeName()) + && (typeof(TPayload).IsVisible || typeof(TPayload).IsAnonymousTypeName()) + && (typeof(TKey).IsVisible || typeof(TKey).IsAnonymousTypeName()), this.IsConstantDuration, this.ConstantDurationLength, this.IsConstantHop, this.ConstantHopLength, this.ConstantHopOffset, this.IsIntervalFree, this.IsSyncTimeSimultaneityFree, this.IsSnapshotSorted, this.IsEventOverlappingFree, newKeyEqualityComparer, this.PayloadEqualityComparer, newKeyComparer, this.PayloadComparer, this.EqualityComparerSelectorMap.Clone(), this.SortSelectorMap.Clone(), this.QueryContainer); } @@ -670,7 +666,7 @@ internal StreamProperties, TPayload> GroupNest /// internal StreamProperties Union(StreamProperties right) { - var result = Clone(); + var result = this.Clone(); // find intersection foreach (var kvp1 in this.EqualityComparerSelectorMap) @@ -718,7 +714,7 @@ internal StreamProperties Union(StreamProperties result.IsSnapshotSorted = false; result.KeyComparer = null; result.PayloadComparer = null; - result.SortSelectorMap = new Dictionary(); + result.SortSelectorMap = []; // Union can be columnar only if both are result.IsColumnar = this.IsColumnar && right.IsColumnar; @@ -774,8 +770,8 @@ internal StreamProperties Join EqualityComparerExpression.Default, newKeyComparer, null, - new Dictionary(), - new Dictionary(), this.QueryContainer); + [], + [], this.QueryContainer); } /// @@ -809,7 +805,7 @@ internal StreamProperties LASJ(StreamProperties /// Clip /// - internal StreamProperties Clip(StreamProperties right) => LASJ(right.ToDecrementable().ToSnapshotSorted(false)); + internal StreamProperties Clip(StreamProperties right) => this.LASJ(right.ToDecrementable().ToSnapshotSorted(false)); /// /// AlterLifetime @@ -820,9 +816,9 @@ internal StreamProperties AlterLifetime(LambdaExpression duratio if (durationExpression == null) return this; if (durationExpression.Body is ConstantExpression constant) - return ToConstantDuration(true, (long)(constant.Value)); + return this.ToConstantDuration(true, (long)(constant.Value)); - return ToDecrementable().ToSnapshotSorted(false); + return this.ToDecrementable().ToSnapshotSorted(false); } internal StreamProperties Snapshot @@ -867,7 +863,7 @@ internal StreamProperties Snapshot internal StreamProperties PointAtEnd() { - var temp = ToConstantDuration(true, 1); + var temp = this.ToConstantDuration(true, 1); return temp; } } @@ -907,11 +903,11 @@ internal sealed class VerifyPropertiesPipe : UnaryPipe lastSyncTimeForSimultaneous = new Dictionary(); + private readonly Dictionary lastSyncTimeForSimultaneous = []; [DataMember] private long lastSeenTimestamp = StreamEvent.MinSyncTime; [DataMember] - private readonly Dictionary lastSeenTimestampPartitioned = new Dictionary(); + private readonly Dictionary lastSeenTimestampPartitioned = []; [Obsolete("Used only by serialization. Do not call directly.")] public VerifyPropertiesPipe() { } @@ -921,13 +917,13 @@ public VerifyPropertiesPipe(StreamProperties properties, IStream { if (properties.IsConstantDuration) { - this.ConstantDurationValidator = ConstantDurationValidation; + this.ConstantDurationValidator = this.ConstantDurationValidation; this.constantDuration = properties.ConstantDurationLength; } if (properties.IsConstantHop) { - this.ConstantHopValidator = ConstantHopValidation; + this.ConstantHopValidator = this.ConstantHopValidation; this.constantHopLength = properties.ConstantHopLength; this.constantHopOffset = properties.ConstantHopOffset; } @@ -938,17 +934,17 @@ public VerifyPropertiesPipe(StreamProperties properties, IStream } if (properties.IsSyncTimeSimultaneityFree) { - this.SyncTimeSimultaneityFreeValidator = SyncTimeSimulteneityFreeValidation; + this.SyncTimeSimultaneityFreeValidator = this.SyncTimeSimulteneityFreeValidation; } if (typeof(TKey).GetPartitionType() != null) { - this.SyncTimeValidator = PartitionedValidation; + this.SyncTimeValidator = this.PartitionedValidation; this.getPartitionKey = GetPartitionExtractor(); } else { - this.SyncTimeValidator = SimpleValidation; + this.SyncTimeValidator = this.SimpleValidation; } } diff --git a/Sources/Core/Microsoft.StreamProcessing/StreamProperties/StreamPropertiesExtensions.cs b/Sources/Core/Microsoft.StreamProcessing/StreamProperties/StreamPropertiesExtensions.cs index 1ce4616b4..6e4f6f26c 100644 --- a/Sources/Core/Microsoft.StreamProcessing/StreamProperties/StreamPropertiesExtensions.cs +++ b/Sources/Core/Microsoft.StreamProcessing/StreamProperties/StreamPropertiesExtensions.cs @@ -38,8 +38,8 @@ internal static StreamProperties Ungroup.Default, newKeyComparer, null, - new Dictionary(), - new Dictionary(), + [], + [], source.QueryContainer); } @@ -59,8 +59,8 @@ internal static StreamProperties Ungroup.Default, null, null, - new Dictionary(), - new Dictionary(), + [], + [], source.QueryContainer); } diff --git a/Sources/Core/Microsoft.StreamProcessing/StreamableAPI/AfaExtensions.cs b/Sources/Core/Microsoft.StreamProcessing/StreamableAPI/AfaExtensions.cs index 8f6ec1064..e03732f49 100644 --- a/Sources/Core/Microsoft.StreamProcessing/StreamableAPI/AfaExtensions.cs +++ b/Sources/Core/Microsoft.StreamProcessing/StreamableAPI/AfaExtensions.cs @@ -5,6 +5,7 @@ using System; using System.Collections.Generic; using System.Linq.Expressions; +using System.Reflection; namespace Microsoft.StreamProcessing { @@ -32,7 +33,7 @@ public static IStreamable Detect source, Afa afa, long maxDuration = 0, bool allowOverlappingInstances = true, bool isDeterministic = false) { - Invariant.IsNotNull(source, nameof(source)); + ArgumentNullException.ThrowIfNull(source); if (maxDuration == 0) { @@ -64,7 +65,7 @@ public static IStreamable Detect( Func, IPattern> pattern, long maxDuration = 0, bool allowOverlappingInstances = true, bool isDeterministic = false) { - Invariant.IsNotNull(source, nameof(source)); + ArgumentNullException.ThrowIfNull(source); if (maxDuration == 0) { @@ -100,7 +101,7 @@ public static IStreamable Detect( Func, IPattern> pattern, long maxDuration = 0, bool allowOverlappingInstances = true, bool isDeterministic = false) { - Invariant.IsNotNull(source, nameof(source)); + ArgumentNullException.ThrowIfNull(source); if (maxDuration == 0) { @@ -139,7 +140,7 @@ public static IStreamable Detect, IPattern> pattern, long maxDuration = 0, bool allowOverlappingInstances = true, bool isDeterministic = false) { - Invariant.IsNotNull(source, nameof(source)); + ArgumentNullException.ThrowIfNull(source); if (maxDuration == 0) { @@ -278,39 +279,37 @@ public static IPattern AllElement CreateMultiElementFunctions(IAbstractPatternRoot source, Expression> accumulatorInitialization, Expression> accumulatorboolField, Expression> fence, bool initialValueForBooleanField, Expression> shortCircuitCondition) { - if (!(accumulatorboolField.Body is MemberExpression memberExpression)) throw new InvalidOperationException("accumulatorboolField must be a lambda that picks out one field from its parameter"); - if (!(memberExpression.Expression is ParameterExpression parameter)) throw new InvalidOperationException("accumulatorboolField must be a lambda that picks out one field from its parameter"); + if (accumulatorboolField.Body is not MemberExpression memberExpression) throw new InvalidOperationException("accumulatorboolField must be a lambda that picks out one field from its parameter"); + if (memberExpression.Expression is not ParameterExpression parameter) throw new InvalidOperationException("accumulatorboolField must be a lambda that picks out one field from its parameter"); var memberInfo = memberExpression.Member; - if (memberInfo is System.Reflection.PropertyInfo propertyInfo && !propertyInfo.CanWrite) throw new InvalidOperationException("accumulatorboolField is specifying a property, " + propertyInfo.Name + "' that does not have a setter"); + if (memberInfo is PropertyInfo propertyInfo && !propertyInfo.CanWrite) throw new InvalidOperationException("accumulatorboolField is specifying a property, " + propertyInfo.Name + "' that does not have a setter"); // "f" is the field specified by the accumulatorboolField lambda. // Create the Initialize function as (ts, reg) => { var acc = accumulatorInitialization(); acc.f = initialValueForBooleanField; return acc; } Expression> initializeTemplate = (ts, reg) => CallInliner.Call(accumulatorInitialization); var userInitializeFunction = initializeTemplate.InlineCalls(); var accumulatorLocalForInitialize = Expression.Parameter(typeof(TAccumulator), "acc"); - var initializeBody = new List() - { - Expression.Assign(accumulatorLocalForInitialize, userInitializeFunction.Body), - Expression.Assign(Expression.MakeMemberAccess(accumulatorLocalForInitialize, memberInfo), Expression.Constant(initialValueForBooleanField, typeof(bool))), - accumulatorLocalForInitialize - }; var initializeFunction = (Expression>)Expression.Lambda( - Expression.Block(new[] { accumulatorLocalForInitialize }, initializeBody), - Expression.Parameter(typeof(long), "ts"), Expression.Parameter(typeof(TRegister), "reg")); + Expression.Block([accumulatorLocalForInitialize], [ + Expression.Assign(accumulatorLocalForInitialize, userInitializeFunction.Body), + Expression.Assign(Expression.MakeMemberAccess(accumulatorLocalForInitialize, memberInfo), Expression.Constant(initialValueForBooleanField, typeof(bool))), + accumulatorLocalForInitialize + ]), + Expression.Parameter(typeof(long), "ts"), + Expression.Parameter(typeof(TRegister), "reg") + ); // Create the Accumulate function as (ts, ev, reg, acc) => { acc.f = fence(ts, ev, reg); return acc; } Expression> userAccumulatorFunctionTemplate = (ts, ev, reg, acc) => CallInliner.Call(fence, ts, ev, reg); var userAccumulatorFunction = userAccumulatorFunctionTemplate.InlineCalls(); var accParmeter = userAccumulatorFunction.Parameters[3]; var accumulateBody = new List() { Expression.Assign(Expression.MakeMemberAccess(accParmeter, memberInfo), userAccumulatorFunction.Body), accParmeter, }; - var parameters = new ParameterExpression[] - { + var accumulateFunction = (Expression>)Expression.Lambda(Expression.Block(accumulateBody), [ userAccumulatorFunction.Parameters[0], userAccumulatorFunction.Parameters[1], userAccumulatorFunction.Parameters[2], - accParmeter, - }; - var accumulateFunction = (Expression>)Expression.Lambda(Expression.Block(accumulateBody), parameters); + accParmeter + ]); // Create the SkipToEnd function as (ts, ev, acc) => acc.f Expression> skipToEndTemplate = (ts, ev, acc) => CallInliner.Call(shortCircuitCondition, CallInliner.Call(accumulatorboolField, acc)); diff --git a/Sources/Core/Microsoft.StreamProcessing/StreamableAPI/GroupAggregateTemplate.cs b/Sources/Core/Microsoft.StreamProcessing/StreamableAPI/GroupAggregateTemplate.cs index ee97396d8..d903229ed 100644 --- a/Sources/Core/Microsoft.StreamProcessing/StreamableAPI/GroupAggregateTemplate.cs +++ b/Sources/Core/Microsoft.StreamProcessing/StreamableAPI/GroupAggregateTemplate.cs @@ -32,10 +32,10 @@ public static IStreamable GroupAggregate, TInput>, IAggregate> aggregate1, Expression, TOutput1, TOutput>> merger) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(keySelector, nameof(keySelector)); - Invariant.IsNotNull(aggregate1, nameof(aggregate1)); - Invariant.IsNotNull(merger, nameof(merger)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(keySelector); + ArgumentNullException.ThrowIfNull(aggregate1); + ArgumentNullException.ThrowIfNull(merger); if (typeof(TOuterKey) == typeof(Empty) && source.Properties.IsStartEdgeOnly && Config.MapArity == 1) { @@ -70,10 +70,10 @@ internal static IStreamable GroupAggregate aggregate1, Expression, TOutput1, TOutput>> merger) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(keySelector, nameof(keySelector)); - Invariant.IsNotNull(aggregate1, nameof(aggregate1)); - Invariant.IsNotNull(merger, nameof(merger)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(keySelector); + ArgumentNullException.ThrowIfNull(aggregate1); + ArgumentNullException.ThrowIfNull(merger); return source.Map(keySelector).Reduce(s => s.Aggregate(aggregate1), merger); } @@ -102,11 +102,11 @@ public static IStreamable GroupAggregate, TInput>, IAggregate> aggregate2, Expression, TOutput1, TOutput2, TOutput>> merger) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(keySelector, nameof(keySelector)); - Invariant.IsNotNull(aggregate1, nameof(aggregate1)); - Invariant.IsNotNull(aggregate2, nameof(aggregate2)); - Invariant.IsNotNull(merger, nameof(merger)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(keySelector); + ArgumentNullException.ThrowIfNull(aggregate1); + ArgumentNullException.ThrowIfNull(aggregate2); + ArgumentNullException.ThrowIfNull(merger); Expression>> aggregateMerger = (output1, output2) => new StructTuple @@ -163,11 +163,11 @@ internal static IStreamable GroupAggregate aggregate2, Expression, TOutput1, TOutput2, TOutput>> merger) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(keySelector, nameof(keySelector)); - Invariant.IsNotNull(aggregate1, nameof(aggregate1)); - Invariant.IsNotNull(aggregate2, nameof(aggregate2)); - Invariant.IsNotNull(merger, nameof(merger)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(keySelector); + ArgumentNullException.ThrowIfNull(aggregate1); + ArgumentNullException.ThrowIfNull(aggregate2); + ArgumentNullException.ThrowIfNull(merger); Expression>> aggregateMerger = (output1, output2) => new StructTuple @@ -212,12 +212,12 @@ public static IStreamable GroupAggregate, TInput>, IAggregate> aggregate3, Expression, TOutput1, TOutput2, TOutput3, TOutput>> merger) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(keySelector, nameof(keySelector)); - Invariant.IsNotNull(aggregate1, nameof(aggregate1)); - Invariant.IsNotNull(aggregate2, nameof(aggregate2)); - Invariant.IsNotNull(aggregate3, nameof(aggregate3)); - Invariant.IsNotNull(merger, nameof(merger)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(keySelector); + ArgumentNullException.ThrowIfNull(aggregate1); + ArgumentNullException.ThrowIfNull(aggregate2); + ArgumentNullException.ThrowIfNull(aggregate3); + ArgumentNullException.ThrowIfNull(merger); Expression>> aggregateMerger = (output1, output2, output3) => new StructTuple @@ -281,12 +281,12 @@ internal static IStreamable GroupAggregate aggregate3, Expression, TOutput1, TOutput2, TOutput3, TOutput>> merger) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(keySelector, nameof(keySelector)); - Invariant.IsNotNull(aggregate1, nameof(aggregate1)); - Invariant.IsNotNull(aggregate2, nameof(aggregate2)); - Invariant.IsNotNull(aggregate3, nameof(aggregate3)); - Invariant.IsNotNull(merger, nameof(merger)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(keySelector); + ArgumentNullException.ThrowIfNull(aggregate1); + ArgumentNullException.ThrowIfNull(aggregate2); + ArgumentNullException.ThrowIfNull(aggregate3); + ArgumentNullException.ThrowIfNull(merger); Expression>> aggregateMerger = (output1, output2, output3) => new StructTuple @@ -336,13 +336,13 @@ public static IStreamable GroupAggregate, TInput>, IAggregate> aggregate4, Expression, TOutput1, TOutput2, TOutput3, TOutput4, TOutput>> merger) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(keySelector, nameof(keySelector)); - Invariant.IsNotNull(aggregate1, nameof(aggregate1)); - Invariant.IsNotNull(aggregate2, nameof(aggregate2)); - Invariant.IsNotNull(aggregate3, nameof(aggregate3)); - Invariant.IsNotNull(aggregate4, nameof(aggregate4)); - Invariant.IsNotNull(merger, nameof(merger)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(keySelector); + ArgumentNullException.ThrowIfNull(aggregate1); + ArgumentNullException.ThrowIfNull(aggregate2); + ArgumentNullException.ThrowIfNull(aggregate3); + ArgumentNullException.ThrowIfNull(aggregate4); + ArgumentNullException.ThrowIfNull(merger); Expression>> aggregateMerger = (output1, output2, output3, output4) => new StructTuple @@ -413,13 +413,13 @@ internal static IStreamable GroupAggregate aggregate4, Expression, TOutput1, TOutput2, TOutput3, TOutput4, TOutput>> merger) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(keySelector, nameof(keySelector)); - Invariant.IsNotNull(aggregate1, nameof(aggregate1)); - Invariant.IsNotNull(aggregate2, nameof(aggregate2)); - Invariant.IsNotNull(aggregate3, nameof(aggregate3)); - Invariant.IsNotNull(aggregate4, nameof(aggregate4)); - Invariant.IsNotNull(merger, nameof(merger)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(keySelector); + ArgumentNullException.ThrowIfNull(aggregate1); + ArgumentNullException.ThrowIfNull(aggregate2); + ArgumentNullException.ThrowIfNull(aggregate3); + ArgumentNullException.ThrowIfNull(aggregate4); + ArgumentNullException.ThrowIfNull(merger); Expression>> aggregateMerger = (output1, output2, output3, output4) => new StructTuple @@ -474,14 +474,14 @@ public static IStreamable GroupAggregate, TInput>, IAggregate> aggregate5, Expression, TOutput1, TOutput2, TOutput3, TOutput4, TOutput5, TOutput>> merger) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(keySelector, nameof(keySelector)); - Invariant.IsNotNull(aggregate1, nameof(aggregate1)); - Invariant.IsNotNull(aggregate2, nameof(aggregate2)); - Invariant.IsNotNull(aggregate3, nameof(aggregate3)); - Invariant.IsNotNull(aggregate4, nameof(aggregate4)); - Invariant.IsNotNull(aggregate5, nameof(aggregate5)); - Invariant.IsNotNull(merger, nameof(merger)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(keySelector); + ArgumentNullException.ThrowIfNull(aggregate1); + ArgumentNullException.ThrowIfNull(aggregate2); + ArgumentNullException.ThrowIfNull(aggregate3); + ArgumentNullException.ThrowIfNull(aggregate4); + ArgumentNullException.ThrowIfNull(aggregate5); + ArgumentNullException.ThrowIfNull(merger); Expression>> aggregateMerger = (output1, output2, output3, output4, output5) => new StructTuple @@ -559,14 +559,14 @@ internal static IStreamable GroupAggregate aggregate5, Expression, TOutput1, TOutput2, TOutput3, TOutput4, TOutput5, TOutput>> merger) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(keySelector, nameof(keySelector)); - Invariant.IsNotNull(aggregate1, nameof(aggregate1)); - Invariant.IsNotNull(aggregate2, nameof(aggregate2)); - Invariant.IsNotNull(aggregate3, nameof(aggregate3)); - Invariant.IsNotNull(aggregate4, nameof(aggregate4)); - Invariant.IsNotNull(aggregate5, nameof(aggregate5)); - Invariant.IsNotNull(merger, nameof(merger)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(keySelector); + ArgumentNullException.ThrowIfNull(aggregate1); + ArgumentNullException.ThrowIfNull(aggregate2); + ArgumentNullException.ThrowIfNull(aggregate3); + ArgumentNullException.ThrowIfNull(aggregate4); + ArgumentNullException.ThrowIfNull(aggregate5); + ArgumentNullException.ThrowIfNull(merger); Expression>> aggregateMerger = (output1, output2, output3, output4, output5) => new StructTuple @@ -626,15 +626,15 @@ public static IStreamable GroupAggregate, TInput>, IAggregate> aggregate6, Expression, TOutput1, TOutput2, TOutput3, TOutput4, TOutput5, TOutput6, TOutput>> merger) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(keySelector, nameof(keySelector)); - Invariant.IsNotNull(aggregate1, nameof(aggregate1)); - Invariant.IsNotNull(aggregate2, nameof(aggregate2)); - Invariant.IsNotNull(aggregate3, nameof(aggregate3)); - Invariant.IsNotNull(aggregate4, nameof(aggregate4)); - Invariant.IsNotNull(aggregate5, nameof(aggregate5)); - Invariant.IsNotNull(aggregate6, nameof(aggregate6)); - Invariant.IsNotNull(merger, nameof(merger)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(keySelector); + ArgumentNullException.ThrowIfNull(aggregate1); + ArgumentNullException.ThrowIfNull(aggregate2); + ArgumentNullException.ThrowIfNull(aggregate3); + ArgumentNullException.ThrowIfNull(aggregate4); + ArgumentNullException.ThrowIfNull(aggregate5); + ArgumentNullException.ThrowIfNull(aggregate6); + ArgumentNullException.ThrowIfNull(merger); Expression>> aggregateMerger = (output1, output2, output3, output4, output5, output6) => new StructTuple @@ -719,15 +719,15 @@ internal static IStreamable GroupAggregate aggregate6, Expression, TOutput1, TOutput2, TOutput3, TOutput4, TOutput5, TOutput6, TOutput>> merger) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(keySelector, nameof(keySelector)); - Invariant.IsNotNull(aggregate1, nameof(aggregate1)); - Invariant.IsNotNull(aggregate2, nameof(aggregate2)); - Invariant.IsNotNull(aggregate3, nameof(aggregate3)); - Invariant.IsNotNull(aggregate4, nameof(aggregate4)); - Invariant.IsNotNull(aggregate5, nameof(aggregate5)); - Invariant.IsNotNull(aggregate6, nameof(aggregate6)); - Invariant.IsNotNull(merger, nameof(merger)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(keySelector); + ArgumentNullException.ThrowIfNull(aggregate1); + ArgumentNullException.ThrowIfNull(aggregate2); + ArgumentNullException.ThrowIfNull(aggregate3); + ArgumentNullException.ThrowIfNull(aggregate4); + ArgumentNullException.ThrowIfNull(aggregate5); + ArgumentNullException.ThrowIfNull(aggregate6); + ArgumentNullException.ThrowIfNull(merger); Expression>> aggregateMerger = (output1, output2, output3, output4, output5, output6) => new StructTuple @@ -792,16 +792,16 @@ public static IStreamable GroupAggregate, TInput>, IAggregate> aggregate7, Expression, TOutput1, TOutput2, TOutput3, TOutput4, TOutput5, TOutput6, TOutput7, TOutput>> merger) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(keySelector, nameof(keySelector)); - Invariant.IsNotNull(aggregate1, nameof(aggregate1)); - Invariant.IsNotNull(aggregate2, nameof(aggregate2)); - Invariant.IsNotNull(aggregate3, nameof(aggregate3)); - Invariant.IsNotNull(aggregate4, nameof(aggregate4)); - Invariant.IsNotNull(aggregate5, nameof(aggregate5)); - Invariant.IsNotNull(aggregate6, nameof(aggregate6)); - Invariant.IsNotNull(aggregate7, nameof(aggregate7)); - Invariant.IsNotNull(merger, nameof(merger)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(keySelector); + ArgumentNullException.ThrowIfNull(aggregate1); + ArgumentNullException.ThrowIfNull(aggregate2); + ArgumentNullException.ThrowIfNull(aggregate3); + ArgumentNullException.ThrowIfNull(aggregate4); + ArgumentNullException.ThrowIfNull(aggregate5); + ArgumentNullException.ThrowIfNull(aggregate6); + ArgumentNullException.ThrowIfNull(aggregate7); + ArgumentNullException.ThrowIfNull(merger); Expression>> aggregateMerger = (output1, output2, output3, output4, output5, output6, output7) => new StructTuple @@ -893,16 +893,16 @@ internal static IStreamable GroupAggregate aggregate7, Expression, TOutput1, TOutput2, TOutput3, TOutput4, TOutput5, TOutput6, TOutput7, TOutput>> merger) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(keySelector, nameof(keySelector)); - Invariant.IsNotNull(aggregate1, nameof(aggregate1)); - Invariant.IsNotNull(aggregate2, nameof(aggregate2)); - Invariant.IsNotNull(aggregate3, nameof(aggregate3)); - Invariant.IsNotNull(aggregate4, nameof(aggregate4)); - Invariant.IsNotNull(aggregate5, nameof(aggregate5)); - Invariant.IsNotNull(aggregate6, nameof(aggregate6)); - Invariant.IsNotNull(aggregate7, nameof(aggregate7)); - Invariant.IsNotNull(merger, nameof(merger)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(keySelector); + ArgumentNullException.ThrowIfNull(aggregate1); + ArgumentNullException.ThrowIfNull(aggregate2); + ArgumentNullException.ThrowIfNull(aggregate3); + ArgumentNullException.ThrowIfNull(aggregate4); + ArgumentNullException.ThrowIfNull(aggregate5); + ArgumentNullException.ThrowIfNull(aggregate6); + ArgumentNullException.ThrowIfNull(aggregate7); + ArgumentNullException.ThrowIfNull(merger); Expression>> aggregateMerger = (output1, output2, output3, output4, output5, output6, output7) => new StructTuple @@ -972,17 +972,17 @@ public static IStreamable GroupAggregate, TInput>, IAggregate> aggregate8, Expression, TOutput1, TOutput2, TOutput3, TOutput4, TOutput5, TOutput6, TOutput7, TOutput8, TOutput>> merger) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(keySelector, nameof(keySelector)); - Invariant.IsNotNull(aggregate1, nameof(aggregate1)); - Invariant.IsNotNull(aggregate2, nameof(aggregate2)); - Invariant.IsNotNull(aggregate3, nameof(aggregate3)); - Invariant.IsNotNull(aggregate4, nameof(aggregate4)); - Invariant.IsNotNull(aggregate5, nameof(aggregate5)); - Invariant.IsNotNull(aggregate6, nameof(aggregate6)); - Invariant.IsNotNull(aggregate7, nameof(aggregate7)); - Invariant.IsNotNull(aggregate8, nameof(aggregate8)); - Invariant.IsNotNull(merger, nameof(merger)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(keySelector); + ArgumentNullException.ThrowIfNull(aggregate1); + ArgumentNullException.ThrowIfNull(aggregate2); + ArgumentNullException.ThrowIfNull(aggregate3); + ArgumentNullException.ThrowIfNull(aggregate4); + ArgumentNullException.ThrowIfNull(aggregate5); + ArgumentNullException.ThrowIfNull(aggregate6); + ArgumentNullException.ThrowIfNull(aggregate7); + ArgumentNullException.ThrowIfNull(aggregate8); + ArgumentNullException.ThrowIfNull(merger); Expression>> aggregateMerger = (output1, output2, output3, output4, output5, output6, output7, output8) => new StructTuple @@ -1081,17 +1081,17 @@ internal static IStreamable GroupAggregate aggregate8, Expression, TOutput1, TOutput2, TOutput3, TOutput4, TOutput5, TOutput6, TOutput7, TOutput8, TOutput>> merger) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(keySelector, nameof(keySelector)); - Invariant.IsNotNull(aggregate1, nameof(aggregate1)); - Invariant.IsNotNull(aggregate2, nameof(aggregate2)); - Invariant.IsNotNull(aggregate3, nameof(aggregate3)); - Invariant.IsNotNull(aggregate4, nameof(aggregate4)); - Invariant.IsNotNull(aggregate5, nameof(aggregate5)); - Invariant.IsNotNull(aggregate6, nameof(aggregate6)); - Invariant.IsNotNull(aggregate7, nameof(aggregate7)); - Invariant.IsNotNull(aggregate8, nameof(aggregate8)); - Invariant.IsNotNull(merger, nameof(merger)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(keySelector); + ArgumentNullException.ThrowIfNull(aggregate1); + ArgumentNullException.ThrowIfNull(aggregate2); + ArgumentNullException.ThrowIfNull(aggregate3); + ArgumentNullException.ThrowIfNull(aggregate4); + ArgumentNullException.ThrowIfNull(aggregate5); + ArgumentNullException.ThrowIfNull(aggregate6); + ArgumentNullException.ThrowIfNull(aggregate7); + ArgumentNullException.ThrowIfNull(aggregate8); + ArgumentNullException.ThrowIfNull(merger); Expression>> aggregateMerger = (output1, output2, output3, output4, output5, output6, output7, output8) => new StructTuple @@ -1166,18 +1166,18 @@ public static IStreamable GroupAggregate, TInput>, IAggregate> aggregate9, Expression, TOutput1, TOutput2, TOutput3, TOutput4, TOutput5, TOutput6, TOutput7, TOutput8, TOutput9, TOutput>> merger) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(keySelector, nameof(keySelector)); - Invariant.IsNotNull(aggregate1, nameof(aggregate1)); - Invariant.IsNotNull(aggregate2, nameof(aggregate2)); - Invariant.IsNotNull(aggregate3, nameof(aggregate3)); - Invariant.IsNotNull(aggregate4, nameof(aggregate4)); - Invariant.IsNotNull(aggregate5, nameof(aggregate5)); - Invariant.IsNotNull(aggregate6, nameof(aggregate6)); - Invariant.IsNotNull(aggregate7, nameof(aggregate7)); - Invariant.IsNotNull(aggregate8, nameof(aggregate8)); - Invariant.IsNotNull(aggregate9, nameof(aggregate9)); - Invariant.IsNotNull(merger, nameof(merger)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(keySelector); + ArgumentNullException.ThrowIfNull(aggregate1); + ArgumentNullException.ThrowIfNull(aggregate2); + ArgumentNullException.ThrowIfNull(aggregate3); + ArgumentNullException.ThrowIfNull(aggregate4); + ArgumentNullException.ThrowIfNull(aggregate5); + ArgumentNullException.ThrowIfNull(aggregate6); + ArgumentNullException.ThrowIfNull(aggregate7); + ArgumentNullException.ThrowIfNull(aggregate8); + ArgumentNullException.ThrowIfNull(aggregate9); + ArgumentNullException.ThrowIfNull(merger); Expression>> aggregateMerger = (output1, output2, output3, output4, output5, output6, output7, output8, output9) => new StructTuple @@ -1283,18 +1283,18 @@ internal static IStreamable GroupAggregate aggregate9, Expression, TOutput1, TOutput2, TOutput3, TOutput4, TOutput5, TOutput6, TOutput7, TOutput8, TOutput9, TOutput>> merger) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(keySelector, nameof(keySelector)); - Invariant.IsNotNull(aggregate1, nameof(aggregate1)); - Invariant.IsNotNull(aggregate2, nameof(aggregate2)); - Invariant.IsNotNull(aggregate3, nameof(aggregate3)); - Invariant.IsNotNull(aggregate4, nameof(aggregate4)); - Invariant.IsNotNull(aggregate5, nameof(aggregate5)); - Invariant.IsNotNull(aggregate6, nameof(aggregate6)); - Invariant.IsNotNull(aggregate7, nameof(aggregate7)); - Invariant.IsNotNull(aggregate8, nameof(aggregate8)); - Invariant.IsNotNull(aggregate9, nameof(aggregate9)); - Invariant.IsNotNull(merger, nameof(merger)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(keySelector); + ArgumentNullException.ThrowIfNull(aggregate1); + ArgumentNullException.ThrowIfNull(aggregate2); + ArgumentNullException.ThrowIfNull(aggregate3); + ArgumentNullException.ThrowIfNull(aggregate4); + ArgumentNullException.ThrowIfNull(aggregate5); + ArgumentNullException.ThrowIfNull(aggregate6); + ArgumentNullException.ThrowIfNull(aggregate7); + ArgumentNullException.ThrowIfNull(aggregate8); + ArgumentNullException.ThrowIfNull(aggregate9); + ArgumentNullException.ThrowIfNull(merger); Expression>> aggregateMerger = (output1, output2, output3, output4, output5, output6, output7, output8, output9) => new StructTuple @@ -1374,19 +1374,19 @@ public static IStreamable GroupAggregate, TInput>, IAggregate> aggregate10, Expression, TOutput1, TOutput2, TOutput3, TOutput4, TOutput5, TOutput6, TOutput7, TOutput8, TOutput9, TOutput10, TOutput>> merger) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(keySelector, nameof(keySelector)); - Invariant.IsNotNull(aggregate1, nameof(aggregate1)); - Invariant.IsNotNull(aggregate2, nameof(aggregate2)); - Invariant.IsNotNull(aggregate3, nameof(aggregate3)); - Invariant.IsNotNull(aggregate4, nameof(aggregate4)); - Invariant.IsNotNull(aggregate5, nameof(aggregate5)); - Invariant.IsNotNull(aggregate6, nameof(aggregate6)); - Invariant.IsNotNull(aggregate7, nameof(aggregate7)); - Invariant.IsNotNull(aggregate8, nameof(aggregate8)); - Invariant.IsNotNull(aggregate9, nameof(aggregate9)); - Invariant.IsNotNull(aggregate10, nameof(aggregate10)); - Invariant.IsNotNull(merger, nameof(merger)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(keySelector); + ArgumentNullException.ThrowIfNull(aggregate1); + ArgumentNullException.ThrowIfNull(aggregate2); + ArgumentNullException.ThrowIfNull(aggregate3); + ArgumentNullException.ThrowIfNull(aggregate4); + ArgumentNullException.ThrowIfNull(aggregate5); + ArgumentNullException.ThrowIfNull(aggregate6); + ArgumentNullException.ThrowIfNull(aggregate7); + ArgumentNullException.ThrowIfNull(aggregate8); + ArgumentNullException.ThrowIfNull(aggregate9); + ArgumentNullException.ThrowIfNull(aggregate10); + ArgumentNullException.ThrowIfNull(merger); Expression>> aggregateMerger = (output1, output2, output3, output4, output5, output6, output7, output8, output9, output10) => new StructTuple @@ -1499,19 +1499,19 @@ internal static IStreamable GroupAggregate aggregate10, Expression, TOutput1, TOutput2, TOutput3, TOutput4, TOutput5, TOutput6, TOutput7, TOutput8, TOutput9, TOutput10, TOutput>> merger) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(keySelector, nameof(keySelector)); - Invariant.IsNotNull(aggregate1, nameof(aggregate1)); - Invariant.IsNotNull(aggregate2, nameof(aggregate2)); - Invariant.IsNotNull(aggregate3, nameof(aggregate3)); - Invariant.IsNotNull(aggregate4, nameof(aggregate4)); - Invariant.IsNotNull(aggregate5, nameof(aggregate5)); - Invariant.IsNotNull(aggregate6, nameof(aggregate6)); - Invariant.IsNotNull(aggregate7, nameof(aggregate7)); - Invariant.IsNotNull(aggregate8, nameof(aggregate8)); - Invariant.IsNotNull(aggregate9, nameof(aggregate9)); - Invariant.IsNotNull(aggregate10, nameof(aggregate10)); - Invariant.IsNotNull(merger, nameof(merger)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(keySelector); + ArgumentNullException.ThrowIfNull(aggregate1); + ArgumentNullException.ThrowIfNull(aggregate2); + ArgumentNullException.ThrowIfNull(aggregate3); + ArgumentNullException.ThrowIfNull(aggregate4); + ArgumentNullException.ThrowIfNull(aggregate5); + ArgumentNullException.ThrowIfNull(aggregate6); + ArgumentNullException.ThrowIfNull(aggregate7); + ArgumentNullException.ThrowIfNull(aggregate8); + ArgumentNullException.ThrowIfNull(aggregate9); + ArgumentNullException.ThrowIfNull(aggregate10); + ArgumentNullException.ThrowIfNull(merger); Expression>> aggregateMerger = (output1, output2, output3, output4, output5, output6, output7, output8, output9, output10) => new StructTuple @@ -1596,20 +1596,20 @@ public static IStreamable GroupAggregate, TInput>, IAggregate> aggregate11, Expression, TOutput1, TOutput2, TOutput3, TOutput4, TOutput5, TOutput6, TOutput7, TOutput8, TOutput9, TOutput10, TOutput11, TOutput>> merger) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(keySelector, nameof(keySelector)); - Invariant.IsNotNull(aggregate1, nameof(aggregate1)); - Invariant.IsNotNull(aggregate2, nameof(aggregate2)); - Invariant.IsNotNull(aggregate3, nameof(aggregate3)); - Invariant.IsNotNull(aggregate4, nameof(aggregate4)); - Invariant.IsNotNull(aggregate5, nameof(aggregate5)); - Invariant.IsNotNull(aggregate6, nameof(aggregate6)); - Invariant.IsNotNull(aggregate7, nameof(aggregate7)); - Invariant.IsNotNull(aggregate8, nameof(aggregate8)); - Invariant.IsNotNull(aggregate9, nameof(aggregate9)); - Invariant.IsNotNull(aggregate10, nameof(aggregate10)); - Invariant.IsNotNull(aggregate11, nameof(aggregate11)); - Invariant.IsNotNull(merger, nameof(merger)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(keySelector); + ArgumentNullException.ThrowIfNull(aggregate1); + ArgumentNullException.ThrowIfNull(aggregate2); + ArgumentNullException.ThrowIfNull(aggregate3); + ArgumentNullException.ThrowIfNull(aggregate4); + ArgumentNullException.ThrowIfNull(aggregate5); + ArgumentNullException.ThrowIfNull(aggregate6); + ArgumentNullException.ThrowIfNull(aggregate7); + ArgumentNullException.ThrowIfNull(aggregate8); + ArgumentNullException.ThrowIfNull(aggregate9); + ArgumentNullException.ThrowIfNull(aggregate10); + ArgumentNullException.ThrowIfNull(aggregate11); + ArgumentNullException.ThrowIfNull(merger); Expression>> aggregateMerger = (output1, output2, output3, output4, output5, output6, output7, output8, output9, output10, output11) => new StructTuple @@ -1729,20 +1729,20 @@ internal static IStreamable GroupAggregate aggregate11, Expression, TOutput1, TOutput2, TOutput3, TOutput4, TOutput5, TOutput6, TOutput7, TOutput8, TOutput9, TOutput10, TOutput11, TOutput>> merger) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(keySelector, nameof(keySelector)); - Invariant.IsNotNull(aggregate1, nameof(aggregate1)); - Invariant.IsNotNull(aggregate2, nameof(aggregate2)); - Invariant.IsNotNull(aggregate3, nameof(aggregate3)); - Invariant.IsNotNull(aggregate4, nameof(aggregate4)); - Invariant.IsNotNull(aggregate5, nameof(aggregate5)); - Invariant.IsNotNull(aggregate6, nameof(aggregate6)); - Invariant.IsNotNull(aggregate7, nameof(aggregate7)); - Invariant.IsNotNull(aggregate8, nameof(aggregate8)); - Invariant.IsNotNull(aggregate9, nameof(aggregate9)); - Invariant.IsNotNull(aggregate10, nameof(aggregate10)); - Invariant.IsNotNull(aggregate11, nameof(aggregate11)); - Invariant.IsNotNull(merger, nameof(merger)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(keySelector); + ArgumentNullException.ThrowIfNull(aggregate1); + ArgumentNullException.ThrowIfNull(aggregate2); + ArgumentNullException.ThrowIfNull(aggregate3); + ArgumentNullException.ThrowIfNull(aggregate4); + ArgumentNullException.ThrowIfNull(aggregate5); + ArgumentNullException.ThrowIfNull(aggregate6); + ArgumentNullException.ThrowIfNull(aggregate7); + ArgumentNullException.ThrowIfNull(aggregate8); + ArgumentNullException.ThrowIfNull(aggregate9); + ArgumentNullException.ThrowIfNull(aggregate10); + ArgumentNullException.ThrowIfNull(aggregate11); + ArgumentNullException.ThrowIfNull(merger); Expression>> aggregateMerger = (output1, output2, output3, output4, output5, output6, output7, output8, output9, output10, output11) => new StructTuple @@ -1832,21 +1832,21 @@ public static IStreamable GroupAggregate, TInput>, IAggregate> aggregate12, Expression, TOutput1, TOutput2, TOutput3, TOutput4, TOutput5, TOutput6, TOutput7, TOutput8, TOutput9, TOutput10, TOutput11, TOutput12, TOutput>> merger) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(keySelector, nameof(keySelector)); - Invariant.IsNotNull(aggregate1, nameof(aggregate1)); - Invariant.IsNotNull(aggregate2, nameof(aggregate2)); - Invariant.IsNotNull(aggregate3, nameof(aggregate3)); - Invariant.IsNotNull(aggregate4, nameof(aggregate4)); - Invariant.IsNotNull(aggregate5, nameof(aggregate5)); - Invariant.IsNotNull(aggregate6, nameof(aggregate6)); - Invariant.IsNotNull(aggregate7, nameof(aggregate7)); - Invariant.IsNotNull(aggregate8, nameof(aggregate8)); - Invariant.IsNotNull(aggregate9, nameof(aggregate9)); - Invariant.IsNotNull(aggregate10, nameof(aggregate10)); - Invariant.IsNotNull(aggregate11, nameof(aggregate11)); - Invariant.IsNotNull(aggregate12, nameof(aggregate12)); - Invariant.IsNotNull(merger, nameof(merger)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(keySelector); + ArgumentNullException.ThrowIfNull(aggregate1); + ArgumentNullException.ThrowIfNull(aggregate2); + ArgumentNullException.ThrowIfNull(aggregate3); + ArgumentNullException.ThrowIfNull(aggregate4); + ArgumentNullException.ThrowIfNull(aggregate5); + ArgumentNullException.ThrowIfNull(aggregate6); + ArgumentNullException.ThrowIfNull(aggregate7); + ArgumentNullException.ThrowIfNull(aggregate8); + ArgumentNullException.ThrowIfNull(aggregate9); + ArgumentNullException.ThrowIfNull(aggregate10); + ArgumentNullException.ThrowIfNull(aggregate11); + ArgumentNullException.ThrowIfNull(aggregate12); + ArgumentNullException.ThrowIfNull(merger); Expression>> aggregateMerger = (output1, output2, output3, output4, output5, output6, output7, output8, output9, output10, output11, output12) => new StructTuple @@ -1973,21 +1973,21 @@ internal static IStreamable GroupAggregate aggregate12, Expression, TOutput1, TOutput2, TOutput3, TOutput4, TOutput5, TOutput6, TOutput7, TOutput8, TOutput9, TOutput10, TOutput11, TOutput12, TOutput>> merger) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(keySelector, nameof(keySelector)); - Invariant.IsNotNull(aggregate1, nameof(aggregate1)); - Invariant.IsNotNull(aggregate2, nameof(aggregate2)); - Invariant.IsNotNull(aggregate3, nameof(aggregate3)); - Invariant.IsNotNull(aggregate4, nameof(aggregate4)); - Invariant.IsNotNull(aggregate5, nameof(aggregate5)); - Invariant.IsNotNull(aggregate6, nameof(aggregate6)); - Invariant.IsNotNull(aggregate7, nameof(aggregate7)); - Invariant.IsNotNull(aggregate8, nameof(aggregate8)); - Invariant.IsNotNull(aggregate9, nameof(aggregate9)); - Invariant.IsNotNull(aggregate10, nameof(aggregate10)); - Invariant.IsNotNull(aggregate11, nameof(aggregate11)); - Invariant.IsNotNull(aggregate12, nameof(aggregate12)); - Invariant.IsNotNull(merger, nameof(merger)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(keySelector); + ArgumentNullException.ThrowIfNull(aggregate1); + ArgumentNullException.ThrowIfNull(aggregate2); + ArgumentNullException.ThrowIfNull(aggregate3); + ArgumentNullException.ThrowIfNull(aggregate4); + ArgumentNullException.ThrowIfNull(aggregate5); + ArgumentNullException.ThrowIfNull(aggregate6); + ArgumentNullException.ThrowIfNull(aggregate7); + ArgumentNullException.ThrowIfNull(aggregate8); + ArgumentNullException.ThrowIfNull(aggregate9); + ArgumentNullException.ThrowIfNull(aggregate10); + ArgumentNullException.ThrowIfNull(aggregate11); + ArgumentNullException.ThrowIfNull(aggregate12); + ArgumentNullException.ThrowIfNull(merger); Expression>> aggregateMerger = (output1, output2, output3, output4, output5, output6, output7, output8, output9, output10, output11, output12) => new StructTuple @@ -2082,22 +2082,22 @@ public static IStreamable GroupAggregate, TInput>, IAggregate> aggregate13, Expression, TOutput1, TOutput2, TOutput3, TOutput4, TOutput5, TOutput6, TOutput7, TOutput8, TOutput9, TOutput10, TOutput11, TOutput12, TOutput13, TOutput>> merger) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(keySelector, nameof(keySelector)); - Invariant.IsNotNull(aggregate1, nameof(aggregate1)); - Invariant.IsNotNull(aggregate2, nameof(aggregate2)); - Invariant.IsNotNull(aggregate3, nameof(aggregate3)); - Invariant.IsNotNull(aggregate4, nameof(aggregate4)); - Invariant.IsNotNull(aggregate5, nameof(aggregate5)); - Invariant.IsNotNull(aggregate6, nameof(aggregate6)); - Invariant.IsNotNull(aggregate7, nameof(aggregate7)); - Invariant.IsNotNull(aggregate8, nameof(aggregate8)); - Invariant.IsNotNull(aggregate9, nameof(aggregate9)); - Invariant.IsNotNull(aggregate10, nameof(aggregate10)); - Invariant.IsNotNull(aggregate11, nameof(aggregate11)); - Invariant.IsNotNull(aggregate12, nameof(aggregate12)); - Invariant.IsNotNull(aggregate13, nameof(aggregate13)); - Invariant.IsNotNull(merger, nameof(merger)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(keySelector); + ArgumentNullException.ThrowIfNull(aggregate1); + ArgumentNullException.ThrowIfNull(aggregate2); + ArgumentNullException.ThrowIfNull(aggregate3); + ArgumentNullException.ThrowIfNull(aggregate4); + ArgumentNullException.ThrowIfNull(aggregate5); + ArgumentNullException.ThrowIfNull(aggregate6); + ArgumentNullException.ThrowIfNull(aggregate7); + ArgumentNullException.ThrowIfNull(aggregate8); + ArgumentNullException.ThrowIfNull(aggregate9); + ArgumentNullException.ThrowIfNull(aggregate10); + ArgumentNullException.ThrowIfNull(aggregate11); + ArgumentNullException.ThrowIfNull(aggregate12); + ArgumentNullException.ThrowIfNull(aggregate13); + ArgumentNullException.ThrowIfNull(merger); Expression>> aggregateMerger = (output1, output2, output3, output4, output5, output6, output7, output8, output9, output10, output11, output12, output13) => new StructTuple @@ -2231,22 +2231,22 @@ internal static IStreamable GroupAggregate aggregate13, Expression, TOutput1, TOutput2, TOutput3, TOutput4, TOutput5, TOutput6, TOutput7, TOutput8, TOutput9, TOutput10, TOutput11, TOutput12, TOutput13, TOutput>> merger) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(keySelector, nameof(keySelector)); - Invariant.IsNotNull(aggregate1, nameof(aggregate1)); - Invariant.IsNotNull(aggregate2, nameof(aggregate2)); - Invariant.IsNotNull(aggregate3, nameof(aggregate3)); - Invariant.IsNotNull(aggregate4, nameof(aggregate4)); - Invariant.IsNotNull(aggregate5, nameof(aggregate5)); - Invariant.IsNotNull(aggregate6, nameof(aggregate6)); - Invariant.IsNotNull(aggregate7, nameof(aggregate7)); - Invariant.IsNotNull(aggregate8, nameof(aggregate8)); - Invariant.IsNotNull(aggregate9, nameof(aggregate9)); - Invariant.IsNotNull(aggregate10, nameof(aggregate10)); - Invariant.IsNotNull(aggregate11, nameof(aggregate11)); - Invariant.IsNotNull(aggregate12, nameof(aggregate12)); - Invariant.IsNotNull(aggregate13, nameof(aggregate13)); - Invariant.IsNotNull(merger, nameof(merger)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(keySelector); + ArgumentNullException.ThrowIfNull(aggregate1); + ArgumentNullException.ThrowIfNull(aggregate2); + ArgumentNullException.ThrowIfNull(aggregate3); + ArgumentNullException.ThrowIfNull(aggregate4); + ArgumentNullException.ThrowIfNull(aggregate5); + ArgumentNullException.ThrowIfNull(aggregate6); + ArgumentNullException.ThrowIfNull(aggregate7); + ArgumentNullException.ThrowIfNull(aggregate8); + ArgumentNullException.ThrowIfNull(aggregate9); + ArgumentNullException.ThrowIfNull(aggregate10); + ArgumentNullException.ThrowIfNull(aggregate11); + ArgumentNullException.ThrowIfNull(aggregate12); + ArgumentNullException.ThrowIfNull(aggregate13); + ArgumentNullException.ThrowIfNull(merger); Expression>> aggregateMerger = (output1, output2, output3, output4, output5, output6, output7, output8, output9, output10, output11, output12, output13) => new StructTuple @@ -2346,23 +2346,23 @@ public static IStreamable GroupAggregate, TInput>, IAggregate> aggregate14, Expression, TOutput1, TOutput2, TOutput3, TOutput4, TOutput5, TOutput6, TOutput7, TOutput8, TOutput9, TOutput10, TOutput11, TOutput12, TOutput13, TOutput14, TOutput>> merger) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(keySelector, nameof(keySelector)); - Invariant.IsNotNull(aggregate1, nameof(aggregate1)); - Invariant.IsNotNull(aggregate2, nameof(aggregate2)); - Invariant.IsNotNull(aggregate3, nameof(aggregate3)); - Invariant.IsNotNull(aggregate4, nameof(aggregate4)); - Invariant.IsNotNull(aggregate5, nameof(aggregate5)); - Invariant.IsNotNull(aggregate6, nameof(aggregate6)); - Invariant.IsNotNull(aggregate7, nameof(aggregate7)); - Invariant.IsNotNull(aggregate8, nameof(aggregate8)); - Invariant.IsNotNull(aggregate9, nameof(aggregate9)); - Invariant.IsNotNull(aggregate10, nameof(aggregate10)); - Invariant.IsNotNull(aggregate11, nameof(aggregate11)); - Invariant.IsNotNull(aggregate12, nameof(aggregate12)); - Invariant.IsNotNull(aggregate13, nameof(aggregate13)); - Invariant.IsNotNull(aggregate14, nameof(aggregate14)); - Invariant.IsNotNull(merger, nameof(merger)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(keySelector); + ArgumentNullException.ThrowIfNull(aggregate1); + ArgumentNullException.ThrowIfNull(aggregate2); + ArgumentNullException.ThrowIfNull(aggregate3); + ArgumentNullException.ThrowIfNull(aggregate4); + ArgumentNullException.ThrowIfNull(aggregate5); + ArgumentNullException.ThrowIfNull(aggregate6); + ArgumentNullException.ThrowIfNull(aggregate7); + ArgumentNullException.ThrowIfNull(aggregate8); + ArgumentNullException.ThrowIfNull(aggregate9); + ArgumentNullException.ThrowIfNull(aggregate10); + ArgumentNullException.ThrowIfNull(aggregate11); + ArgumentNullException.ThrowIfNull(aggregate12); + ArgumentNullException.ThrowIfNull(aggregate13); + ArgumentNullException.ThrowIfNull(aggregate14); + ArgumentNullException.ThrowIfNull(merger); Expression>> aggregateMerger = (output1, output2, output3, output4, output5, output6, output7, output8, output9, output10, output11, output12, output13, output14) => new StructTuple @@ -2503,23 +2503,23 @@ internal static IStreamable GroupAggregate aggregate14, Expression, TOutput1, TOutput2, TOutput3, TOutput4, TOutput5, TOutput6, TOutput7, TOutput8, TOutput9, TOutput10, TOutput11, TOutput12, TOutput13, TOutput14, TOutput>> merger) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(keySelector, nameof(keySelector)); - Invariant.IsNotNull(aggregate1, nameof(aggregate1)); - Invariant.IsNotNull(aggregate2, nameof(aggregate2)); - Invariant.IsNotNull(aggregate3, nameof(aggregate3)); - Invariant.IsNotNull(aggregate4, nameof(aggregate4)); - Invariant.IsNotNull(aggregate5, nameof(aggregate5)); - Invariant.IsNotNull(aggregate6, nameof(aggregate6)); - Invariant.IsNotNull(aggregate7, nameof(aggregate7)); - Invariant.IsNotNull(aggregate8, nameof(aggregate8)); - Invariant.IsNotNull(aggregate9, nameof(aggregate9)); - Invariant.IsNotNull(aggregate10, nameof(aggregate10)); - Invariant.IsNotNull(aggregate11, nameof(aggregate11)); - Invariant.IsNotNull(aggregate12, nameof(aggregate12)); - Invariant.IsNotNull(aggregate13, nameof(aggregate13)); - Invariant.IsNotNull(aggregate14, nameof(aggregate14)); - Invariant.IsNotNull(merger, nameof(merger)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(keySelector); + ArgumentNullException.ThrowIfNull(aggregate1); + ArgumentNullException.ThrowIfNull(aggregate2); + ArgumentNullException.ThrowIfNull(aggregate3); + ArgumentNullException.ThrowIfNull(aggregate4); + ArgumentNullException.ThrowIfNull(aggregate5); + ArgumentNullException.ThrowIfNull(aggregate6); + ArgumentNullException.ThrowIfNull(aggregate7); + ArgumentNullException.ThrowIfNull(aggregate8); + ArgumentNullException.ThrowIfNull(aggregate9); + ArgumentNullException.ThrowIfNull(aggregate10); + ArgumentNullException.ThrowIfNull(aggregate11); + ArgumentNullException.ThrowIfNull(aggregate12); + ArgumentNullException.ThrowIfNull(aggregate13); + ArgumentNullException.ThrowIfNull(aggregate14); + ArgumentNullException.ThrowIfNull(merger); Expression>> aggregateMerger = (output1, output2, output3, output4, output5, output6, output7, output8, output9, output10, output11, output12, output13, output14) => new StructTuple @@ -2624,24 +2624,24 @@ public static IStreamable GroupAggregate, TInput>, IAggregate> aggregate15, Expression, TOutput1, TOutput2, TOutput3, TOutput4, TOutput5, TOutput6, TOutput7, TOutput8, TOutput9, TOutput10, TOutput11, TOutput12, TOutput13, TOutput14, TOutput15, TOutput>> merger) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(keySelector, nameof(keySelector)); - Invariant.IsNotNull(aggregate1, nameof(aggregate1)); - Invariant.IsNotNull(aggregate2, nameof(aggregate2)); - Invariant.IsNotNull(aggregate3, nameof(aggregate3)); - Invariant.IsNotNull(aggregate4, nameof(aggregate4)); - Invariant.IsNotNull(aggregate5, nameof(aggregate5)); - Invariant.IsNotNull(aggregate6, nameof(aggregate6)); - Invariant.IsNotNull(aggregate7, nameof(aggregate7)); - Invariant.IsNotNull(aggregate8, nameof(aggregate8)); - Invariant.IsNotNull(aggregate9, nameof(aggregate9)); - Invariant.IsNotNull(aggregate10, nameof(aggregate10)); - Invariant.IsNotNull(aggregate11, nameof(aggregate11)); - Invariant.IsNotNull(aggregate12, nameof(aggregate12)); - Invariant.IsNotNull(aggregate13, nameof(aggregate13)); - Invariant.IsNotNull(aggregate14, nameof(aggregate14)); - Invariant.IsNotNull(aggregate15, nameof(aggregate15)); - Invariant.IsNotNull(merger, nameof(merger)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(keySelector); + ArgumentNullException.ThrowIfNull(aggregate1); + ArgumentNullException.ThrowIfNull(aggregate2); + ArgumentNullException.ThrowIfNull(aggregate3); + ArgumentNullException.ThrowIfNull(aggregate4); + ArgumentNullException.ThrowIfNull(aggregate5); + ArgumentNullException.ThrowIfNull(aggregate6); + ArgumentNullException.ThrowIfNull(aggregate7); + ArgumentNullException.ThrowIfNull(aggregate8); + ArgumentNullException.ThrowIfNull(aggregate9); + ArgumentNullException.ThrowIfNull(aggregate10); + ArgumentNullException.ThrowIfNull(aggregate11); + ArgumentNullException.ThrowIfNull(aggregate12); + ArgumentNullException.ThrowIfNull(aggregate13); + ArgumentNullException.ThrowIfNull(aggregate14); + ArgumentNullException.ThrowIfNull(aggregate15); + ArgumentNullException.ThrowIfNull(merger); Expression>> aggregateMerger = (output1, output2, output3, output4, output5, output6, output7, output8, output9, output10, output11, output12, output13, output14, output15) => new StructTuple @@ -2789,24 +2789,24 @@ internal static IStreamable GroupAggregate aggregate15, Expression, TOutput1, TOutput2, TOutput3, TOutput4, TOutput5, TOutput6, TOutput7, TOutput8, TOutput9, TOutput10, TOutput11, TOutput12, TOutput13, TOutput14, TOutput15, TOutput>> merger) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(keySelector, nameof(keySelector)); - Invariant.IsNotNull(aggregate1, nameof(aggregate1)); - Invariant.IsNotNull(aggregate2, nameof(aggregate2)); - Invariant.IsNotNull(aggregate3, nameof(aggregate3)); - Invariant.IsNotNull(aggregate4, nameof(aggregate4)); - Invariant.IsNotNull(aggregate5, nameof(aggregate5)); - Invariant.IsNotNull(aggregate6, nameof(aggregate6)); - Invariant.IsNotNull(aggregate7, nameof(aggregate7)); - Invariant.IsNotNull(aggregate8, nameof(aggregate8)); - Invariant.IsNotNull(aggregate9, nameof(aggregate9)); - Invariant.IsNotNull(aggregate10, nameof(aggregate10)); - Invariant.IsNotNull(aggregate11, nameof(aggregate11)); - Invariant.IsNotNull(aggregate12, nameof(aggregate12)); - Invariant.IsNotNull(aggregate13, nameof(aggregate13)); - Invariant.IsNotNull(aggregate14, nameof(aggregate14)); - Invariant.IsNotNull(aggregate15, nameof(aggregate15)); - Invariant.IsNotNull(merger, nameof(merger)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(keySelector); + ArgumentNullException.ThrowIfNull(aggregate1); + ArgumentNullException.ThrowIfNull(aggregate2); + ArgumentNullException.ThrowIfNull(aggregate3); + ArgumentNullException.ThrowIfNull(aggregate4); + ArgumentNullException.ThrowIfNull(aggregate5); + ArgumentNullException.ThrowIfNull(aggregate6); + ArgumentNullException.ThrowIfNull(aggregate7); + ArgumentNullException.ThrowIfNull(aggregate8); + ArgumentNullException.ThrowIfNull(aggregate9); + ArgumentNullException.ThrowIfNull(aggregate10); + ArgumentNullException.ThrowIfNull(aggregate11); + ArgumentNullException.ThrowIfNull(aggregate12); + ArgumentNullException.ThrowIfNull(aggregate13); + ArgumentNullException.ThrowIfNull(aggregate14); + ArgumentNullException.ThrowIfNull(aggregate15); + ArgumentNullException.ThrowIfNull(merger); Expression>> aggregateMerger = (output1, output2, output3, output4, output5, output6, output7, output8, output9, output10, output11, output12, output13, output14, output15) => new StructTuple diff --git a/Sources/Core/Microsoft.StreamProcessing/StreamableAPI/GroupAggregateTemplate.tt b/Sources/Core/Microsoft.StreamProcessing/StreamableAPI/GroupAggregateTemplate.tt index bdc1939e0..a3afabaf9 100644 --- a/Sources/Core/Microsoft.StreamProcessing/StreamableAPI/GroupAggregateTemplate.tt +++ b/Sources/Core/Microsoft.StreamProcessing/StreamableAPI/GroupAggregateTemplate.tt @@ -36,10 +36,10 @@ namespace Microsoft.StreamProcessing Func, TInput>, IAggregate> aggregate1, Expression, TOutput1, TOutput>> merger) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(keySelector, nameof(keySelector)); - Invariant.IsNotNull(aggregate1, nameof(aggregate1)); - Invariant.IsNotNull(merger, nameof(merger)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(keySelector); + ArgumentNullException.ThrowIfNull(aggregate1); + ArgumentNullException.ThrowIfNull(merger); if (typeof(TOuterKey) == typeof(Empty) && source.Properties.IsStartEdgeOnly && Config.MapArity == 1) { @@ -74,10 +74,10 @@ namespace Microsoft.StreamProcessing IAggregate aggregate1, Expression, TOutput1, TOutput>> merger) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(keySelector, nameof(keySelector)); - Invariant.IsNotNull(aggregate1, nameof(aggregate1)); - Invariant.IsNotNull(merger, nameof(merger)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(keySelector); + ArgumentNullException.ThrowIfNull(aggregate1); + ArgumentNullException.ThrowIfNull(merger); return source.Map(keySelector).Reduce(s => s.Aggregate(aggregate1), merger); } @@ -107,10 +107,10 @@ namespace Microsoft.StreamProcessing <#= IterateLine(" Func, TInput>, IAggregate> aggregate$,", count) #> Expression, <#= IterateComma("TOutput$", count) #>, TOutput>> merger) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(keySelector, nameof(keySelector)); -<#= IterateLine(" Invariant.IsNotNull(aggregate$, nameof(aggregate$));", count) #> - Invariant.IsNotNull(merger, nameof(merger)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(keySelector); +<#= IterateLine(" ArgumentNullException.ThrowIfNull(aggregate$);", count) #> + ArgumentNullException.ThrowIfNull(merger); Expression, StructTuple<<#= IterateComma("TOutput$", count) #>>>> aggregateMerger = (<#= IterateComma("output$", count) #>) => new StructTuple<<#= IterateComma("TOutput$", count) #>> @@ -160,10 +160,10 @@ namespace Microsoft.StreamProcessing <#= IterateLine(" IAggregate aggregate$,", count) #> Expression, <#= IterateComma("TOutput$", count) #>, TOutput>> merger) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(keySelector, nameof(keySelector)); -<#= IterateLine(" Invariant.IsNotNull(aggregate$, nameof(aggregate$));", count) #> - Invariant.IsNotNull(merger, nameof(merger)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(keySelector); +<#= IterateLine(" ArgumentNullException.ThrowIfNull(aggregate$);", count) #> + ArgumentNullException.ThrowIfNull(merger); Expression, StructTuple<<#= IterateComma("TOutput$", count) #>>>> aggregateMerger = (<#= IterateComma("output$", count) #>) => new StructTuple<<#= IterateComma("TOutput$", count) #>> diff --git a/Sources/Core/Microsoft.StreamProcessing/StreamableAPI/LifetimeExtensions.cs b/Sources/Core/Microsoft.StreamProcessing/StreamableAPI/LifetimeExtensions.cs index 3098c1e34..1033730ae 100644 --- a/Sources/Core/Microsoft.StreamProcessing/StreamableAPI/LifetimeExtensions.cs +++ b/Sources/Core/Microsoft.StreamProcessing/StreamableAPI/LifetimeExtensions.cs @@ -41,7 +41,7 @@ public static IStreamable TumblingWindowLifetime long tumbleDuration, long offset = 0) { - Invariant.IsNotNull(source, nameof(source)); + ArgumentNullException.ThrowIfNull(source); return source.HoppingWindowLifetime(tumbleDuration, tumbleDuration, offset); } @@ -106,9 +106,9 @@ public static IStreamable QuantizeLifetime( long period, long offset = 0) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsPositive(windowSize, nameof(windowSize)); - Invariant.IsPositive(period, nameof(period)); + ArgumentNullException.ThrowIfNull(source); + ArgumentOutOfRangeException.ThrowIfNegativeOrZero(windowSize); + ArgumentOutOfRangeException.ThrowIfNegativeOrZero(period); return new QuantizeLifetimeStreamable(source, windowSize, period, period, offset); } @@ -134,10 +134,10 @@ public static IStreamable ProgressiveQuantizeLifetime ProgressiveQuantizeLifetime RepetitiveHoppingWindowLifetime( this IStreamable source, long windowSize, long period, long offset = 0) { - Invariant.IsNotNull(source, nameof(source)); + ArgumentNullException.ThrowIfNull(source); return source.HoppingWindowLifetime(windowSize, period, offset).Chop(offset, period); } @@ -180,7 +180,7 @@ public static IStreamable SessionTimeoutWindow( long timeout, long maxDuration = 0L) { - Invariant.IsNotNull(source, nameof(source)); + ArgumentNullException.ThrowIfNull(source); if (maxDuration <= 0L) maxDuration = StreamEvent.InfinitySyncTime; return new SessionWindowStreamable(source, timeout, maxDuration); @@ -195,8 +195,8 @@ public static IStreamable AlterEventDuration( this IStreamable source, Expression> durationSelector) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(durationSelector, nameof(durationSelector)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(durationSelector); return new AlterLifetimeStreamable(source, null, durationSelector); } @@ -210,8 +210,8 @@ public static IStreamable AlterEventDuration( this IStreamable source, Expression> durationSelector) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(durationSelector, nameof(durationSelector)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(durationSelector); return new AlterLifetimeStreamable(source, null, durationSelector); } @@ -225,12 +225,12 @@ public static IStreamable AlterEventDuration( this IStreamable source, long duration) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsPositive(duration, nameof(duration)); + ArgumentNullException.ThrowIfNull(source); + ArgumentOutOfRangeException.ThrowIfNegativeOrZero(duration); return source is IFusibleStreamable s ? s.FuseSetDurationConstant(duration) - : (IStreamable)new AlterLifetimeStreamable(source, null, Expression.Lambda>(Expression.Constant(duration))); + : new AlterLifetimeStreamable(source, null, Expression.Lambda>(Expression.Constant(duration))); } /// @@ -242,7 +242,7 @@ public static IStreamable ShiftEventLifetime( this IStreamable source, Expression> shiftSelector) { - Invariant.IsNotNull(source, nameof(source)); + ArgumentNullException.ThrowIfNull(source); if (shiftSelector == null) return source; @@ -267,7 +267,7 @@ public static IStreamable ShiftEventLifetime( this IStreamable source, long shiftAmount) { - Invariant.IsNotNull(source, nameof(source)); + ArgumentNullException.ThrowIfNull(source); return source.ShiftEventLifetime(s => shiftAmount); } @@ -282,9 +282,9 @@ public static IStreamable AlterEventLifetime( Expression> startTimeSelector, Expression> durationSelector) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(startTimeSelector, nameof(startTimeSelector)); - Invariant.IsNotNull(durationSelector, nameof(durationSelector)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(startTimeSelector); + ArgumentNullException.ThrowIfNull(durationSelector); return new AlterLifetimeStreamable(source, startTimeSelector, durationSelector); } @@ -300,9 +300,9 @@ public static IStreamable AlterEventLifetime( Expression> startTimeSelector, Expression> durationSelector) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(startTimeSelector, nameof(startTimeSelector)); - Invariant.IsNotNull(durationSelector, nameof(durationSelector)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(startTimeSelector); + ArgumentNullException.ThrowIfNull(durationSelector); return new AlterLifetimeStreamable(source, startTimeSelector, durationSelector); } @@ -319,9 +319,9 @@ public static IStreamable, TPayload> AlterEventLifetime Expression> startTimeSelector, Expression> durationSelector) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(startTimeSelector, nameof(startTimeSelector)); - Invariant.IsNotNull(durationSelector, nameof(durationSelector)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(startTimeSelector); + ArgumentNullException.ThrowIfNull(durationSelector); return new AlterLifetimeStreamable, TPayload>(source, startTimeSelector, durationSelector); } @@ -340,9 +340,9 @@ public static IStreamable AlterEventLifetime( Expression> startTimeSelector, long duration) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(startTimeSelector, nameof(startTimeSelector)); - Invariant.IsPositive(duration, nameof(duration)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(startTimeSelector); + ArgumentOutOfRangeException.ThrowIfNegativeOrZero(duration); return new AlterLifetimeStreamable(source, startTimeSelector, Expression.Lambda>(Expression.Constant(duration))); } @@ -354,8 +354,8 @@ public static IStreamable ClipEventDuration( this IStreamable source, long limit) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsPositive(limit, nameof(limit)); + ArgumentNullException.ThrowIfNull(source); + ArgumentOutOfRangeException.ThrowIfNegativeOrZero(limit); return source.Properties.IsConstantDuration && limit < source.Properties.ConstantDurationLength.Value ? AlterEventDuration(source, limit) diff --git a/Sources/Core/Microsoft.StreamProcessing/StreamableAPI/PivotExtensions.cs b/Sources/Core/Microsoft.StreamProcessing/StreamableAPI/PivotExtensions.cs index a1f4cc306..f5410a6dd 100644 --- a/Sources/Core/Microsoft.StreamProcessing/StreamableAPI/PivotExtensions.cs +++ b/Sources/Core/Microsoft.StreamProcessing/StreamableAPI/PivotExtensions.cs @@ -42,20 +42,20 @@ public static IStreamable Pivot, TValue>, IAggregate> aggregate) where TOutput : new() { bool sourceHasNullableValues = IsNullable(typeof(TValue)); - if (initializer == null) throw new ArgumentNullException(nameof(initializer)); + ArgumentNullException.ThrowIfNull(initializer); var window = new Window, TValue>(inputStreamable.Properties.GroupNested(keySelector).Select(valueSelector, false, false)); var agg = aggregate(window); var valueAgg = agg.TransformInput(valueSelector); var outputPublicFields = - typeof(TOutput).GetTypeInfo() + typeof(TOutput) .GetFields(BindingFlags.Public | BindingFlags.Instance) .Select(f => Tuple.Create(f.Name, f.FieldType, (MemberInfo)f, !sourceHasNullableValues && IsNullable(f.FieldType))) .Concat( - typeof(TOutput).GetTypeInfo().GetProperties(BindingFlags.Public | BindingFlags.Instance) + typeof(TOutput).GetProperties(BindingFlags.Public | BindingFlags.Instance) .Where(p => p.GetIndexParameters().Length == 0) .Select(f => Tuple.Create(f.Name, f.PropertyType, (MemberInfo)f, !sourceHasNullableValues && IsNullable(f.PropertyType)))) - .Where(m => m.Item2.GetTypeInfo().IsAssignableFrom(typeof(TAggValue))).ToArray(); + .Where(m => m.Item2.IsAssignableFrom(typeof(TAggValue))).ToArray(); var aggArray = outputPublicFields.Select( m => valueAgg.ApplyFilter( Expression.Lambda>( @@ -104,7 +104,7 @@ public static IStreamable Pivot Pivot Pivot Pivot Expression.Bind( a.Item3, a.Item4 - ? (Expression)Expression.New(typeof(Nullable<>).MakeGenericType(typeof(TValue)).GetTypeInfo().GetConstructor(new[] { typeof(TValue) }), Expression.ArrayIndex(aggvalues, Expression.Constant(i))) + ? (Expression)Expression.New(typeof(Nullable<>).MakeGenericType(typeof(TValue)).GetConstructor([typeof(TValue)]), Expression.ArrayIndex(aggvalues, Expression.Constant(i))) : Expression.ArrayIndex(aggvalues, Expression.Constant(i)))))); var resultConstructor = Expression.Lambda, TAggValue[], TOutput>>( constructor, groupkey, aggvalues); @@ -187,11 +187,11 @@ public static IStreamable Unpivot> attributeSelector, Expression> valueSelector) where TResult : new() { - Invariant.IsNotNull(inputStreamable, nameof(inputStreamable)); - Invariant.IsNotNull(initializer, nameof(initializer)); - Invariant.IsNotNull(keySelector, nameof(keySelector)); - Invariant.IsNotNull(attributeSelector, nameof(attributeSelector)); - Invariant.IsNotNull(valueSelector, nameof(valueSelector)); + ArgumentNullException.ThrowIfNull(inputStreamable); + ArgumentNullException.ThrowIfNull(initializer); + ArgumentNullException.ThrowIfNull(keySelector); + ArgumentNullException.ThrowIfNull(attributeSelector); + ArgumentNullException.ThrowIfNull(valueSelector); if (!(initializer.Body is NewExpression newExpression)) throw new ArgumentException("Initializer must return a constructor expression.", nameof(initializer)); if (!(attributeSelector.Body is MemberExpression attributeField)) throw new ArgumentException("Attribute selector expression must refer to a single field in the return type."); @@ -204,8 +204,8 @@ public static IStreamable Unpivot { - private readonly Dictionary> fields = new Dictionary>(); - private readonly Dictionary> isNull = new Dictionary>(); + private readonly Dictionary> fields = []; + private readonly Dictionary> isNull = []; public UnpivotEnumerable(Expression> keySelector, NewExpression newExpression, MemberExpression attributeField, MemberExpression valueField) { @@ -222,7 +222,7 @@ public UnpivotEnumerable(Expression> keySelector, NewExp { var selector = keySelector.Body as MemberExpression; keyAssignments.Add(Expression.Bind( - typeof(TResult).GetTypeInfo().GetMember(selector.Member.Name).Single(), + typeof(TResult).GetMember(selector.Member.Name).Single(), Expression.PropertyOrField(input, selector.Member.Name))); keyFields.Add(selector.Member.Name); break; @@ -238,14 +238,14 @@ public UnpivotEnumerable(Expression> keySelector, NewExp if (singleInit.Expression is MemberExpression rightSide) { keyAssignments.Add(Expression.Bind( - typeof(TResult).GetTypeInfo().GetMember(singleInit.Member.Name).Single(), + typeof(TResult).GetMember(singleInit.Member.Name).Single(), Expression.PropertyOrField(input, rightSide.Member.Name))); keyFields.Add(rightSide.Member.Name); } else { keyAssignments.Add(Expression.Bind( - typeof(TResult).GetTypeInfo().GetMember(singleInit.Member.Name).Single(), ParameterSubstituter.Replace(keySelector.Parameters[0], input, singleInit.Expression))); + typeof(TResult).GetMember(singleInit.Member.Name).Single(), ParameterSubstituter.Replace(keySelector.Parameters[0], input, singleInit.Expression))); } } break; @@ -261,14 +261,14 @@ public UnpivotEnumerable(Expression> keySelector, NewExp if (newInit.Arguments[i] is MemberExpression rightSide) { keyAssignments.Add(Expression.Bind( - typeof(TResult).GetTypeInfo().GetMember(leftSide.Name).Single(), + typeof(TResult).GetMember(leftSide.Name).Single(), Expression.PropertyOrField(input, rightSide.Member.Name))); keyFields.Add(rightSide.Member.Name); } else { keyAssignments.Add(Expression.Bind( - typeof(TResult).GetTypeInfo().GetMember(leftSide.Name).Single(), ParameterSubstituter.Replace(keySelector.Parameters[0], input, newInit.Arguments[i]))); + typeof(TResult).GetMember(leftSide.Name).Single(), ParameterSubstituter.Replace(keySelector.Parameters[0], input, newInit.Arguments[i]))); } } } @@ -276,54 +276,54 @@ public UnpivotEnumerable(Expression> keySelector, NewExp { // Currently do the same thing as the default case, but we might be able to be smarter here. // If we have an arbitrary expression, assume we have only one remaining field that is not the attribute or value fields and assign to it. - var outputFields = typeof(TResult).GetTypeInfo().GetFields(BindingFlags.Public | BindingFlags.Instance).OrderBy(o => o.Name).Select(o => o.Name) + var outputFields = typeof(TResult).GetFields(BindingFlags.Public | BindingFlags.Instance).OrderBy(o => o.Name).Select(o => o.Name) .Concat( - typeof(TResult).GetTypeInfo().GetProperties(BindingFlags.Public | BindingFlags.Instance).Where(p => p.GetIndexParameters().Length == 0).OrderBy(o => o.Name).Select(o => o.Name)) + typeof(TResult).GetProperties(BindingFlags.Public | BindingFlags.Instance).Where(p => p.GetIndexParameters().Length == 0).OrderBy(o => o.Name).Select(o => o.Name)) .Where(o => o != attributeField.Member.Name && o != valueField.Member.Name).ToList(); if (outputFields.Count != 1) throw new NotSupportedException("Unpivot operation could not determine a unique field to which to assign key values."); keyAssignments.Add(Expression.Bind( - typeof(TResult).GetTypeInfo().GetMember(outputFields.Single()).Single(), keySelector.ReplaceParametersInBody(input))); + typeof(TResult).GetMember(outputFields.Single()).Single(), keySelector.ReplaceParametersInBody(input))); } break; } default: { // If we have an arbitrary expression, assume we have only one remaining field that is not the attribute or value fields and assign to it. - var outputFields = typeof(TResult).GetTypeInfo().GetFields(BindingFlags.Public | BindingFlags.Instance).OrderBy(o => o.Name).Select(o => o.Name) + var outputFields = typeof(TResult).GetFields(BindingFlags.Public | BindingFlags.Instance).OrderBy(o => o.Name).Select(o => o.Name) .Concat( - typeof(TResult).GetTypeInfo().GetProperties(BindingFlags.Public | BindingFlags.Instance).Where(p => p.GetIndexParameters().Length == 0).OrderBy(o => o.Name).Select(o => o.Name)) + typeof(TResult).GetProperties(BindingFlags.Public | BindingFlags.Instance).Where(p => p.GetIndexParameters().Length == 0).OrderBy(o => o.Name).Select(o => o.Name)) .Where(o => o != attributeField.Member.Name && o != valueField.Member.Name).ToList(); if (outputFields.Count != 1) throw new NotSupportedException("Unpivot operation could not determine a unique field to which to assign key values."); keyAssignments.Add(Expression.Bind( - typeof(TResult).GetTypeInfo().GetMember(outputFields.Single()).Single(), keySelector.ReplaceParametersInBody(input))); + typeof(TResult).GetMember(outputFields.Single()).Single(), keySelector.ReplaceParametersInBody(input))); break; } } keyAssignments.Add(Expression.Bind(attributeField.Member, attribute)); - foreach (var field in typeof(TInput).GetTypeInfo().GetProperties(BindingFlags.Public | BindingFlags.Instance).Where(p => p.GetIndexParameters().Length == 0).Where(o => !keyFields.Contains(o.Name)).OrderBy(o => o.Name)) + foreach (var field in typeof(TInput).GetProperties(BindingFlags.Public | BindingFlags.Instance).Where(p => p.GetIndexParameters().Length == 0).Where(o => !keyFields.Contains(o.Name)).OrderBy(o => o.Name)) { if (IsNullable(field.PropertyType)) { - if (!typeof(TValue).GetTypeInfo().IsAssignableFrom(field.PropertyType.GetTypeInfo().GetGenericArguments()[0])) continue; + if (!typeof(TValue).IsAssignableFrom(field.PropertyType.GetGenericArguments()[0])) continue; this.isNull.Add( field.Name, Expression.Lambda>( Expression.IsTrue(Expression.PropertyOrField(Expression.PropertyOrField(input, field.Name), "HasValue")), - new[] { input }).Compile()); + [input]).Compile()); } - else if (valueField.Type.GetTypeInfo().IsClass) + else if (valueField.Type.IsClass) { - if (!typeof(TValue).GetTypeInfo().IsAssignableFrom(field.PropertyType)) continue; + if (!typeof(TValue).IsAssignableFrom(field.PropertyType)) continue; this.isNull.Add( field.Name, Expression.Lambda>( Expression.Equal(Expression.PropertyOrField(input, field.Name), Expression.Constant(null)), - new[] { input }).Compile()); + [input]).Compile()); } else { - if (!typeof(TValue).GetTypeInfo().IsAssignableFrom(field.PropertyType)) continue; + if (!typeof(TValue).IsAssignableFrom(field.PropertyType)) continue; this.isNull.Add(field.Name, (TInput o) => true); } @@ -339,27 +339,27 @@ public UnpivotEnumerable(Expression> keySelector, NewExp var fieldResult = Expression.Lambda>(constructor, input, attribute); this.fields.Add(field.Name, fieldResult.Compile()); } - foreach (var field in typeof(TInput).GetTypeInfo().GetFields(BindingFlags.Public | BindingFlags.Instance).Where(o => !keyFields.Contains(o.Name)).OrderBy(o => o.Name)) + foreach (var field in typeof(TInput).GetFields(BindingFlags.Public | BindingFlags.Instance).Where(o => !keyFields.Contains(o.Name)).OrderBy(o => o.Name)) { if (IsNullable(field.FieldType)) { - if (!typeof(TValue).GetTypeInfo().IsAssignableFrom(field.FieldType.GetTypeInfo().GetGenericArguments()[0])) continue; + if (!typeof(TValue).IsAssignableFrom(field.FieldType.GetGenericArguments()[0])) continue; this.isNull.Add( field.Name, Expression.Lambda>( Expression.IsFalse(Expression.PropertyOrField(Expression.PropertyOrField(input, field.Name), "HasValue")), - new[] { input }).Compile()); + [input]).Compile()); } - else if (valueField.Type.GetTypeInfo().IsClass) + else if (valueField.Type.IsClass) { - if (!typeof(TValue).GetTypeInfo().IsAssignableFrom(field.FieldType)) continue; + if (!typeof(TValue).IsAssignableFrom(field.FieldType)) continue; this.isNull.Add( field.Name, Expression.Lambda>( Expression.Equal(Expression.PropertyOrField(input, field.Name), Expression.Constant(null)), - new[] { input }).Compile()); + [input]).Compile()); } else { - if (!typeof(TValue).GetTypeInfo().IsAssignableFrom(field.FieldType)) continue; + if (!typeof(TValue).IsAssignableFrom(field.FieldType)) continue; this.isNull.Add(field.Name, (TInput o) => true); } @@ -383,6 +383,6 @@ public IEnumerable GetEnumerable(TInput obj) } } - private static bool IsNullable(Type type) => type.GetTypeInfo().IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>); + private static bool IsNullable(Type type) => type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>); } } \ No newline at end of file diff --git a/Sources/Core/Microsoft.StreamProcessing/StreamableAPI/SelectExtensions.cs b/Sources/Core/Microsoft.StreamProcessing/StreamableAPI/SelectExtensions.cs index ec5c1ad36..50a42af6f 100644 --- a/Sources/Core/Microsoft.StreamProcessing/StreamableAPI/SelectExtensions.cs +++ b/Sources/Core/Microsoft.StreamProcessing/StreamableAPI/SelectExtensions.cs @@ -24,8 +24,8 @@ public static IStreamable Select( this IStreamable source, Expression> selector) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(selector); return source is IFusibleStreamable s && s.CanFuseSelect(selector, false, false) ? s.FuseSelect(selector) @@ -41,8 +41,8 @@ public static IStreamable Select( this IStreamable source, Expression> selector) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(selector); return source is IFusibleStreamable s && s.CanFuseSelect(selector, true, false) ? s.FuseSelect(selector) @@ -58,8 +58,8 @@ public static IStreamable SelectByKey( this IStreamable source, Expression> selector) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(selector); return source is IFusibleStreamable s && s.CanFuseSelect(selector, false, true) ? s.FuseSelectWithKey(selector) @@ -75,8 +75,8 @@ public static IStreamable SelectByKey( this IStreamable source, Expression> selector) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(selector); return source is IFusibleStreamable s && s.CanFuseSelect(selector, true, true) ? s.FuseSelectWithKey(selector) @@ -98,15 +98,15 @@ public static IStreamable Select( Expression> initializer, IDictionary>> newColumnFormulas = null) where TNew : new() { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(initializer, nameof(initializer)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(initializer); // Validate that the dictionary parameter references proper fields if (newColumnFormulas == null) newColumnFormulas = new Dictionary>>(); Type newType = typeof(TNew); foreach (var pair in newColumnFormulas) { - if (newType.GetTypeInfo().GetMember(pair.Key).Length == 0) throw new ArgumentException("Dictionary keys must refer to valid members of the destination type", nameof(newColumnFormulas)); + if (newType.GetMember(pair.Key).Length == 0) throw new ArgumentException("Dictionary keys must refer to valid members of the destination type", nameof(newColumnFormulas)); } if (!(initializer.Body is NewExpression newExpression)) throw new ArgumentException("Initializer must return a constructor expression.", nameof(initializer)); @@ -134,8 +134,8 @@ public static IStreamable Select( Expression> fieldSelector1, Expression> fieldInitializer1) where TNew : new() { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(initializer, nameof(initializer)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(initializer); // Validate that the field selector formulas are actually selector expressions if (fieldSelector1.Body.NodeType != ExpressionType.MemberAccess) @@ -174,8 +174,8 @@ public static IStreamable Select Expression> fieldSelector2, Expression> fieldInitializer2) where TNew : new() { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(initializer, nameof(initializer)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(initializer); // Validate that the field selector formulas are actually selector expressions if (fieldSelector1.Body.NodeType != ExpressionType.MemberAccess) @@ -204,25 +204,25 @@ private static Expression> CreateAdjustColumnsExpression o.Name) + oldType.GetFields(BindingFlags.Public | BindingFlags.Instance).Select(o => o.Name) .Union( - oldType.GetTypeInfo().GetProperties(BindingFlags.Public | BindingFlags.Instance).Where(p => p.GetIndexParameters().Length == 0).Select(o => o.Name)); + oldType.GetProperties(BindingFlags.Public | BindingFlags.Instance).Where(p => p.GetIndexParameters().Length == 0).Select(o => o.Name)); var newPublicFields = - newType.GetTypeInfo().GetFields(BindingFlags.Public | BindingFlags.Instance).Select(o => o.Name) + newType.GetFields(BindingFlags.Public | BindingFlags.Instance).Select(o => o.Name) .Union( - newType.GetTypeInfo().GetProperties(BindingFlags.Public | BindingFlags.Instance).Where(p => p.GetIndexParameters().Length == 0).Select(o => o.Name)); + newType.GetProperties(BindingFlags.Public | BindingFlags.Instance).Where(p => p.GetIndexParameters().Length == 0).Select(o => o.Name)); var fieldsInCommon = oldPublicFields.Intersect(newPublicFields).Except(newColumnFormulas.Keys); var commonFieldAssignments = fieldsInCommon.Select( - o => Expression.Bind(newType.GetTypeInfo().GetMember(o).Single(), Expression.PropertyOrField(inputParameter, o))); + o => Expression.Bind(newType.GetMember(o).Single(), Expression.PropertyOrField(inputParameter, o))); var newFieldAssignments = newColumnFormulas.Select( - o => Expression.Bind(newType.GetTypeInfo().GetMember(o.Key).Single(), o.Value.RemoveCastToObject().ReplaceParametersInBody(inputParameter))); + o => Expression.Bind(newType.GetMember(o.Key).Single(), o.Value.RemoveCastToObject().ReplaceParametersInBody(inputParameter))); var member = Expression.MemberInit(newExpression, commonFieldAssignments.Concat(newFieldAssignments).ToArray()); - var lambda = Expression.Lambda>(member, new ParameterExpression[] { inputParameter }); + var lambda = Expression.Lambda>(member, [inputParameter]); return lambda; } } diff --git a/Sources/Core/Microsoft.StreamProcessing/StreamableAPI/StreamableExtensions.cs b/Sources/Core/Microsoft.StreamProcessing/StreamableAPI/StreamableExtensions.cs index a574cba90..0d21b9bde 100644 --- a/Sources/Core/Microsoft.StreamProcessing/StreamableAPI/StreamableExtensions.cs +++ b/Sources/Core/Microsoft.StreamProcessing/StreamableAPI/StreamableExtensions.cs @@ -187,7 +187,7 @@ public static partial class Streamable internal static IStreamable ToEndEdgeFreeStream( this IStreamable stream) { - Invariant.IsNotNull(stream, nameof(stream)); + ArgumentNullException.ThrowIfNull(stream); return new EndEdgeFreeOutputStreamable(stream); } @@ -198,7 +198,7 @@ internal static IStreamable ToEndEdgeFreeStream PointAtEnd( this IStreamable stream) { - Invariant.IsNotNull(stream, nameof(stream)); + ArgumentNullException.ThrowIfNull(stream); return new PointAtEndStreamable(stream); } @@ -210,7 +210,7 @@ public static IStreamable ExtendLifetime( this IStreamable stream, long duration) { - Contract.Requires(stream != null); + ArgumentNullException.ThrowIfNull(stream); if (stream.Properties.IsConstantDuration) { var newDuration = duration + stream.Properties.ConstantDurationLength.Value; @@ -233,7 +233,7 @@ public static IStreamable ExtendLifetime( /// public static IConnectableStreamable Publish(this IStreamable source) { - Invariant.IsNotNull(source, nameof(source)); + ArgumentNullException.ThrowIfNull(source); return new ConnectableStreamable(source); } @@ -243,8 +243,8 @@ public static IConnectableStreamable Publish(thi /// public static IStreamable Multicast(this IStreamable source, Func, IStreamable> selector) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(selector); return new MulticastStreamable(source, selector); } @@ -254,8 +254,8 @@ public static IStreamable Multicast(this /// public static IStreamable[] Multicast(this IStreamable source, int outputCount) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsPositive(outputCount, nameof(outputCount)); + ArgumentNullException.ThrowIfNull(source); + ArgumentOutOfRangeException.ThrowIfNegativeOrZero(outputCount); return NWayMulticast.GenerateStreamableArray(source, outputCount); } @@ -265,9 +265,9 @@ public static IStreamable[] Multicast(this IStre /// public static IStreamable Multicast(this IStreamable sourceLeft, IStreamable sourceRight, Func, IStreamable, IStreamable> selector) { - Invariant.IsNotNull(sourceLeft, nameof(sourceLeft)); - Invariant.IsNotNull(sourceRight, nameof(sourceRight)); - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(sourceLeft); + ArgumentNullException.ThrowIfNull(sourceRight); + ArgumentNullException.ThrowIfNull(selector); return new BinaryMulticastStreamable(sourceLeft, sourceRight, selector); } @@ -277,7 +277,7 @@ public static IStreamable Multicast internal static IStreamable ColumnToRow(this IStreamable source) { - Invariant.IsNotNull(source, nameof(source)); + ArgumentNullException.ThrowIfNull(source); return !source.Properties.IsColumnar ? source @@ -289,7 +289,7 @@ internal static IStreamable ColumnToRow(this ISt /// internal static IStreamable RowToColumn(this IStreamable source) { - Invariant.IsNotNull(source, nameof(source)); + ArgumentNullException.ThrowIfNull(source); return source.Properties.IsColumnar ? source @@ -303,8 +303,8 @@ internal static IStreamable RowToColumn(this ISt /// The predicate to apply to all data in the stream public static IStreamable Where(this IStreamable source, Expression> predicate) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(predicate, nameof(predicate)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(predicate); return source is IFusibleStreamable s ? s.FuseWhere(predicate) @@ -319,7 +319,7 @@ public static IStreamable Chop( long offset, long period) { - Invariant.IsNotNull(source, nameof(source)); + ArgumentNullException.ThrowIfNull(source); return new BeatStreamable(source, offset, period); } @@ -331,8 +331,8 @@ public static IStreamable SelectMany( this IStreamable source, Expression>> selector) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(selector); return source is IFusibleStreamable s && s.CanFuseSelectMany(selector, false, false) ? s.FuseSelectMany(selector) @@ -346,8 +346,8 @@ public static IStreamable SelectMany( this IStreamable source, Expression>> selector) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(selector); return source is IFusibleStreamable s && s.CanFuseSelectMany(selector, true, false) ? s.FuseSelectMany(selector) @@ -361,8 +361,8 @@ public static IStreamable SelectManyByKey source, Expression>> selector) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(selector); return source is IFusibleStreamable s && s.CanFuseSelectMany(selector, false, true) ? s.FuseSelectManyWithKey(selector) @@ -376,8 +376,8 @@ public static IStreamable SelectManyByKey source, Expression>> selector) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(selector); return source is IFusibleStreamable s && s.CanFuseSelectMany(selector, true, true) ? s.FuseSelectManyWithKey(selector) @@ -392,9 +392,9 @@ public static IStreamable SelectMany> right, Expression> resultSelector) { - Invariant.IsNotNull(left, nameof(left)); - Invariant.IsNotNull(right, nameof(right)); - Invariant.IsNotNull(resultSelector, nameof(resultSelector)); + ArgumentNullException.ThrowIfNull(left); + ArgumentNullException.ThrowIfNull(right); + ArgumentNullException.ThrowIfNull(resultSelector); return new EquiJoinStreamable(left, right(Empty.Default), resultSelector); } @@ -410,7 +410,7 @@ public static IStreamable SelectMany public static IStreamable Stitch(this IStreamable source) { - Invariant.IsNotNull(source, nameof(source)); + ArgumentNullException.ThrowIfNull(source); return new StitchStreamable(source); } @@ -424,8 +424,8 @@ public static IStreamable Union( this IStreamable left, IStreamable right) { - Invariant.IsNotNull(left, nameof(left)); - Invariant.IsNotNull(right, nameof(right)); + ArgumentNullException.ThrowIfNull(left); + ArgumentNullException.ThrowIfNull(right); return new UnionStreamable(left, right); } @@ -477,11 +477,11 @@ public static IStreamable Join> resultSelector, OperationalHint joinOptions = OperationalHint.None) { - Invariant.IsNotNull(left, nameof(left)); - Invariant.IsNotNull(right, nameof(right)); - Invariant.IsNotNull(leftKeySelector, nameof(leftKeySelector)); - Invariant.IsNotNull(rightKeySelector, nameof(rightKeySelector)); - Invariant.IsNotNull(resultSelector, nameof(resultSelector)); + ArgumentNullException.ThrowIfNull(left); + ArgumentNullException.ThrowIfNull(right); + ArgumentNullException.ThrowIfNull(leftKeySelector); + ArgumentNullException.ThrowIfNull(rightKeySelector); + ArgumentNullException.ThrowIfNull(resultSelector); var map1 = left.Map(leftKeySelector); var map2 = right.Map(rightKeySelector); @@ -497,8 +497,8 @@ public static IStreamable Join( IStreamable right, Expression> resultSelector) { - Invariant.IsNotNull(left, nameof(left)); - Invariant.IsNotNull(right, nameof(right)); + ArgumentNullException.ThrowIfNull(left); + ArgumentNullException.ThrowIfNull(right); return new EquiJoinStreamable(left, right, resultSelector); } @@ -512,10 +512,10 @@ public static IStreamable WhereNotExists> leftKeySelector, Expression> rightKeySelector) { - Invariant.IsNotNull(left, nameof(left)); - Invariant.IsNotNull(right, nameof(right)); - Invariant.IsNotNull(leftKeySelector, nameof(leftKeySelector)); - Invariant.IsNotNull(rightKeySelector, nameof(rightKeySelector)); + ArgumentNullException.ThrowIfNull(left); + ArgumentNullException.ThrowIfNull(right); + ArgumentNullException.ThrowIfNull(leftKeySelector); + ArgumentNullException.ThrowIfNull(rightKeySelector); var map1 = left.Map(leftKeySelector); var map2 = right.Map(rightKeySelector); @@ -534,8 +534,8 @@ public static IStreamable WhereNotExists( this IStreamable left, IStreamable right) { - Invariant.IsNotNull(left, nameof(left)); - Invariant.IsNotNull(right, nameof(right)); + ArgumentNullException.ThrowIfNull(left); + ArgumentNullException.ThrowIfNull(right); return new LeftAntiSemiJoinStreamable(left, right); } @@ -548,8 +548,8 @@ public static IStreamable ClipEventDuration source, IStreamable clip) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(clip, nameof(clip)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(clip); return new ClipJoinStreamable(source, clip); } @@ -565,10 +565,10 @@ public static IStreamable ClipEventDuration> leftKeySelector, Expression> rightKeySelector) { - Invariant.IsNotNull(left, nameof(left)); - Invariant.IsNotNull(right, nameof(right)); - Invariant.IsNotNull(leftKeySelector, nameof(leftKeySelector)); - Invariant.IsNotNull(rightKeySelector, nameof(rightKeySelector)); + ArgumentNullException.ThrowIfNull(left); + ArgumentNullException.ThrowIfNull(right); + ArgumentNullException.ThrowIfNull(leftKeySelector); + ArgumentNullException.ThrowIfNull(rightKeySelector); var map1 = left.Map(leftKeySelector); var map2 = right.Map(rightKeySelector); @@ -590,8 +590,8 @@ public static IStreamable GroupApply, TPayload>, IStreamable, TBind>> applyFunc, Expression, TBind, TResult>> resultSelector) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(keySelector, nameof(keySelector)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(keySelector); return source.Map(keySelector).Reduce(applyFunc, resultSelector); } @@ -612,8 +612,8 @@ public static IMapDefinition this IStreamable source, Expression> keySelector) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(keySelector, nameof(keySelector)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(keySelector); return new MapDefinition(source, null, (a, b) => a, keySelector); } @@ -626,9 +626,9 @@ public static IStreamable SelectMany, TResult>, IStreamable, TBind>> apply, Expression, TBind, TOutput>> resultSelector) { - Invariant.IsNotNull(groupDefinition, nameof(groupDefinition)); - Invariant.IsNotNull(apply, nameof(apply)); - Invariant.IsNotNull(resultSelector, nameof(resultSelector)); + ArgumentNullException.ThrowIfNull(groupDefinition); + ArgumentNullException.ThrowIfNull(apply); + ArgumentNullException.ThrowIfNull(resultSelector); return ((MapDefinition)groupDefinition).CreateStreamable(apply, resultSelector); } @@ -720,8 +720,8 @@ public static IStreamable CountNotNull( this IStreamable source, Expression> selector) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(selector); return source.Aggregate(w => w.CountNotNull(selector)); } @@ -739,8 +739,8 @@ public static IStreamable Min( this IStreamable source, Expression> selector) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(selector); return source.Aggregate(w => w.Min(selector)); } @@ -751,8 +751,8 @@ public static IStreamable Min( this IStreamable source, Expression> comparer) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(comparer, nameof(comparer)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(comparer); return source.Aggregate(w => w.Min(v => v, new ComparerExpression(comparer))); } @@ -764,9 +764,9 @@ public static IStreamable Min( Expression> selector, Expression> comparer) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(selector, nameof(selector)); - Invariant.IsNotNull(comparer, nameof(comparer)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(selector); + ArgumentNullException.ThrowIfNull(comparer); return source.Aggregate(w => w.Min(selector, new ComparerExpression(comparer))); } @@ -784,8 +784,8 @@ public static IStreamable Max( this IStreamable source, Expression> selector) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(selector); return source.Aggregate(w => w.Max(selector)); } @@ -796,8 +796,8 @@ public static IStreamable Max( this IStreamable source, Expression> comparer) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(comparer, nameof(comparer)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(comparer); return source.Aggregate(w => w.Max(v => v, new ComparerExpression(comparer))); } @@ -809,9 +809,9 @@ public static IStreamable Max( Expression> selector, Expression> comparer) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(selector, nameof(selector)); - Invariant.IsNotNull(comparer, nameof(comparer)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(selector); + ArgumentNullException.ThrowIfNull(comparer); return source.Aggregate(w => w.Max(selector, new ComparerExpression(comparer))); } @@ -822,8 +822,8 @@ public static IStreamable>> TopK source, int k) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsPositive(k, nameof(k)); + ArgumentNullException.ThrowIfNull(source); + ArgumentOutOfRangeException.ThrowIfNegativeOrZero(k); return source.Aggregate(w => w.TopK(v => v, k)); } @@ -835,9 +835,9 @@ public static IStreamable>> TopK> selector, int k) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(selector, nameof(selector)); - Invariant.IsPositive(k, nameof(k)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(selector); + ArgumentOutOfRangeException.ThrowIfNegativeOrZero(k); return source.Aggregate(w => w.TopK(selector, k)); } @@ -849,9 +849,9 @@ public static IStreamable>> TopK> comparer, int k) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(comparer, nameof(comparer)); - Invariant.IsPositive(k, nameof(k)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(comparer); + ArgumentOutOfRangeException.ThrowIfNegativeOrZero(k); return source.Aggregate(w => w.TopK(v => v, new ComparerExpression(comparer), k)); } @@ -864,10 +864,10 @@ public static IStreamable>> TopK> comparer, int k) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(selector, nameof(selector)); - Invariant.IsNotNull(comparer, nameof(comparer)); - Invariant.IsPositive(k, nameof(k)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(selector); + ArgumentNullException.ThrowIfNull(comparer); + ArgumentOutOfRangeException.ThrowIfNegativeOrZero(k); return source.Aggregate(w => w.TopK(selector, new ComparerExpression(comparer), k)); } #endregion @@ -881,8 +881,8 @@ public static IStreamable Aggregate source, Func, IAggregate> aggregate) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(aggregate, nameof(aggregate)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(aggregate); return new SnapshotWindowStreamable(source, aggregate(new Window(source.Properties))); } @@ -894,9 +894,9 @@ internal static IStreamable Aggregate right, Func, Window, IBinaryAggregate> aggregate) { - Invariant.IsNotNull(left, nameof(left)); - Invariant.IsNotNull(right, nameof(right)); - Invariant.IsNotNull(aggregate, nameof(aggregate)); + ArgumentNullException.ThrowIfNull(left); + ArgumentNullException.ThrowIfNull(right); + ArgumentNullException.ThrowIfNull(aggregate); var source = left.Select(o => new DiscriminatedUnion { Left = o, isLeft = true }) .Union(right.Select(o => new DiscriminatedUnion { Right = o, isLeft = false })); @@ -911,8 +911,8 @@ internal static IStreamable Aggregate source, IAggregate aggregate) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(aggregate, nameof(aggregate)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(aggregate); return new SnapshotWindowStreamable(source, aggregate); } @@ -924,9 +924,9 @@ internal static IStreamable Aggregate right, IBinaryAggregate aggregate) { - Invariant.IsNotNull(left, nameof(left)); - Invariant.IsNotNull(right, nameof(right)); - Invariant.IsNotNull(aggregate, nameof(aggregate)); + ArgumentNullException.ThrowIfNull(left); + ArgumentNullException.ThrowIfNull(right); + ArgumentNullException.ThrowIfNull(aggregate); var source = left.Select(o => new DiscriminatedUnion { Left = o, isLeft = true }) .Union(right.Select(o => new DiscriminatedUnion { Right = o, isLeft = false })); @@ -958,8 +958,8 @@ public static IStreamable LeftOuterJoin> outerResultSelector, Expression> innerResultSelector) { - Invariant.IsNotNull(left, nameof(left)); - Invariant.IsNotNull(right, nameof(right)); + ArgumentNullException.ThrowIfNull(left); + ArgumentNullException.ThrowIfNull(right); return left.Multicast(right, (l_mc, r_mc) => { @@ -994,8 +994,8 @@ public static IStreamable FullOuterJoin> rightResultSelector, Expression> innerResultSelector) { - Invariant.IsNotNull(left, nameof(left)); - Invariant.IsNotNull(right, nameof(right)); + ArgumentNullException.ThrowIfNull(left); + ArgumentNullException.ThrowIfNull(right); return left.Multicast(right, (l_mc, r_mc) => { @@ -1026,14 +1026,14 @@ public static IStreamable WhereNotExists> rightKeySelector, Expression> postPredicate) { - Invariant.IsNotNull(left, nameof(left)); - Invariant.IsNotNull(right, nameof(right)); + ArgumentNullException.ThrowIfNull(left); + ArgumentNullException.ThrowIfNull(right); var e1 = Expression.Parameter(typeof(StructTuple), "e1"); var postPredicateTransformed = Expression.Lambda, bool>> ( Expression.Invoke(postPredicate, Expression.Field(e1, "Item1"), Expression.Field(e1, "Item2")), - new ParameterExpression[] { e1 }); + [e1]); var leftMC = left.Multicast(2); @@ -1071,8 +1071,8 @@ public static IStreamable LeftOuterJoin> outerResultSelector, Expression> innerResultSelector) { - Invariant.IsNotNull(left, nameof(left)); - Invariant.IsNotNull(right, nameof(right)); + ArgumentNullException.ThrowIfNull(left); + ArgumentNullException.ThrowIfNull(right); Expression, bool>> postPredicateTemplate = st => CallInliner.Call(postPredicate, st.Item1, st.Item2); @@ -1111,7 +1111,7 @@ public static IStreamable Sessionize> sessionKey, Expression> sessionResultSelector) { - Invariant.IsNotNull(sessionStream, nameof(sessionStream)); + ArgumentNullException.ThrowIfNull(sessionStream); return sessionStream.GroupApply( sessionKey, @@ -1135,7 +1135,7 @@ public static IStreamable Sessionize Distinct( this IStreamable source) { - Invariant.IsNotNull(source, nameof(source)); + ArgumentNullException.ThrowIfNull(source); return source.GroupApply(e => e, apply => apply.Count(), (g, c) => g.Key); } @@ -1154,8 +1154,8 @@ public static IStreamable Distinct( this IStreamable source, Expression> selector) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(selector); return source.GroupApply(selector, apply => apply.Aggregate(w => w.Count()), (g, c) => g.Key); } @@ -1171,7 +1171,7 @@ internal static IStreamable ScaledOutCount(this ISt public static IStreamable Validate( this IStreamable source) { - Invariant.IsNotNull(source, nameof(source)); + ArgumentNullException.ThrowIfNull(source); return new VerifyPropertiesStreamable(source); } #endif diff --git a/Sources/Core/Microsoft.StreamProcessing/StreamableAPI/StreamableExtensionsTemplate.cs b/Sources/Core/Microsoft.StreamProcessing/StreamableAPI/StreamableExtensionsTemplate.cs index ba49940a2..3a52cf028 100644 --- a/Sources/Core/Microsoft.StreamProcessing/StreamableAPI/StreamableExtensionsTemplate.cs +++ b/Sources/Core/Microsoft.StreamProcessing/StreamableAPI/StreamableExtensionsTemplate.cs @@ -24,8 +24,8 @@ public static partial class Streamable /// A stream of data whose payloads have been summed acccording to snapshot semanics. public static IStreamable Sum(this IStreamable source, Expression> selector) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(selector); return source.Aggregate(w => w.Sum(selector)); } @@ -39,8 +39,8 @@ public static IStreamable Sum(this IStreamableA stream of data whose payloads have been summed acccording to snapshot semanics. public static IStreamable Sum(this IStreamable source, Expression> selector) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(selector); return source.Aggregate(w => w.Sum(selector)); } @@ -54,8 +54,8 @@ public static IStreamable Sum(this IStreamableA stream of data whose payloads have been summed acccording to snapshot semanics. public static IStreamable Sum(this IStreamable source, Expression> selector) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(selector); return source.Aggregate(w => w.Sum(selector)); } @@ -69,8 +69,8 @@ public static IStreamable Sum(this IStreamableA stream of data whose payloads have been summed acccording to snapshot semanics. public static IStreamable Sum(this IStreamable source, Expression> selector) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(selector); return source.Aggregate(w => w.Sum(selector)); } @@ -84,8 +84,8 @@ public static IStreamable Sum(this IStreamableA stream of data whose payloads have been summed acccording to snapshot semanics. public static IStreamable Sum(this IStreamable source, Expression> selector) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(selector); return source.Aggregate(w => w.Sum(selector)); } @@ -99,8 +99,8 @@ public static IStreamable Sum(this IStreamableA stream of data whose payloads have been summed acccording to snapshot semanics. public static IStreamable Sum(this IStreamable source, Expression> selector) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(selector); return source.Aggregate(w => w.Sum(selector)); } @@ -114,8 +114,8 @@ public static IStreamable Sum(this IStreamableA stream of data whose payloads have been summed acccording to snapshot semanics. public static IStreamable Sum(this IStreamable source, Expression> selector) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(selector); return source.Aggregate(w => w.Sum(selector)); } @@ -129,8 +129,8 @@ public static IStreamable Sum(this IStreamableA stream of data whose payloads have been summed acccording to snapshot semanics. public static IStreamable Sum(this IStreamable source, Expression> selector) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(selector); return source.Aggregate(w => w.Sum(selector)); } @@ -144,8 +144,8 @@ public static IStreamable Sum(this IStreamableA stream of data whose payloads have been summed acccording to snapshot semanics. public static IStreamable Sum(this IStreamable source, Expression> selector) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(selector); return source.Aggregate(w => w.Sum(selector)); } @@ -159,8 +159,8 @@ public static IStreamable Sum(this IStreamableA stream of data whose payloads have been summed acccording to snapshot semanics. public static IStreamable Sum(this IStreamable source, Expression> selector) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(selector); return source.Aggregate(w => w.Sum(selector)); } @@ -174,8 +174,8 @@ public static IStreamable Sum(this IStreamableA stream of data whose payloads have been summed acccording to snapshot semanics. public static IStreamable Sum(this IStreamable source, Expression> selector) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(selector); return source.Aggregate(w => w.Sum(selector)); } @@ -189,8 +189,8 @@ public static IStreamable Sum(this IStreamableA stream of data whose payloads have been summed acccording to snapshot semanics. public static IStreamable Sum(this IStreamable source, Expression> selector) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(selector); return source.Aggregate(w => w.Sum(selector)); } @@ -204,8 +204,8 @@ public static IStreamable Sum(this IStreamable /// A stream of data whose payloads have been summed acccording to snapshot semanics. public static IStreamable Sum(this IStreamable source, Expression> selector) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(selector); return source.Aggregate(w => w.Sum(selector)); } @@ -220,8 +220,8 @@ public static IStreamable Sum(this IStreamableA stream of data whose payloads have been summed acccording to snapshot semanics. public static IStreamable Sum(this IStreamable source, Expression> selector) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(selector); return source.Aggregate(w => w.Sum(selector)); } @@ -236,8 +236,8 @@ public static IStreamable Sum(this IStreamableA stream of data whose payloads have been summed acccording to snapshot semanics. public static IStreamable Sum(this IStreamable source, Expression> selector) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(selector); return source.Aggregate(w => w.Sum(selector)); } @@ -252,8 +252,8 @@ public static IStreamable Sum(this IStreamableA stream of data whose payloads have been summed acccording to snapshot semanics. public static IStreamable Sum(this IStreamable source, Expression> selector) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(selector); return source.Aggregate(w => w.Sum(selector)); } @@ -268,8 +268,8 @@ public static IStreamable Sum(this IStreamableA stream of data whose payloads have been summed acccording to snapshot semanics. public static IStreamable Sum(this IStreamable source, Expression> selector) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(selector); return source.Aggregate(w => w.Sum(selector)); } @@ -284,8 +284,8 @@ public static IStreamable Sum(this IStreamableA stream of data whose payloads have been summed acccording to snapshot semanics. public static IStreamable Sum(this IStreamable source, Expression> selector) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(selector); return source.Aggregate(w => w.Sum(selector)); } @@ -300,8 +300,8 @@ public static IStreamable Sum(this IStreamableA stream of data whose payloads have been summed acccording to snapshot semanics. public static IStreamable Sum(this IStreamable source, Expression> selector) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(selector); return source.Aggregate(w => w.Sum(selector)); } @@ -316,8 +316,8 @@ public static IStreamable Sum(this IStreamableA stream of data whose payloads have been summed acccording to snapshot semanics. public static IStreamable Sum(this IStreamable source, Expression> selector) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(selector); return source.Aggregate(w => w.Sum(selector)); } @@ -332,8 +332,8 @@ public static IStreamable Sum(this IStreamableA stream of data whose payloads have been summed acccording to snapshot semanics. public static IStreamable Sum(this IStreamable source, Expression> selector) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(selector); return source.Aggregate(w => w.Sum(selector)); } @@ -348,8 +348,8 @@ public static IStreamable Sum(this IStreamableA stream of data whose payloads have been summed acccording to snapshot semanics. public static IStreamable Sum(this IStreamable source, Expression> selector) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(selector); return source.Aggregate(w => w.Sum(selector)); } @@ -364,8 +364,8 @@ public static IStreamable Sum(this IStreamableA stream of data whose payloads have been summed acccording to snapshot semanics. public static IStreamable Sum(this IStreamable source, Expression> selector) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(selector); return source.Aggregate(w => w.Sum(selector)); } @@ -380,8 +380,8 @@ public static IStreamable Sum(this IStreamableA stream of data whose payloads have been summed acccording to snapshot semanics. public static IStreamable Sum(this IStreamable source, Expression> selector) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(selector); return source.Aggregate(w => w.Sum(selector)); } @@ -396,8 +396,8 @@ public static IStreamable Sum(this IStreamableA stream of data whose payloads have been summed acccording to snapshot semanics. public static IStreamable Sum(this IStreamable source, Expression> selector) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(selector); return source.Aggregate(w => w.Sum(selector)); } @@ -412,8 +412,8 @@ public static IStreamable Sum(this IStreamable /// A stream of data whose payloads have been summed acccording to snapshot semanics. public static IStreamable Sum(this IStreamable source, Expression> selector) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(selector); return source.Aggregate(w => w.Sum(selector)); } @@ -427,8 +427,8 @@ public static IStreamable Sum(this IStreamableA stream of data whose payloads have had its squares summed acccording to snapshot semanics. public static IStreamable SumSquares(this IStreamable source, Expression> selector) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(selector); return source.Aggregate(w => w.SumSquares(selector)); } @@ -442,8 +442,8 @@ public static IStreamable SumSquares(this IStreamab /// A stream of data whose payloads have had its squares summed acccording to snapshot semanics. public static IStreamable SumSquares(this IStreamable source, Expression> selector) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(selector); return source.Aggregate(w => w.SumSquares(selector)); } @@ -457,8 +457,8 @@ public static IStreamable SumSquares(this IStreamabl /// A stream of data whose payloads have had its squares summed acccording to snapshot semanics. public static IStreamable SumSquares(this IStreamable source, Expression> selector) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(selector); return source.Aggregate(w => w.SumSquares(selector)); } @@ -472,8 +472,8 @@ public static IStreamable SumSquares(this IStreamab /// A stream of data whose payloads have had its squares summed acccording to snapshot semanics. public static IStreamable SumSquares(this IStreamable source, Expression> selector) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(selector); return source.Aggregate(w => w.SumSquares(selector)); } @@ -487,8 +487,8 @@ public static IStreamable SumSquares(this IStreama /// A stream of data whose payloads have had its squares summed acccording to snapshot semanics. public static IStreamable SumSquares(this IStreamable source, Expression> selector) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(selector); return source.Aggregate(w => w.SumSquares(selector)); } @@ -502,8 +502,8 @@ public static IStreamable SumSquares(this IStreamable /// A stream of data whose payloads have had its squares summed acccording to snapshot semanics. public static IStreamable SumSquares(this IStreamable source, Expression> selector) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(selector); return source.Aggregate(w => w.SumSquares(selector)); } @@ -517,8 +517,8 @@ public static IStreamable SumSquares(this IStreamabl /// A stream of data whose payloads have had its squares summed acccording to snapshot semanics. public static IStreamable SumSquares(this IStreamable source, Expression> selector) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(selector); return source.Aggregate(w => w.SumSquares(selector)); } @@ -532,8 +532,8 @@ public static IStreamable SumSquares(this IStreamabl /// A stream of data whose payloads have had its squares summed acccording to snapshot semanics. public static IStreamable SumSquares(this IStreamable source, Expression> selector) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(selector); return source.Aggregate(w => w.SumSquares(selector)); } @@ -547,8 +547,8 @@ public static IStreamable SumSquares(this IStreamab /// A stream of data whose payloads have had its squares summed acccording to snapshot semanics. public static IStreamable SumSquares(this IStreamable source, Expression> selector) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(selector); return source.Aggregate(w => w.SumSquares(selector)); } @@ -562,8 +562,8 @@ public static IStreamable SumSquares(this IStreamab /// A stream of data whose payloads have had its squares summed acccording to snapshot semanics. public static IStreamable SumSquares(this IStreamable source, Expression> selector) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(selector); return source.Aggregate(w => w.SumSquares(selector)); } @@ -577,8 +577,8 @@ public static IStreamable SumSquares(this IStreama /// A stream of data whose payloads have had its squares summed acccording to snapshot semanics. public static IStreamable SumSquares(this IStreamable source, Expression> selector) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(selector); return source.Aggregate(w => w.SumSquares(selector)); } @@ -592,8 +592,8 @@ public static IStreamable SumSquares(this IStream /// A stream of data whose payloads have had its squares summed acccording to snapshot semanics. public static IStreamable SumSquares(this IStreamable source, Expression> selector) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(selector); return source.Aggregate(w => w.SumSquares(selector)); } @@ -607,8 +607,8 @@ public static IStreamable SumSquares(this IStr /// A stream of data whose payloads have had its squares summed acccording to snapshot semanics. public static IStreamable SumSquares(this IStreamable source, Expression> selector) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(selector); return source.Aggregate(w => w.SumSquares(selector)); } @@ -623,8 +623,8 @@ public static IStreamable SumSquares(this IStream /// A stream of data whose payloads have had its squares summed acccording to snapshot semanics. public static IStreamable SumSquares(this IStreamable source, Expression> selector) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(selector); return source.Aggregate(w => w.SumSquares(selector)); } @@ -639,8 +639,8 @@ public static IStreamable SumSquares(this IStreamab /// A stream of data whose payloads have had its squares summed acccording to snapshot semanics. public static IStreamable SumSquares(this IStreamable source, Expression> selector) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(selector); return source.Aggregate(w => w.SumSquares(selector)); } @@ -655,8 +655,8 @@ public static IStreamable SumSquares(this IStreamabl /// A stream of data whose payloads have had its squares summed acccording to snapshot semanics. public static IStreamable SumSquares(this IStreamable source, Expression> selector) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(selector); return source.Aggregate(w => w.SumSquares(selector)); } @@ -671,8 +671,8 @@ public static IStreamable SumSquares(this IStreamab /// A stream of data whose payloads have had its squares summed acccording to snapshot semanics. public static IStreamable SumSquares(this IStreamable source, Expression> selector) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(selector); return source.Aggregate(w => w.SumSquares(selector)); } @@ -687,8 +687,8 @@ public static IStreamable SumSquares(this IStreama /// A stream of data whose payloads have had its squares summed acccording to snapshot semanics. public static IStreamable SumSquares(this IStreamable source, Expression> selector) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(selector); return source.Aggregate(w => w.SumSquares(selector)); } @@ -703,8 +703,8 @@ public static IStreamable SumSquares(this IStreamable /// A stream of data whose payloads have had its squares summed acccording to snapshot semanics. public static IStreamable SumSquares(this IStreamable source, Expression> selector) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(selector); return source.Aggregate(w => w.SumSquares(selector)); } @@ -719,8 +719,8 @@ public static IStreamable SumSquares(this IStreamabl /// A stream of data whose payloads have had its squares summed acccording to snapshot semanics. public static IStreamable SumSquares(this IStreamable source, Expression> selector) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(selector); return source.Aggregate(w => w.SumSquares(selector)); } @@ -735,8 +735,8 @@ public static IStreamable SumSquares(this IStreamabl /// A stream of data whose payloads have had its squares summed acccording to snapshot semanics. public static IStreamable SumSquares(this IStreamable source, Expression> selector) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(selector); return source.Aggregate(w => w.SumSquares(selector)); } @@ -751,8 +751,8 @@ public static IStreamable SumSquares(this IStreamab /// A stream of data whose payloads have had its squares summed acccording to snapshot semanics. public static IStreamable SumSquares(this IStreamable source, Expression> selector) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(selector); return source.Aggregate(w => w.SumSquares(selector)); } @@ -767,8 +767,8 @@ public static IStreamable SumSquares(this IStreamab /// A stream of data whose payloads have had its squares summed acccording to snapshot semanics. public static IStreamable SumSquares(this IStreamable source, Expression> selector) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(selector); return source.Aggregate(w => w.SumSquares(selector)); } @@ -783,8 +783,8 @@ public static IStreamable SumSquares(this IStreama /// A stream of data whose payloads have had its squares summed acccording to snapshot semanics. public static IStreamable SumSquares(this IStreamable source, Expression> selector) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(selector); return source.Aggregate(w => w.SumSquares(selector)); } @@ -799,8 +799,8 @@ public static IStreamable SumSquares(this IStream /// A stream of data whose payloads have had its squares summed acccording to snapshot semanics. public static IStreamable SumSquares(this IStreamable source, Expression> selector) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(selector); return source.Aggregate(w => w.SumSquares(selector)); } @@ -815,8 +815,8 @@ public static IStreamable SumSquares(this IStr /// A stream of data whose payloads have had its squares summed acccording to snapshot semanics. public static IStreamable SumSquares(this IStreamable source, Expression> selector) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(selector); return source.Aggregate(w => w.SumSquares(selector)); } @@ -830,8 +830,8 @@ public static IStreamable SumSquares(this IStream /// A stream of data whose payloads have been multiplied acccording to snapshot semanics. public static IStreamable Product(this IStreamable source, Expression> selector) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(selector); return source.Aggregate(w => w.Product(selector)); } @@ -845,8 +845,8 @@ public static IStreamable Product(this IStreamable< /// A stream of data whose payloads have been multiplied acccording to snapshot semanics. public static IStreamable Product(this IStreamable source, Expression> selector) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(selector); return source.Aggregate(w => w.Product(selector)); } @@ -860,8 +860,8 @@ public static IStreamable Product(this IStreamableA stream of data whose payloads have been multiplied acccording to snapshot semanics. public static IStreamable Product(this IStreamable source, Expression> selector) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(selector); return source.Aggregate(w => w.Product(selector)); } @@ -875,8 +875,8 @@ public static IStreamable Product(this IStreamable< /// A stream of data whose payloads have been multiplied acccording to snapshot semanics. public static IStreamable Product(this IStreamable source, Expression> selector) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(selector); return source.Aggregate(w => w.Product(selector)); } @@ -890,8 +890,8 @@ public static IStreamable Product(this IStreamable /// A stream of data whose payloads have been multiplied acccording to snapshot semanics. public static IStreamable Product(this IStreamable source, Expression> selector) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(selector); return source.Aggregate(w => w.Product(selector)); } @@ -905,8 +905,8 @@ public static IStreamable Product(this IStreamableA stream of data whose payloads have been multiplied acccording to snapshot semanics. public static IStreamable Product(this IStreamable source, Expression> selector) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(selector); return source.Aggregate(w => w.Product(selector)); } @@ -920,8 +920,8 @@ public static IStreamable Product(this IStreamableA stream of data whose payloads have been multiplied acccording to snapshot semanics. public static IStreamable Product(this IStreamable source, Expression> selector) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(selector); return source.Aggregate(w => w.Product(selector)); } @@ -935,8 +935,8 @@ public static IStreamable Product(this IStreamableA stream of data whose payloads have been multiplied acccording to snapshot semanics. public static IStreamable Product(this IStreamable source, Expression> selector) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(selector); return source.Aggregate(w => w.Product(selector)); } @@ -950,8 +950,8 @@ public static IStreamable Product(this IStreamable< /// A stream of data whose payloads have been multiplied acccording to snapshot semanics. public static IStreamable Product(this IStreamable source, Expression> selector) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(selector); return source.Aggregate(w => w.Product(selector)); } @@ -965,8 +965,8 @@ public static IStreamable Product(this IStreamable< /// A stream of data whose payloads have been multiplied acccording to snapshot semanics. public static IStreamable Product(this IStreamable source, Expression> selector) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(selector); return source.Aggregate(w => w.Product(selector)); } @@ -980,8 +980,8 @@ public static IStreamable Product(this IStreamable /// A stream of data whose payloads have been multiplied acccording to snapshot semanics. public static IStreamable Product(this IStreamable source, Expression> selector) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(selector); return source.Aggregate(w => w.Product(selector)); } @@ -995,8 +995,8 @@ public static IStreamable Product(this IStreamabl /// A stream of data whose payloads have been multiplied acccording to snapshot semanics. public static IStreamable Product(this IStreamable source, Expression> selector) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(selector); return source.Aggregate(w => w.Product(selector)); } @@ -1010,8 +1010,8 @@ public static IStreamable Product(this IStream /// A stream of data whose payloads have been multiplied acccording to snapshot semanics. public static IStreamable Product(this IStreamable source, Expression> selector) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(selector); return source.Aggregate(w => w.Product(selector)); } @@ -1026,8 +1026,8 @@ public static IStreamable Product(this IStreamabl /// A stream of data whose payloads have been multiplied acccording to snapshot semanics. public static IStreamable Product(this IStreamable source, Expression> selector) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(selector); return source.Aggregate(w => w.Product(selector)); } @@ -1042,8 +1042,8 @@ public static IStreamable Product(this IStreamable< /// A stream of data whose payloads have been multiplied acccording to snapshot semanics. public static IStreamable Product(this IStreamable source, Expression> selector) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(selector); return source.Aggregate(w => w.Product(selector)); } @@ -1058,8 +1058,8 @@ public static IStreamable Product(this IStreamableA stream of data whose payloads have been multiplied acccording to snapshot semanics. public static IStreamable Product(this IStreamable source, Expression> selector) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(selector); return source.Aggregate(w => w.Product(selector)); } @@ -1074,8 +1074,8 @@ public static IStreamable Product(this IStreamable< /// A stream of data whose payloads have been multiplied acccording to snapshot semanics. public static IStreamable Product(this IStreamable source, Expression> selector) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(selector); return source.Aggregate(w => w.Product(selector)); } @@ -1090,8 +1090,8 @@ public static IStreamable Product(this IStreamable /// A stream of data whose payloads have been multiplied acccording to snapshot semanics. public static IStreamable Product(this IStreamable source, Expression> selector) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(selector); return source.Aggregate(w => w.Product(selector)); } @@ -1106,8 +1106,8 @@ public static IStreamable Product(this IStreamableA stream of data whose payloads have been multiplied acccording to snapshot semanics. public static IStreamable Product(this IStreamable source, Expression> selector) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(selector); return source.Aggregate(w => w.Product(selector)); } @@ -1122,8 +1122,8 @@ public static IStreamable Product(this IStreamableA stream of data whose payloads have been multiplied acccording to snapshot semanics. public static IStreamable Product(this IStreamable source, Expression> selector) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(selector); return source.Aggregate(w => w.Product(selector)); } @@ -1138,8 +1138,8 @@ public static IStreamable Product(this IStreamableA stream of data whose payloads have been multiplied acccording to snapshot semanics. public static IStreamable Product(this IStreamable source, Expression> selector) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(selector); return source.Aggregate(w => w.Product(selector)); } @@ -1154,8 +1154,8 @@ public static IStreamable Product(this IStreamable< /// A stream of data whose payloads have been multiplied acccording to snapshot semanics. public static IStreamable Product(this IStreamable source, Expression> selector) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(selector); return source.Aggregate(w => w.Product(selector)); } @@ -1170,8 +1170,8 @@ public static IStreamable Product(this IStreamable< /// A stream of data whose payloads have been multiplied acccording to snapshot semanics. public static IStreamable Product(this IStreamable source, Expression> selector) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(selector); return source.Aggregate(w => w.Product(selector)); } @@ -1186,8 +1186,8 @@ public static IStreamable Product(this IStreamable /// A stream of data whose payloads have been multiplied acccording to snapshot semanics. public static IStreamable Product(this IStreamable source, Expression> selector) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(selector); return source.Aggregate(w => w.Product(selector)); } @@ -1202,8 +1202,8 @@ public static IStreamable Product(this IStreamabl /// A stream of data whose payloads have been multiplied acccording to snapshot semanics. public static IStreamable Product(this IStreamable source, Expression> selector) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(selector); return source.Aggregate(w => w.Product(selector)); } @@ -1218,8 +1218,8 @@ public static IStreamable Product(this IStream /// A stream of data whose payloads have been multiplied acccording to snapshot semanics. public static IStreamable Product(this IStreamable source, Expression> selector) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(selector); return source.Aggregate(w => w.Product(selector)); } @@ -1234,8 +1234,8 @@ public static IStreamable Product(this IStreamabl /// A stream of data whose payloads have been averaged acccording to snapshot semanics. public static IStreamable Average(this IStreamable source, Expression> selector) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(selector); return source.Aggregate(w => w.Average(selector)); } @@ -1250,8 +1250,8 @@ public static IStreamable Average(this IStreamable /// A stream of data whose payloads have been averaged acccording to snapshot semanics. public static IStreamable Average(this IStreamable source, Expression> selector) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(selector); return source.Aggregate(w => w.Average(selector)); } @@ -1266,8 +1266,8 @@ public static IStreamable Average(this IStreamable /// A stream of data whose payloads have been averaged acccording to snapshot semanics. public static IStreamable Average(this IStreamable source, Expression> selector) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(selector); return source.Aggregate(w => w.Average(selector)); } @@ -1282,8 +1282,8 @@ public static IStreamable Average(this IStreamable /// A stream of data whose payloads have been averaged acccording to snapshot semanics. public static IStreamable Average(this IStreamable source, Expression> selector) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(selector); return source.Aggregate(w => w.Average(selector)); } @@ -1298,8 +1298,8 @@ public static IStreamable Average(this IStreamable /// A stream of data whose payloads have been averaged acccording to snapshot semanics. public static IStreamable Average(this IStreamable source, Expression> selector) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(selector); return source.Aggregate(w => w.Average(selector)); } @@ -1314,8 +1314,8 @@ public static IStreamable Average(this IStreamable /// A stream of data whose payloads have been averaged acccording to snapshot semanics. public static IStreamable Average(this IStreamable source, Expression> selector) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(selector); return source.Aggregate(w => w.Average(selector)); } @@ -1330,8 +1330,8 @@ public static IStreamable Average(this IStreamable /// A stream of data whose payloads have been averaged acccording to snapshot semanics. public static IStreamable Average(this IStreamable source, Expression> selector) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(selector); return source.Aggregate(w => w.Average(selector)); } @@ -1346,8 +1346,8 @@ public static IStreamable Average(this IStreamable /// A stream of data whose payloads have been averaged acccording to snapshot semanics. public static IStreamable Average(this IStreamable source, Expression> selector) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(selector); return source.Aggregate(w => w.Average(selector)); } @@ -1362,8 +1362,8 @@ public static IStreamable Average(this IStreamable /// A stream of data whose payloads have been averaged acccording to snapshot semanics. public static IStreamable Average(this IStreamable source, Expression> selector) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(selector); return source.Aggregate(w => w.Average(selector)); } @@ -1378,8 +1378,8 @@ public static IStreamable Average(this IStreamable< /// A stream of data whose payloads have been averaged acccording to snapshot semanics. public static IStreamable Average(this IStreamable source, Expression> selector) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(selector); return source.Aggregate(w => w.Average(selector)); } @@ -1394,8 +1394,8 @@ public static IStreamable Average(this IStreamable /// A stream of data whose payloads have been averaged acccording to snapshot semanics. public static IStreamable Average(this IStreamable source, Expression> selector) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(selector); return source.Aggregate(w => w.Average(selector)); } @@ -1410,8 +1410,8 @@ public static IStreamable Average(this IStreamabl /// A stream of data whose payloads have been averaged acccording to snapshot semanics. public static IStreamable Average(this IStreamable source, Expression> selector) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(selector); return source.Aggregate(w => w.Average(selector)); } @@ -1426,8 +1426,8 @@ public static IStreamable Average(this IStreamable /// A stream of data whose payloads have been averaged acccording to snapshot semanics. public static IStreamable Average(this IStreamable source, Expression> selector) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(selector); return source.Aggregate(w => w.Average(selector)); } @@ -1442,8 +1442,8 @@ public static IStreamable Average(this IStreamabl /// A stream of data whose payloads have been averaged acccording to snapshot semanics. public static IStreamable Average(this IStreamable source, Expression> selector) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(selector); return source.Aggregate(w => w.Average(selector)); } @@ -1458,8 +1458,8 @@ public static IStreamable Average(this IStreamabl /// A stream of data whose payloads have been averaged acccording to snapshot semanics. public static IStreamable Average(this IStreamable source, Expression> selector) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(selector); return source.Aggregate(w => w.Average(selector)); } @@ -1474,8 +1474,8 @@ public static IStreamable Average(this IStreamabl /// A stream of data whose payloads have been averaged acccording to snapshot semanics. public static IStreamable Average(this IStreamable source, Expression> selector) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(selector); return source.Aggregate(w => w.Average(selector)); } @@ -1490,8 +1490,8 @@ public static IStreamable Average(this IStreamabl /// A stream of data whose payloads have been averaged acccording to snapshot semanics. public static IStreamable Average(this IStreamable source, Expression> selector) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(selector); return source.Aggregate(w => w.Average(selector)); } @@ -1506,8 +1506,8 @@ public static IStreamable Average(this IStreamabl /// A stream of data whose payloads have been averaged acccording to snapshot semanics. public static IStreamable Average(this IStreamable source, Expression> selector) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(selector); return source.Aggregate(w => w.Average(selector)); } @@ -1522,8 +1522,8 @@ public static IStreamable Average(this IStreamabl /// A stream of data whose payloads have been averaged acccording to snapshot semanics. public static IStreamable Average(this IStreamable source, Expression> selector) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(selector); return source.Aggregate(w => w.Average(selector)); } @@ -1538,8 +1538,8 @@ public static IStreamable Average(this IStreamabl /// A stream of data whose payloads have been averaged acccording to snapshot semanics. public static IStreamable Average(this IStreamable source, Expression> selector) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(selector); return source.Aggregate(w => w.Average(selector)); } @@ -1554,8 +1554,8 @@ public static IStreamable Average(this IStreamabl /// A stream of data whose payloads have been averaged acccording to snapshot semanics. public static IStreamable Average(this IStreamable source, Expression> selector) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(selector); return source.Aggregate(w => w.Average(selector)); } @@ -1570,8 +1570,8 @@ public static IStreamable Average(this IStreamabl /// A stream of data whose payloads have been averaged acccording to snapshot semanics. public static IStreamable Average(this IStreamable source, Expression> selector) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(selector); return source.Aggregate(w => w.Average(selector)); } @@ -1586,8 +1586,8 @@ public static IStreamable Average(this IStreamabl /// A stream of data whose payloads have been averaged acccording to snapshot semanics. public static IStreamable Average(this IStreamable source, Expression> selector) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(selector); return source.Aggregate(w => w.Average(selector)); } @@ -1602,8 +1602,8 @@ public static IStreamable Average(this IStreamabl /// A stream of data whose payloads have been averaged acccording to snapshot semanics. public static IStreamable Average(this IStreamable source, Expression> selector) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(selector); return source.Aggregate(w => w.Average(selector)); } @@ -1618,8 +1618,8 @@ public static IStreamable Average(this IStreamabl /// A stream of data whose payloads have been averaged acccording to snapshot semanics. public static IStreamable Average(this IStreamable source, Expression> selector) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(selector); return source.Aggregate(w => w.Average(selector)); } @@ -1634,8 +1634,8 @@ public static IStreamable Average(this IStreamabl /// A stream of data whose payloads have been averaged acccording to snapshot semanics. public static IStreamable Average(this IStreamable source, Expression> selector) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(selector); return source.Aggregate(w => w.Average(selector)); } @@ -1650,8 +1650,8 @@ public static IStreamable Average(this IStreamabl /// A stream of data whose payloads have had its squares averaged acccording to snapshot semanics. public static IStreamable AverageSquares(this IStreamable source, Expression> selector) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(selector); return source.Aggregate(w => w.AverageSquares(selector)); } @@ -1666,8 +1666,8 @@ public static IStreamable AverageSquares(this IStr /// A stream of data whose payloads have had its squares averaged acccording to snapshot semanics. public static IStreamable AverageSquares(this IStreamable source, Expression> selector) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(selector); return source.Aggregate(w => w.AverageSquares(selector)); } @@ -1682,8 +1682,8 @@ public static IStreamable AverageSquares(this IStr /// A stream of data whose payloads have had its squares averaged acccording to snapshot semanics. public static IStreamable AverageSquares(this IStreamable source, Expression> selector) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(selector); return source.Aggregate(w => w.AverageSquares(selector)); } @@ -1698,8 +1698,8 @@ public static IStreamable AverageSquares(this IStr /// A stream of data whose payloads have had its squares averaged acccording to snapshot semanics. public static IStreamable AverageSquares(this IStreamable source, Expression> selector) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(selector); return source.Aggregate(w => w.AverageSquares(selector)); } @@ -1714,8 +1714,8 @@ public static IStreamable AverageSquares(this IStr /// A stream of data whose payloads have had its squares averaged acccording to snapshot semanics. public static IStreamable AverageSquares(this IStreamable source, Expression> selector) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(selector); return source.Aggregate(w => w.AverageSquares(selector)); } @@ -1730,8 +1730,8 @@ public static IStreamable AverageSquares(this IStr /// A stream of data whose payloads have had its squares averaged acccording to snapshot semanics. public static IStreamable AverageSquares(this IStreamable source, Expression> selector) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(selector); return source.Aggregate(w => w.AverageSquares(selector)); } @@ -1746,8 +1746,8 @@ public static IStreamable AverageSquares(this IStr /// A stream of data whose payloads have had its squares averaged acccording to snapshot semanics. public static IStreamable AverageSquares(this IStreamable source, Expression> selector) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(selector); return source.Aggregate(w => w.AverageSquares(selector)); } @@ -1762,8 +1762,8 @@ public static IStreamable AverageSquares(this IStr /// A stream of data whose payloads have had its squares averaged acccording to snapshot semanics. public static IStreamable AverageSquares(this IStreamable source, Expression> selector) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(selector); return source.Aggregate(w => w.AverageSquares(selector)); } @@ -1778,8 +1778,8 @@ public static IStreamable AverageSquares(this IStr /// A stream of data whose payloads have had its squares averaged acccording to snapshot semanics. public static IStreamable AverageSquares(this IStreamable source, Expression> selector) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(selector); return source.Aggregate(w => w.AverageSquares(selector)); } @@ -1794,8 +1794,8 @@ public static IStreamable AverageSquares(this IStre /// A stream of data whose payloads have had its squares averaged acccording to snapshot semanics. public static IStreamable AverageSquares(this IStreamable source, Expression> selector) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(selector); return source.Aggregate(w => w.AverageSquares(selector)); } @@ -1810,8 +1810,8 @@ public static IStreamable AverageSquares(this IStr /// A stream of data whose payloads have had its squares averaged acccording to snapshot semanics. public static IStreamable AverageSquares(this IStreamable source, Expression> selector) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(selector); return source.Aggregate(w => w.AverageSquares(selector)); } @@ -1826,8 +1826,8 @@ public static IStreamable AverageSquares(this ISt /// A stream of data whose payloads have had its squares averaged acccording to snapshot semanics. public static IStreamable AverageSquares(this IStreamable source, Expression> selector) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(selector); return source.Aggregate(w => w.AverageSquares(selector)); } @@ -1842,8 +1842,8 @@ public static IStreamable AverageSquares(this IStr /// A stream of data whose payloads have had its squares averaged acccording to snapshot semanics. public static IStreamable AverageSquares(this IStreamable source, Expression> selector) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(selector); return source.Aggregate(w => w.AverageSquares(selector)); } @@ -1858,8 +1858,8 @@ public static IStreamable AverageSquares(this ISt /// A stream of data whose payloads have had its squares averaged acccording to snapshot semanics. public static IStreamable AverageSquares(this IStreamable source, Expression> selector) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(selector); return source.Aggregate(w => w.AverageSquares(selector)); } @@ -1874,8 +1874,8 @@ public static IStreamable AverageSquares(this ISt /// A stream of data whose payloads have had its squares averaged acccording to snapshot semanics. public static IStreamable AverageSquares(this IStreamable source, Expression> selector) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(selector); return source.Aggregate(w => w.AverageSquares(selector)); } @@ -1890,8 +1890,8 @@ public static IStreamable AverageSquares(this ISt /// A stream of data whose payloads have had its squares averaged acccording to snapshot semanics. public static IStreamable AverageSquares(this IStreamable source, Expression> selector) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(selector); return source.Aggregate(w => w.AverageSquares(selector)); } @@ -1906,8 +1906,8 @@ public static IStreamable AverageSquares(this ISt /// A stream of data whose payloads have had its squares averaged acccording to snapshot semanics. public static IStreamable AverageSquares(this IStreamable source, Expression> selector) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(selector); return source.Aggregate(w => w.AverageSquares(selector)); } @@ -1922,8 +1922,8 @@ public static IStreamable AverageSquares(this ISt /// A stream of data whose payloads have had its squares averaged acccording to snapshot semanics. public static IStreamable AverageSquares(this IStreamable source, Expression> selector) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(selector); return source.Aggregate(w => w.AverageSquares(selector)); } @@ -1938,8 +1938,8 @@ public static IStreamable AverageSquares(this ISt /// A stream of data whose payloads have had its squares averaged acccording to snapshot semanics. public static IStreamable AverageSquares(this IStreamable source, Expression> selector) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(selector); return source.Aggregate(w => w.AverageSquares(selector)); } @@ -1954,8 +1954,8 @@ public static IStreamable AverageSquares(this ISt /// A stream of data whose payloads have had its squares averaged acccording to snapshot semanics. public static IStreamable AverageSquares(this IStreamable source, Expression> selector) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(selector); return source.Aggregate(w => w.AverageSquares(selector)); } @@ -1970,8 +1970,8 @@ public static IStreamable AverageSquares(this ISt /// A stream of data whose payloads have had its squares averaged acccording to snapshot semanics. public static IStreamable AverageSquares(this IStreamable source, Expression> selector) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(selector); return source.Aggregate(w => w.AverageSquares(selector)); } @@ -1986,8 +1986,8 @@ public static IStreamable AverageSquares(this ISt /// A stream of data whose payloads have had its squares averaged acccording to snapshot semanics. public static IStreamable AverageSquares(this IStreamable source, Expression> selector) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(selector); return source.Aggregate(w => w.AverageSquares(selector)); } @@ -2002,8 +2002,8 @@ public static IStreamable AverageSquares(this ISt /// A stream of data whose payloads have had its squares averaged acccording to snapshot semanics. public static IStreamable AverageSquares(this IStreamable source, Expression> selector) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(selector); return source.Aggregate(w => w.AverageSquares(selector)); } @@ -2018,8 +2018,8 @@ public static IStreamable AverageSquares(this ISt /// A stream of data whose payloads have had its squares averaged acccording to snapshot semanics. public static IStreamable AverageSquares(this IStreamable source, Expression> selector) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(selector); return source.Aggregate(w => w.AverageSquares(selector)); } @@ -2034,8 +2034,8 @@ public static IStreamable AverageSquares(this ISt /// A stream of data whose payloads have had its squares averaged acccording to snapshot semanics. public static IStreamable AverageSquares(this IStreamable source, Expression> selector) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(selector); return source.Aggregate(w => w.AverageSquares(selector)); } @@ -2050,8 +2050,8 @@ public static IStreamable AverageSquares(this ISt /// A stream of data whose payloads have had its squares averaged acccording to snapshot semanics. public static IStreamable AverageSquares(this IStreamable source, Expression> selector) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(selector); return source.Aggregate(w => w.AverageSquares(selector)); } @@ -2076,10 +2076,10 @@ public static IStreamable Aggregate, IAggregate> aggregate2, Expression> merger) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(aggregate1, nameof(aggregate1)); - Invariant.IsNotNull(aggregate2, nameof(aggregate2)); - Invariant.IsNotNull(merger, nameof(merger)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(aggregate1); + ArgumentNullException.ThrowIfNull(aggregate2); + ArgumentNullException.ThrowIfNull(merger); var window = new Window(source.Properties); var agg1 = aggregate1(window); @@ -2097,10 +2097,10 @@ internal static IStreamable Aggregate aggregate2, Expression> merger) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(aggregate1, nameof(aggregate1)); - Invariant.IsNotNull(aggregate2, nameof(aggregate2)); - Invariant.IsNotNull(merger, nameof(merger)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(aggregate1); + ArgumentNullException.ThrowIfNull(aggregate2); + ArgumentNullException.ThrowIfNull(merger); var compound = AggregateFunctions.Combine(aggregate1, aggregate2, merger); return new SnapshotWindowStreamable, TOutput>(source, compound); @@ -2131,11 +2131,11 @@ public static IStreamable Aggregate, IAggregate> aggregate3, Expression> merger) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(aggregate1, nameof(aggregate1)); - Invariant.IsNotNull(aggregate2, nameof(aggregate2)); - Invariant.IsNotNull(aggregate3, nameof(aggregate3)); - Invariant.IsNotNull(merger, nameof(merger)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(aggregate1); + ArgumentNullException.ThrowIfNull(aggregate2); + ArgumentNullException.ThrowIfNull(aggregate3); + ArgumentNullException.ThrowIfNull(merger); var window = new Window(source.Properties); var agg1 = aggregate1(window); @@ -2155,11 +2155,11 @@ internal static IStreamable Aggregate aggregate3, Expression> merger) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(aggregate1, nameof(aggregate1)); - Invariant.IsNotNull(aggregate2, nameof(aggregate2)); - Invariant.IsNotNull(aggregate3, nameof(aggregate3)); - Invariant.IsNotNull(merger, nameof(merger)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(aggregate1); + ArgumentNullException.ThrowIfNull(aggregate2); + ArgumentNullException.ThrowIfNull(aggregate3); + ArgumentNullException.ThrowIfNull(merger); var compound = AggregateFunctions.Combine(aggregate1, aggregate2, aggregate3, merger); return new SnapshotWindowStreamable, TOutput>(source, compound); @@ -2194,12 +2194,12 @@ public static IStreamable Aggregate, IAggregate> aggregate4, Expression> merger) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(aggregate1, nameof(aggregate1)); - Invariant.IsNotNull(aggregate2, nameof(aggregate2)); - Invariant.IsNotNull(aggregate3, nameof(aggregate3)); - Invariant.IsNotNull(aggregate4, nameof(aggregate4)); - Invariant.IsNotNull(merger, nameof(merger)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(aggregate1); + ArgumentNullException.ThrowIfNull(aggregate2); + ArgumentNullException.ThrowIfNull(aggregate3); + ArgumentNullException.ThrowIfNull(aggregate4); + ArgumentNullException.ThrowIfNull(merger); var window = new Window(source.Properties); var agg1 = aggregate1(window); @@ -2221,12 +2221,12 @@ internal static IStreamable Aggregate aggregate4, Expression> merger) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(aggregate1, nameof(aggregate1)); - Invariant.IsNotNull(aggregate2, nameof(aggregate2)); - Invariant.IsNotNull(aggregate3, nameof(aggregate3)); - Invariant.IsNotNull(aggregate4, nameof(aggregate4)); - Invariant.IsNotNull(merger, nameof(merger)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(aggregate1); + ArgumentNullException.ThrowIfNull(aggregate2); + ArgumentNullException.ThrowIfNull(aggregate3); + ArgumentNullException.ThrowIfNull(aggregate4); + ArgumentNullException.ThrowIfNull(merger); var compound = AggregateFunctions.Combine(aggregate1, aggregate2, aggregate3, aggregate4, merger); return new SnapshotWindowStreamable, TOutput>(source, compound); @@ -2265,13 +2265,13 @@ public static IStreamable Aggregate, IAggregate> aggregate5, Expression> merger) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(aggregate1, nameof(aggregate1)); - Invariant.IsNotNull(aggregate2, nameof(aggregate2)); - Invariant.IsNotNull(aggregate3, nameof(aggregate3)); - Invariant.IsNotNull(aggregate4, nameof(aggregate4)); - Invariant.IsNotNull(aggregate5, nameof(aggregate5)); - Invariant.IsNotNull(merger, nameof(merger)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(aggregate1); + ArgumentNullException.ThrowIfNull(aggregate2); + ArgumentNullException.ThrowIfNull(aggregate3); + ArgumentNullException.ThrowIfNull(aggregate4); + ArgumentNullException.ThrowIfNull(aggregate5); + ArgumentNullException.ThrowIfNull(merger); var window = new Window(source.Properties); var agg1 = aggregate1(window); @@ -2295,13 +2295,13 @@ internal static IStreamable Aggregate aggregate5, Expression> merger) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(aggregate1, nameof(aggregate1)); - Invariant.IsNotNull(aggregate2, nameof(aggregate2)); - Invariant.IsNotNull(aggregate3, nameof(aggregate3)); - Invariant.IsNotNull(aggregate4, nameof(aggregate4)); - Invariant.IsNotNull(aggregate5, nameof(aggregate5)); - Invariant.IsNotNull(merger, nameof(merger)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(aggregate1); + ArgumentNullException.ThrowIfNull(aggregate2); + ArgumentNullException.ThrowIfNull(aggregate3); + ArgumentNullException.ThrowIfNull(aggregate4); + ArgumentNullException.ThrowIfNull(aggregate5); + ArgumentNullException.ThrowIfNull(merger); var compound = AggregateFunctions.Combine(aggregate1, aggregate2, aggregate3, aggregate4, aggregate5, merger); return new SnapshotWindowStreamable, TOutput>(source, compound); @@ -2344,14 +2344,14 @@ public static IStreamable Aggregate, IAggregate> aggregate6, Expression> merger) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(aggregate1, nameof(aggregate1)); - Invariant.IsNotNull(aggregate2, nameof(aggregate2)); - Invariant.IsNotNull(aggregate3, nameof(aggregate3)); - Invariant.IsNotNull(aggregate4, nameof(aggregate4)); - Invariant.IsNotNull(aggregate5, nameof(aggregate5)); - Invariant.IsNotNull(aggregate6, nameof(aggregate6)); - Invariant.IsNotNull(merger, nameof(merger)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(aggregate1); + ArgumentNullException.ThrowIfNull(aggregate2); + ArgumentNullException.ThrowIfNull(aggregate3); + ArgumentNullException.ThrowIfNull(aggregate4); + ArgumentNullException.ThrowIfNull(aggregate5); + ArgumentNullException.ThrowIfNull(aggregate6); + ArgumentNullException.ThrowIfNull(merger); var window = new Window(source.Properties); var agg1 = aggregate1(window); @@ -2377,14 +2377,14 @@ internal static IStreamable Aggregate aggregate6, Expression> merger) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(aggregate1, nameof(aggregate1)); - Invariant.IsNotNull(aggregate2, nameof(aggregate2)); - Invariant.IsNotNull(aggregate3, nameof(aggregate3)); - Invariant.IsNotNull(aggregate4, nameof(aggregate4)); - Invariant.IsNotNull(aggregate5, nameof(aggregate5)); - Invariant.IsNotNull(aggregate6, nameof(aggregate6)); - Invariant.IsNotNull(merger, nameof(merger)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(aggregate1); + ArgumentNullException.ThrowIfNull(aggregate2); + ArgumentNullException.ThrowIfNull(aggregate3); + ArgumentNullException.ThrowIfNull(aggregate4); + ArgumentNullException.ThrowIfNull(aggregate5); + ArgumentNullException.ThrowIfNull(aggregate6); + ArgumentNullException.ThrowIfNull(merger); var compound = AggregateFunctions.Combine(aggregate1, aggregate2, aggregate3, aggregate4, aggregate5, aggregate6, merger); return new SnapshotWindowStreamable, TOutput>(source, compound); @@ -2431,15 +2431,15 @@ public static IStreamable Aggregate, IAggregate> aggregate7, Expression> merger) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(aggregate1, nameof(aggregate1)); - Invariant.IsNotNull(aggregate2, nameof(aggregate2)); - Invariant.IsNotNull(aggregate3, nameof(aggregate3)); - Invariant.IsNotNull(aggregate4, nameof(aggregate4)); - Invariant.IsNotNull(aggregate5, nameof(aggregate5)); - Invariant.IsNotNull(aggregate6, nameof(aggregate6)); - Invariant.IsNotNull(aggregate7, nameof(aggregate7)); - Invariant.IsNotNull(merger, nameof(merger)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(aggregate1); + ArgumentNullException.ThrowIfNull(aggregate2); + ArgumentNullException.ThrowIfNull(aggregate3); + ArgumentNullException.ThrowIfNull(aggregate4); + ArgumentNullException.ThrowIfNull(aggregate5); + ArgumentNullException.ThrowIfNull(aggregate6); + ArgumentNullException.ThrowIfNull(aggregate7); + ArgumentNullException.ThrowIfNull(merger); var window = new Window(source.Properties); var agg1 = aggregate1(window); @@ -2467,15 +2467,15 @@ internal static IStreamable Aggregate aggregate7, Expression> merger) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(aggregate1, nameof(aggregate1)); - Invariant.IsNotNull(aggregate2, nameof(aggregate2)); - Invariant.IsNotNull(aggregate3, nameof(aggregate3)); - Invariant.IsNotNull(aggregate4, nameof(aggregate4)); - Invariant.IsNotNull(aggregate5, nameof(aggregate5)); - Invariant.IsNotNull(aggregate6, nameof(aggregate6)); - Invariant.IsNotNull(aggregate7, nameof(aggregate7)); - Invariant.IsNotNull(merger, nameof(merger)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(aggregate1); + ArgumentNullException.ThrowIfNull(aggregate2); + ArgumentNullException.ThrowIfNull(aggregate3); + ArgumentNullException.ThrowIfNull(aggregate4); + ArgumentNullException.ThrowIfNull(aggregate5); + ArgumentNullException.ThrowIfNull(aggregate6); + ArgumentNullException.ThrowIfNull(aggregate7); + ArgumentNullException.ThrowIfNull(merger); var compound = AggregateFunctions.Combine(aggregate1, aggregate2, aggregate3, aggregate4, aggregate5, aggregate6, aggregate7, merger); return new SnapshotWindowStreamable, TOutput>(source, compound); @@ -2526,16 +2526,16 @@ public static IStreamable Aggregate, IAggregate> aggregate8, Expression> merger) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(aggregate1, nameof(aggregate1)); - Invariant.IsNotNull(aggregate2, nameof(aggregate2)); - Invariant.IsNotNull(aggregate3, nameof(aggregate3)); - Invariant.IsNotNull(aggregate4, nameof(aggregate4)); - Invariant.IsNotNull(aggregate5, nameof(aggregate5)); - Invariant.IsNotNull(aggregate6, nameof(aggregate6)); - Invariant.IsNotNull(aggregate7, nameof(aggregate7)); - Invariant.IsNotNull(aggregate8, nameof(aggregate8)); - Invariant.IsNotNull(merger, nameof(merger)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(aggregate1); + ArgumentNullException.ThrowIfNull(aggregate2); + ArgumentNullException.ThrowIfNull(aggregate3); + ArgumentNullException.ThrowIfNull(aggregate4); + ArgumentNullException.ThrowIfNull(aggregate5); + ArgumentNullException.ThrowIfNull(aggregate6); + ArgumentNullException.ThrowIfNull(aggregate7); + ArgumentNullException.ThrowIfNull(aggregate8); + ArgumentNullException.ThrowIfNull(merger); var window = new Window(source.Properties); var agg1 = aggregate1(window); @@ -2565,16 +2565,16 @@ internal static IStreamable Aggregate aggregate8, Expression> merger) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(aggregate1, nameof(aggregate1)); - Invariant.IsNotNull(aggregate2, nameof(aggregate2)); - Invariant.IsNotNull(aggregate3, nameof(aggregate3)); - Invariant.IsNotNull(aggregate4, nameof(aggregate4)); - Invariant.IsNotNull(aggregate5, nameof(aggregate5)); - Invariant.IsNotNull(aggregate6, nameof(aggregate6)); - Invariant.IsNotNull(aggregate7, nameof(aggregate7)); - Invariant.IsNotNull(aggregate8, nameof(aggregate8)); - Invariant.IsNotNull(merger, nameof(merger)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(aggregate1); + ArgumentNullException.ThrowIfNull(aggregate2); + ArgumentNullException.ThrowIfNull(aggregate3); + ArgumentNullException.ThrowIfNull(aggregate4); + ArgumentNullException.ThrowIfNull(aggregate5); + ArgumentNullException.ThrowIfNull(aggregate6); + ArgumentNullException.ThrowIfNull(aggregate7); + ArgumentNullException.ThrowIfNull(aggregate8); + ArgumentNullException.ThrowIfNull(merger); var compound = AggregateFunctions.Combine(aggregate1, aggregate2, aggregate3, aggregate4, aggregate5, aggregate6, aggregate7, aggregate8, merger); return new SnapshotWindowStreamable, TOutput>(source, compound); @@ -2629,17 +2629,17 @@ public static IStreamable Aggregate, IAggregate> aggregate9, Expression> merger) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(aggregate1, nameof(aggregate1)); - Invariant.IsNotNull(aggregate2, nameof(aggregate2)); - Invariant.IsNotNull(aggregate3, nameof(aggregate3)); - Invariant.IsNotNull(aggregate4, nameof(aggregate4)); - Invariant.IsNotNull(aggregate5, nameof(aggregate5)); - Invariant.IsNotNull(aggregate6, nameof(aggregate6)); - Invariant.IsNotNull(aggregate7, nameof(aggregate7)); - Invariant.IsNotNull(aggregate8, nameof(aggregate8)); - Invariant.IsNotNull(aggregate9, nameof(aggregate9)); - Invariant.IsNotNull(merger, nameof(merger)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(aggregate1); + ArgumentNullException.ThrowIfNull(aggregate2); + ArgumentNullException.ThrowIfNull(aggregate3); + ArgumentNullException.ThrowIfNull(aggregate4); + ArgumentNullException.ThrowIfNull(aggregate5); + ArgumentNullException.ThrowIfNull(aggregate6); + ArgumentNullException.ThrowIfNull(aggregate7); + ArgumentNullException.ThrowIfNull(aggregate8); + ArgumentNullException.ThrowIfNull(aggregate9); + ArgumentNullException.ThrowIfNull(merger); var window = new Window(source.Properties); var agg1 = aggregate1(window); @@ -2671,17 +2671,17 @@ internal static IStreamable Aggregate aggregate9, Expression> merger) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(aggregate1, nameof(aggregate1)); - Invariant.IsNotNull(aggregate2, nameof(aggregate2)); - Invariant.IsNotNull(aggregate3, nameof(aggregate3)); - Invariant.IsNotNull(aggregate4, nameof(aggregate4)); - Invariant.IsNotNull(aggregate5, nameof(aggregate5)); - Invariant.IsNotNull(aggregate6, nameof(aggregate6)); - Invariant.IsNotNull(aggregate7, nameof(aggregate7)); - Invariant.IsNotNull(aggregate8, nameof(aggregate8)); - Invariant.IsNotNull(aggregate9, nameof(aggregate9)); - Invariant.IsNotNull(merger, nameof(merger)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(aggregate1); + ArgumentNullException.ThrowIfNull(aggregate2); + ArgumentNullException.ThrowIfNull(aggregate3); + ArgumentNullException.ThrowIfNull(aggregate4); + ArgumentNullException.ThrowIfNull(aggregate5); + ArgumentNullException.ThrowIfNull(aggregate6); + ArgumentNullException.ThrowIfNull(aggregate7); + ArgumentNullException.ThrowIfNull(aggregate8); + ArgumentNullException.ThrowIfNull(aggregate9); + ArgumentNullException.ThrowIfNull(merger); var compound = AggregateFunctions.Combine(aggregate1, aggregate2, aggregate3, aggregate4, aggregate5, aggregate6, aggregate7, aggregate8, aggregate9, merger); return new SnapshotWindowStreamable, TOutput>(source, compound); @@ -2740,18 +2740,18 @@ public static IStreamable Aggregate, IAggregate> aggregate10, Expression> merger) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(aggregate1, nameof(aggregate1)); - Invariant.IsNotNull(aggregate2, nameof(aggregate2)); - Invariant.IsNotNull(aggregate3, nameof(aggregate3)); - Invariant.IsNotNull(aggregate4, nameof(aggregate4)); - Invariant.IsNotNull(aggregate5, nameof(aggregate5)); - Invariant.IsNotNull(aggregate6, nameof(aggregate6)); - Invariant.IsNotNull(aggregate7, nameof(aggregate7)); - Invariant.IsNotNull(aggregate8, nameof(aggregate8)); - Invariant.IsNotNull(aggregate9, nameof(aggregate9)); - Invariant.IsNotNull(aggregate10, nameof(aggregate10)); - Invariant.IsNotNull(merger, nameof(merger)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(aggregate1); + ArgumentNullException.ThrowIfNull(aggregate2); + ArgumentNullException.ThrowIfNull(aggregate3); + ArgumentNullException.ThrowIfNull(aggregate4); + ArgumentNullException.ThrowIfNull(aggregate5); + ArgumentNullException.ThrowIfNull(aggregate6); + ArgumentNullException.ThrowIfNull(aggregate7); + ArgumentNullException.ThrowIfNull(aggregate8); + ArgumentNullException.ThrowIfNull(aggregate9); + ArgumentNullException.ThrowIfNull(aggregate10); + ArgumentNullException.ThrowIfNull(merger); var window = new Window(source.Properties); var agg1 = aggregate1(window); @@ -2785,18 +2785,18 @@ internal static IStreamable Aggregate aggregate10, Expression> merger) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(aggregate1, nameof(aggregate1)); - Invariant.IsNotNull(aggregate2, nameof(aggregate2)); - Invariant.IsNotNull(aggregate3, nameof(aggregate3)); - Invariant.IsNotNull(aggregate4, nameof(aggregate4)); - Invariant.IsNotNull(aggregate5, nameof(aggregate5)); - Invariant.IsNotNull(aggregate6, nameof(aggregate6)); - Invariant.IsNotNull(aggregate7, nameof(aggregate7)); - Invariant.IsNotNull(aggregate8, nameof(aggregate8)); - Invariant.IsNotNull(aggregate9, nameof(aggregate9)); - Invariant.IsNotNull(aggregate10, nameof(aggregate10)); - Invariant.IsNotNull(merger, nameof(merger)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(aggregate1); + ArgumentNullException.ThrowIfNull(aggregate2); + ArgumentNullException.ThrowIfNull(aggregate3); + ArgumentNullException.ThrowIfNull(aggregate4); + ArgumentNullException.ThrowIfNull(aggregate5); + ArgumentNullException.ThrowIfNull(aggregate6); + ArgumentNullException.ThrowIfNull(aggregate7); + ArgumentNullException.ThrowIfNull(aggregate8); + ArgumentNullException.ThrowIfNull(aggregate9); + ArgumentNullException.ThrowIfNull(aggregate10); + ArgumentNullException.ThrowIfNull(merger); var compound = AggregateFunctions.Combine(aggregate1, aggregate2, aggregate3, aggregate4, aggregate5, aggregate6, aggregate7, aggregate8, aggregate9, aggregate10, merger); return new SnapshotWindowStreamable, TOutput>(source, compound); @@ -2859,19 +2859,19 @@ public static IStreamable Aggregate, IAggregate> aggregate11, Expression> merger) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(aggregate1, nameof(aggregate1)); - Invariant.IsNotNull(aggregate2, nameof(aggregate2)); - Invariant.IsNotNull(aggregate3, nameof(aggregate3)); - Invariant.IsNotNull(aggregate4, nameof(aggregate4)); - Invariant.IsNotNull(aggregate5, nameof(aggregate5)); - Invariant.IsNotNull(aggregate6, nameof(aggregate6)); - Invariant.IsNotNull(aggregate7, nameof(aggregate7)); - Invariant.IsNotNull(aggregate8, nameof(aggregate8)); - Invariant.IsNotNull(aggregate9, nameof(aggregate9)); - Invariant.IsNotNull(aggregate10, nameof(aggregate10)); - Invariant.IsNotNull(aggregate11, nameof(aggregate11)); - Invariant.IsNotNull(merger, nameof(merger)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(aggregate1); + ArgumentNullException.ThrowIfNull(aggregate2); + ArgumentNullException.ThrowIfNull(aggregate3); + ArgumentNullException.ThrowIfNull(aggregate4); + ArgumentNullException.ThrowIfNull(aggregate5); + ArgumentNullException.ThrowIfNull(aggregate6); + ArgumentNullException.ThrowIfNull(aggregate7); + ArgumentNullException.ThrowIfNull(aggregate8); + ArgumentNullException.ThrowIfNull(aggregate9); + ArgumentNullException.ThrowIfNull(aggregate10); + ArgumentNullException.ThrowIfNull(aggregate11); + ArgumentNullException.ThrowIfNull(merger); var window = new Window(source.Properties); var agg1 = aggregate1(window); @@ -2907,19 +2907,19 @@ internal static IStreamable Aggregate aggregate11, Expression> merger) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(aggregate1, nameof(aggregate1)); - Invariant.IsNotNull(aggregate2, nameof(aggregate2)); - Invariant.IsNotNull(aggregate3, nameof(aggregate3)); - Invariant.IsNotNull(aggregate4, nameof(aggregate4)); - Invariant.IsNotNull(aggregate5, nameof(aggregate5)); - Invariant.IsNotNull(aggregate6, nameof(aggregate6)); - Invariant.IsNotNull(aggregate7, nameof(aggregate7)); - Invariant.IsNotNull(aggregate8, nameof(aggregate8)); - Invariant.IsNotNull(aggregate9, nameof(aggregate9)); - Invariant.IsNotNull(aggregate10, nameof(aggregate10)); - Invariant.IsNotNull(aggregate11, nameof(aggregate11)); - Invariant.IsNotNull(merger, nameof(merger)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(aggregate1); + ArgumentNullException.ThrowIfNull(aggregate2); + ArgumentNullException.ThrowIfNull(aggregate3); + ArgumentNullException.ThrowIfNull(aggregate4); + ArgumentNullException.ThrowIfNull(aggregate5); + ArgumentNullException.ThrowIfNull(aggregate6); + ArgumentNullException.ThrowIfNull(aggregate7); + ArgumentNullException.ThrowIfNull(aggregate8); + ArgumentNullException.ThrowIfNull(aggregate9); + ArgumentNullException.ThrowIfNull(aggregate10); + ArgumentNullException.ThrowIfNull(aggregate11); + ArgumentNullException.ThrowIfNull(merger); var compound = AggregateFunctions.Combine(aggregate1, aggregate2, aggregate3, aggregate4, aggregate5, aggregate6, aggregate7, aggregate8, aggregate9, aggregate10, aggregate11, merger); return new SnapshotWindowStreamable, TOutput>(source, compound); @@ -2986,20 +2986,20 @@ public static IStreamable Aggregate, IAggregate> aggregate12, Expression> merger) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(aggregate1, nameof(aggregate1)); - Invariant.IsNotNull(aggregate2, nameof(aggregate2)); - Invariant.IsNotNull(aggregate3, nameof(aggregate3)); - Invariant.IsNotNull(aggregate4, nameof(aggregate4)); - Invariant.IsNotNull(aggregate5, nameof(aggregate5)); - Invariant.IsNotNull(aggregate6, nameof(aggregate6)); - Invariant.IsNotNull(aggregate7, nameof(aggregate7)); - Invariant.IsNotNull(aggregate8, nameof(aggregate8)); - Invariant.IsNotNull(aggregate9, nameof(aggregate9)); - Invariant.IsNotNull(aggregate10, nameof(aggregate10)); - Invariant.IsNotNull(aggregate11, nameof(aggregate11)); - Invariant.IsNotNull(aggregate12, nameof(aggregate12)); - Invariant.IsNotNull(merger, nameof(merger)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(aggregate1); + ArgumentNullException.ThrowIfNull(aggregate2); + ArgumentNullException.ThrowIfNull(aggregate3); + ArgumentNullException.ThrowIfNull(aggregate4); + ArgumentNullException.ThrowIfNull(aggregate5); + ArgumentNullException.ThrowIfNull(aggregate6); + ArgumentNullException.ThrowIfNull(aggregate7); + ArgumentNullException.ThrowIfNull(aggregate8); + ArgumentNullException.ThrowIfNull(aggregate9); + ArgumentNullException.ThrowIfNull(aggregate10); + ArgumentNullException.ThrowIfNull(aggregate11); + ArgumentNullException.ThrowIfNull(aggregate12); + ArgumentNullException.ThrowIfNull(merger); var window = new Window(source.Properties); var agg1 = aggregate1(window); @@ -3037,20 +3037,20 @@ internal static IStreamable Aggregate aggregate12, Expression> merger) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(aggregate1, nameof(aggregate1)); - Invariant.IsNotNull(aggregate2, nameof(aggregate2)); - Invariant.IsNotNull(aggregate3, nameof(aggregate3)); - Invariant.IsNotNull(aggregate4, nameof(aggregate4)); - Invariant.IsNotNull(aggregate5, nameof(aggregate5)); - Invariant.IsNotNull(aggregate6, nameof(aggregate6)); - Invariant.IsNotNull(aggregate7, nameof(aggregate7)); - Invariant.IsNotNull(aggregate8, nameof(aggregate8)); - Invariant.IsNotNull(aggregate9, nameof(aggregate9)); - Invariant.IsNotNull(aggregate10, nameof(aggregate10)); - Invariant.IsNotNull(aggregate11, nameof(aggregate11)); - Invariant.IsNotNull(aggregate12, nameof(aggregate12)); - Invariant.IsNotNull(merger, nameof(merger)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(aggregate1); + ArgumentNullException.ThrowIfNull(aggregate2); + ArgumentNullException.ThrowIfNull(aggregate3); + ArgumentNullException.ThrowIfNull(aggregate4); + ArgumentNullException.ThrowIfNull(aggregate5); + ArgumentNullException.ThrowIfNull(aggregate6); + ArgumentNullException.ThrowIfNull(aggregate7); + ArgumentNullException.ThrowIfNull(aggregate8); + ArgumentNullException.ThrowIfNull(aggregate9); + ArgumentNullException.ThrowIfNull(aggregate10); + ArgumentNullException.ThrowIfNull(aggregate11); + ArgumentNullException.ThrowIfNull(aggregate12); + ArgumentNullException.ThrowIfNull(merger); var compound = AggregateFunctions.Combine(aggregate1, aggregate2, aggregate3, aggregate4, aggregate5, aggregate6, aggregate7, aggregate8, aggregate9, aggregate10, aggregate11, aggregate12, merger); return new SnapshotWindowStreamable, TOutput>(source, compound); @@ -3121,21 +3121,21 @@ public static IStreamable Aggregate, IAggregate> aggregate13, Expression> merger) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(aggregate1, nameof(aggregate1)); - Invariant.IsNotNull(aggregate2, nameof(aggregate2)); - Invariant.IsNotNull(aggregate3, nameof(aggregate3)); - Invariant.IsNotNull(aggregate4, nameof(aggregate4)); - Invariant.IsNotNull(aggregate5, nameof(aggregate5)); - Invariant.IsNotNull(aggregate6, nameof(aggregate6)); - Invariant.IsNotNull(aggregate7, nameof(aggregate7)); - Invariant.IsNotNull(aggregate8, nameof(aggregate8)); - Invariant.IsNotNull(aggregate9, nameof(aggregate9)); - Invariant.IsNotNull(aggregate10, nameof(aggregate10)); - Invariant.IsNotNull(aggregate11, nameof(aggregate11)); - Invariant.IsNotNull(aggregate12, nameof(aggregate12)); - Invariant.IsNotNull(aggregate13, nameof(aggregate13)); - Invariant.IsNotNull(merger, nameof(merger)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(aggregate1); + ArgumentNullException.ThrowIfNull(aggregate2); + ArgumentNullException.ThrowIfNull(aggregate3); + ArgumentNullException.ThrowIfNull(aggregate4); + ArgumentNullException.ThrowIfNull(aggregate5); + ArgumentNullException.ThrowIfNull(aggregate6); + ArgumentNullException.ThrowIfNull(aggregate7); + ArgumentNullException.ThrowIfNull(aggregate8); + ArgumentNullException.ThrowIfNull(aggregate9); + ArgumentNullException.ThrowIfNull(aggregate10); + ArgumentNullException.ThrowIfNull(aggregate11); + ArgumentNullException.ThrowIfNull(aggregate12); + ArgumentNullException.ThrowIfNull(aggregate13); + ArgumentNullException.ThrowIfNull(merger); var window = new Window(source.Properties); var agg1 = aggregate1(window); @@ -3175,21 +3175,21 @@ internal static IStreamable Aggregate aggregate13, Expression> merger) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(aggregate1, nameof(aggregate1)); - Invariant.IsNotNull(aggregate2, nameof(aggregate2)); - Invariant.IsNotNull(aggregate3, nameof(aggregate3)); - Invariant.IsNotNull(aggregate4, nameof(aggregate4)); - Invariant.IsNotNull(aggregate5, nameof(aggregate5)); - Invariant.IsNotNull(aggregate6, nameof(aggregate6)); - Invariant.IsNotNull(aggregate7, nameof(aggregate7)); - Invariant.IsNotNull(aggregate8, nameof(aggregate8)); - Invariant.IsNotNull(aggregate9, nameof(aggregate9)); - Invariant.IsNotNull(aggregate10, nameof(aggregate10)); - Invariant.IsNotNull(aggregate11, nameof(aggregate11)); - Invariant.IsNotNull(aggregate12, nameof(aggregate12)); - Invariant.IsNotNull(aggregate13, nameof(aggregate13)); - Invariant.IsNotNull(merger, nameof(merger)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(aggregate1); + ArgumentNullException.ThrowIfNull(aggregate2); + ArgumentNullException.ThrowIfNull(aggregate3); + ArgumentNullException.ThrowIfNull(aggregate4); + ArgumentNullException.ThrowIfNull(aggregate5); + ArgumentNullException.ThrowIfNull(aggregate6); + ArgumentNullException.ThrowIfNull(aggregate7); + ArgumentNullException.ThrowIfNull(aggregate8); + ArgumentNullException.ThrowIfNull(aggregate9); + ArgumentNullException.ThrowIfNull(aggregate10); + ArgumentNullException.ThrowIfNull(aggregate11); + ArgumentNullException.ThrowIfNull(aggregate12); + ArgumentNullException.ThrowIfNull(aggregate13); + ArgumentNullException.ThrowIfNull(merger); var compound = AggregateFunctions.Combine(aggregate1, aggregate2, aggregate3, aggregate4, aggregate5, aggregate6, aggregate7, aggregate8, aggregate9, aggregate10, aggregate11, aggregate12, aggregate13, merger); return new SnapshotWindowStreamable, TOutput>(source, compound); @@ -3264,22 +3264,22 @@ public static IStreamable Aggregate, IAggregate> aggregate14, Expression> merger) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(aggregate1, nameof(aggregate1)); - Invariant.IsNotNull(aggregate2, nameof(aggregate2)); - Invariant.IsNotNull(aggregate3, nameof(aggregate3)); - Invariant.IsNotNull(aggregate4, nameof(aggregate4)); - Invariant.IsNotNull(aggregate5, nameof(aggregate5)); - Invariant.IsNotNull(aggregate6, nameof(aggregate6)); - Invariant.IsNotNull(aggregate7, nameof(aggregate7)); - Invariant.IsNotNull(aggregate8, nameof(aggregate8)); - Invariant.IsNotNull(aggregate9, nameof(aggregate9)); - Invariant.IsNotNull(aggregate10, nameof(aggregate10)); - Invariant.IsNotNull(aggregate11, nameof(aggregate11)); - Invariant.IsNotNull(aggregate12, nameof(aggregate12)); - Invariant.IsNotNull(aggregate13, nameof(aggregate13)); - Invariant.IsNotNull(aggregate14, nameof(aggregate14)); - Invariant.IsNotNull(merger, nameof(merger)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(aggregate1); + ArgumentNullException.ThrowIfNull(aggregate2); + ArgumentNullException.ThrowIfNull(aggregate3); + ArgumentNullException.ThrowIfNull(aggregate4); + ArgumentNullException.ThrowIfNull(aggregate5); + ArgumentNullException.ThrowIfNull(aggregate6); + ArgumentNullException.ThrowIfNull(aggregate7); + ArgumentNullException.ThrowIfNull(aggregate8); + ArgumentNullException.ThrowIfNull(aggregate9); + ArgumentNullException.ThrowIfNull(aggregate10); + ArgumentNullException.ThrowIfNull(aggregate11); + ArgumentNullException.ThrowIfNull(aggregate12); + ArgumentNullException.ThrowIfNull(aggregate13); + ArgumentNullException.ThrowIfNull(aggregate14); + ArgumentNullException.ThrowIfNull(merger); var window = new Window(source.Properties); var agg1 = aggregate1(window); @@ -3321,22 +3321,22 @@ internal static IStreamable Aggregate aggregate14, Expression> merger) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(aggregate1, nameof(aggregate1)); - Invariant.IsNotNull(aggregate2, nameof(aggregate2)); - Invariant.IsNotNull(aggregate3, nameof(aggregate3)); - Invariant.IsNotNull(aggregate4, nameof(aggregate4)); - Invariant.IsNotNull(aggregate5, nameof(aggregate5)); - Invariant.IsNotNull(aggregate6, nameof(aggregate6)); - Invariant.IsNotNull(aggregate7, nameof(aggregate7)); - Invariant.IsNotNull(aggregate8, nameof(aggregate8)); - Invariant.IsNotNull(aggregate9, nameof(aggregate9)); - Invariant.IsNotNull(aggregate10, nameof(aggregate10)); - Invariant.IsNotNull(aggregate11, nameof(aggregate11)); - Invariant.IsNotNull(aggregate12, nameof(aggregate12)); - Invariant.IsNotNull(aggregate13, nameof(aggregate13)); - Invariant.IsNotNull(aggregate14, nameof(aggregate14)); - Invariant.IsNotNull(merger, nameof(merger)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(aggregate1); + ArgumentNullException.ThrowIfNull(aggregate2); + ArgumentNullException.ThrowIfNull(aggregate3); + ArgumentNullException.ThrowIfNull(aggregate4); + ArgumentNullException.ThrowIfNull(aggregate5); + ArgumentNullException.ThrowIfNull(aggregate6); + ArgumentNullException.ThrowIfNull(aggregate7); + ArgumentNullException.ThrowIfNull(aggregate8); + ArgumentNullException.ThrowIfNull(aggregate9); + ArgumentNullException.ThrowIfNull(aggregate10); + ArgumentNullException.ThrowIfNull(aggregate11); + ArgumentNullException.ThrowIfNull(aggregate12); + ArgumentNullException.ThrowIfNull(aggregate13); + ArgumentNullException.ThrowIfNull(aggregate14); + ArgumentNullException.ThrowIfNull(merger); var compound = AggregateFunctions.Combine(aggregate1, aggregate2, aggregate3, aggregate4, aggregate5, aggregate6, aggregate7, aggregate8, aggregate9, aggregate10, aggregate11, aggregate12, aggregate13, aggregate14, merger); return new SnapshotWindowStreamable, TOutput>(source, compound); @@ -3415,23 +3415,23 @@ public static IStreamable Aggregate, IAggregate> aggregate15, Expression> merger) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(aggregate1, nameof(aggregate1)); - Invariant.IsNotNull(aggregate2, nameof(aggregate2)); - Invariant.IsNotNull(aggregate3, nameof(aggregate3)); - Invariant.IsNotNull(aggregate4, nameof(aggregate4)); - Invariant.IsNotNull(aggregate5, nameof(aggregate5)); - Invariant.IsNotNull(aggregate6, nameof(aggregate6)); - Invariant.IsNotNull(aggregate7, nameof(aggregate7)); - Invariant.IsNotNull(aggregate8, nameof(aggregate8)); - Invariant.IsNotNull(aggregate9, nameof(aggregate9)); - Invariant.IsNotNull(aggregate10, nameof(aggregate10)); - Invariant.IsNotNull(aggregate11, nameof(aggregate11)); - Invariant.IsNotNull(aggregate12, nameof(aggregate12)); - Invariant.IsNotNull(aggregate13, nameof(aggregate13)); - Invariant.IsNotNull(aggregate14, nameof(aggregate14)); - Invariant.IsNotNull(aggregate15, nameof(aggregate15)); - Invariant.IsNotNull(merger, nameof(merger)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(aggregate1); + ArgumentNullException.ThrowIfNull(aggregate2); + ArgumentNullException.ThrowIfNull(aggregate3); + ArgumentNullException.ThrowIfNull(aggregate4); + ArgumentNullException.ThrowIfNull(aggregate5); + ArgumentNullException.ThrowIfNull(aggregate6); + ArgumentNullException.ThrowIfNull(aggregate7); + ArgumentNullException.ThrowIfNull(aggregate8); + ArgumentNullException.ThrowIfNull(aggregate9); + ArgumentNullException.ThrowIfNull(aggregate10); + ArgumentNullException.ThrowIfNull(aggregate11); + ArgumentNullException.ThrowIfNull(aggregate12); + ArgumentNullException.ThrowIfNull(aggregate13); + ArgumentNullException.ThrowIfNull(aggregate14); + ArgumentNullException.ThrowIfNull(aggregate15); + ArgumentNullException.ThrowIfNull(merger); var window = new Window(source.Properties); var agg1 = aggregate1(window); @@ -3475,23 +3475,23 @@ internal static IStreamable Aggregate aggregate15, Expression> merger) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(aggregate1, nameof(aggregate1)); - Invariant.IsNotNull(aggregate2, nameof(aggregate2)); - Invariant.IsNotNull(aggregate3, nameof(aggregate3)); - Invariant.IsNotNull(aggregate4, nameof(aggregate4)); - Invariant.IsNotNull(aggregate5, nameof(aggregate5)); - Invariant.IsNotNull(aggregate6, nameof(aggregate6)); - Invariant.IsNotNull(aggregate7, nameof(aggregate7)); - Invariant.IsNotNull(aggregate8, nameof(aggregate8)); - Invariant.IsNotNull(aggregate9, nameof(aggregate9)); - Invariant.IsNotNull(aggregate10, nameof(aggregate10)); - Invariant.IsNotNull(aggregate11, nameof(aggregate11)); - Invariant.IsNotNull(aggregate12, nameof(aggregate12)); - Invariant.IsNotNull(aggregate13, nameof(aggregate13)); - Invariant.IsNotNull(aggregate14, nameof(aggregate14)); - Invariant.IsNotNull(aggregate15, nameof(aggregate15)); - Invariant.IsNotNull(merger, nameof(merger)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(aggregate1); + ArgumentNullException.ThrowIfNull(aggregate2); + ArgumentNullException.ThrowIfNull(aggregate3); + ArgumentNullException.ThrowIfNull(aggregate4); + ArgumentNullException.ThrowIfNull(aggregate5); + ArgumentNullException.ThrowIfNull(aggregate6); + ArgumentNullException.ThrowIfNull(aggregate7); + ArgumentNullException.ThrowIfNull(aggregate8); + ArgumentNullException.ThrowIfNull(aggregate9); + ArgumentNullException.ThrowIfNull(aggregate10); + ArgumentNullException.ThrowIfNull(aggregate11); + ArgumentNullException.ThrowIfNull(aggregate12); + ArgumentNullException.ThrowIfNull(aggregate13); + ArgumentNullException.ThrowIfNull(aggregate14); + ArgumentNullException.ThrowIfNull(aggregate15); + ArgumentNullException.ThrowIfNull(merger); var compound = AggregateFunctions.Combine(aggregate1, aggregate2, aggregate3, aggregate4, aggregate5, aggregate6, aggregate7, aggregate8, aggregate9, aggregate10, aggregate11, aggregate12, aggregate13, aggregate14, aggregate15, merger); return new SnapshotWindowStreamable, TOutput>(source, compound); diff --git a/Sources/Core/Microsoft.StreamProcessing/StreamableAPI/StreamableExtensionsTemplate.tt b/Sources/Core/Microsoft.StreamProcessing/StreamableAPI/StreamableExtensionsTemplate.tt index 34fcc3093..02d512b7c 100644 --- a/Sources/Core/Microsoft.StreamProcessing/StreamableAPI/StreamableExtensionsTemplate.tt +++ b/Sources/Core/Microsoft.StreamProcessing/StreamableAPI/StreamableExtensionsTemplate.tt @@ -32,8 +32,8 @@ namespace Microsoft.StreamProcessing /// A stream of data whose payloads have been summed acccording to snapshot semanics. public static IStreamable> Sum(this IStreamable source, Expression>> selector) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(selector); return source.Aggregate(w => w.Sum(selector)); } <# } @@ -55,8 +55,8 @@ namespace Microsoft.StreamProcessing /// A stream of data whose payloads have been summed acccording to snapshot semanics. public static IStreamable> Sum(this IStreamable source, Expression?>> selector) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(selector); return source.Aggregate(w => w.Sum(selector)); } <# } @@ -77,8 +77,8 @@ namespace Microsoft.StreamProcessing /// A stream of data whose payloads have had its squares summed acccording to snapshot semanics. public static IStreamable> SumSquares(this IStreamable source, Expression>> selector) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(selector); return source.Aggregate(w => w.SumSquares(selector)); } <# } @@ -100,8 +100,8 @@ namespace Microsoft.StreamProcessing /// A stream of data whose payloads have had its squares summed acccording to snapshot semanics. public static IStreamable> SumSquares(this IStreamable source, Expression?>> selector) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(selector); return source.Aggregate(w => w.SumSquares(selector)); } <# } @@ -122,8 +122,8 @@ namespace Microsoft.StreamProcessing /// A stream of data whose payloads have been multiplied acccording to snapshot semanics. public static IStreamable> Product(this IStreamable source, Expression>> selector) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(selector); return source.Aggregate(w => w.Product(selector)); } <# } @@ -145,8 +145,8 @@ namespace Microsoft.StreamProcessing /// A stream of data whose payloads have been multiplied acccording to snapshot semanics. public static IStreamable> Product(this IStreamable source, Expression?>> selector) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(selector); return source.Aggregate(w => w.Product(selector)); } <# } @@ -170,8 +170,8 @@ namespace Microsoft.StreamProcessing /// A stream of data whose payloads have been averaged acccording to snapshot semanics. public static IStreamable> Average(this IStreamable source, Expression>> selector) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(selector); return source.Aggregate(w => w.Average(selector)); } <# } @@ -195,8 +195,8 @@ namespace Microsoft.StreamProcessing /// A stream of data whose payloads have been averaged acccording to snapshot semanics. public static IStreamable?> Average(this IStreamable source, Expression?>> selector) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(selector); return source.Aggregate(w => w.Average(selector)); } <# } @@ -220,8 +220,8 @@ namespace Microsoft.StreamProcessing /// A stream of data whose payloads have had its squares averaged acccording to snapshot semanics. public static IStreamable> AverageSquares(this IStreamable source, Expression>> selector) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(selector); return source.Aggregate(w => w.AverageSquares(selector)); } <# } @@ -245,8 +245,8 @@ namespace Microsoft.StreamProcessing /// A stream of data whose payloads have had its squares averaged acccording to snapshot semanics. public static IStreamable?> AverageSquares(this IStreamable source, Expression?>> selector) { - Invariant.IsNotNull(source, nameof(source)); - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(selector); return source.Aggregate(w => w.AverageSquares(selector)); } <# } @@ -272,9 +272,9 @@ namespace Microsoft.StreamProcessing <#= IterateLine(" Func, IAggregate> aggregate$,", count) #> Expression, TOutput>> merger) { - Invariant.IsNotNull(source, nameof(source)); -<#= IterateLine(" Invariant.IsNotNull(aggregate$, nameof(aggregate$));", count) #> - Invariant.IsNotNull(merger, nameof(merger)); + ArgumentNullException.ThrowIfNull(source); +<#= IterateLine(" ArgumentNullException.ThrowIfNull(aggregate$);", count) #> + ArgumentNullException.ThrowIfNull(merger); var window = new Window(source.Properties); <#= IterateLine(" var agg$ = aggregate$(window);", count) #> @@ -290,9 +290,9 @@ namespace Microsoft.StreamProcessing <#= IterateLine(" IAggregate aggregate$,", count) #> Expression, TOutput>> merger) { - Invariant.IsNotNull(source, nameof(source)); -<#= IterateLine(" Invariant.IsNotNull(aggregate$, nameof(aggregate$));", count) #> - Invariant.IsNotNull(merger, nameof(merger)); + ArgumentNullException.ThrowIfNull(source); +<#= IterateLine(" ArgumentNullException.ThrowIfNull(aggregate$);", count) #> + ArgumentNullException.ThrowIfNull(merger); var compound = AggregateFunctions.Combine(<#= IterateComma("aggregate$", count) #>, merger); return new SnapshotWindowStreamable>, TOutput>(source, compound); diff --git a/Sources/Core/Microsoft.StreamProcessing/Streamables/BinaryStreamable.cs b/Sources/Core/Microsoft.StreamProcessing/Streamables/BinaryStreamable.cs index 867055b85..8c44ec1a6 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Streamables/BinaryStreamable.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Streamables/BinaryStreamable.cs @@ -20,8 +20,8 @@ protected BinaryStreamable(StreamProperties properties, IStreamab IStreamable right, bool registerInputs = false) : base(properties) { - Contract.Requires(left != null); - Contract.Requires(right != null); + ArgumentNullException.ThrowIfNull(left); + ArgumentNullException.ThrowIfNull(right); this.Left = left; this.Right = right; @@ -30,7 +30,7 @@ protected BinaryStreamable(StreamProperties properties, IStreamab public override sealed IDisposable Subscribe(IStreamObserver observer) { - var binaryPipe = CreatePipe(observer); + var binaryPipe = this.CreatePipe(observer); return Utility.CreateDisposable(this.Left.Subscribe(this.registerInputs ? Config.StreamScheduler.RegisterStreamObserver(binaryPipe.Left) : binaryPipe.Left), this.Right.Subscribe(this.registerInputs ? Config.StreamScheduler.RegisterStreamObserver(binaryPipe.Right) : binaryPipe.Right)); } @@ -40,7 +40,7 @@ protected void Initialize() { if (this.Left.Properties.IsColumnar && this.Right.Properties.IsColumnar) { - if (!CanGenerateColumnar()) + if (!this.CanGenerateColumnar()) { this.properties = this.properties.ToRowBased(); this.Left = this.Left.ColumnToRow(); diff --git a/Sources/Core/Microsoft.StreamProcessing/Streamables/SetPropertyStreamable.cs b/Sources/Core/Microsoft.StreamProcessing/Streamables/SetPropertyStreamable.cs index 9b86d292b..8a76dc31f 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Streamables/SetPropertyStreamable.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Streamables/SetPropertyStreamable.cs @@ -14,7 +14,7 @@ internal sealed class SetPropertyStreamable : Streamable source, Func, StreamProperties> propertySetter) : base(propertySetter(source.Properties)) { - Contract.Requires(source != null); + ArgumentNullException.ThrowIfNull(source); this.Source = source; } diff --git a/Sources/Core/Microsoft.StreamProcessing/Streamables/Streamable.cs b/Sources/Core/Microsoft.StreamProcessing/Streamables/Streamable.cs index 4ed2ec1b1..7e2396f3b 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Streamables/Streamable.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Streamables/Streamable.cs @@ -31,7 +31,7 @@ public abstract class Streamable : IStreamable internal Streamable(StreamProperties properties) { - Contract.Requires(properties != null); + ArgumentNullException.ThrowIfNull(properties); this.properties = properties; } @@ -61,15 +61,12 @@ internal Streamable(StreamProperties properties) } [ContractClassFor(typeof(Streamable<,>))] - internal abstract class StreamableContract : Streamable + internal abstract class StreamableContract(StreamProperties properties) + : Streamable(properties) { - public StreamableContract(StreamProperties properties) - : base(properties) - { } - public override IDisposable Subscribe(IStreamObserver observer) { - Contract.Requires(observer != null); + ArgumentNullException.ThrowIfNull(observer); return null; // Dummy return } } diff --git a/Sources/Core/Microsoft.StreamProcessing/Streamables/UnaryStreamable.cs b/Sources/Core/Microsoft.StreamProcessing/Streamables/UnaryStreamable.cs index 65684388e..1cfd86e97 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Streamables/UnaryStreamable.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Streamables/UnaryStreamable.cs @@ -14,13 +14,13 @@ internal abstract class UnaryStreamable : Streamable source, StreamProperties properties) : base(properties) { - Contract.Requires(source != null); + ArgumentNullException.ThrowIfNull(source); this.Source = source; } public override IDisposable Subscribe(IStreamObserver observer) { - var pipe = CreatePipe(observer); + var pipe = this.CreatePipe(observer); return this.Source.Subscribe(pipe); } @@ -28,7 +28,7 @@ public override IDisposable Subscribe(IStreamObserver observer) protected void Initialize() { - if (this.Source.Properties.IsColumnar && !CanGenerateColumnar()) + if (this.Source.Properties.IsColumnar && !this.CanGenerateColumnar()) { this.properties = this.properties.ToRowBased(); this.Source = this.Source.ColumnToRow(); diff --git a/Sources/Core/Microsoft.StreamProcessing/StringHandling/CharArrayPool.cs b/Sources/Core/Microsoft.StreamProcessing/StringHandling/CharArrayPool.cs index 9de16bdee..27c25b54f 100644 --- a/Sources/Core/Microsoft.StreamProcessing/StringHandling/CharArrayPool.cs +++ b/Sources/Core/Microsoft.StreamProcessing/StringHandling/CharArrayPool.cs @@ -64,11 +64,11 @@ public override string GetStatusReport() } return string.Format(CultureInfo.InvariantCulture, "[{0}] Objects Created - {1,5} - Queue Size - {2,5}\t{3}", - !SomethingIsWrong() ? " " : "X", this.createdObjects, totalCount, "CharArray"); + !this.SomethingIsWrong() ? " " : "X", this.createdObjects, totalCount, "CharArray"); } public override ColumnPoolBase Leaked - => ((!Config.DisableMemoryPooling) && SomethingIsWrong()) ? this : null; + => ((!Config.DisableMemoryPooling) && this.SomethingIsWrong()) ? this : null; private bool SomethingIsWrong() { diff --git a/Sources/Core/Microsoft.StreamProcessing/StringHandling/MultiString.cs b/Sources/Core/Microsoft.StreamProcessing/StringHandling/MultiString.cs index e2346d252..ae29c0bed 100644 --- a/Sources/Core/Microsoft.StreamProcessing/StringHandling/MultiString.cs +++ b/Sources/Core/Microsoft.StreamProcessing/StringHandling/MultiString.cs @@ -20,7 +20,7 @@ namespace Microsoft.StreamProcessing.Internal.Collections /// [DataContract] [EditorBrowsable(EditorBrowsableState.Never)] - public sealed class MultiString : IDisposable + public sealed partial class MultiString : IDisposable { [DataMember] internal CharArrayWrapper col; @@ -223,8 +223,8 @@ public static ICollection LiveIndices(ColumnBatch bv, int n) [EditorBrowsable(EditorBrowsableState.Never)] public static unsafe ColumnBatch InvertLeftThenOrWithRight(ColumnBatch left, ColumnBatch right, ColumnPool pool) { - Contract.Requires(left != null); - Contract.Requires(right != null); + ArgumentNullException.ThrowIfNull(left); + ArgumentNullException.ThrowIfNull(right); Contract.Requires(left.UsedLength == right.UsedLength); pool.Get(out var result); @@ -250,8 +250,8 @@ public static unsafe ColumnBatch InvertLeftThenOrWithRight(ColumnBatch left, ColumnBatch right) { - Contract.Requires(left != null); - Contract.Requires(right != null); + ArgumentNullException.ThrowIfNull(left); + ArgumentNullException.ThrowIfNull(right); Contract.Requires(left.UsedLength == right.UsedLength); fixed (long* leftCol = left.col) @@ -343,8 +343,8 @@ public void AddString(string str) Contract.Requires(this.State == MultiStringState.Unsealed); Contract.Ensures(this.State == MultiStringState.Unsealed); - if (str == null) str = string.Empty; - Initialize(-1); + str ??= string.Empty; + this.Initialize(-1); this.msb.Append(str); this.starts.col[this.Count] = this.EndOffset; @@ -367,12 +367,7 @@ public void Initialize(int size = -1) if (this.lengths == null) this.shortPool.Get(out this.lengths); - if (this.msb == null) - { - this.msb = size < 1 - ? new MyStringBuilder(this.charArrayPool) - : new MyStringBuilder(size, this.charArrayPool); - } + this.msb ??= (size < 1 ? new(this.charArrayPool) : new(size, this.charArrayPool)); } /// @@ -385,7 +380,7 @@ public void Initialize(int size = -1) public unsafe void AddString(MultiString other, int index) { Contract.Requires(this.State == MultiStringState.Unsealed); - Contract.Requires(other != null); + ArgumentNullException.ThrowIfNull(other); Contract.Requires(other.State == MultiStringState.Sealed); Contract.Requires(index >= 0 && index < other.Count); @@ -411,11 +406,11 @@ public unsafe void AddString(MultiString other, int index) [MethodImpl(MethodImplOptions.AggressiveInlining)] internal static unsafe MultiString FromColumnBatch(ColumnBatch columnOfStrings, ColumnBatch livenessBitVector, CharArrayPool caPool, ColumnPool intPool, ColumnPool shortPool, ColumnPool bitvectorPool) { - Contract.Requires(columnOfStrings != null); - Contract.Requires(livenessBitVector != null); - Contract.Requires(caPool != null); - Contract.Requires(intPool != null); - Contract.Requires(bitvectorPool != null); + ArgumentNullException.ThrowIfNull(columnOfStrings); + ArgumentNullException.ThrowIfNull(livenessBitVector); + ArgumentNullException.ThrowIfNull(caPool); + ArgumentNullException.ThrowIfNull(intPool); + ArgumentNullException.ThrowIfNull(bitvectorPool); Contract.Ensures(Contract.Result().State == MultiStringState.Sealed); var multiString = new MultiString(caPool, intPool, shortPool, bitvectorPool); @@ -452,7 +447,7 @@ internal static unsafe MultiString FromColumnBatch(ColumnBatch columnOfS [EditorBrowsable(EditorBrowsableState.Never)] public unsafe ColumnBatch ToColumnBatch(ColumnPool stringPool, ColumnBatch livenessBitVector) { - Contract.Requires(stringPool != null); + ArgumentNullException.ThrowIfNull(stringPool); Contract.Requires(this.State == MultiStringState.Sealed); stringPool.Get(out var stringColumn); @@ -480,7 +475,7 @@ public void Seal() if (this.col == null) // null check so method is idempotent { - Initialize(-1); // degenerate case: no string was ever added + this.Initialize(-1); // degenerate case: no string was ever added this.col = this.msb.ToCharArrayWrapperAndDispose(); this.msb = null; @@ -634,7 +629,7 @@ public unsafe MultiString ApplyString(Expression> expressio Contract.Requires(this.State == MultiStringState.Sealed); Contract.Ensures(this.State == MultiStringState.Sealed); - MultiString result = CloneShell(); + MultiString result = this.CloneShell(); var func = expression.Compile(); var bv = inBV.col; var startscol = this.starts.col; @@ -680,7 +675,7 @@ public unsafe ColumnBatch Contains(string str, ColumnBatch inBV, boo Contract.Ensures(this.State == MultiStringState.Sealed); var reg = new Regex(Regex.Escape(str)); - return IsMatch(reg, 0, inBV, inPlace); + return this.IsMatch(reg, 0, inBV, inPlace); } /// @@ -927,11 +922,11 @@ private static bool IsSimpleRegex(string pattern) pattern = pattern.Replace("\\}", "A"); pattern = pattern.Replace("\\{", "A"); - var isGreedy = new Regex(@"([\*\+\}](?!\?))|([^\*\+\}\?]\?(?!\?))"); + var isGreedy = GreedyRegex(); return !isGreedy.IsMatch(pattern) - && !pattern.StartsWith("^", StringComparison.Ordinal) - && !pattern.EndsWith("$", StringComparison.Ordinal) + && !pattern.StartsWith('^') + && !pattern.EndsWith('$') && !pattern.Contains("\\A") && !pattern.Contains("\\Z") && !pattern.Contains("\\z"); @@ -941,7 +936,7 @@ private unsafe ColumnBatch IsMatchBackoff(Regex regex, int startat, Column { if ((regex.Options & RegexOptions.RightToLeft) == RegexOptions.RightToLeft) { - return ApplyBoolean(e => regex.IsMatch(e), inBV, inPlace); + return this.ApplyBoolean(e => regex.IsMatch(e), inBV, inPlace); } ColumnBatch result; @@ -991,7 +986,7 @@ public unsafe ColumnBatch IsMatch(string regex, ColumnBatch inBV, bo Contract.Ensures(this.State == MultiStringState.Sealed); var reg = new Regex(regex); - return IsMatch(reg, 0, inBV, inPlace); + return this.IsMatch(reg, 0, inBV, inPlace); } /// @@ -1010,12 +1005,12 @@ public unsafe ColumnBatch IsMatch(Regex regex, int startat, ColumnBatch regex.IsMatch(e), inBV, false); + return this.ApplyBoolean(e => regex.IsMatch(e), inBV, false); } if (!IsSimpleRegex(regex.ToString())) { - return IsMatchBackoff(regex, startat, inBV, false); + return this.IsMatchBackoff(regex, startat, inBV, false); } ColumnBatch result; @@ -1118,7 +1113,7 @@ public unsafe MultiString ToLower(bool inPlace = true) { if (*p < '\x0080') // ascii { - if ((*p <= 'Z') && (*p >= 'A')) + if (*p is <= 'Z' and >= 'A') { *p = (char)(*p | ' '); } @@ -1134,7 +1129,7 @@ public unsafe MultiString ToLower(bool inPlace = true) } else { - MultiString result = Clone(); + MultiString result = this.Clone(); result.col.MakeWritable(result.charArrayPool, false); fixed (char* src = this.col.charArray.content) @@ -1146,7 +1141,7 @@ public unsafe MultiString ToLower(bool inPlace = true) char* end = src + this.EndOffset; while (p < end) { - *q = *p < '\x0080' ? (*p <= 'Z') && (*p >= 'A') ? (char)(*p | ' ') : *p : textInfo.ToLower(*p); + *q = *p < '\x0080' ? *p is <= 'Z' and >= 'A' ? (char)(*p | ' ') : *p : textInfo.ToLower(*p); p++; q++; } @@ -1178,7 +1173,7 @@ public unsafe MultiString ToUpper(bool inPlace = true) { if (*p < '\x0080') // ascii { - if ((*p >= 'a') && (*p <= 'z')) + if (*p is >= 'a' and <= 'z') { *p = (char)(*p & '￟'); } @@ -1194,7 +1189,7 @@ public unsafe MultiString ToUpper(bool inPlace = true) } else { - MultiString result = Clone(); + MultiString result = this.Clone(); result.col.MakeWritable(result.charArrayPool, false); fixed (char* src = this.col.charArray.content) @@ -1207,7 +1202,7 @@ public unsafe MultiString ToUpper(bool inPlace = true) while (p < end) { *q = *p < '\x0080' - ? (*p >= 'a') && (*p <= 'z') ? (char)(*p & '￟') : *p + ? *p is >= 'a' and <= 'z' ? (char)(*p & '￟') : *p : textInfo.ToUpper(*p); p++; q++; @@ -1243,7 +1238,7 @@ public unsafe ICollection Split(Regex regex, ColumnBatch inBV var resultList = new List(); this.intPool.Get(out multiplicity); - var current = Clone(); + var current = this.Clone(); current.Count = 0; current.starts = current.starts.MakeWritable(this.intPool); current.lengths = current.lengths.MakeWritable(this.shortPool); @@ -1282,7 +1277,7 @@ public unsafe ICollection Split(Regex regex, ColumnBatch inBV if (current.Count == rstartscol.Length) { resultList.Add(current); - current = Clone(); + current = this.Clone(); current.Count = 0; current.starts = current.starts.MakeWritable(this.intPool); current.lengths = current.lengths.MakeWritable(this.shortPool); @@ -1302,7 +1297,7 @@ public unsafe ICollection Split(Regex regex, ColumnBatch inBV if (current.Count == rstartscol.Length) { resultList.Add(current); - current = Clone(); + current = this.Clone(); current.Count = 0; current.starts = current.starts.MakeWritable(this.intPool); current.lengths = current.lengths.MakeWritable(this.shortPool); @@ -1335,7 +1330,7 @@ public unsafe ICollection Split(Regex regex, ColumnBatch inBV if (current.Count == rstartscol.Length) { resultList.Add(current); - current = Clone(); + current = this.Clone(); current.Count = 0; current.starts = current.starts.MakeWritable(this.intPool); current.lengths = current.lengths.MakeWritable(this.shortPool); @@ -1395,7 +1390,7 @@ public unsafe ICollection Split(char separator, ColumnBatch i var resultList = new List(); this.intPool.Get(out multiplicity); - var current = Clone(); + var current = this.Clone(); current.Count = 0; current.starts = current.starts.MakeWritable(this.intPool); current.lengths = current.lengths.MakeWritable(this.shortPool); @@ -1433,7 +1428,7 @@ public unsafe ICollection Split(char separator, ColumnBatch i { current.Count = count; resultList.Add(current); - current = Clone(); + current = this.Clone(); current.Count = 0; count = 0; current.starts = current.starts.MakeWritable(this.intPool); @@ -1455,7 +1450,7 @@ public unsafe ICollection Split(char separator, ColumnBatch i { current.Count = count; resultList.Add(current); - current = Clone(); + current = this.Clone(); current.Count = 0; count = 0; current.starts = current.starts.MakeWritable(this.intPool); @@ -1499,7 +1494,7 @@ public ICollection Split(ColumnBatch inBV, out ColumnBatch inBV) Contract.Requires(this.State == MultiStringState.Sealed); Contract.Ensures(this.State == MultiStringState.Sealed); - MultiString result = Clone(); + MultiString result = this.Clone(); result.Count = 0; result.EndOffset = 0; var bv = inBV.col; @@ -1736,14 +1731,14 @@ public MultiStringWrapper(MultiString m) this.theActualMultiString = m; this.rowIndex = 0; } - private int StartIndex => this.theActualMultiString.starts.col[this.rowIndex] + 2; + private readonly int StartIndex => this.theActualMultiString.starts.col[this.rowIndex] + 2; /// /// Used internally, but also is the wrapper implementation for String.Length /// [EditorBrowsable(EditorBrowsableState.Never)] - public int Length => this.theActualMultiString.lengths.col[this.rowIndex]; - private string String => this.theActualMultiString.col.charArray.contentString; + public readonly int Length => this.theActualMultiString.lengths.col[this.rowIndex]; + private readonly string String => this.theActualMultiString.col.charArray.contentString; #region IndexOf @@ -1753,7 +1748,7 @@ public MultiStringWrapper(MultiString m) /// /// [EditorBrowsable(EditorBrowsableState.Never)] - public int IndexOf(char value) + public readonly int IndexOf(char value) { var realResult = this.String.IndexOf(value, this.StartIndex, this.Length); return realResult == -1 ? -1 : realResult - this.StartIndex; @@ -1768,7 +1763,7 @@ public int IndexOf(char value) MessageId = "System.String.IndexOf(System.String,System.Int32,System.Int32)", Justification = "This is CLR API substitution, additional intent should not be added on behalf of the user of the API.")] [EditorBrowsable(EditorBrowsableState.Never)] - public int IndexOf(string value) + public readonly int IndexOf(string value) { var realResult = this.String.IndexOf(value, this.StartIndex, this.Length); return realResult == -1 ? -1 : realResult - this.StartIndex; @@ -1781,7 +1776,7 @@ public int IndexOf(string value) /// /// [EditorBrowsable(EditorBrowsableState.Never)] - public int IndexOf(char value, int startIndex) + public readonly int IndexOf(char value, int startIndex) { var realResult = this.String.IndexOf(value, this.StartIndex + startIndex, this.Length - startIndex); return realResult == -1 ? -1 : realResult - this.StartIndex; @@ -1797,7 +1792,7 @@ public int IndexOf(char value, int startIndex) MessageId = "System.String.IndexOf(System.String,System.Int32,System.Int32)", Justification = "This is CLR API substitution, additional intent should not be added on behalf of the user of the API.")] [EditorBrowsable(EditorBrowsableState.Never)] - public int IndexOf(string value, int startIndex) + public readonly int IndexOf(string value, int startIndex) { var realResult = this.String.IndexOf(value, this.StartIndex + startIndex, this.Length - startIndex); return realResult == -1 ? -1 : realResult - this.StartIndex; @@ -1810,7 +1805,7 @@ public int IndexOf(string value, int startIndex) /// /// [EditorBrowsable(EditorBrowsableState.Never)] - public int IndexOf(string value, StringComparison comparisonType) + public readonly int IndexOf(string value, StringComparison comparisonType) { var realResult = this.String.IndexOf(value, this.StartIndex, this.Length, comparisonType); return realResult == -1 ? -1 : realResult - this.StartIndex; @@ -1824,7 +1819,7 @@ public int IndexOf(string value, StringComparison comparisonType) /// /// [EditorBrowsable(EditorBrowsableState.Never)] - public int IndexOf(char value, int startIndex, int count) + public readonly int IndexOf(char value, int startIndex, int count) { var realResult = this.String.IndexOf(value, this.StartIndex + startIndex, count); return realResult == -1 ? -1 : realResult - this.StartIndex; @@ -1841,7 +1836,7 @@ public int IndexOf(char value, int startIndex, int count) MessageId = "System.String.IndexOf(System.String,System.Int32,System.Int32)", Justification = "This is CLR API substitution, additional intent should not be added on behalf of the user of the API.")] [EditorBrowsable(EditorBrowsableState.Never)] - public int IndexOf(string value, int startIndex, int count) + public readonly int IndexOf(string value, int startIndex, int count) { var realResult = this.String.IndexOf(value, this.StartIndex + startIndex, count); return realResult == -1 ? -1 : realResult - this.StartIndex; @@ -1855,7 +1850,7 @@ public int IndexOf(string value, int startIndex, int count) /// /// [EditorBrowsable(EditorBrowsableState.Never)] - public int IndexOf(string value, int startIndex, StringComparison comparisonType) + public readonly int IndexOf(string value, int startIndex, StringComparison comparisonType) { var realResult = this.String.IndexOf(value, this.StartIndex + startIndex, this.Length - startIndex, comparisonType); return realResult == -1 ? -1 : realResult - this.StartIndex; @@ -1870,7 +1865,7 @@ public int IndexOf(string value, int startIndex, StringComparison comparisonType /// /// [EditorBrowsable(EditorBrowsableState.Never)] - public int IndexOf(string value, int startIndex, int count, StringComparison comparisonType) + public readonly int IndexOf(string value, int startIndex, int count, StringComparison comparisonType) { var realResult = this.String.IndexOf(value, this.StartIndex + startIndex, count, comparisonType); return realResult == -1 ? -1 : realResult - this.StartIndex; @@ -1885,7 +1880,7 @@ public int IndexOf(string value, int startIndex, int count, StringComparison com /// /// [EditorBrowsable(EditorBrowsableState.Never)] - public int LastIndexOf(char value) + public readonly int LastIndexOf(char value) { var realResult = this.String.LastIndexOf(value, this.StartIndex + this.Length - 1, this.Length); return realResult == -1 ? -1 : realResult - this.StartIndex; @@ -1900,7 +1895,7 @@ public int LastIndexOf(char value) MessageId = "System.String.LastIndexOf(System.String,System.Int32,System.Int32)", Justification = "This is CLR API substitution, additional intent should not be added on behalf of the user of the API.")] [EditorBrowsable(EditorBrowsableState.Never)] - public int LastIndexOf(string value) + public readonly int LastIndexOf(string value) { var realResult = this.String.LastIndexOf(value, this.StartIndex + this.Length - 1, this.Length); return realResult == -1 ? -1 : realResult - this.StartIndex; @@ -1913,7 +1908,7 @@ public int LastIndexOf(string value) /// /// [EditorBrowsable(EditorBrowsableState.Never)] - public int LastIndexOf(char value, int startIndex) + public readonly int LastIndexOf(char value, int startIndex) { var realResult = this.String.LastIndexOf(value, this.StartIndex + startIndex, this.Length - startIndex); return realResult == -1 ? -1 : realResult - this.StartIndex; @@ -1929,7 +1924,7 @@ public int LastIndexOf(char value, int startIndex) MessageId = "System.String.LastIndexOf(System.String,System.Int32,System.Int32)", Justification = "This is CLR API substitution, additional intent should not be added on behalf of the user of the API.")] [EditorBrowsable(EditorBrowsableState.Never)] - public int LastIndexOf(string value, int startIndex) + public readonly int LastIndexOf(string value, int startIndex) { var realResult = this.String.LastIndexOf(value, this.StartIndex + startIndex, this.Length - startIndex); return realResult == -1 ? -1 : realResult - this.StartIndex; @@ -1942,7 +1937,7 @@ public int LastIndexOf(string value, int startIndex) /// /// [EditorBrowsable(EditorBrowsableState.Never)] - public int LastIndexOf(string value, StringComparison comparisonType) + public readonly int LastIndexOf(string value, StringComparison comparisonType) { var realResult = this.String.LastIndexOf(value, this.StartIndex + this.Length - 1, this.Length, comparisonType); return realResult == -1 ? -1 : realResult - this.StartIndex; @@ -1956,7 +1951,7 @@ public int LastIndexOf(string value, StringComparison comparisonType) /// /// [EditorBrowsable(EditorBrowsableState.Never)] - public int LastIndexOf(char value, int startIndex, int count) + public readonly int LastIndexOf(char value, int startIndex, int count) { var realResult = this.String.LastIndexOf(value, this.StartIndex + startIndex, count); return realResult == -1 ? -1 : realResult - this.StartIndex; @@ -1973,7 +1968,7 @@ public int LastIndexOf(char value, int startIndex, int count) MessageId = "System.String.LastIndexOf(System.String,System.Int32,System.Int32)", Justification = "This is CLR API substitution, additional intent should not be added on behalf of the user of the API.")] [EditorBrowsable(EditorBrowsableState.Never)] - public int LastIndexOf(string value, int startIndex, int count) + public readonly int LastIndexOf(string value, int startIndex, int count) { var realResult = this.String.LastIndexOf(value, this.StartIndex + startIndex, count); return realResult == -1 ? -1 : realResult - this.StartIndex; @@ -1987,7 +1982,7 @@ public int LastIndexOf(string value, int startIndex, int count) /// /// [EditorBrowsable(EditorBrowsableState.Never)] - public int LastIndexOf(string value, int startIndex, StringComparison comparisonType) + public readonly int LastIndexOf(string value, int startIndex, StringComparison comparisonType) { var realResult = this.String.LastIndexOf(value, this.StartIndex + startIndex, this.Length - startIndex, comparisonType); return realResult == -1 ? -1 : realResult - this.StartIndex; @@ -2002,12 +1997,15 @@ public int LastIndexOf(string value, int startIndex, StringComparison comparison /// /// [EditorBrowsable(EditorBrowsableState.Never)] - public int LastIndexOf(string value, int startIndex, int count, StringComparison comparisonType) + public readonly int LastIndexOf(string value, int startIndex, int count, StringComparison comparisonType) { var realResult = this.String.LastIndexOf(value, this.StartIndex + startIndex, count, comparisonType); return realResult == -1 ? -1 : realResult - this.StartIndex; } #endregion } + + [GeneratedRegex(@"([\*\+\}](?!\?))|([^\*\+\}\?]\?(?!\?))")] + private static partial Regex GreedyRegex(); } } \ No newline at end of file diff --git a/Sources/Core/Microsoft.StreamProcessing/StringHandling/MyStringBuilder.cs b/Sources/Core/Microsoft.StreamProcessing/StringHandling/MyStringBuilder.cs index a99ffb9f6..6b36cfd6e 100644 --- a/Sources/Core/Microsoft.StreamProcessing/StringHandling/MyStringBuilder.cs +++ b/Sources/Core/Microsoft.StreamProcessing/StringHandling/MyStringBuilder.cs @@ -84,10 +84,7 @@ public unsafe MyStringBuilder(string value, int startIndex, int length, int capa { value = string.Empty; } - else if (startIndex > (value.Length - length)) - { - throw new ArgumentOutOfRangeException(nameof(length)); - } + else ArgumentOutOfRangeException.ThrowIfGreaterThan(startIndex, value.Length - length); this.m_MaxCapacity = 0x7fffffff; if (capacity == 0) @@ -166,7 +163,7 @@ public unsafe MyStringBuilder Append(string value) } else { - AppendHelper(value); + this.AppendHelper(value); } } return this; @@ -174,7 +171,7 @@ public unsafe MyStringBuilder Append(string value) public MyStringBuilder Append(char value, int repeatCount) { - if (repeatCount < 0) throw new ArgumentOutOfRangeException(nameof(repeatCount)); + ArgumentOutOfRangeException.ThrowIfNegative(repeatCount); if (repeatCount != 0) { int chunkLength = this.m_ChunkLength; @@ -188,7 +185,7 @@ public MyStringBuilder Append(char value, int repeatCount) else { this.m_ChunkLength = chunkLength; - ExpandByABlock(repeatCount); + this.ExpandByABlock(repeatCount); chunkLength = 0; } } @@ -216,7 +213,7 @@ internal unsafe MyStringBuilder Append(char* value, int valueCount) this.m_ChunkLength = this.m_ChunkChars.Length; } int minBlockCharCount = valueCount - count; - ExpandByABlock(minBlockCharCount); + this.ExpandByABlock(minBlockCharCount); ThreadSafeCopy(value + count, this.m_ChunkChars, 0, minBlockCharCount); this.m_ChunkLength = minBlockCharCount; } @@ -228,7 +225,7 @@ private unsafe void AppendHelper(string value) fixed (char* str = value) { char* charPtr = str; - Append(charPtr, value.Length); + this.Append(charPtr, value.Length); } } @@ -323,8 +320,8 @@ public unsafe CharArrayWrapper ToCharArrayWrapperAndDispose() } else { - var result = ToCharArrayWrapper(); - Dispose(); + var result = this.ToCharArrayWrapper(); + this.Dispose(); return result; } } @@ -335,12 +332,9 @@ public int Capacity set { - if (value < 0) - throw new ArgumentOutOfRangeException(nameof(value)); - if (value > this.MaxCapacity) - throw new ArgumentOutOfRangeException(nameof(value)); - if (value < this.Length) - throw new ArgumentOutOfRangeException(nameof(value)); + ArgumentOutOfRangeException.ThrowIfNegative(value); + ArgumentOutOfRangeException.ThrowIfGreaterThan(value, this.MaxCapacity); + ArgumentOutOfRangeException.ThrowIfLessThan(value, this.Length); if (this.Capacity != value) { int num = value - this.m_ChunkOffset; @@ -357,8 +351,8 @@ public int Length set { - if (value < 0 || value > this.MaxCapacity) - throw new ArgumentOutOfRangeException(nameof(value)); + ArgumentOutOfRangeException.ThrowIfNegative(value); + ArgumentOutOfRangeException.ThrowIfGreaterThan(value, this.MaxCapacity); int capacity = this.Capacity; if ((value == 0) && (this.m_ChunkPrevious == null)) { @@ -370,16 +364,16 @@ public int Length int repeatCount = value - this.Length; if (repeatCount > 0) { - Append('\0', repeatCount); + this.Append('\0', repeatCount); } else { - var builder = FindChunkForIndex(value); + var builder = this.FindChunkForIndex(value); if (builder != this) { int num3 = capacity - builder.m_ChunkOffset; char[] destinationArray = new char[num3]; - Array.Copy(builder.m_ChunkChars, destinationArray, builder.m_ChunkLength); + builder.m_ChunkChars.AsSpan(0, builder.m_ChunkLength).CopyTo(destinationArray); this.m_ChunkChars = destinationArray; this.m_ChunkPrevious = builder.m_ChunkPrevious; this.m_ChunkOffset = builder.m_ChunkOffset; diff --git a/Sources/Core/Microsoft.StreamProcessing/Transformer/CommonBaseTemplate.cs b/Sources/Core/Microsoft.StreamProcessing/Transformer/CommonBaseTemplate.cs index 69f83649e..da146bba1 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Transformer/CommonBaseTemplate.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Transformer/CommonBaseTemplate.cs @@ -26,7 +26,7 @@ internal abstract class CommonBaseTemplate /// /// A list of the lengths of each indent that was added with PushIndent /// - private List IndentLengths { get; } = new List(); + private List IndentLengths { get; } = []; /// /// Gets the current indent we use when adding lines to the output @@ -80,7 +80,7 @@ public void Write(string textToAppend) /// public void WriteLine(string textToAppend) { - Write(textToAppend); + this.Write(textToAppend); this.GenerationEnvironment.AppendLine(); this.endsWithNewline = true; } @@ -89,13 +89,13 @@ public void WriteLine(string textToAppend) /// Write formatted text directly into the generated output /// public void Write(string format, params object[] args) - => Write(string.Format(CultureInfo.CurrentCulture, format, args)); + => this.Write(string.Format(CultureInfo.CurrentCulture, format, args)); /// /// Write formatted text directly into the generated output /// public void WriteLine(string format, params object[] args) - => WriteLine(string.Format(CultureInfo.CurrentCulture, format, args)); + => this.WriteLine(string.Format(CultureInfo.CurrentCulture, format, args)); /// /// Increase the indent @@ -114,12 +114,12 @@ public string PopIndent() string returnValue = string.Empty; if (this.IndentLengths.Count > 0) { - int indentLength = this.IndentLengths[this.IndentLengths.Count - 1]; + int indentLength = this.IndentLengths[^1]; this.IndentLengths.RemoveAt(this.IndentLengths.Count - 1); if (indentLength > 0) { - returnValue = this.CurrentIndent.Substring(this.CurrentIndent.Length - indentLength); - this.CurrentIndent = this.CurrentIndent.Remove(this.CurrentIndent.Length - indentLength); + returnValue = this.CurrentIndent[^indentLength..]; + this.CurrentIndent = this.CurrentIndent[..^indentLength]; } } return returnValue; @@ -160,14 +160,14 @@ public IFormatProvider FormatProvider /// public string ToStringWithCulture(object objectToConvert) { - if (objectToConvert == null) throw new ArgumentNullException(nameof(objectToConvert)); + ArgumentNullException.ThrowIfNull(objectToConvert); var t = objectToConvert.GetType(); - var method = t.GetTypeInfo().GetMethod("ToString", new Type[] { typeof(IFormatProvider) }); + var method = t.GetMethod("ToString", [typeof(IFormatProvider)]); return method == null ? objectToConvert.ToString() - : (string)method.Invoke(objectToConvert, new object[] { this.formatProviderField }); + : (string)method.Invoke(objectToConvert, [this.formatProviderField]); } } diff --git a/Sources/Core/Microsoft.StreamProcessing/Transformer/CommonBinaryTemplate.cs b/Sources/Core/Microsoft.StreamProcessing/Transformer/CommonBinaryTemplate.cs index 59bc7bd03..b2f6e54d8 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Transformer/CommonBinaryTemplate.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Transformer/CommonBinaryTemplate.cs @@ -38,47 +38,49 @@ protected CommonBinaryTemplate(string className, Type keyType, Type leftType, Ty this.TResult = this.tm.CSharpNameFor(resultType); } - protected Tuple Generate() => GenerateInternal(2, null); + protected Tuple Generate() => this.GenerateInternal(2, null); protected Tuple Generate(Expression expression = null) - => GenerateInternal(3, expression); + => this.GenerateInternal(3, expression); protected Tuple Generate(Expression expression = null) - => GenerateInternal(4, expression); + => this.GenerateInternal(4, expression); private Tuple GenerateInternal(int numParameters, Expression expression) { string errorMessages = null; try { - var expandedCode = TransformText(); + var expandedCode = this.TransformText(); var assemblyReferences = Transformer.AssemblyReferencesNeededFor(this.keyType, this.leftType, this.rightType, this.resultType); - assemblyReferences.Add(typeof(IStreamable<,>).GetTypeInfo().Assembly); + assemblyReferences.Add(typeof(IStreamable<,>).Assembly); assemblyReferences.Add(Transformer.GeneratedStreamMessageAssembly()); assemblyReferences.Add(Transformer.GeneratedStreamMessageAssembly()); assemblyReferences.Add(Transformer.GeneratedStreamMessageAssembly()); if (expression != null) assemblyReferences.AddRange(Transformer.AssemblyReferencesNeededFor(expression)); - var a = Transformer.CompileSourceCode(expandedCode, assemblyReferences, out errorMessages); + var t = Transformer.CompileSourceCode(expandedCode, assemblyReferences, a => + { + var types = new List { this.keyType, this.leftType }; + if (numParameters > 2) types.Add(this.rightType); + if (numParameters == 4) types.Add(this.resultType); + return a.GetType(this.className.AddNumberOfNecessaryGenericArguments([.. types])); + }, out errorMessages); if (this.keyType.IsAnonymousType()) { - if (errorMessages == null) errorMessages = string.Empty; + errorMessages ??= string.Empty; errorMessages += "\nCodegen Warning: The key type for a binary operator is an anonymous type (or contains an anonymous type), preventing the inlining of the key equality and hashcode functions. This may lead to poor performance.\n"; } - var types = new List { this.keyType, this.leftType }; - if (numParameters > 2) types.Add(this.rightType); - if (numParameters == 4) types.Add(this.resultType); - var realClassName = this.className.AddNumberOfNecessaryGenericArguments(types.ToArray()); - var t = a.GetType(realClassName); - if (t.GetTypeInfo().IsGenericType) + + if (t.IsGenericType) { var list = this.keyType.GetAnonymousTypes(); list.AddRange(this.leftType.GetAnonymousTypes()); if (numParameters > 2) list.AddRange(this.rightType.GetAnonymousTypes()); if (numParameters == 4) list.AddRange(this.resultType.GetAnonymousTypes()); - t = t.MakeGenericType(list.ToArray()); + t = t.MakeGenericType([.. list]); } return Tuple.Create(t, errorMessages); } diff --git a/Sources/Core/Microsoft.StreamProcessing/Transformer/CommonUnaryTemplate.cs b/Sources/Core/Microsoft.StreamProcessing/Transformer/CommonUnaryTemplate.cs index 6b91fb944..50c666361 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Transformer/CommonUnaryTemplate.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Transformer/CommonUnaryTemplate.cs @@ -58,20 +58,22 @@ protected Tuple Generate(params Type[] types) string errorMessages = null; try { - var expandedCode = TransformText(); + var expandedCode = this.TransformText(); var assemblyReferences = Transformer.AssemblyReferencesNeededFor(this.keyType, this.payloadType, typeof(SortedDictionary<,>)); assemblyReferences.AddRange(Transformer.AssemblyReferencesNeededFor(types)); assemblyReferences.Add(Transformer.GeneratedStreamMessageAssembly()); - var a = Transformer.CompileSourceCode(expandedCode, assemblyReferences, out errorMessages); - var realClassName = this.className.AddNumberOfNecessaryGenericArguments(this.keyType, this.payloadType); - var t = a.GetType(realClassName); - if (t.GetTypeInfo().IsGenericType) + var t = Transformer.CompileSourceCode(expandedCode, assemblyReferences, a => + { + var realClassName = this.className.AddNumberOfNecessaryGenericArguments(this.keyType, this.payloadType); + return a.GetType(realClassName); + }, out errorMessages); + if (t.IsGenericType) { var list = this.keyType.GetAnonymousTypes(); list.AddRange(this.payloadType.GetAnonymousTypes()); - return Tuple.Create(t.MakeGenericType(list.ToArray()), errorMessages); + return Tuple.Create(t.MakeGenericType([.. list]), errorMessages); } else return Tuple.Create(t, errorMessages); } @@ -89,7 +91,7 @@ protected Tuple Generate(Type[] types, Ex string errorMessages = null; try { - var expandedCode = TransformText(); + var expandedCode = this.TransformText(); var assemblyReferences = Transformer.AssemblyReferencesNeededFor(this.keyType, this.payloadType, this.resultType, typeof(SortedDictionary<,>)); assemblyReferences.AddRange(Transformer.AssemblyReferencesNeededFor(types)); @@ -101,14 +103,16 @@ protected Tuple Generate(Type[] types, Ex assemblyReferences.Add(Transformer.GeneratedStreamMessageAssembly()); assemblyReferences.Add(Transformer.GeneratedStreamMessageAssembly()); - var a = Transformer.CompileSourceCode(expandedCode, assemblyReferences, out errorMessages); - var realClassName = this.className.AddNumberOfNecessaryGenericArguments(this.keyType, this.payloadType); - var t = a.GetType(realClassName); - if (t.GetTypeInfo().IsGenericType) + var t = Transformer.CompileSourceCode(expandedCode, assemblyReferences,a=> + { + var realClassName = this.className.AddNumberOfNecessaryGenericArguments(this.keyType, this.payloadType); + return a.GetType(realClassName); + }, out errorMessages); + if (t.IsGenericType) { var list = this.keyType.GetAnonymousTypes(); list.AddRange(this.payloadType.GetAnonymousTypes()); - return Tuple.Create(t.MakeGenericType(list.ToArray()), errorMessages); + return Tuple.Create(t.MakeGenericType([.. list]), errorMessages); } else return Tuple.Create(t, errorMessages); } diff --git a/Sources/Core/Microsoft.StreamProcessing/Transformer/EventBatchManager.cs b/Sources/Core/Microsoft.StreamProcessing/Transformer/EventBatchManager.cs index c6b39fcd0..d3823ee3b 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Transformer/EventBatchManager.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Transformer/EventBatchManager.cs @@ -18,11 +18,18 @@ internal static class StreamMessageManager /// /// Maps pair TKey,TPayload to the generated batch type /// - private static readonly SafeConcurrentDictionary cachedObjects = new SafeConcurrentDictionary(); + private static readonly SafeConcurrentDictionary cachedObjects = new(); public static IEnumerable GeneratedTypes() { var enumerator = cachedObjects.GetEnumerator(); - while (enumerator.MoveNext()) yield return enumerator.Current.Value; + while (enumerator.MoveNext()) + { + var t = enumerator.Current.Value; + if (t is not null) + { + yield return t; + } + } } public static Type GetStreamMessageType() @@ -35,7 +42,8 @@ public static Type GetStreamMessageType() var lookupKey = CacheKey.Create(typeOfTKey, typeOfTPayload); - return cachedObjects.GetOrAdd(lookupKey, key => Transformer.GenerateBatchClass()); + var generated = cachedObjects.GetOrAddUnlessNull(lookupKey, key => Transformer.GenerateBatchClass()); + return generated ?? typeof(StreamMessage); } public static StreamMessage GetStreamMessage(MemoryPool pool) diff --git a/Sources/Core/Microsoft.StreamProcessing/Transformer/MemoryPoolTemplate.cs b/Sources/Core/Microsoft.StreamProcessing/Transformer/MemoryPoolTemplate.cs index 9cd4cbbcf..fa8c5e1b0 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Transformer/MemoryPoolTemplate.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Transformer/MemoryPoolTemplate.cs @@ -53,13 +53,13 @@ public override string TransformText() } this.Write("\r\n"); - var typeInfos = types.Select(t => + var poolColumnTypeEntries = types.Select(t => Tuple.Create(String.Format("_{0}_Pool", Transformer.GetValidIdentifier(t)), t.GetCSharpSourceSyntax())); this.Write("\r\npublic sealed class "); this.Write(this.ToStringHelper.ToStringWithCulture(className)); this.Write("<_Key, _Payload> : MemoryPool<_Key, _Payload>\r\n{\r\n"); - foreach (var t in typeInfos) { + foreach (var t in poolColumnTypeEntries) { this.Write("\r\n public ColumnPool<"); this.Write(this.ToStringHelper.ToStringWithCulture(t.Item2)); this.Write("> "); @@ -74,7 +74,7 @@ public override string TransformText() this.Write("\r\n public "); this.Write(this.ToStringHelper.ToStringWithCulture(className)); this.Write("() : base(true)\r\n {\r\n"); - foreach (var t in typeInfos) { + foreach (var t in poolColumnTypeEntries) { this.Write("\r\n "); this.Write(this.ToStringHelper.ToStringWithCulture(t.Item1)); this.Write(" = MemoryManager.GetColumnPool<"); diff --git a/Sources/Core/Microsoft.StreamProcessing/Transformer/MemoryPoolTemplate.tt b/Sources/Core/Microsoft.StreamProcessing/Transformer/MemoryPoolTemplate.tt index b71a0c07e..8da90cbef 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Transformer/MemoryPoolTemplate.tt +++ b/Sources/Core/Microsoft.StreamProcessing/Transformer/MemoryPoolTemplate.tt @@ -26,13 +26,13 @@ using <#= this.payloadType.Namespace #>; <# } #> <# - var typeInfos = types.Select(t => + var poolColumnTypeEntries = types.Select(t => Tuple.Create(String.Format("_{0}_Pool", Transformer.GetValidIdentifier(t)), t.GetCSharpSourceSyntax())); #> public sealed class <#= className #><_Key, _Payload> : MemoryPool<_Key, _Payload> { -<# foreach (var t in typeInfos) { #> +<# foreach (var t in poolColumnTypeEntries) { #> public ColumnPool<<#= t.Item2 #>> <#= t.Item1 #>; @@ -45,7 +45,7 @@ public sealed class <#= className #><_Key, _Payload> : MemoryPool<_Key, _Payload public <#= className #>() : base(true) { -<# foreach (var t in typeInfos) { #> +<# foreach (var t in poolColumnTypeEntries) { #> <#= t.Item1 #> = MemoryManager.GetColumnPool<<#= t.Item2 #>>(); <# } #> diff --git a/Sources/Core/Microsoft.StreamProcessing/Transformer/SelectTransformation.cs b/Sources/Core/Microsoft.StreamProcessing/Transformer/SelectTransformation.cs index 61d68635f..546d6a3f8 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Transformer/SelectTransformation.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Transformer/SelectTransformation.cs @@ -35,7 +35,7 @@ internal sealed class SelectTransformer : ExpressionVisitor private bool error; private readonly List> swingingFields; private readonly Dictionary computedFields; - private readonly ColumnarRepresentation resultTypeInformation; + private readonly ColumnarRepresentation resultColumnarRepresentation; private readonly bool noSwingingFields; private readonly Dictionary parameterInformation; private readonly Expression ProjectionReturningResultInstance; @@ -47,22 +47,22 @@ internal sealed class SelectTransformer : ExpressionVisitor internal static SelectTransformationResult Transform( LambdaExpression function, IEnumerable> substitutionInformation, - ColumnarRepresentation resultTypeInformation, + ColumnarRepresentation resultColumnarRepresentation, bool noSwingingFields = false, bool hasStartEdge = false) { - Contract.Requires(function != null); - Contract.Requires(substitutionInformation != null); - Contract.Requires(resultTypeInformation != null); + ArgumentNullException.ThrowIfNull(function); + ArgumentNullException.ThrowIfNull(substitutionInformation); + ArgumentNullException.ThrowIfNull(resultColumnarRepresentation); - var me = new SelectTransformer(function, substitutionInformation, resultTypeInformation, noSwingingFields, + var me = new SelectTransformer(function, substitutionInformation, resultColumnarRepresentation, noSwingingFields, Config.UseMultiString && ((Config.MultiStringTransforms & Config.CodegenOptions.MultiStringFlags.VectorOperations) != 0), hasStartEdge); // Need to find any unmentioned fields from the result type var unmentionedFields = new List(); if (me.ProjectionReturningResultInstance == null) { - foreach (var kv in resultTypeInformation.Fields) + foreach (var kv in resultColumnarRepresentation.Fields) { var fieldInfo = kv.Value; if (me.swingingFields.Any(t => t.Item1.Equals(fieldInfo))) continue; @@ -91,60 +91,60 @@ internal static SelectTransformationResult Transform( private SelectTransformer( LambdaExpression function, IEnumerable> substitutionInformation, - ColumnarRepresentation resultTypeInformation, + ColumnarRepresentation resultColumnarRepresentation, bool noSwingingFields, bool doMultiStringTransform, bool hasStartEdge) { - this.parameterInformation = new Dictionary(); + this.parameterInformation = []; foreach (var tup in substitutionInformation) { this.parameterInformation.Add(tup.Item1, tup.Item2); } - this.resultTypeInformation = resultTypeInformation; + this.resultColumnarRepresentation = resultColumnarRepresentation; this.noSwingingFields = noSwingingFields; this.doMultiStringTransform = doMultiStringTransform; - this.swingingFields = new List>(); - this.computedFields = new Dictionary(); - this.multiStringOperations = new List(); - this.multiStringResultFields = new List(); + this.swingingFields = []; + this.computedFields = []; + this.multiStringOperations = []; + this.multiStringResultFields = []; var body = function.Body; // The projection might just be (e_1, e_2, ..., e_n) => e_i, i.e., projecting just the single parameter e_i. if (body is ParameterExpression parameter) { - TransformSingleParameterSelect(parameter, hasStartEdge); + this.TransformSingleParameterSelect(parameter, hasStartEdge); return; } // The projection might just be (e_1, e_2, ..., e_n) => e_i.f, i.e., projecting just the single field f from one of the parameters e_i. if (body is MemberExpression memberExpression) { - TransformSingleFieldSelect(memberExpression); + this.TransformSingleFieldSelect(memberExpression); return; } // Case: projection is (e_1, e_2, ..., e_n) => new { f1 = ..., f2 = ..., ...}), i.e., projecting into an anonymous type if (body is NewExpression newExpression && newExpression.Type.IsAnonymousType()) { - Contract.Assume(newExpression.Type == resultTypeInformation.RepresentationFor); + Contract.Assume(newExpression.Type == resultColumnarRepresentation.RepresentationFor); // REVIEW: Should these be turned into part of the if-test? Contract.Assume(newExpression.Arguments != null); Contract.Assume(newExpression.Members != null); Contract.Assume(newExpression.Arguments.Count == newExpression.Members.Count); - TransformAnonymousTypeSelect(newExpression); + this.TransformAnonymousTypeSelect(newExpression); return; } // Case: projection is (e_1, e_2, ..., e_n) => new T{ f1 = ..., f2 = ..., ... }), i.e., T is *not* an anonymous type // TODO: See if this can be unified with the code above for anonymous types. - if (body is MemberInitExpression && !this.resultTypeInformation.noFields) + if (body is MemberInitExpression && !this.resultColumnarRepresentation.noFields) { - Visit(body); + this.Visit(body); return; } @@ -153,16 +153,16 @@ private SelectTransformer( // column's pseudo-field, "payload". // Note that f is either a real method call or else just an expression // that computes a result value (e.g., a type cast which shows up as a unary expression). - if (this.resultTypeInformation.noFields) + if (this.resultColumnarRepresentation.noFields) { if (this.doMultiStringTransform && IsMultiStringCall(body, out string s)) { - this.multiStringOperations.Add($"resultBatch.{this.resultTypeInformation.PseudoField.Name} = {s};"); + this.multiStringOperations.Add($"resultBatch.{this.resultColumnarRepresentation.PseudoField.Name} = {s};"); } else { - var transformedBody = Visit(body); - this.computedFields.Add(this.resultTypeInformation.PseudoField, transformedBody); + var transformedBody = this.Visit(body); + this.computedFields.Add(this.resultColumnarRepresentation.PseudoField, transformedBody); } return; } @@ -172,14 +172,14 @@ private SelectTransformer( (methodCallBody.Method.ReflectedType == typeof(ValueTuple) || methodCallBody.Method.ReflectedType == typeof(Tuple)) && methodCallBody.Method.Name == "Create") { - TransformTupleCreateSelect(methodCallBody); + this.TransformTupleCreateSelect(methodCallBody); return; } // Otherwise, degenerate case: need to just evaluate the expression (with source field access transformed to columnar). // That expression will be passed to the setter for the indexer on the generated batch. // REVIEW: this is where something should be signalled so the user knows it isn't as fast as it could be. - var transformedBody2 = Visit(body); + var transformedBody2 = this.Visit(body); this.ProjectionReturningResultInstance = transformedBody2; return; } @@ -204,20 +204,20 @@ private void TransformSingleFieldSelect(MemberExpression m) return; } var columnarField = selectParameter.parameterRepresentation.Fields[fieldOrAutoProp.Name]; - if (this.resultTypeInformation.noFields) + if (this.resultColumnarRepresentation.noFields) { // Then e.f is of type R (the result type) where R is a primitive type or some type that doesn't get decomposed. // In that case, there doesn't need to be a loop at all. The pointer to the column for f can just be swung to the // corresponding field in the output batch. if (this.noSwingingFields) { - var a = GetBatchColumnIndexer(parameter, columnarField); - this.computedFields.Add(this.resultTypeInformation.PseudoField, a); + var a = this.GetBatchColumnIndexer(parameter, columnarField); + this.computedFields.Add(this.resultColumnarRepresentation.PseudoField, a); } else { this.swingingFields.Add( - Tuple.Create(this.resultTypeInformation.PseudoField, columnarField)); + Tuple.Create(this.resultColumnarRepresentation.PseudoField, columnarField)); } } else @@ -225,8 +225,8 @@ private void TransformSingleFieldSelect(MemberExpression m) // Then e.f is of type R where R is a type that gets decomposed into a column for each field/autoprop. // So this has to behave as RowToCol: the value e.f needs to have its subfields assigned to // the corresponding columns. - var indexVariable = GetIndexVariable(parameter); - foreach (var resultField in this.resultTypeInformation.Fields.Values) + var indexVariable = this.GetIndexVariable(parameter); + foreach (var resultField in this.resultColumnarRepresentation.Fields.Values) { var correspondingVariable = Expression.Variable(columnarField.Type.MakeArrayType(), columnarField.Name + "_col"); var arrayAccess = Expression.ArrayAccess(correspondingVariable, indexVariable); @@ -257,7 +257,7 @@ private IndexExpression GetBatchColumnIndexer(ParameterExpression parameter, MyF var indexVariable = Expression.Variable(typeof(int), parameterInfo.IndexVariableName); if (column.Type.Equals(typeof(Internal.Collections.MultiString))) { - var indexer = typeof(Internal.Collections.MultiString).GetTypeInfo().GetProperty("Item"); + var indexer = typeof(Internal.Collections.MultiString).GetProperty("Item"); return Expression.MakeIndex(column, indexer, new List() { indexVariable }); } else @@ -277,27 +277,27 @@ private IndexExpression GetBatchColumnIndexer(ParameterExpression parameter, MyF /// private void TransformSingleParameterSelect(ParameterExpression parameter, bool hasStartEdge) { - Contract.Assume(parameter.Type == this.resultTypeInformation.RepresentationFor); + Contract.Assume(parameter.Type == this.resultColumnarRepresentation.RepresentationFor); if (!this.parameterInformation.TryGetValue(parameter, out var selectParameter)) { - if (!hasStartEdge && !this.resultTypeInformation.noFields) + if (!hasStartEdge && !this.resultColumnarRepresentation.noFields) { this.error = true; return; } else { - this.computedFields.Add(this.resultTypeInformation.PseudoField, parameter); + this.computedFields.Add(this.resultColumnarRepresentation.PseudoField, parameter); return; } } - foreach (var resultField in this.resultTypeInformation.AllFields) + foreach (var resultField in this.resultColumnarRepresentation.AllFields) { var matchingField = selectParameter.parameterRepresentation.AllFields.First(f => f.OriginalName == resultField.OriginalName); if (this.noSwingingFields) { - var a = GetBatchColumnIndexer(parameter, matchingField); + var a = this.GetBatchColumnIndexer(parameter, matchingField); this.computedFields.Add(resultField, a); } else @@ -314,7 +314,7 @@ private void TransformSingleParameterSelect(ParameterExpression parameter, bool /// private void TransformAnonymousTypeSelect(NewExpression newExpression) { - Contract.Requires(newExpression != null); + ArgumentNullException.ThrowIfNull(newExpression); Contract.Requires(newExpression.Arguments != null); Contract.Requires(newExpression.Members != null); Contract.Requires(newExpression.Arguments.Count == newExpression.Members.Count); @@ -326,7 +326,7 @@ private void TransformAnonymousTypeSelect(NewExpression newExpression) Contract.Assume(destinationField != null); var argument = newExpression.Arguments[i]; - var resultField = this.resultTypeInformation.Fields[destinationField.Name]; // result type must have Fields + var resultField = this.resultColumnarRepresentation.Fields[destinationField.Name]; // result type must have Fields // Special case for MultiString: right-hand side of the assignment could be a method call // (or property, like Length) on a MultiString. This is optimized (but only if @@ -341,10 +341,10 @@ private void TransformAnonymousTypeSelect(NewExpression newExpression) } } - if (HandleSimpleAssignments(argument, resultField)) + if (this.HandleSimpleAssignments(argument, resultField)) continue; - var e = Visit(argument); + var e = this.Visit(argument); this.computedFields.Add(resultField, e); } } @@ -354,13 +354,13 @@ private void TransformAnonymousTypeSelect(NewExpression newExpression) /// private void TransformTupleCreateSelect(MethodCallExpression methodCall) { - Contract.Requires(methodCall != null); + ArgumentNullException.ThrowIfNull(methodCall); Contract.Requires(methodCall.Arguments != null); for (int i = 0; i < methodCall.Arguments.Count; i++) { var argument = methodCall.Arguments[i]; - var resultField = this.resultTypeInformation.Fields[$"Item{i + 1}"]; + var resultField = this.resultColumnarRepresentation.Fields[$"Item{i + 1}"]; // Special case for MultiString: right-hand side of the assignment could be a method call // (or property, like Length) on a MultiString. This is optimized (but only if @@ -371,9 +371,9 @@ private void TransformTupleCreateSelect(MethodCallExpression methodCall) this.multiStringResultFields.Add(resultField); this.multiStringOperations.Add($"resultBatch.{resultField.Name} = {s};"); } - else if (!HandleSimpleAssignments(argument, resultField)) + else if (!this.HandleSimpleAssignments(argument, resultField)) { - var e = Visit(argument); + var e = this.Visit(argument); this.computedFields.Add(resultField, e); } } @@ -394,15 +394,15 @@ protected override MemberAssignment VisitMemberAssignment(MemberAssignment node) this.error = true; return node; } - if (!m.DeclaringType.GetTypeInfo().IsAssignableFrom(this.resultTypeInformation.RepresentationFor)) + if (!m.DeclaringType.IsAssignableFrom(this.resultColumnarRepresentation.RepresentationFor)) { this.error = true; return node; } - var destinationColumn = this.resultTypeInformation.Fields[m.Name]; + var destinationColumn = this.resultColumnarRepresentation.Fields[m.Name]; - if (HandleSimpleAssignments(node.Expression, destinationColumn)) return node; + if (this.HandleSimpleAssignments(node.Expression, destinationColumn)) return node; // Otherwise it is either a MultiString vector operation or just a point-wise computation of a particular row for g if (this.doMultiStringTransform && IsMultiStringCall(node.Expression, out string s)) @@ -413,7 +413,7 @@ protected override MemberAssignment VisitMemberAssignment(MemberAssignment node) else { // Transform all occurrences on the right-hand side into a columnar form. - this.computedFields.Add(destinationColumn, Visit(node.Expression)); + this.computedFields.Add(destinationColumn, this.Visit(node.Expression)); } return node; } @@ -428,7 +428,7 @@ protected override Expression VisitMember(MemberExpression node) if (this.parameterInformation.TryGetValue(parameter, out var selectParameter)) { var columnarField = selectParameter.parameterRepresentation.Fields[member.Name]; - var a = GetBatchColumnIndexer(parameter, columnarField); + var a = this.GetBatchColumnIndexer(parameter, columnarField); return a; } } @@ -467,7 +467,7 @@ protected override Expression VisitParameter(ParameterExpression node) if (selectParameter.parameterRepresentation.noFields) { var columnarField = selectParameter.parameterRepresentation.PseudoField; - var a = GetBatchColumnIndexer(node, columnarField); + var a = this.GetBatchColumnIndexer(node, columnarField); return a; } else @@ -673,7 +673,7 @@ private bool HandleSimpleAssignments(Expression e, MyFieldInfo destinationColumn var columnarField = spi.parameterRepresentation.Fields[simpleAssignedValue.Member.Name]; if (this.noSwingingFields) { - var a = GetBatchColumnIndexer(parameter, columnarField); + var a = this.GetBatchColumnIndexer(parameter, columnarField); this.computedFields.Add(destinationColumn, a); } else @@ -693,7 +693,7 @@ private bool HandleSimpleAssignments(Expression e, MyFieldInfo destinationColumn } if (this.noSwingingFields) { - var a = GetBatchColumnIndexer(parameter, cr.PseudoField); + var a = this.GetBatchColumnIndexer(parameter, cr.PseudoField); this.computedFields.Add(destinationColumn, a); } else diff --git a/Sources/Core/Microsoft.StreamProcessing/Transformer/TemplateClasses.cs b/Sources/Core/Microsoft.StreamProcessing/Transformer/TemplateClasses.cs index 92386842b..76074efe7 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Transformer/TemplateClasses.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Transformer/TemplateClasses.cs @@ -5,16 +5,19 @@ using System; using System.Collections.Concurrent; using System.Collections.Generic; -#if CODEGEN_TIMING using System.Diagnostics; -#endif +using System.Diagnostics.CodeAnalysis; using System.Diagnostics.Contracts; using System.Globalization; using System.IO; using System.Linq; using System.Linq.Expressions; using System.Reflection; +using System.Reflection.Emit; +using System.Runtime.CompilerServices; using System.Runtime.InteropServices; +using System.Runtime.Loader; +using System.Security.Cryptography; using System.Text; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp; @@ -26,22 +29,45 @@ namespace Microsoft.StreamProcessing { internal static class Transformer { - // For .Net Framework, the framework name is like ".NET Framework 4.x.x.x", and uses Net Framework Assembly - // For .Net Core and .Net, the framework name is like ".NET Core 3.x.x" or ".NET 5.x.x", and use Net Core Assembly - private static readonly bool IsNetCore = !RuntimeInformation.FrameworkDescription.StartsWith(".NET Framework"); + private static readonly Lazy> baseAssemblyReferences = new(GetAssemblyReferences); + private static readonly Action updateTopLevelBinderFlags = CreateUpdateTopLevelBinderFlags(); + + private static Action CreateUpdateTopLevelBinderFlags() + { + DynamicMethod method = new("UpdateTopLevelBinderFlags", typeof(void), [typeof(CSharpCompilationOptions)], owner: typeof(Transformer), skipVisibility: true); + ILGenerator generator = method.GetILGenerator(); + generator.Emit(OpCodes.Ldarg_0); + // Get property and enum flags. + var topLevelBinderFlagsProperty = typeof(CSharpCompilationOptions).GetProperty("TopLevelBinderFlags", BindingFlags.Instance | BindingFlags.NonPublic); + var binderFlagsType = topLevelBinderFlagsProperty.PropertyType; + var ignoreCorLibraryDuplicatedTypesMember = binderFlagsType.GetField("IgnoreCorLibraryDuplicatedTypes", BindingFlags.Static | BindingFlags.Public); + var ignoreAccessibility = binderFlagsType.GetField("IgnoreAccessibility", BindingFlags.Static | BindingFlags.Public); + // Combine uints and cast as int for Ldc_I4. + generator.Emit(OpCodes.Ldc_I4, (int)((uint)ignoreCorLibraryDuplicatedTypesMember.GetValue(null) | (uint)ignoreAccessibility.GetValue(null))); + generator.Emit(OpCodes.Callvirt, topLevelBinderFlagsProperty.GetSetMethod(nonPublic: true)); + generator.Emit(OpCodes.Ret); + return (Action)method.CreateDelegate(typeof(Action)); + } - private static readonly Lazy> baseAssemblyReferences - = new Lazy>(() => IsNetCore ? GetNetCoreAssemblyReferences() : GetNetFrameworkAssemblyReferences()); - private static readonly Func AssemblyFromMemoryStream - = IsNetCore ? (Func)AssemblyFromMemoryStreamNetCore : AssemblyFromMemoryStreamNetFramework; - private static readonly Func AssemblyFromFile - = IsNetCore ? (Func)AssemblyFromFileNetCore : AssemblyFromFileNetFramework; + private static readonly SortedDictionary fingerprintReferenceAssemblies = new() + { + ["corlib"] = typeof(object).Assembly, + ["roslynFeatures"] = typeof(Compilation).Assembly, + ["roslynCSharp"] = typeof(CSharpCompilation).Assembly, + ["trill"] = typeof(StreamMessage).Assembly, + }; // used so the compiler has access to the Microsoft.StramProcessing types it needs. // Fix this when there is a static location so we don't have to use Reflection to get it each time - public static Assembly SystemRuntimeSerializationDll = typeof(System.Runtime.Serialization.DataContractAttribute).GetTypeInfo().Assembly; - public static Assembly SystemDll = typeof(Uri).GetTypeInfo().Assembly; - public static Assembly SystemCoreDll = typeof(BinaryExpression).GetTypeInfo().Assembly; + public static Assembly SystemRuntimeSerializationDll = typeof(System.Runtime.Serialization.DataContractAttribute).Assembly; + public static Assembly SystemDll = typeof(Uri).Assembly; + public static Assembly SystemCoreDll = typeof(BinaryExpression).Assembly; + + /// Increments when a Roslyn emit is avoided by loading a matching DLL from . + internal static long CodegenAssemblyCacheHits; + + /// Increments when Roslyn emit runs for a compilation eligible for disk caching (miss or skipped cache). + internal static long CodegenAssemblyCacheMisses; /// /// This is used as part of constructing the name of a field in a StreamMessage that is a column representing a field of the payload type. @@ -75,123 +101,534 @@ public static Type GenerateBatchClass() var payloadType = typeof(TPayload); SafeBatchTemplate.GetGeneratedCode(keyType, payloadType, out string generatedClassName, out string expandedCode, out List assemblyReferences); - assemblyReferences.Add(MemoryManager.GetMemoryPool().GetType().GetTypeInfo().Assembly); + assemblyReferences.Add(MemoryManager.GetMemoryPool().GetType().Assembly); assemblyReferences.Add(SystemRuntimeSerializationDll); if (keyType != typeof(Empty)) { - assemblyReferences.Add(typeof(Empty).GetTypeInfo().Assembly); - assemblyReferences.Add(StreamMessageManager.GetStreamMessageType().GetTypeInfo().Assembly); + assemblyReferences.Add(typeof(Empty).Assembly); + assemblyReferences.Add(StreamMessageManager.GetStreamMessageType().Assembly); } - var a = CompileSourceCode(expandedCode, assemblyReferences, out string errorMessages); - var t = a.GetType(generatedClassName); - if (t.GetTypeInfo().IsGenericType) - { - var list = keyType.GetAnonymousTypes(); - list.AddRange(payloadType.GetAnonymousTypes()); - t = t.MakeGenericType(list.ToArray()); - } + var t = CompileSourceCode( + expandedCode, + assemblyReferences, + a => + { + var ty = a.GetType(generatedClassName); + if (ty is null) + { + return null; + } + + if (ty.IsGenericType) + { + var list = keyType.GetAnonymousTypes(); + list.AddRange(payloadType.GetAnonymousTypes()); + ty = ty.MakeGenericType([.. list]); + } + + return ty; + }, + out string errorMessages); #if CODEGEN_TIMING sw.Stop(); Console.WriteLine("Time to generate and instantiate a batch for {0},{1}: {2}ms", - keyType.GetCSharpSourceSyntax(), payload.GetCSharpSourceSyntax(), sw.ElapsedMilliseconds); + keyType.GetCSharpSourceSyntax(), payloadType.GetCSharpSourceSyntax(), sw.ElapsedMilliseconds); #endif return t; } + internal static void PrepareCompileSourceCodeFingerprintInputs( + string sourceCode, + IEnumerable references, + bool includeIgnoreAccessChecksAssembly, + bool includeDebugInfo, + out List refs, + out CSharpCompilationOptions options, + out SyntaxTree treeForFingerprint) + { + var uniqueReferences = references.Distinct(); + if (includeIgnoreAccessChecksAssembly) + { + uniqueReferences = uniqueReferences.Concat([IgnoreAccessChecks.Assembly]); + } + + uniqueReferences = uniqueReferences.Where(r => !r.FullName.Contains("System.Private.CoreLib")); + + + refs = [ + MetadataReference.CreateFromFile(typeof(StreamMessage).Assembly.Location), + ..baseAssemblyReferences.Value, + ..uniqueReferences.Where(r => Path.IsPathRooted(r.Location)).Select(r => MetadataReference.CreateFromFile(r.Location)), + ..uniqueReferences.Where(reference => metadataReferenceCache.ContainsKey(reference)).Select(reference => metadataReferenceCache[reference]) + ]; + + options = new CSharpCompilationOptions( + OutputKind.DynamicallyLinkedLibrary, + metadataImportOptions: MetadataImportOptions.All, + allowUnsafe: true, + optimizationLevel: includeDebugInfo ? OptimizationLevel.Debug : OptimizationLevel.Release); + + updateTopLevelBinderFlags.Invoke(options); + + treeForFingerprint = CSharpSyntaxTree.ParseText( + sourceCode, + encoding: Encoding.GetEncoding(0), + options: new CSharpParseOptions(LanguageVersion.Latest)); + } + /// - /// Given a string, , that represents a compilable assembly, compile it into an assembly which is located - /// in a sub-directory of the current working directory named "Generated", unless overriden by changing value of Config.GeneratedCodePath. - /// If it is successful, then the resulting assembly is loaded and returned. Otherwise, null is returned and the - /// parameter will contain the compiler errors. - /// The parameter allows the client to specify the location of assemblies that are needed to compile - /// the code. - /// The parameter allows the generated assembly to reference - /// the IgnoreAccessChecksTo attribute for access to Microsoft.StreamProcessing. + /// Compiles with Roslyn and loads the resulting assembly (including from the codegen disk cache when configured). + /// Runs on that assembly immediately. If resolution fails but the assembly was loaded from the disk cache, + /// the cached DLL for that fingerprint is removed and compilation is retried once with a fresh emit. + /// When debug codegen is enabled and paths are set, sources may be written under . + /// On failure, null is returned and contains compiler diagnostics and/or resolution details. /// - [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Reliability", "CA2001:AvoidCallingProblematicMethods", MessageId = "System.Reflection.GetTypeInfo().Assembly.LoadFrom", Justification = "There is no better way to load dynamically generated assembly.")] - public static Assembly CompileSourceCode(string sourceCode, IEnumerable references, out string errorMessages, bool includeIgnoreAccessChecksAssembly = true) + /// C# source text for the dynamic assembly. + /// Additional assemblies to reference during compilation. + /// Obtains the required from the loaded assembly (for example via and ). + /// Roslyn diagnostics when compilation fails; resolution failures append explanatory text (including when a stale cache entry is discarded). + /// If , includes the synthesized IgnoresAccessChecksTo assembly so generated code can use Trill internals. + /// The type produced by , or null if compilation or loading failed or returned null after retry. + public static Type CompileSourceCode( + string sourceCode, + IEnumerable references, + Func resolveType, + out string errorMessages, + bool includeIgnoreAccessChecksAssembly = true) { + ArgumentNullException.ThrowIfNull(resolveType); + #if CODEGEN_TIMING Stopwatch sw = new Stopwatch(); sw.Start(); #endif bool includeDebugInfo = Config.CodegenOptions.GenerateDebugInfo; - var uniqueReferences = references.Distinct(); + bool diskCacheRequested = !string.IsNullOrWhiteSpace(Config.CodegenAssemblyCachePath); - if (includeIgnoreAccessChecksAssembly) - uniqueReferences = uniqueReferences.Concat(new Assembly[] { IgnoreAccessChecks.Assembly }); + PrepareCompileSourceCodeFingerprintInputs(sourceCode, references, includeIgnoreAccessChecksAssembly, includeDebugInfo, out List refs, out CSharpCompilationOptions options, out SyntaxTree treeForFingerprint); - if (IsNetCore) + var assemblyName = Path.GetFileNameWithoutExtension(Path.GetRandomFileName()); + string fingerprintHex = null; + + if (diskCacheRequested && TryComputeCodegenDiskCacheIdentity( + treeForFingerprint, + refs, + options, + includeIgnoreAccessChecksAssembly, + includeDebugInfo, + out string deterministicName, + out fingerprintHex)) { - uniqueReferences = uniqueReferences.Where(r => !r.FullName.Contains("System.Private.CoreLib")); + assemblyName = deterministicName; + } + else + { + assemblyName = Path.GetFileNameWithoutExtension(Path.GetRandomFileName()); + fingerprintHex = null; } - - var assemblyName = Path.GetFileNameWithoutExtension(Path.GetRandomFileName()); SyntaxTree tree; - - if (includeDebugInfo) + if (includeDebugInfo + && diskCacheRequested + && !string.IsNullOrWhiteSpace(Config.GeneratedCodePath)) { if (!Directory.Exists(Config.GeneratedCodePath)) { Directory.CreateDirectory(Config.GeneratedCodePath); // let any exceptions bleed through } + var baseFile = Path.Combine(Config.GeneratedCodePath, assemblyName); - var sourceFile = Path.ChangeExtension(baseFile, ".cs"); - tree = CSharpSyntaxTree.ParseText( - sourceCode, - path: Path.GetFullPath(sourceFile), - encoding: Encoding.GetEncoding(0), - options: new CSharpParseOptions(LanguageVersion.Latest)); + string sourcePath = Path.GetFullPath(Path.ChangeExtension(baseFile, ".cs")); + tree = treeForFingerprint.WithFilePath(sourcePath); } else { - tree = CSharpSyntaxTree.ParseText( - sourceCode, - encoding: Encoding.GetEncoding(0), - options: new CSharpParseOptions(LanguageVersion.Latest)); + tree = treeForFingerprint; } - MetadataReference trill = MetadataReference.CreateFromFile(typeof(StreamMessage).GetTypeInfo().Assembly.Location); - var baseReferences = new List() { trill }; - - var refs = baseReferences - .Concat(baseAssemblyReferences.Value) - .Concat(uniqueReferences.Where(r => Path.IsPathRooted(r.Location)).Select(r => MetadataReference.CreateFromFile(r.Location))) - .Concat(uniqueReferences.Where(reference => metadataReferenceCache.ContainsKey(reference)).Select(reference => metadataReferenceCache[reference])); + // Disk codegen cache (read/write under CodegenAssemblyCachePath) only when configured and fingerprinting succeeded. + string cacheRoot = diskCacheRequested && fingerprintHex != null ? Config.CodegenAssemblyCachePath : null; - var options = new CSharpCompilationOptions( - OutputKind.DynamicallyLinkedLibrary, - metadataImportOptions: MetadataImportOptions.All, - allowUnsafe: true, - optimizationLevel: (includeDebugInfo ? OptimizationLevel.Debug : OptimizationLevel.Release)); - - var topLevelBinderFlagsProperty = typeof(CSharpCompilationOptions).GetTypeInfo().GetProperty("TopLevelBinderFlags", BindingFlags.Instance | BindingFlags.NonPublic); - var binderFlagsType = typeof(CSharpCompilationOptions).GetTypeInfo().Assembly.GetType("Microsoft.CodeAnalysis.CSharp.BinderFlags"); - var ignoreCorLibraryDuplicatedTypesMember = binderFlagsType.GetTypeInfo().GetField("IgnoreCorLibraryDuplicatedTypes", BindingFlags.Static | BindingFlags.Public); - var ignoreAccessibility = binderFlagsType.GetTypeInfo().GetField("IgnoreAccessibility", BindingFlags.Static | BindingFlags.Public); - topLevelBinderFlagsProperty.SetValue(options, (uint)ignoreCorLibraryDuplicatedTypesMember.GetValue(null) | (uint)ignoreAccessibility.GetValue(null)); + for (int resolveAttempt = 0; resolveAttempt < 2; resolveAttempt++) + { + // After a failed resolve on a cache hit, the first assembly remains loaded in the default ALC; a retry emit + // must use a new simple name so LoadFromStream can succeed. + string emitAssemblyName = resolveAttempt == 0 ? assemblyName : $"{assemblyName}__retry{resolveAttempt}"; + var compilation = CSharpCompilation.Create(emitAssemblyName, [tree], refs, options); + + var assembly = EmitCompilationAndLoadAssembly( + compilation, + includeDebugInfo, + out errorMessages, + out bool loadedFromCodegenDiskCache, + cacheRoot, + fingerprintHex); + + if (assembly is null) + { +#if CODEGEN_TIMING + sw.Stop(); + Console.WriteLine("Time to compile: {0}ms", sw.ElapsedMilliseconds); +#endif + return null; + } - SyntaxTree[] trees = { tree }; - var compilation = CSharpCompilation.Create(assemblyName, trees, refs, options); - var assembly = EmitCompilationAndLoadAssembly(compilation, includeDebugInfo, out errorMessages); + try + { + Type resolved = resolveType(assembly); + if (resolved is null) + { + const string msg = "Type resolution returned null for the generated assembly."; + if (resolveAttempt == 0 + && loadedFromCodegenDiskCache + && !string.IsNullOrEmpty(cacheRoot) + && !string.IsNullOrEmpty(fingerprintHex)) + { + TryDeleteCodegenCacheDll(cacheRoot, fingerprintHex); + string retryNote = msg + " Discarded codegen cache entry and retrying with a fresh emit."; + errorMessages = string.IsNullOrEmpty(errorMessages) ? retryNote : errorMessages + Environment.NewLine + retryNote; + continue; + } + + errorMessages = string.IsNullOrEmpty(errorMessages) ? msg : errorMessages + Environment.NewLine + msg; +#if CODEGEN_TIMING + sw.Stop(); + Console.WriteLine("Time to compile: {0}ms", sw.ElapsedMilliseconds); +#endif + return null; + } #if CODEGEN_TIMING - sw.Stop(); - Console.WriteLine("Time to compile: {0}ms", sw.ElapsedMilliseconds); + sw.Stop(); + Console.WriteLine("Time to compile: {0}ms", sw.ElapsedMilliseconds); #endif - return assembly; + return resolved; + } + catch (Exception ex) when (resolveAttempt == 0 + && loadedFromCodegenDiskCache + && !string.IsNullOrEmpty(cacheRoot) + && !string.IsNullOrEmpty(fingerprintHex)) + { + TryDeleteCodegenCacheDll(cacheRoot, fingerprintHex); + string retryNote = "Type resolution failed on a cached assembly; discarded codegen cache entry and retrying with a fresh emit." + Environment.NewLine + ex; + errorMessages = string.IsNullOrEmpty(errorMessages) ? retryNote : errorMessages + Environment.NewLine + retryNote; + } + } + + throw new InvalidOperationException("Internal error: codegen resolve retry exceeded."); } - public static ConcurrentDictionary metadataReferenceCache = new ConcurrentDictionary(); - private static readonly InteractiveAssemblyLoader loader = new InteractiveAssemblyLoader(); + public static ConcurrentDictionary metadataReferenceCache = new(); + + /// + /// SHA256-based identity for each in-memory PE we expose as a Roslyn stream reference, so disk-cache + /// fingerprints stay correct and we do not disable caching merely because a ref is stream-backed. + /// + private static readonly ConcurrentDictionary codegenPeIdentityByAssembly = new(); - internal static Assembly EmitCompilationAndLoadAssembly(CSharpCompilation compilation, bool makeAssemblyDebuggable, out string errorMessages) + private static readonly InteractiveAssemblyLoader loader = new(); + + private static void RegisterCodegenPeIdentity(Assembly assembly, ReadOnlySpan peImage) { - Contract.Requires(compilation.SyntaxTrees.Count() == 1); + if (assembly is null) + { + return; + } + + string id = "pe|" + Convert.ToHexString(SHA256.HashData(peImage)).ToLowerInvariant(); + _ = codegenPeIdentityByAssembly.TryAdd(assembly, id); + } + + private static bool TryFindAssemblyForPortableExecutableMetadata(PortableExecutableReference per, out Assembly assembly) + { + foreach (KeyValuePair kv in metadataReferenceCache) + { + if (ReferenceEquals(kv.Value, per)) + { + assembly = kv.Key; + return true; + } + } + + assembly = null; + return false; + } + + private static string GetAssemblyFingerprint(Assembly asm) + { + string info = asm.GetCustomAttribute()?.InformationalVersion; + if (!string.IsNullOrEmpty(info)) + { + return info; + } + + return asm.GetName().Version?.ToString() ?? asm.FullName ?? string.Empty; + } + + /// + /// Builds a fingerprint of Roslyn inputs and a deterministic assembly name so the same logical compilation + /// produces the same PE across processes when disk caching is enabled. Includes whether portable PDB emit is + /// used so debug and release codegen paths do not share a cache entry when they differ. + /// + internal static bool TryComputeFingerprint( + string source, + [AllowNull] ParseOptions parseOptions, + List refs, + CSharpCompilationOptions options, + bool includeIgnoreAccessChecksAssembly, + bool emitPortablePdb, + [MaybeNullWhen(false)] out string assemblyName, + [MaybeNullWhen(false)] out string fingerprintHex) + { + assemblyName = null; + fingerprintHex = null; + + var parseOpts = parseOptions as CSharpParseOptions; + var langVer = parseOpts?.LanguageVersion.ToString() ?? string.Empty; + using MemoryStream ms = new(Math.Max(1024, source.Length + refs.Count * 128)); + using (StreamWriter writer = new(ms, leaveOpen: true)) + { + writer.WriteLine("v3"); + WriteBoolean(includeIgnoreAccessChecksAssembly); + WriteBoolean(emitPortablePdb); + Write(options.OptimizationLevel, "optimization"); + WriteBoolean(options.AllowUnsafe, "allowUnsafe"); + Write(langVer); + Write(RuntimeInformation.FrameworkDescription, "framework"); + Write(RuntimeInformation.ProcessArchitecture, "architecture"); + Write(Environment.Version, "runtimeVersion"); + Write(AppContext.GetData("TARGETFRAMEWORKNAME")?.ToString() ?? string.Empty, "tfm"); + foreach ((string key, Assembly assembly) in fingerprintReferenceAssemblies) + { + Write(GetAssemblyFingerprint(assembly), key); + } + Write(source); + WriteKey("refs"); + writer.WriteLine(); + foreach (var mr in refs.OrderBy(r => r.Display ?? string.Empty, StringComparer.Ordinal)) + { + if (mr is not PortableExecutableReference per) + { + return false; + } + + if (!string.IsNullOrEmpty(per.FilePath) && File.Exists(per.FilePath)) + { + AssemblyName refIdentity; + try + { + refIdentity = AssemblyName.GetAssemblyName(per.FilePath); + } + catch (BadImageFormatException) + { + return false; + } + catch (FileNotFoundException) + { + return false; + } + catch (ArgumentException) + { + return false; + } + catch (IOException) + { + return false; + } + writer.WriteLine($"F|{per.FilePath}|{refIdentity.FullName}"); + } + else + { + if (!TryFindAssemblyForPortableExecutableMetadata(per, out Assembly dynAsm) + || !codegenPeIdentityByAssembly.TryGetValue(dynAsm, out string peId)) + { + return false; + } + writer.WriteLine($"S|{peId}"); + } + } + + void WriteKey(string key) + { + writer.Write($"{key}:"); + } + + void WriteBoolean(bool value, [CallerArgumentExpression(nameof(value))] string key = "") + { + WriteKey(key); + writer.WriteLine(value); + } + + void Write([AllowNull] T value, [CallerArgumentExpression(nameof(value))] string key = "") + { + WriteKey(key); + writer.WriteLine(value); + } + } + ms.Position = 0; // Seek to beginning before computing hash. + fingerprintHex = Convert.ToHexString(SHA256.HashData(ms)).ToLowerInvariant(); + assemblyName = $"tg{fingerprintHex[..16]}"; + return true; + } + + private static bool TryComputeCodegenDiskCacheIdentity( + SyntaxTree tree, + List refs, + CSharpCompilationOptions options, + bool includeIgnoreAccessChecksAssembly, + bool emitPortablePdb, + out string assemblyName, + out string fingerprintHex) + => TryComputeFingerprint( + tree.GetRoot().ToFullString(), + tree.Options, + refs, + options, + includeIgnoreAccessChecksAssembly, + emitPortablePdb, + out assemblyName, + out fingerprintHex); + + private static bool TryLoadAssemblyFromCodegenCache(string cacheRoot, string fingerprintHex, out Assembly assembly) + { + assembly = null; + var path = Path.Combine(cacheRoot, fingerprintHex + ".dll"); + if (!File.Exists(path)) + { + return false; + } + + byte[] bytes; + try + { + bytes = File.ReadAllBytes(path); + } + catch (IOException) + { + return false; + } + catch (UnauthorizedAccessException) + { + return false; + } + + if (bytes.Length == 0) + { + return false; + } + + try + { + assembly = AssemblyFromMemoryStream(new MemoryStream(bytes)); + loader.RegisterDependency(assembly); + var aref = MetadataReference.CreateFromStream(new MemoryStream(bytes)); + if (metadataReferenceCache.TryAdd(assembly, aref)) + { + RegisterCodegenPeIdentity(assembly, bytes); + } + + CodegenAssemblyCacheHits++; + return true; + } + catch (BadImageFormatException) + { + assembly = null; + return false; + } + catch (FileLoadException) + { + assembly = null; + return false; + } + } + + private static void TryWriteCodegenCacheFile(string cacheRoot, string fingerprintHex, byte[] peImage) + { + try + { + if (!Directory.Exists(cacheRoot)) + { + Directory.CreateDirectory(cacheRoot); + } + + var dest = Path.Combine(cacheRoot, fingerprintHex + ".dll"); + var tmp = Path.Combine(cacheRoot, fingerprintHex + "." + Guid.NewGuid().ToString("N") + ".tmp"); + File.WriteAllBytes(tmp, peImage); + File.Move(tmp, dest, overwrite: true); + } + catch (IOException) + { + } + catch (UnauthorizedAccessException) + { + } + } + + /// Removes a fingerprinted codegen cache DLL so the next load is forced through Roslyn emit. + private static void TryDeleteCodegenCacheDll(string cacheRoot, string fingerprintHex) + { + if (string.IsNullOrEmpty(cacheRoot) || string.IsNullOrEmpty(fingerprintHex)) + { + return; + } + + try + { + var path = Path.Combine(cacheRoot, fingerprintHex + ".dll"); + if (File.Exists(path)) + { + File.Delete(path); + } + } + catch (IOException) + { + } + catch (UnauthorizedAccessException) + { + } + } + + internal static Assembly EmitCompilationAndLoadAssembly( + CSharpCompilation compilation, + bool makeAssemblyDebuggable, + out string errorMessages, + out bool loadedFromCodegenDiskCache, + string codegenCacheRoot = null, + string fingerprintHex = null) + { + Contract.Requires(compilation.SyntaxTrees.Length == 1); + + loadedFromCodegenDiskCache = false; + + if (!string.IsNullOrEmpty(codegenCacheRoot) + && !string.IsNullOrEmpty(fingerprintHex) + && TryLoadAssemblyFromCodegenCache(codegenCacheRoot, fingerprintHex, out Assembly cached)) + { + if (makeAssemblyDebuggable) + { + // Optional: sync .cs next to the debug output path when loading from CodegenAssemblyCachePath (already non-empty here). + SyntaxTree tree = compilation.SyntaxTrees.Single(); + string baseFile = tree.FilePath; + if (!string.IsNullOrEmpty(baseFile)) + { + string dir = Path.GetDirectoryName(baseFile); + if (!string.IsNullOrEmpty(dir) && !Directory.Exists(dir)) + { + Directory.CreateDirectory(dir); + } + + string sourceFile = Path.ChangeExtension(baseFile, ".cs"); + File.WriteAllText(sourceFile, tree.GetRoot().ToFullString()); + } + } + + errorMessages = string.Empty; + loadedFromCodegenDiskCache = true; + return cached; + } Assembly assembly = null; EmitResult emitResult; @@ -199,34 +636,99 @@ internal static Assembly EmitCompilationAndLoadAssembly(CSharpCompilation compil if (makeAssemblyDebuggable) { var tree = compilation.SyntaxTrees.Single(); - var baseFile = tree.FilePath; - var sourceFile = Path.ChangeExtension(baseFile, ".cs"); - File.WriteAllText(sourceFile, tree.GetRoot().ToFullString()); - var assemblyFile = Path.ChangeExtension(baseFile, ".dll"); - using (var assemblyStream = File.Open(assemblyFile, FileMode.Create, FileAccess.Write)) - using (var pdbStream = File.Open(Path.ChangeExtension(baseFile, ".pdb"), FileMode.Create, FileAccess.Write)) + string baseFile = tree.FilePath; + if (!string.IsNullOrEmpty(baseFile)) { - emitResult = compilation.Emit(assemblyStream, pdbStream, options: new EmitOptions(debugInformationFormat: DebugInformationFormat.PortablePdb)); - } + var sourceFile = Path.ChangeExtension(baseFile, ".cs"); + File.WriteAllText(sourceFile, tree.GetRoot().ToFullString()); + var assemblyFile = Path.ChangeExtension(baseFile, ".dll"); + using (var assemblyStream = File.Open(assemblyFile, FileMode.Create, FileAccess.Write)) + using (var pdbStream = File.Open(Path.ChangeExtension(baseFile, ".pdb"), FileMode.Create, FileAccess.Write)) + { + emitResult = compilation.Emit(assemblyStream, pdbStream, options: new EmitOptions(debugInformationFormat: DebugInformationFormat.PortablePdb)); + } - if (emitResult.Success) + if (emitResult.Success) + { + if (!string.IsNullOrEmpty(codegenCacheRoot)) + { + CodegenAssemblyCacheMisses++; + } + + assembly = AssemblyFromFile(assemblyFile); + if (!string.IsNullOrEmpty(codegenCacheRoot) && !string.IsNullOrEmpty(fingerprintHex)) + { + try + { + byte[] peImage = File.ReadAllBytes(assemblyFile); + TryWriteCodegenCacheFile(codegenCacheRoot, fingerprintHex, peImage); + var aref = MetadataReference.CreateFromStream(new MemoryStream(peImage)); + if (metadataReferenceCache.TryAdd(assembly, aref)) + { + RegisterCodegenPeIdentity(assembly, peImage); + } + } + catch (IOException) + { + } + catch (UnauthorizedAccessException) + { + } + } + } + } + else { - assembly = AssemblyFromFile(assemblyFile); + using var peStream = new MemoryStream(); + using var pdbStream = new MemoryStream(); + emitResult = compilation.Emit(peStream, pdbStream, options: new EmitOptions(debugInformationFormat: DebugInformationFormat.PortablePdb)); + if (emitResult.Success) + { + if (!string.IsNullOrEmpty(codegenCacheRoot)) + { + CodegenAssemblyCacheMisses++; + } + + byte[] peImage = peStream.ToArray(); + if (!string.IsNullOrEmpty(codegenCacheRoot) && !string.IsNullOrEmpty(fingerprintHex)) + { + TryWriteCodegenCacheFile(codegenCacheRoot, fingerprintHex, peImage); + } + + assembly = AssemblyFromMemoryStream(new MemoryStream(peImage)); + loader.RegisterDependency(assembly); + var aref = MetadataReference.CreateFromStream(new MemoryStream(peImage)); + if (metadataReferenceCache.TryAdd(assembly, aref)) + { + RegisterCodegenPeIdentity(assembly, peImage); + } + } } } else { - using (var stream = new MemoryStream()) + using var stream = new MemoryStream(); + emitResult = compilation.Emit(stream); + if (emitResult.Success) { - emitResult = compilation.Emit(stream); - if (emitResult.Success) + if (!string.IsNullOrEmpty(codegenCacheRoot)) { - stream.Position = 0; - assembly = AssemblyFromMemoryStream(stream); + CodegenAssemblyCacheMisses++; + } - loader.RegisterDependency(assembly); - var aref = MetadataReference.CreateFromStream(stream); - metadataReferenceCache.TryAdd(assembly, aref); + byte[] peImage = stream.ToArray(); + if (!string.IsNullOrEmpty(codegenCacheRoot) && !string.IsNullOrEmpty(fingerprintHex)) + { + TryWriteCodegenCacheFile(codegenCacheRoot, fingerprintHex, peImage); + } + + assembly = AssemblyFromMemoryStream(new MemoryStream(peImage)); + + loader.RegisterDependency(assembly); + var aref = MetadataReference.CreateFromStream(new MemoryStream(peImage)); + if (metadataReferenceCache.TryAdd(assembly, aref)) + { + RegisterCodegenPeIdentity(assembly, peImage); } } } @@ -234,14 +736,12 @@ internal static Assembly EmitCompilationAndLoadAssembly(CSharpCompilation compil errorMessages = string.Join("\n", emitResult.Diagnostics); if (makeAssemblyDebuggable && emitResult.Diagnostics.Any(d => d.Severity == DiagnosticSeverity.Error)) - System.Diagnostics.Debug.WriteLine(errorMessages); + Debug.WriteLine(errorMessages); return assembly; } - #region netcore - - internal static IEnumerable GetNetCoreAssemblyReferences() + internal static IEnumerable GetAssemblyReferences() { var allAvailableAssemblies = ((string)AppContext.GetData("TRUSTED_PLATFORM_ASSEMBLIES")) .Split(RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? ';' : ':'); @@ -277,50 +777,25 @@ internal static IEnumerable GetNetCoreAssemblyRefer "System.Threading.Tasks.Parallel", "System.Threading.Thread", }; - var filteredPaths = allAvailableAssemblies.Where(p => files.Concat(new string[] { "mscorlib", "netstandard", "System.Private.CoreLib", "System.Runtime.Serialization.Primitives", }).Any(f => Path.GetFileNameWithoutExtension(p).Equals(f))); - return filteredPaths.Select(p => MetadataReference.CreateFromFile(p)); + var filteredPaths = allAvailableAssemblies.Where(p => files.Concat(["mscorlib", "netstandard", "System.Private.CoreLib", "System.Runtime.Serialization.Primitives",]).Any(f => Path.GetFileNameWithoutExtension(p).Equals(f))); + return filteredPaths.Select(path => MetadataReference.CreateFromFile(path)); } - // Important - System.Runtime.Loader should not be referenced by any function that can run in a net framework environment! - internal static Assembly AssemblyFromMemoryStreamNetCore(MemoryStream stream) + internal static Assembly AssemblyFromMemoryStream(MemoryStream stream) { - var assembly = System.Runtime.Loader.AssemblyLoadContext.Default.LoadFromStream(stream); + var assembly = AssemblyLoadContext.Default.LoadFromStream(stream); stream.Position = 0; // Must reset it! Loading leaves its position at the end return assembly; } - internal static Assembly AssemblyFromFileNetCore(string file) => System.Runtime.Loader.AssemblyLoadContext.Default.LoadFromAssemblyPath(file); - - #endregion netcore - - #region netframework - - internal static IEnumerable GetNetFrameworkAssemblyReferences() - { - MetadataReference mscorlib = MetadataReference.CreateFromFile(typeof(object).GetTypeInfo().Assembly.Location); - MetadataReference numerics = MetadataReference.CreateFromFile(typeof(System.Numerics.Complex).GetTypeInfo().Assembly.Location); - MetadataReference linq = MetadataReference.CreateFromFile(typeof(Enumerable).GetTypeInfo().Assembly.Location); - MetadataReference contracts = MetadataReference.CreateFromFile(typeof(System.Runtime.Serialization.DataContractAttribute).GetTypeInfo().Assembly.Location); - - // If we are compiling a netstandard binary from net framework environment, we have to explicitly add a reference to netstandard - var netstandardPath = Path.Combine(Path.GetDirectoryName(typeof(object).GetTypeInfo().Assembly.Location), "netstandard.dll"); - MetadataReference netstandard = MetadataReference.CreateFromFile(netstandardPath); - - return new MetadataReference[] { mscorlib, numerics, linq, contracts, netstandard }; - } - - internal static Assembly AssemblyFromMemoryStreamNetFramework(MemoryStream stream) => Assembly.Load(stream.ToArray()); - - internal static Assembly AssemblyFromFileNetFramework(string file) => Assembly.LoadFrom(file); - - #endregion netframework + internal static Assembly AssemblyFromFile(string file) => AssemblyLoadContext.Default.LoadFromAssemblyPath(file); internal static IEnumerable AssemblyReferencesNeededForType(Type type) { var closure = new HashSet(); CollectAssemblyReferences(type, closure); var result = closure - .Select(t => t.GetTypeInfo().Assembly) + .Select(t => t.Assembly) .Where(t => !t.IsDynamic) .Distinct(); return result; @@ -330,18 +805,18 @@ internal static void CollectAssemblyReferences(Type t, HashSet partialClos { if (partialClosure.Add(t)) { - if (t.GetTypeInfo().BaseType != null) - CollectAssemblyReferences(t.GetTypeInfo().BaseType, partialClosure); + if (t.BaseType != null) + CollectAssemblyReferences(t.BaseType, partialClosure); if (t.IsNested) CollectAssemblyReferences(t.DeclaringType, partialClosure); - foreach (var j in t.GetTypeInfo().GetInterfaces()) + foreach (var j in t.GetInterfaces()) CollectAssemblyReferences(j, partialClosure); foreach (var genericArgument in t.GenericTypeArguments) CollectAssemblyReferences(genericArgument, partialClosure); - foreach (var f in t.GetTypeInfo().GetFields(BindingFlags.Public | BindingFlags.Instance)) + foreach (var f in t.GetFields(BindingFlags.Public | BindingFlags.Instance)) CollectAssemblyReferences(f.FieldType, partialClosure); - foreach (var p in t.GetTypeInfo().GetProperties(BindingFlags.Public | BindingFlags.Instance)) + foreach (var p in t.GetProperties(BindingFlags.Public | BindingFlags.Instance)) CollectAssemblyReferences(p.PropertyType, partialClosure); } } @@ -350,22 +825,11 @@ public static IEnumerable AssemblyReferencesNeededFor(Expression expre => AssemblyLocationFinder.GetAssemblyLocationsFor(expression); public static IEnumerable AssemblyReferencesNeededFor(params Expression[] expressions) - { - var assemblies = new HashSet(); - foreach (var expression in expressions) - { - foreach (var assembly in AssemblyLocationFinder.GetAssemblyLocationsFor(expression)) - { - assemblies.Add(assembly); - } - } - - return assemblies; - } + => expressions.SelectMany(AssemblyLocationFinder.GetAssemblyLocationsFor).Distinct(); private sealed class AssemblyLocationFinder : ExpressionVisitor { - private readonly HashSet assemblyLocations = new HashSet(); + private readonly HashSet assemblyLocations = []; private AssemblyLocationFinder() { } public static IEnumerable GetAssemblyLocationsFor(Expression e) @@ -376,7 +840,7 @@ public static IEnumerable GetAssemblyLocationsFor(Expression e) } protected override Expression VisitMember(MemberExpression node) { - var a = node.Member.DeclaringType.GetTypeInfo().Assembly; + var a = node.Member.DeclaringType.Assembly; this.assemblyLocations.Add(a); return base.VisitMember(node); } @@ -385,7 +849,7 @@ protected override Expression VisitMethodCall(MethodCallExpression node) var method = node.Method; if (method.IsStatic) { - var a = method.DeclaringType.GetTypeInfo().Assembly; + var a = method.DeclaringType.Assembly; this.assemblyLocations.Add(a); } return base.VisitMethodCall(node); @@ -413,21 +877,27 @@ public IgnoresAccessChecksToAttribute(string assemblyName) internal static Assembly Assembly => lazySingleton.Value; - private static readonly Lazy lazySingleton = new Lazy(() => CreateIgnoreAccessChecksAssembly()); + private static readonly Lazy lazySingleton = new(CreateIgnoreAccessChecksAssembly); private static Assembly CreateIgnoreAccessChecksAssembly() { - var assembly = CompileSourceCode(IgnoreAccessChecksSourceCode, Array.Empty(), out _, false); - if (assembly == null) + var ignorerType = CompileSourceCode( + IgnoreAccessChecksSourceCode, + [], + static a => a.GetType("System.Runtime.CompilerServices.IgnoresAccessChecksToAttribute"), + out _, + false); + if (ignorerType is null) { throw new InvalidOperationException("Code Generation failed for IgnoresAccessChecksToAttribute!"); } - return assembly; + + return ignorerType.Assembly; } } private static int BatchClassSequenceNumber = 0; - private static readonly SafeConcurrentDictionary batchType2Name = new SafeConcurrentDictionary(); + private static readonly SafeConcurrentDictionary batchType2Name = new(); internal static string GetBatchClassName(Type keyType, Type payloadType) { @@ -465,13 +935,13 @@ internal static string GenericParameterList(params string[] ps) { var validStrings = ps.Where(x => !string.IsNullOrWhiteSpace(x)); var commaSeparatedList = string.Join(",", validStrings); - return string.IsNullOrWhiteSpace(commaSeparatedList) ? string.Empty : "<" + commaSeparatedList + ">"; + return string.IsNullOrWhiteSpace(commaSeparatedList) ? string.Empty : $"<{commaSeparatedList}>"; } internal static Type GenerateMemoryPoolClass() { Contract.Ensures(Contract.Result() != null); - Contract.Ensures(typeof(MemoryPool).GetTypeInfo().IsAssignableFrom(Contract.Result())); + Contract.Ensures(typeof(MemoryPool).IsAssignableFrom(Contract.Result())); #if CODEGEN_TIMING Stopwatch sw = new Stopwatch(); @@ -489,14 +959,24 @@ internal static Type GenerateMemoryPoolClass() assemblyReferences = mpt.assemblyReferences; generatedClassName = mpt.generatedClassName; - var a = CompileSourceCode(expandedCode, assemblyReferences, out string errorMessages); + var instantiatedType = CompileSourceCode( + expandedCode, + assemblyReferences, + a => + { + var ty = a.GetType(generatedClassName); + if (ty is null) + { + return null; + } - var t = a.GetType(generatedClassName); - var instantiatedType = t.MakeGenericType(new Type[] { keyType, payloadType }); + return ty.MakeGenericType([keyType, payloadType]); + }, + out string errorMessages); #if CODEGEN_TIMING sw.Stop(); Console.WriteLine("Time to generate and instantiate a memory pool for {0},{1}: {2}ms", - tKey.GetCSharpSourceSyntax(), tPayload.GetCSharpSourceSyntax(), sw.ElapsedMilliseconds); + keyType.GetCSharpSourceSyntax(), payloadType.GetCSharpSourceSyntax(), sw.ElapsedMilliseconds); #endif return instantiatedType; } @@ -506,7 +986,7 @@ internal static Type GenerateMemoryPoolClass() /// if it is any type T that is not a CompoundGroupKey or is a valid CGK. /// internal static bool IsValidKeyType(Type t) - => !t.GetTypeInfo().IsGenericType || t.GetGenericTypeDefinition() != typeof(CompoundGroupKey<,>) || IsValidCGK(t); + => !t.IsGenericType || t.GetGenericTypeDefinition() != typeof(CompoundGroupKey<,>) || IsValidCGK(t); /// /// A type is a valid CGK (i.e., it can be used as a Key type for a StreamMessage) @@ -516,18 +996,18 @@ internal static bool IsValidKeyType(Type t) /// private static bool IsValidCGK(Type t) { - Contract.Requires(t.GetTypeInfo().IsGenericType && t.GetGenericTypeDefinition() == typeof(CompoundGroupKey<,>)); + Contract.Requires(t.IsGenericType && t.GetGenericTypeDefinition() == typeof(CompoundGroupKey<,>)); - var typeArgs = t.GetTypeInfo().GetGenericArguments(); + var typeArgs = t.GetGenericArguments(); var innerKeyType = typeArgs[1]; - return (!innerKeyType.GetTypeInfo().IsGenericType || innerKeyType.GetGenericTypeDefinition() != typeof(CompoundGroupKey<,>)) && IsValidKeyType(typeArgs[0]); + return (!innerKeyType.IsGenericType || innerKeyType.GetGenericTypeDefinition() != typeof(CompoundGroupKey<,>)) && IsValidKeyType(typeArgs[0]); } public static Assembly GeneratedStreamMessageAssembly() - => StreamMessageManager.GetStreamMessageType().GetTypeInfo().Assembly; + => StreamMessageManager.GetStreamMessageType().Assembly; public static Assembly GeneratedMemoryPoolAssembly() - => MemoryManager.GetMemoryPool().GetType().GetTypeInfo().Assembly; + => MemoryManager.GetMemoryPool().GetType().Assembly; } internal sealed class TypeMapper @@ -549,9 +1029,9 @@ public IEnumerable GenericTypeVariables(params Type[] types) continue; } - if (!t.GetTypeInfo().Assembly.IsDynamic && t.GetTypeInfo().IsGenericType) + if (!t.Assembly.IsDynamic && t.IsGenericType) { - foreach (var gta in t.GenericTypeArguments) l.AddRange(GenericTypeVariables(gta)); + foreach (var gta in t.GenericTypeArguments) l.AddRange(this.GenericTypeVariables(gta)); } } return l.Distinct(); @@ -568,8 +1048,8 @@ private static Dictionary GetCSharpTypeNames(params Type[] types) private static void TurnTypeIntoCSharpSourceHelper(Type t, Dictionary d, ref int anonymousTypeCount) { - Contract.Requires(t != null); - Contract.Requires(d != null); + ArgumentNullException.ThrowIfNull(t); + ArgumentNullException.ThrowIfNull(d); if (d.TryGetValue(t, out _)) return; var typeName = t.FullName.Replace('#', '_').Replace('+', '.'); @@ -580,13 +1060,13 @@ private static void TurnTypeIntoCSharpSourceHelper(Type t, Dictionary"); + sb.Append('>'); typeName = sb.ToString(); d.Add(t, typeName); return; @@ -612,7 +1092,7 @@ internal sealed class ColumnarRepresentation public readonly MyFieldInfo PseudoField; // used only when noFields is true public IEnumerable AllFields => this.noFields - ? new List() { this.PseudoField } + ? [this.PseudoField] : this.Fields.Values; public ColumnarRepresentation(Type t) @@ -620,35 +1100,35 @@ public ColumnarRepresentation(Type t) this.RepresentationFor = t; var d = new Dictionary(); this.Fields = d; - foreach (var f in t.GetTypeInfo().GetFields(BindingFlags.Instance | BindingFlags.Public)) + foreach (var f in t.GetFields(BindingFlags.Instance | BindingFlags.Public)) d.Add(f.Name, new MyFieldInfo(f/*, prefix*/)); // Any autoprops should be treated just as if they were a field - foreach (var p in t.GetTypeInfo().GetProperties(BindingFlags.Instance | BindingFlags.Public)) + foreach (var p in t.GetProperties(BindingFlags.Instance | BindingFlags.Public)) { var getMethod = p.GetMethod; if (getMethod == null) continue; - if (!getMethod.IsDefined(typeof(System.Runtime.CompilerServices.CompilerGeneratedAttribute))) continue; + if (!getMethod.IsDefined(typeof(CompilerGeneratedAttribute))) continue; var setMethod = p.SetMethod; if (setMethod == null) continue; - if (!setMethod.IsDefined(typeof(System.Runtime.CompilerServices.CompilerGeneratedAttribute))) continue; + if (!setMethod.IsDefined(typeof(CompilerGeneratedAttribute))) continue; - d.Add(p.Name, new MyFieldInfo(p/*, prefix*/)); + d.Add(p.Name, new(p/*, prefix*/)); } if (!this.Fields.Any()) { if (t.HasSupportedParameterizedConstructor()) { - foreach (var p in t.GetTypeInfo().GetProperties(BindingFlags.Public | BindingFlags.Instance)) + foreach (var p in t.GetProperties(BindingFlags.Public | BindingFlags.Instance)) { - d.Add(p.Name, new MyFieldInfo(p/*, prefix*/)); + d.Add(p.Name, new(p/*, prefix*/)); } } else { this.noFields = true; - this.PseudoField = new MyFieldInfo(t, "payload"); + this.PseudoField = new(t, "payload"); } } } @@ -657,7 +1137,7 @@ public ColumnarRepresentation(Type t, string pseudoFieldName) { this.RepresentationFor = t; this.noFields = true; - this.PseudoField = new MyFieldInfo(t, pseudoFieldName); + this.PseudoField = new(t, pseudoFieldName); } } @@ -709,7 +1189,7 @@ public MyFieldInfo(Type t, string name = "payload") this.DeclaringType = t.DeclaringType; } - public override string ToString() => "|" + this.TypeName + ", " + this.Name + "|"; + public override readonly string ToString() => "|" + this.TypeName + ", " + this.Name + "|"; } internal partial class SafeBatchTemplate @@ -734,20 +1214,18 @@ public static void GetGeneratedCode(Type keyType, Type payloadType, out string g { var template = new SafeBatchTemplate(); - assemblyReferences = new List - { - Transformer.SystemRuntimeSerializationDll // needed for [DataContract] and [DataMember] in generated code - }; - - assemblyReferences.AddRange(Transformer.AssemblyReferencesNeededFor(keyType)); + assemblyReferences = + [ + Transformer.SystemRuntimeSerializationDll, .. Transformer.AssemblyReferencesNeededFor(keyType) // needed for [DataContract] and [DataMember] in generated code + ]; template.keyType = keyType; assemblyReferences.AddRange(Transformer.AssemblyReferencesNeededFor(payloadType)); template.payloadType = payloadType; template.needsPolymorphismCheck = - !payloadType.GetTypeInfo().IsValueType && + !payloadType.IsValueType && !payloadType.IsAnonymousTypeName() && - !payloadType.GetTypeInfo().IsSealed; + !payloadType.IsSealed; template.payloadMightBeNull = payloadType.CanContainNull(); generatedClassName = Transformer.GetBatchClassName(keyType, payloadType); @@ -780,30 +1258,29 @@ internal partial class MemoryPoolTemplate internal MemoryPoolTemplate(ColumnarRepresentation keyRepresentation, ColumnarRepresentation payloadRepresentation) { - this.assemblyReferences = new List(); + this.assemblyReferences = []; - var keyType = keyRepresentation == null ? typeof(Empty) : keyRepresentation.RepresentationFor; + var keyType = keyRepresentation?.RepresentationFor ?? typeof(Empty); Contract.Assume(Transformer.IsValidKeyType(keyType)); this.assemblyReferences.AddRange(Transformer.AssemblyReferencesNeededFor(keyType)); this.keyType = keyType; -#region Decompose TPayload into columns + #region Decompose TPayload into columns var payloadType = payloadRepresentation.RepresentationFor; this.assemblyReferences.AddRange(Transformer.AssemblyReferencesNeededFor(payloadType)); this.payloadType = payloadType; - var payloadTypes = payloadRepresentation.AllFields.Select(f => f.Type).Where(t => !t.MemoryPoolHasGetMethodFor()); - this.types = new HashSet(payloadTypes.Distinct()); + this.types = [.. payloadRepresentation.AllFields.Select(f => f.Type).Where(t => !t.MemoryPoolHasGetMethodFor())]; this.assemblyReferences.AddRange(this.types.SelectMany(t => Transformer.AssemblyReferencesNeededFor(t))); -#endregion + #endregion this.generatedClassName = Transformer.GetMemoryPoolClassName(keyType, payloadType); this.className = this.generatedClassName.CleanUpIdentifierName(); this.generatedClassName += "`2"; - this.expandedCode = TransformText(); + this.expandedCode = this.TransformText(); } } } \ No newline at end of file diff --git a/Sources/Core/Microsoft.StreamProcessing/Utilities/ComparerExpression.cs b/Sources/Core/Microsoft.StreamProcessing/Utilities/ComparerExpression.cs index 90e82c91f..fd1c0f49a 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Utilities/ComparerExpression.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Utilities/ComparerExpression.cs @@ -9,6 +9,7 @@ using System.Linq; using System.Linq.Expressions; using System.Reflection; +using System.Threading; namespace Microsoft.StreamProcessing { @@ -27,25 +28,25 @@ public interface IComparerExpression internal sealed class ComparerExpressionCache { - private static readonly ConcurrentDictionary typeComparerCache = new ConcurrentDictionary(); + private static readonly ConcurrentDictionary typeComparerCache = new(); static ComparerExpressionCache() { - typeComparerCache.TryAdd(typeof(byte), new PrimitiveComparerExpression((x, y) => x < y ? -1 : x == y ? 0 : 1)); - typeComparerCache.TryAdd(typeof(sbyte), new PrimitiveComparerExpression((x, y) => x < y ? -1 : x == y ? 0 : 1)); - typeComparerCache.TryAdd(typeof(char), new PrimitiveComparerExpression((x, y) => x < y ? -1 : x == y ? 0 : 1)); - typeComparerCache.TryAdd(typeof(short), new PrimitiveComparerExpression((x, y) => x < y ? -1 : x == y ? 0 : 1)); - typeComparerCache.TryAdd(typeof(ushort), new PrimitiveComparerExpression((x, y) => x < y ? -1 : x == y ? 0 : 1)); - typeComparerCache.TryAdd(typeof(int), new PrimitiveComparerExpression((x, y) => x < y ? -1 : x == y ? 0 : 1)); - typeComparerCache.TryAdd(typeof(uint), new PrimitiveComparerExpression((x, y) => x < y ? -1 : x == y ? 0 : 1)); - typeComparerCache.TryAdd(typeof(long), new PrimitiveComparerExpression((x, y) => x < y ? -1 : x == y ? 0 : 1)); - typeComparerCache.TryAdd(typeof(ulong), new PrimitiveComparerExpression((x, y) => x < y ? -1 : x == y ? 0 : 1)); - typeComparerCache.TryAdd(typeof(decimal), new PrimitiveComparerExpression((x, y) => x < y ? -1 : x == y ? 0 : 1)); + typeComparerCache.TryAdd(typeof(byte), new PrimitiveComparerExpression(static (x, y) => x < y ? -1 : x == y ? 0 : 1)); + typeComparerCache.TryAdd(typeof(sbyte), new PrimitiveComparerExpression(static (x, y) => x < y ? -1 : x == y ? 0 : 1)); + typeComparerCache.TryAdd(typeof(char), new PrimitiveComparerExpression(static (x, y) => x < y ? -1 : x == y ? 0 : 1)); + typeComparerCache.TryAdd(typeof(short), new PrimitiveComparerExpression(static (x, y) => x < y ? -1 : x == y ? 0 : 1)); + typeComparerCache.TryAdd(typeof(ushort), new PrimitiveComparerExpression(static (x, y) => x < y ? -1 : x == y ? 0 : 1)); + typeComparerCache.TryAdd(typeof(int), new PrimitiveComparerExpression(static (x, y) => x < y ? -1 : x == y ? 0 : 1)); + typeComparerCache.TryAdd(typeof(uint), new PrimitiveComparerExpression(static (x, y) => x < y ? -1 : x == y ? 0 : 1)); + typeComparerCache.TryAdd(typeof(long), new PrimitiveComparerExpression(static (x, y) => x < y ? -1 : x == y ? 0 : 1)); + typeComparerCache.TryAdd(typeof(ulong), new PrimitiveComparerExpression(static (x, y) => x < y ? -1 : x == y ? 0 : 1)); + typeComparerCache.TryAdd(typeof(decimal), new PrimitiveComparerExpression(static (x, y) => x < y ? -1 : x == y ? 0 : 1)); typeComparerCache.TryAdd(typeof(string), new GenericComparableExpression()); typeComparerCache.TryAdd(typeof(TimeSpan), new GenericComparableExpression()); typeComparerCache.TryAdd(typeof(DateTime), new GenericComparableExpression()); typeComparerCache.TryAdd(typeof(DateTimeOffset), new GenericComparableExpression()); - typeComparerCache.TryAdd(typeof(Empty), new PrimitiveComparerExpression((x, y) => 0)); + typeComparerCache.TryAdd(typeof(Empty), new PrimitiveComparerExpression(static (x, y) => 0)); } public static bool TryGetCachedComparer(out IComparerExpression comparer) @@ -63,20 +64,17 @@ public static bool TryGetCachedComparer(out IComparerExpression comparer) public static void Add(IComparerExpression comparer) => typeComparerCache.TryAdd(typeof(T), comparer); } - internal class ComparerExpression : IComparerExpression + internal class ComparerExpression(Expression> compareExpr) : IComparerExpression { - private static readonly object sentinel = new object(); - private readonly Expression> CompareExpr; - - public ComparerExpression(Expression> compareExpr) => this.CompareExpr = compareExpr; + private static readonly Lock sentinel = new(); public static IComparerExpression Default { get { - var type = typeof(T).GetTypeInfo(); + var type = typeof(T); - lock (sentinel) + using (sentinel.EnterScope()) { if (ComparerExpressionCache.TryGetCachedComparer(out IComparerExpression comparer)) return comparer; @@ -85,17 +83,17 @@ public static IComparerExpression Default { // equivalent to: return new CompoundGroupKeyComparer(ComparerExpression.Default, ComparerExpression.Default); var comparerExpressionOfT1 = typeof(ComparerExpression<>).MakeGenericType(t1); - var defaultPropertyForT1 = comparerExpressionOfT1.GetTypeInfo().GetProperty("Default"); + var defaultPropertyForT1 = comparerExpressionOfT1.GetProperty("Default"); var default1 = defaultPropertyForT1.GetValue(null); var comparerExpressionOfT2 = typeof(ComparerExpression<>).MakeGenericType(t2); - var defaultPropertyForT2 = comparerExpressionOfT2.GetTypeInfo().GetProperty("Default"); + var defaultPropertyForT2 = comparerExpressionOfT2.GetProperty("Default"); var default2 = defaultPropertyForT2.GetValue(null); var cgkc = typeof(CompoundGroupKeyComparer<,>); var genericInstance = cgkc.MakeGenericType(t1, t2); - var ctor = genericInstance.GetTypeInfo().GetConstructor(new Type[] { comparerExpressionOfT1, comparerExpressionOfT2, }); - var result = ctor.Invoke(new object[] { default1, default2, }); + var ctor = genericInstance.GetConstructor([comparerExpressionOfT1, comparerExpressionOfT2,]); + var result = ctor.Invoke([default1, default2,]); comparer = (IComparerExpression)result; ComparerExpressionCache.Add(comparer); return comparer; @@ -114,10 +112,10 @@ public static IComparerExpression Default // then fall back to using a lambda of the form: // (x,y) => x.CompareTo(y) var genericInstanceOfComparerExpressionForGenericIComparable = typeof(GenericComparableExpression<>).MakeGenericType(type); - var ctorForComparerExpressionForGenericIComparer = genericInstanceOfComparerExpressionForGenericIComparable.GetTypeInfo().GetConstructor(Array.Empty()); + var ctorForComparerExpressionForGenericIComparer = genericInstanceOfComparerExpressionForGenericIComparable.GetConstructor([]); if (ctorForComparerExpressionForGenericIComparer != null) { - comparer = (IComparerExpression)ctorForComparerExpressionForGenericIComparer.Invoke(Array.Empty()); + comparer = (IComparerExpression)ctorForComparerExpressionForGenericIComparer.Invoke([]); ComparerExpressionCache.Add(comparer); return comparer; } @@ -129,16 +127,16 @@ public static IComparerExpression Default // (x,y) => o.IComparer.Compare(x,y) // for an arbitrary o that is created of type T by calling its nullary ctor (if such a ctor exists) var genericInstanceOfComparerExpressionForGenericIComparer = typeof(ComparerExpressionForGenericIComparer<>).MakeGenericType(type); - var ctorForComparerExpressionForGenericIComparer = genericInstanceOfComparerExpressionForGenericIComparer.GetTypeInfo().GetConstructor(new Type[] { type, }); + var ctorForComparerExpressionForGenericIComparer = genericInstanceOfComparerExpressionForGenericIComparer.GetConstructor([type,]); if (ctorForComparerExpressionForGenericIComparer != null) { var ctorForType = type.GetConstructor(Type.EmptyTypes); if (ctorForType != null) { - var instanceOfType = ctorForType.Invoke(Array.Empty()); + var instanceOfType = ctorForType.Invoke([]); if (instanceOfType != null) { - comparer = (IComparerExpression)ctorForComparerExpressionForGenericIComparer.Invoke(new object[] { instanceOfType, }); + comparer = (IComparerExpression)ctorForComparerExpressionForGenericIComparer.Invoke([instanceOfType,]); ComparerExpressionCache.Add(comparer); return comparer; } @@ -146,22 +144,22 @@ public static IComparerExpression Default } } - if (type.GetInterface("System.Collections.IComparer") != null) + if (typeof(IComparer).IsAssignableFrom(type)) { // then fall back to using a lambda of the form: // (x,y) => o.IComparer.Compare(x,y) // for an arbitrary o that is created of type T by calling its nullary ctor (if such a ctor exists) var genericInstanceOfComparerExpressionForNonGenericIComparer = typeof(ComparerExpressionForNonGenericIComparer<>).MakeGenericType(type); - var ctorForComparerExpressionForNonGenericIComparer = genericInstanceOfComparerExpressionForNonGenericIComparer.GetTypeInfo().GetConstructor(new Type[] { type, }); + var ctorForComparerExpressionForNonGenericIComparer = genericInstanceOfComparerExpressionForNonGenericIComparer.GetConstructor([type,]); if (ctorForComparerExpressionForNonGenericIComparer != null) { var ctorForType = type.GetConstructor(Type.EmptyTypes); if (ctorForType != null) { - var instanceOfType = ctorForType.Invoke(Array.Empty()); + var instanceOfType = ctorForType.Invoke([]); if (instanceOfType != null) { - comparer = (IComparerExpression)ctorForComparerExpressionForNonGenericIComparer.Invoke(new object[] { instanceOfType, }); + comparer = (IComparerExpression)ctorForComparerExpressionForNonGenericIComparer.Invoke([instanceOfType,]); ComparerExpressionCache.Add(comparer); return comparer; } @@ -202,7 +200,7 @@ public static IComparerExpression Default private static Expression> ComparerExprForAnonymousType(Type t) { if (t == null || !t.IsAnonymousTypeName()) return null; - var properties = t.GetTypeInfo().GetProperties(BindingFlags.Public | BindingFlags.Instance); + var properties = t.GetProperties(BindingFlags.Public | BindingFlags.Instance); if (properties.Length == 0) return null; var left = Expression.Parameter(t, "left"); var right = Expression.Parameter(t, "right"); @@ -232,43 +230,40 @@ private static Expression> ComparerExprForAnonymousType(Type t) private static ConditionalExpression MakeComparisonExpression(ParameterExpression left, ParameterExpression right, PropertyInfo p, Expression e) { var comparerTypeForPropertyType = typeof(ComparerExpression<>).MakeGenericType(p.PropertyType); - var comparerDefaultProperty = comparerTypeForPropertyType.GetTypeInfo().GetProperty("Default"); + var comparerDefaultProperty = comparerTypeForPropertyType.GetProperty("Default"); var getter = comparerDefaultProperty.GetMethod; var comparerExpressionObject = getter.Invoke(null, null); - var comparerExpression = (LambdaExpression)comparerExpressionObject.GetType().GetTypeInfo() + var comparerExpression = (LambdaExpression)comparerExpressionObject.GetType() .GetMethod("GetCompareExpr").Invoke(comparerExpressionObject, null); var inlinedComparerExpression = comparerExpression.ReplaceParametersInBody(Expression.Property(left, p), Expression.Property(right, p)); return Expression.Condition(Expression.Equal(inlinedComparerExpression, zero), e, inlinedComparerExpression); } - public Expression> GetCompareExpr() => this.CompareExpr; + public Expression> GetCompareExpr() => compareExpr; internal static bool IsSimpleDefault(IComparerExpression input) => input == Default && input is PrimitiveComparerExpression; } - internal class PrimitiveComparerExpression : ComparerExpression + internal class PrimitiveComparerExpression(Expression> compareExpr) : ComparerExpression(compareExpr) { - public PrimitiveComparerExpression(Expression> compareExpr) : base(compareExpr) { } } internal sealed class GenericComparerExpression : ComparerExpression { - public GenericComparerExpression() : base(compareExpr: (x, y) => Comparer.Default.Compare(x, y)) { } + public GenericComparerExpression() : base(compareExpr: static (x, y) => Comparer.Default.Compare(x, y)) { } } internal sealed class GenericComparableExpression : ComparerExpression where T : IComparable { - public GenericComparableExpression() : base(compareExpr: (x, y) => x.CompareTo(y)) { } + public GenericComparableExpression() : base(compareExpr: static (x, y) => x.CompareTo(y)) { } } - internal sealed class ComparerExpressionForGenericIComparer : ComparerExpression where T : IComparer + internal sealed class ComparerExpressionForGenericIComparer(T t) : ComparerExpression(compareExpr: (x, y) => t.Compare(x, y)) where T : IComparer { - public ComparerExpressionForGenericIComparer(T t) : base(compareExpr: (x, y) => t.Compare(x, y)) { } } - internal sealed class ComparerExpressionForNonGenericIComparer : ComparerExpression where T : IComparer + internal sealed class ComparerExpressionForNonGenericIComparer(T t) : ComparerExpression(compareExpr: (x, y) => t.Compare(x, y)) where T : IComparer { - public ComparerExpressionForNonGenericIComparer(T t) : base(compareExpr: (x, y) => t.Compare(x, y)) { } } } \ No newline at end of file diff --git a/Sources/Core/Microsoft.StreamProcessing/Utilities/ComparerExpressionExtensions.cs b/Sources/Core/Microsoft.StreamProcessing/Utilities/ComparerExpressionExtensions.cs index 3b1142546..b18359ca4 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Utilities/ComparerExpressionExtensions.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Utilities/ComparerExpressionExtensions.cs @@ -12,8 +12,8 @@ internal static class ComparerExpressionExtensions { public static IComparerExpression TransformInput(this IComparerExpression comparer, Expression> transform) { - Contract.Requires(comparer != null); - Contract.Requires(transform != null); + ArgumentNullException.ThrowIfNull(comparer); + ArgumentNullException.ThrowIfNull(transform); var expression = comparer.GetCompareExpr(); Expression> template = (left, right) => CallInliner.Call(expression, CallInliner.Call(transform, left), CallInliner.Call(transform, right)); diff --git a/Sources/Core/Microsoft.StreamProcessing/Utilities/ComparerExtensions.cs b/Sources/Core/Microsoft.StreamProcessing/Utilities/ComparerExtensions.cs index a93a32e04..e450b0492 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Utilities/ComparerExtensions.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Utilities/ComparerExtensions.cs @@ -75,11 +75,11 @@ public static bool ExpressionEquals(this IEqualityComparerExpression sourc public static bool EqualityExpressionEquals(this object source, object other) { var t = source.GetType(); - foreach (var iface in t.GetTypeInfo().GetInterfaces()) + foreach (var iface in t.GetInterfaces()) { - if (!iface.GetTypeInfo().IsGenericType) continue; + if (!iface.IsGenericType) continue; if (!iface.GetGenericTypeDefinition().Equals(typeof(IEqualityComparerExpression<>))) continue; - if (iface.GetTypeInfo().IsAssignableFrom(other.GetType())) + if (iface.IsAssignableFrom(other.GetType())) return TryIsEqualIECE(source, other); } return false; diff --git a/Sources/Core/Microsoft.StreamProcessing/Utilities/Config.cs b/Sources/Core/Microsoft.StreamProcessing/Utilities/Config.cs index badaa164f..6d205d195 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Utilities/Config.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Utilities/Config.cs @@ -53,6 +53,22 @@ public static class Config private static SerializationCompressionLevel serializationCompressionLevel = SerializationCompressionLevel.None; private static int aggregateHashTableInitSize = 1; private static string generatedCodePath = "Generated"; + private static string codegenAssemblyCachePath; + + /// + /// When null or empty, Roslyn output is not persisted across process restarts (default). + /// When set to a directory path, Trill writes compiled codegen assemblies under that folder keyed by a + /// content fingerprint and reloads them on subsequent runs to skip Roslyn emit when inputs match. + /// + public static string CodegenAssemblyCachePath + { + get => codegenAssemblyCachePath; + set + { + TraceConfigChanges("CodegenAssemblyCachePath", codegenAssemblyCachePath, value); + codegenAssemblyCachePath = value; + } + } /// /// The file system location to which any generated code artifacts should be stored. @@ -401,7 +417,7 @@ private static void TraceConfigChanges(string name, T from, T to) // Change to false to disable tracing Config values tracing. if (true) { - if (typeof(IInternalScheduler).GetTypeInfo().IsAssignableFrom(typeof(T))) + if (typeof(IInternalScheduler).IsAssignableFrom(typeof(T))) { var fromSch = (IInternalScheduler)from; var toSch = (IInternalScheduler)to; @@ -441,6 +457,7 @@ public static string Describe() MultiStringTransforms, Scheduler = SchedToStr(StreamScheduler.scheduler), GeneratedCodePath, + CodegenAssemblyCachePath, CodegenOptions.GenerateDebugInfo, CodegenOptions.BreakIntoCodeGen, CodegenOptions.DontFallBackToRowBasedExecution, @@ -467,11 +484,15 @@ public static string Describe() // in VSTest, which is a good thing, since Config is static and those tests may clash otherwise. internal sealed class ConfigModifier { - // lockable gate allowing only one ConfigModifier active at a time - private static readonly object gate = new object(); + // Serializes concurrent ConfigModifier usage across tests. + // SemaphoreSlim instead of Monitor so that async tests can release from a different thread. + // AsyncLocal depth counter makes it re-entrant within the same async call context (e.g. nested + // using blocks within a single test) without blocking on the semaphore a second time. + private static readonly SemaphoreSlim gate = new(1, 1); + private static readonly AsyncLocal gateDepth = new(); // collection of Config modifications - private readonly List modifications = new List(); + private readonly List modifications = []; public ConfigModifier GeneratedCodePath(string value) { @@ -486,6 +507,19 @@ public ConfigModifier GeneratedCodePath(string value) return this; } + public ConfigModifier CodegenAssemblyCachePath(string value) + { + this.modifications.Add(GatedModification.Create( + value, + v => + { + var old = Config.CodegenAssemblyCachePath; + Config.CodegenAssemblyCachePath = v; + return old; + })); + return this; + } + public ConfigModifier MapArity(int value) { this.modifications.Add(GatedModification.Create( @@ -723,7 +757,8 @@ public ConfigModifier SerializationCompressionLevel(SerializationCompressionLeve public IDisposable Modify() { - Monitor.Enter(gate); + if (gateDepth.Value == 0) gate.Wait(); + gateDepth.Value++; foreach (var m in this.modifications) m.Modify(); @@ -732,7 +767,8 @@ public IDisposable Modify() foreach (var m in this.modifications) m.Modify(); - Monitor.Exit(gate); + gateDepth.Value--; + if (gateDepth.Value == 0) gate.Release(); }); } @@ -758,7 +794,7 @@ private sealed class GatedModification : IGatedModification private Func modifier; public static GatedModification Create(T newValue, Func modifier) - => new GatedModification + => new() { val = newValue, modifier = modifier diff --git a/Sources/Core/Microsoft.StreamProcessing/Utilities/Empty.cs b/Sources/Core/Microsoft.StreamProcessing/Utilities/Empty.cs index b85f32bfa..574187295 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Utilities/Empty.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Utilities/Empty.cs @@ -19,26 +19,26 @@ public struct Empty : IEquatable /// /// An Empty value to compare to the current Empty value. /// Because there is only one value of type Empty, this always returns true. - public bool Equals(Empty other) => true; + public readonly bool Equals(Empty other) => true; /// /// Determines whether the specified System.Object is equal to the current Empty. /// /// The System.Object to compare with the current Empty. /// true if the specified System.Object is a Empty value; otherwise, false. - public override bool Equals(object obj) => obj is Empty; + public override readonly bool Equals(object obj) => obj is Empty; /// /// Returns the hash code for the Empty value. /// /// A hash code for the Empty value. - public override int GetHashCode() => 0; + public override readonly int GetHashCode() => 0; /// /// Returns a string representation of the Empty value. /// /// String representation of the Empty value. - public override string ToString() => "()"; + public override readonly string ToString() => "()"; /// /// Determines whether the two specified Emtpy values are equal. Because Empty has a single value, this always returns true. diff --git a/Sources/Core/Microsoft.StreamProcessing/Utilities/EqualityComparerExpression.cs b/Sources/Core/Microsoft.StreamProcessing/Utilities/EqualityComparerExpression.cs index c41875ace..55468f1c6 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Utilities/EqualityComparerExpression.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Utilities/EqualityComparerExpression.cs @@ -9,6 +9,7 @@ using System.Linq; using System.Linq.Expressions; using System.Reflection; +using System.Threading; namespace Microsoft.StreamProcessing { @@ -38,9 +39,9 @@ public interface IEqualityComparerExpression internal static class EqualityComparerExpressionCache { - private static readonly ConcurrentDictionary typeComparerCache = new ConcurrentDictionary(); - private static readonly ConcurrentDictionary equalsCache = new ConcurrentDictionary(); - private static readonly ConcurrentDictionary getHashCodeCache = new ConcurrentDictionary(); + private static readonly ConcurrentDictionary typeComparerCache = new(); + private static readonly ConcurrentDictionary equalsCache = new(); + private static readonly ConcurrentDictionary getHashCodeCache = new(); static EqualityComparerExpressionCache() { @@ -109,29 +110,20 @@ public static bool TryGetCachedGetHashCodeFunction(out Func getHashCo /// into an . /// /// The type for which the equality comparers are defined. - public class EqualityComparerExpression : IEqualityComparerExpression + /// + /// A function used to test equality on type . + /// + /// + /// A function used to compute hash values for values of type . + /// + /// + /// Creates an instance to be used as an argument for many of the query methods. + /// + public class EqualityComparerExpression(Expression> equalsExpr, Expression> getHashCodeExpr) : IEqualityComparerExpression { - private static readonly object sentinel = new object(); - private static readonly object equalsSentinel = new object(); - private static readonly object getHashCodeSentinel = new object(); - - private readonly Expression> EqualsExpr; - private readonly Expression> GetHashCodeExpr; - - /// - /// Creates an instance to be used as an argument for many of the query methods. - /// - /// - /// A function used to test equality on type . - /// - /// - /// A function used to compute hash values for values of type . - /// - public EqualityComparerExpression(Expression> equalsExpr, Expression> getHashCodeExpr) - { - this.EqualsExpr = equalsExpr; - this.GetHashCodeExpr = getHashCodeExpr; - } + private static readonly Lock sentinel = new(); + private static readonly Lock equalsSentinel = new(); + private static readonly Lock getHashCodeSentinel = new(); /// /// A default equality comparer. @@ -140,125 +132,122 @@ public static IEqualityComparerExpression Default { get { - var type = typeof(T).GetTypeInfo(); - - lock (sentinel) - { - if (EqualityComparerExpressionCache.TryGetCachedComparer(out IEqualityComparerExpression comparer)) - return comparer; - - if (type.ImplementsIEqualityComparerExpression()) - { - if (type.IsValueType) - { - comparer = (IEqualityComparerExpression)default(T); - EqualityComparerExpressionCache.Add(comparer); - return comparer; - } - var ctor = type.GetConstructor(Type.EmptyTypes); - if (ctor != null) - { - var result = ctor.Invoke(Array.Empty()); - comparer = (IEqualityComparerExpression)result; - EqualityComparerExpressionCache.Add(comparer); - return comparer; - } - } + var type = typeof(T); - if (type.ImplementsIEqualityComparer()) - { - // then fall back to using lambdas of the form: - // (x,y) => o.IEqualityComparer.Equals(x,y) - // (x) => o.IEqualityComparer.GetHashCode(x) - // for an arbitrary o that is created of type T by calling its nullary ctor (if such a ctor exists) - var genericInstanceOfComparerExpressionForIEqualityComparer = typeof(ComparerExpressionForIEqualityComparer<>).MakeGenericType(type); - var ctorForComparerExpressionForIEqualityComparer = genericInstanceOfComparerExpressionForIEqualityComparer.GetTypeInfo().GetConstructor(new Type[] { type }); - if (ctorForComparerExpressionForIEqualityComparer != null) - { - var ctorForType = type.GetConstructor(Type.EmptyTypes); - if (ctorForType != null) - { - var instanceOfType = ctorForType.Invoke(Array.Empty()); - if (instanceOfType != null) - { - var result = ctorForComparerExpressionForIEqualityComparer.Invoke(new object[] { instanceOfType, }); - comparer = (IEqualityComparerExpression)result; - EqualityComparerExpressionCache.Add(comparer); - return comparer; - } - } - } - } + using Lock.Scope _ = sentinel.EnterScope(); + if (EqualityComparerExpressionCache.TryGetCachedComparer(out IEqualityComparerExpression comparer)) + return comparer; - if (type.ImplementsIEquatable()) + if (type.ImplementsIEqualityComparerExpression()) + { + if (type.IsValueType) { - // then fall back to using lambdas of the form: - // (x,y) => x.IEquatable.Equals(y) - // (x) => x.GetHashCode() - var genericInstanceOfComparerExpressionForIEquatable = typeof(ComparerExpressionForIEquatable<>).MakeGenericType(type); - var ctorForComparerExpressionForIEquatable = genericInstanceOfComparerExpressionForIEquatable.GetTypeInfo().GetConstructor(Type.EmptyTypes); - var comparerExpression = ctorForComparerExpressionForIEquatable.Invoke(Array.Empty()); - comparer = (IEqualityComparerExpression)comparerExpression; + comparer = (IEqualityComparerExpression)default(T); EqualityComparerExpressionCache.Add(comparer); return comparer; } - - if (type.IsCompoundGroupKey(out var t1, out var t2)) + if (type.GetConstructor(Type.EmptyTypes) is { } ctor) { - // equivalent to: return new CompoundGroupKeyEqualityComparer(EqualityComparerExpression.Default, EqualityComparerExpression.Default); - var equalityComparerExpressionOfT1 = typeof(EqualityComparerExpression<>).MakeGenericType(t1); - var defaultPropertyForT1 = equalityComparerExpressionOfT1.GetTypeInfo().GetProperty("Default"); - var default1 = defaultPropertyForT1.GetValue(null); - - var equalityComparerExpressionOfT2 = typeof(EqualityComparerExpression<>).MakeGenericType(t2); - var defaultPropertyForT2 = equalityComparerExpressionOfT2.GetTypeInfo().GetProperty("Default"); - var default2 = defaultPropertyForT2.GetValue(null); - - var cgkec = typeof(CompoundGroupKeyEqualityComparer<,>); - var genericInstance = cgkec.MakeGenericType(t1, t2); - var ctor = genericInstance.GetTypeInfo().GetConstructor(new Type[] { equalityComparerExpressionOfT1, equalityComparerExpressionOfT2, }); - var result = ctor.Invoke(new object[] { default1, default2, }); + var result = ctor.Invoke([]); comparer = (IEqualityComparerExpression)result; EqualityComparerExpressionCache.Add(comparer); return comparer; } + } - if (type.IsGenericType && type.GenericTypeArguments.Length == 1 && type.GetGenericTypeDefinition() == typeof(PartitionKey<>)) + if (type.ImplementsIEqualityComparer()) + { + // then fall back to using lambdas of the form: + // (x,y) => o.IEqualityComparer.Equals(x,y) + // (x) => o.IEqualityComparer.GetHashCode(x) + // for an arbitrary o that is created of type T by calling its nullary ctor (if such a ctor exists) + var genericInstanceOfComparerExpressionForIEqualityComparer = typeof(ComparerExpressionForIEqualityComparer<>).MakeGenericType(type); + var ctorForComparerExpressionForIEqualityComparer = genericInstanceOfComparerExpressionForIEqualityComparer.GetConstructor([type]); + if (ctorForComparerExpressionForIEqualityComparer != null) { - var t = type.GenericTypeArguments[0]; - var equalityComparerExpressionOfT = typeof(EqualityComparerExpression<>).MakeGenericType(t); - var defaultPropertyForT = equalityComparerExpressionOfT.GetTypeInfo().GetProperty("Default"); - var default1 = defaultPropertyForT.GetValue(null); - - var pkec = typeof(ComparerExpressionForPartitionKey<>); - var genericInstance = pkec.MakeGenericType(t); - var ctor = genericInstance.GetTypeInfo().GetConstructor(new Type[] { equalityComparerExpressionOfT, }); - var result = ctor.Invoke(new object[] { default1, }); - comparer = (IEqualityComparerExpression)result; - EqualityComparerExpressionCache.Add(comparer); - return comparer; + var ctorForType = type.GetConstructor(Type.EmptyTypes); + if (ctorForType != null) + { + var instanceOfType = ctorForType.Invoke([]); + if (instanceOfType != null) + { + var result = ctorForComparerExpressionForIEqualityComparer.Invoke([instanceOfType,]); + comparer = (IEqualityComparerExpression)result; + EqualityComparerExpressionCache.Add(comparer); + return comparer; + } + } } + } - if (type.IsAnonymousTypeName()) - { - var tup = ExpressionsForAnonymousType(type); - comparer = new EqualityComparerExpression(tup.Item1, tup.Item2); - EqualityComparerExpressionCache.Add(comparer); - return comparer; - } + if (type.ImplementsIEquatable()) + { + // then fall back to using lambdas of the form: + // (x,y) => x.IEquatable.Equals(y) + // (x) => x.GetHashCode() + var genericInstanceOfComparerExpressionForIEquatable = typeof(ComparerExpressionForIEquatable<>).MakeGenericType(type); + var ctorForComparerExpressionForIEquatable = genericInstanceOfComparerExpressionForIEquatable.GetConstructor(Type.EmptyTypes); + var comparerExpression = ctorForComparerExpressionForIEquatable.Invoke([]); + comparer = (IEqualityComparerExpression)comparerExpression; + EqualityComparerExpressionCache.Add(comparer); + return comparer; + } - if (IsSimpleStruct(type)) - { - var tup = ExpressionsForTypeByFields(type); - comparer = new EqualityComparerExpression(tup.Item1, tup.Item2); - EqualityComparerExpressionCache.Add(comparer); - return comparer; - } + if (type.IsCompoundGroupKey(out var t1, out var t2)) + { + // equivalent to: return new CompoundGroupKeyEqualityComparer(EqualityComparerExpression.Default, EqualityComparerExpression.Default); + var equalityComparerExpressionOfT1 = typeof(EqualityComparerExpression<>).MakeGenericType(t1); + var defaultPropertyForT1 = equalityComparerExpressionOfT1.GetProperty("Default"); + var default1 = defaultPropertyForT1.GetValue(null); + + var equalityComparerExpressionOfT2 = typeof(EqualityComparerExpression<>).MakeGenericType(t2); + var defaultPropertyForT2 = equalityComparerExpressionOfT2.GetProperty("Default"); + var default2 = defaultPropertyForT2.GetValue(null); + + var cgkec = typeof(CompoundGroupKeyEqualityComparer<,>); + var genericInstance = cgkec.MakeGenericType(t1, t2); + var ctor = genericInstance.GetConstructor([equalityComparerExpressionOfT1, equalityComparerExpressionOfT2,]); + var result = ctor.Invoke([default1, default2,]); + comparer = (IEqualityComparerExpression)result; + EqualityComparerExpressionCache.Add(comparer); + return comparer; + } + + if (type.IsGenericType && type.GenericTypeArguments.Length == 1 && type.GetGenericTypeDefinition() == typeof(PartitionKey<>)) + { + var t = type.GenericTypeArguments[0]; + var equalityComparerExpressionOfT = typeof(EqualityComparerExpression<>).MakeGenericType(t); + var defaultPropertyForT = equalityComparerExpressionOfT.GetProperty("Default"); + var default1 = defaultPropertyForT.GetValue(null); + + var pkec = typeof(ComparerExpressionForPartitionKey<>); + var genericInstance = pkec.MakeGenericType(t); + var ctor = genericInstance.GetConstructor([equalityComparerExpressionOfT,]); + var result = ctor.Invoke([default1,]); + comparer = (IEqualityComparerExpression)result; + EqualityComparerExpressionCache.Add(comparer); + return comparer; + } + + if (type.IsAnonymousTypeName()) + { + var tup = ExpressionsForAnonymousType(type); + comparer = new EqualityComparerExpression(tup.Item1, tup.Item2); + EqualityComparerExpressionCache.Add(comparer); + return comparer; + } - comparer = new GenericEqualityComparerExpression(); + if (IsSimpleStruct(type)) + { + var tup = ExpressionsForTypeByFields(type); + comparer = new EqualityComparerExpression(tup.Item1, tup.Item2); EqualityComparerExpressionCache.Add(comparer); return comparer; } + + comparer = new GenericEqualityComparerExpression(); + EqualityComparerExpressionCache.Add(comparer); + return comparer; } } @@ -269,14 +258,11 @@ public static Func DefaultEqualsFunction { get { - Func equals; - lock (equalsSentinel) + using Lock.Scope _ = equalsSentinel.EnterScope(); + if (!EqualityComparerExpressionCache.TryGetCachedEqualsFunction(out Func equals)) { - if (!EqualityComparerExpressionCache.TryGetCachedEqualsFunction(out equals)) - { - equals = Default.GetEqualsExpr().Compile(); - EqualityComparerExpressionCache.Add(equals); - } + equals = Default.GetEqualsExpr().Compile(); + EqualityComparerExpressionCache.Add(equals); } return equals; } @@ -289,14 +275,11 @@ public static Func DefaultGetHashCodeFunction { get { - Func getHashCode; - lock (getHashCodeSentinel) + using Lock.Scope _ = getHashCodeSentinel.EnterScope(); + if (!EqualityComparerExpressionCache.TryGetCachedGetHashCodeFunction(out Func getHashCode)) { - if (!EqualityComparerExpressionCache.TryGetCachedGetHashCodeFunction(out getHashCode)) - { - getHashCode = Default.GetGetHashCodeExpr().Compile(); - EqualityComparerExpressionCache.Add(getHashCode); - } + getHashCode = Default.GetGetHashCodeExpr().Compile(); + EqualityComparerExpressionCache.Add(getHashCode); } return getHashCode; } @@ -308,7 +291,7 @@ public static Func DefaultGetHashCodeFunction /// ToString, but not overrides for GetHashCode or Equals. It also may not have /// any properties at all. /// - private static bool IsSimpleStruct(TypeInfo type) + private static bool IsSimpleStruct(Type type) => type.IsValueType && !type.IsPrimitive && !Recursive(type) @@ -317,18 +300,18 @@ private static bool IsSimpleStruct(TypeInfo type) && type.GetProperties().Length == 0 && type.GetFields().All(f => f.IsPublic); - private static bool Recursive(TypeInfo type) + private static bool Recursive(Type type) { - var hashSet = new HashSet { type }; + var hashSet = new HashSet { type }; return RecursiveHelper(type, hashSet); } - private static bool RecursiveHelper(TypeInfo type, HashSet hashSet) + private static bool RecursiveHelper(Type type, HashSet hashSet) { var fields = type.GetFields(BindingFlags.Public | BindingFlags.Instance); foreach (var field in fields) { - var t = field.FieldType.GetTypeInfo(); + var t = field.FieldType; if (!t.IsValueType || t.IsPrimitive) continue; if (hashSet.Contains(t)) return true; hashSet.Add(t); @@ -343,13 +326,13 @@ private static bool RecursiveHelper(TypeInfo type, HashSet hashSet) /// An accessor for the equals function. /// /// The function used for equality tests. - public Expression> GetEqualsExpr() => this.EqualsExpr; + public Expression> GetEqualsExpr() => equalsExpr; /// /// An accessor for the hash function. /// /// The function used for computing hashes. - public Expression> GetGetHashCodeExpr() => this.GetHashCodeExpr; + public Expression> GetGetHashCodeExpr() => getHashCodeExpr; /// /// Returns (unfortunately) weakly-typed expressions for the two functions @@ -378,7 +361,7 @@ private static bool RecursiveHelper(TypeInfo type, HashSet hashSet) private static Tuple>, Expression>> ExpressionsForAnonymousType(Type t) { if (t == null || !t.IsAnonymousTypeName()) return null; - var properties = t.GetTypeInfo().GetProperties(BindingFlags.Public | BindingFlags.Instance); + var properties = t.GetProperties(BindingFlags.Public | BindingFlags.Instance); var left = Expression.Parameter(t, "left"); var right = Expression.Parameter(t, "right"); var a = Expression.Parameter(t, "a"); @@ -394,7 +377,7 @@ private static Tuple>, Expression>> Exp private static Tuple>, Expression>> ExpressionsForTypeByFields(Type t) { - var fields = t.GetTypeInfo().GetFields(BindingFlags.Public | BindingFlags.Instance); + var fields = t.GetFields(BindingFlags.Public | BindingFlags.Instance); var left = Expression.Parameter(t, "left"); var right = Expression.Parameter(t, "right"); var a = Expression.Parameter(t, "a"); @@ -421,13 +404,13 @@ private static Tuple>, Expression>> Exp private static Tuple MakeEqualityAndHashCodeExpressions(ParameterExpression left, ParameterExpression right, ParameterExpression a, Type pType, string pName) { var equalityComparerTypeForPropertyType = typeof(EqualityComparerExpression<>).MakeGenericType(pType); - var equalityComparerDefaultProperty = equalityComparerTypeForPropertyType.GetTypeInfo().GetProperty("Default"); + var equalityComparerDefaultProperty = equalityComparerTypeForPropertyType.GetProperty("Default"); var getter = equalityComparerDefaultProperty.GetMethod; var equalityComparerExpressionObject = getter.Invoke(null, null); var equalityComparerExpressionObjectType = equalityComparerExpressionObject.GetType(); - var equalityComparerExpression = (LambdaExpression)equalityComparerExpressionObjectType.GetTypeInfo() + var equalityComparerExpression = (LambdaExpression)equalityComparerExpressionObjectType .GetMethod("GetEqualsExpr").Invoke(equalityComparerExpressionObject, null); - var hashCodeExpression = (LambdaExpression)equalityComparerExpressionObjectType.GetTypeInfo() + var hashCodeExpression = (LambdaExpression)equalityComparerExpressionObjectType .GetMethod("GetGetHashCodeExpr").Invoke(equalityComparerExpressionObject, null); var inlinedEqualityExpression = equalityComparerExpression.ReplaceParametersInBody(Expression.PropertyOrField(left, pName), Expression.PropertyOrField(right, pName)); var inlinedHashCodeExpression = hashCodeExpression.ReplaceParametersInBody(Expression.PropertyOrField(a, pName)); @@ -449,12 +432,12 @@ public GenericEqualityComparerExpression() private static Expression> ComputeGetHashCodeExpr() { var type = typeof(T); - if (type.GetTypeInfo().IsGenericType) + if (type.IsGenericType) { var def = type.GetGenericTypeDefinition(); if (def.Equals(typeof(Nullable<>))) { - var args = type.GetTypeInfo().GetGenericArguments(); + var args = type.GetGenericArguments(); Contract.Assume(args.Length == 1); if (ShouldUseCastToInt(args[0])) { @@ -478,12 +461,12 @@ private static bool ShouldUseCastToInt(Type t) if (t == typeof(short)) return true; if (t == typeof(int)) return true; if (t == typeof(long)) return true; - if (t.GetTypeInfo().IsGenericType) + if (t.IsGenericType) { var def = t.GetGenericTypeDefinition(); if (def.Equals(typeof(Nullable<>))) { - var args = t.GetTypeInfo().GetGenericArguments(); + var args = t.GetGenericArguments(); Contract.Assume(args.Length == 1); return ShouldUseCastToInt(args[0]); } @@ -492,10 +475,9 @@ private static bool ShouldUseCastToInt(Type t) } } - internal class PrimitiveEqualityComparerExpression : EqualityComparerExpression + internal class PrimitiveEqualityComparerExpression(Expression> equalsExpr, Expression> getHashCodeExpr) + : EqualityComparerExpression(equalsExpr, getHashCodeExpr) { - public PrimitiveEqualityComparerExpression(Expression> equalsExpr, Expression> getHashCodeExpr) - : base(equalsExpr, getHashCodeExpr) { } } internal sealed class StringEqualityComparerExpression : PrimitiveEqualityComparerExpression @@ -507,13 +489,10 @@ public StringEqualityComparerExpression() { } } - internal sealed class ComparerExpressionForIEqualityComparer : EqualityComparerExpression where T : IEqualityComparer + internal sealed class ComparerExpressionForIEqualityComparer(T t) : EqualityComparerExpression( + equalsExpr: (x, y) => t.Equals(x, y), + getHashCodeExpr: (obj) => t.GetHashCode(obj)) where T : IEqualityComparer { - public ComparerExpressionForIEqualityComparer(T t) - : base( - equalsExpr: (x, y) => t.Equals(x, y), - getHashCodeExpr: (obj) => t.GetHashCode(obj)) - { } } internal sealed class ComparerExpressionForIEquatable : PrimitiveEqualityComparerExpression where T : IEquatable @@ -525,12 +504,9 @@ public ComparerExpressionForIEquatable() { } } - internal sealed class ComparerExpressionForPartitionKey : IEqualityComparerExpression> + internal sealed class ComparerExpressionForPartitionKey(IEqualityComparerExpression comparer) : IEqualityComparerExpression> { - [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes", Justification = "Comparer is a function and thus immutable")] - public readonly IEqualityComparerExpression baseComparer; - - public ComparerExpressionForPartitionKey(IEqualityComparerExpression comparer) => this.baseComparer = comparer; + public readonly IEqualityComparerExpression baseComparer = comparer; public Expression, PartitionKey, bool>> GetEqualsExpr() { diff --git a/Sources/Core/Microsoft.StreamProcessing/Utilities/ExpressionExtensions.cs b/Sources/Core/Microsoft.StreamProcessing/Utilities/ExpressionExtensions.cs index 94f5ccf96..df60c3e48 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Utilities/ExpressionExtensions.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Utilities/ExpressionExtensions.cs @@ -22,37 +22,37 @@ internal static class ExpressionExtensions { public static Expression> InlineCalls(this Expression> function) { - Contract.Requires(function != null); + ArgumentNullException.ThrowIfNull(function); return CallInlinerCallRewriter.Inline>(function); } public static Expression> InlineCalls(this Expression> function) { - Contract.Requires(function != null); + ArgumentNullException.ThrowIfNull(function); return CallInlinerCallRewriter.Inline>(function); } public static Expression> InlineCalls(this Expression> function) { - Contract.Requires(function != null); + ArgumentNullException.ThrowIfNull(function); return CallInlinerCallRewriter.Inline>(function); } public static Expression> InlineCalls(this Expression> function) { - Contract.Requires(function != null); + ArgumentNullException.ThrowIfNull(function); return CallInlinerCallRewriter.Inline>(function); } public static Expression> InlineCalls(this Expression> function) { - Contract.Requires(function != null); + ArgumentNullException.ThrowIfNull(function); return CallInlinerCallRewriter.Inline>(function); } public static Expression> InlineCalls(this Expression> function) { - Contract.Requires(function != null); + ArgumentNullException.ThrowIfNull(function); return CallInlinerCallRewriter.Inline>(function); } @@ -63,11 +63,10 @@ public static Expression> InlineCalls public static string ExpressionToCSharp(this Expression e) { - var stringBuilder = new StringBuilder(); - var visitor = new ConvertToCSharp(new StringWriter(stringBuilder, CultureInfo.InvariantCulture)); + using StringWriter writer = new(CultureInfo.InvariantCulture); + ConvertToCSharp visitor = new(writer); visitor.Visit(e); - var s = stringBuilder.ToString(); - return s; + return writer.ToString(); } /// @@ -81,7 +80,7 @@ public static string ExpressionToCSharp(this Expression e) /// public static string Inline(this LambdaExpression function, params string[] arguments) { - Contract.Requires(function != null); + ArgumentNullException.ThrowIfNull(function); var map = new Dictionary(arguments.Length); for (int i = 0; i < arguments.Length; i++) @@ -106,18 +105,22 @@ public static string Inline(this LambdaExpression function, params string[] argu /// public static string ExpressionToCSharpStringWithParameterSubstitution(this Expression e, Dictionary map) { - var stringBuilder = new StringBuilder(); - var visitor = new ConvertToCSharpButWithStringParameters(new StringWriter(stringBuilder, CultureInfo.InvariantCulture), map); + using StringWriter writer = new(CultureInfo.InvariantCulture); + ConvertToCSharpButWithStringParameters visitor = new(writer,map); visitor.Visit(e); - return stringBuilder.ToString(); + return writer.ToString(); } - public static LambdaExpression RemoveCastToObject(this LambdaExpression lambda) - => lambda.Body is UnaryExpression body - && (body.NodeType == ExpressionType.Convert || body.NodeType == ExpressionType.TypeAs) - && (body.Type == typeof(object)) - ? Expression.Lambda(body.Operand, lambda.Parameters) - : lambda; + public static LambdaExpression RemoveCastToObject(this LambdaExpression lambda) => lambda.Body switch + { + UnaryExpression + { + NodeType: ExpressionType.Convert or ExpressionType.TypeAs, + Type: { } type, + Operand: { } operand + } when type == typeof(object) => Expression.Lambda(operand, lambda.Parameters), + _ => lambda + }; public static Expression ReplaceParametersInBody(this LambdaExpression lambda, params Expression[] expressions) => ParameterSubstituter.Replace(lambda.Parameters, lambda.Body, expressions); @@ -132,7 +135,7 @@ internal sealed class ConstantExpressionFinder : ExpressionVisitor public static bool IsClosedExpression(LambdaExpression function) { - Contract.Requires(function != null); + ArgumentNullException.ThrowIfNull(function); var hashSet = new HashSet(function.Parameters); var me = new ConstantExpressionFinder(hashSet); @@ -143,15 +146,19 @@ public static bool IsClosedExpression(LambdaExpression function) protected override Expression VisitConstant(ConstantExpression node) { var t = node.Type; - if (!t.GetTypeInfo().IsPrimitive) this.isConstant = false; + if (!t.IsPrimitive) this.isConstant = false; return base.VisitConstant(node); } protected override Expression VisitMember(MemberExpression node) { - if (!(node.Expression is MemberExpression)) // if it is a member expression, then let visitor recurse down to the left-most branch + if (node.Expression is MemberExpression) // if it is a member expression, then let visitor recurse down to the left-most branch + { + return base.VisitMember(node); + } + if (node.Expression is not ParameterExpression p || !this.parameters.Contains(p)) { - if (!(node.Expression is ParameterExpression p) || !this.parameters.Contains(p)) this.isConstant = false; + this.isConstant = false; } return base.VisitMember(node); } @@ -176,7 +183,7 @@ protected override Expression VisitMethodCall(MethodCallExpression node) var realArguments = new Expression[callArguments.Count - 1]; for (int i = 1; i < callArguments.Count; i++) { - realArguments[i - 1] = Visit(callArguments[i]); + realArguments[i - 1] = this.Visit(callArguments[i]); } return realFunction.ReplaceParametersInBody(realArguments); @@ -188,7 +195,7 @@ protected override Expression VisitMethodCall(MethodCallExpression node) internal sealed class EqualityComparer : ExpressionVisitor { - private readonly Dictionary parameterMap = new Dictionary(); + private readonly Dictionary parameterMap = []; private int uniqueParameterNumber; private EqualityComparer() => this.uniqueParameterNumber = 0; @@ -204,108 +211,128 @@ private bool Equals(Expression e1, Expression e2) if (e1 == e2) return true; if (e1 == null || e2 == null) return false; if (e1.NodeType != e2.NodeType) return false; - if (e1 is BinaryExpression b1) - { - var b2 = e2 as BinaryExpression; - return Equals(b1.Left, b2.Left) && Equals(b1.Right, b2.Right); - } - if (e1 is UnaryExpression u1) - { - var u2 = e2 as UnaryExpression; - return Equals(u1.Operand, u2.Operand); - } - if (e1 is ConditionalExpression conditional1) - { - var conditional2 = e2 as ConditionalExpression; - return Equals(conditional1.Test, conditional2.Test) && Equals(conditional1.IfTrue, conditional2.IfTrue) && Equals(conditional1.IfFalse, conditional2.IfFalse); - } - if (e1 is ConstantExpression constant1) + switch (e1) { - var constant2 = e2 as ConstantExpression; - return constant1.Value == null ? constant2.Value == null : constant1.Value.Equals(constant2.Value); - } - if (e1 is ParameterExpression param1) - { - var param2 = e2 as ParameterExpression; - return this.parameterMap[param1] == this.parameterMap[param2]; - } - if (e1 is IndexExpression index1) - { - var index2 = e2 as IndexExpression; - return Equals(index1.Object, index2.Object) && Equals(index1.Arguments, index2.Arguments); - } - if (e1 is InvocationExpression invoke1) - { - var invoke2 = e2 as InvocationExpression; - return Equals(invoke1.Expression, invoke2.Expression) && Equals(invoke1.Arguments, invoke2.Arguments); - } - if (e1 is LambdaExpression lambda1) - { - var lambda2 = e2 as LambdaExpression; - if (!lambda1.ReturnType.Equals(lambda2.ReturnType)) return false; - if (lambda1.Parameters.Count != lambda2.Parameters.Count) return false; - for (int i = 0; i < lambda1.Parameters.Count; i++) - { - var v1 = lambda1.Parameters[i]; - var v2 = lambda2.Parameters[i]; - this.parameterMap.Add(v1, this.uniqueParameterNumber); - if (v1 != v2) this.parameterMap.Add(v2, this.uniqueParameterNumber); - this.uniqueParameterNumber++; - } - var result = Equals(lambda1.Body, lambda2.Body); - for (int i = 0; i < lambda1.Parameters.Count; i++) - { - this.parameterMap.Remove(lambda1.Parameters[i]); - this.parameterMap.Remove(lambda2.Parameters[i]); - } - return result; - } - if (e1 is MemberExpression member1) - { - var member2 = e2 as MemberExpression; - return member1.Member.Equals(member2.Member) && Equals(member1.Expression, member2.Expression); - } - if (e1 is MethodCallExpression mc1) - { - var mc2 = e2 as MethodCallExpression; - return mc1.Method.Equals(mc2.Method) && Equals(mc1.Arguments, mc2.Arguments); - } - if (e1 is NewExpression new1) - { - var new2 = e2 as NewExpression; - return new1.Constructor == null - ? new2.Constructor == null - : new1.Constructor.Equals(new2.Constructor) && Equals(new1.Arguments, new2.Arguments); - } - if (e1 is NewArrayExpression newarr1) - { - var newarr2 = e2 as NewArrayExpression; - return newarr1.Type.Equals(newarr2.Type) && Equals(newarr1.Expressions, newarr2.Expressions); - } - if (e1 is MemberInitExpression memInit1) - { - var memInit2 = e2 as MemberInitExpression; - return Equals(memInit1.NewExpression, memInit2.NewExpression) && memInit1.Bindings.Count == memInit2.Bindings.Count - && memInit1.Bindings.Zip(memInit2.Bindings, (a, b) => Tuple.Create(a, b)).All(r => Equals(r.Item1, r.Item2)); - } - if (e1 is BlockExpression block1) - { - var block2 = e2 as BlockExpression; - return Equals(block1.Expressions, block2.Expressions); - } - if (e1 is LoopExpression loop1) - { - var loop2 = e2 as LoopExpression; - return Equals(loop1.Body, loop2.Body) - && loop1.BreakLabel.Name == loop2.BreakLabel.Name - && loop1.ContinueLabel.Name == loop2.ContinueLabel.Name; - } - if (e1 is LabelExpression label1) - { - var label2 = e2 as LabelExpression; - return Equals(label1.DefaultValue, label2.DefaultValue) && label1.Target.Name == label2.Target.Name; + case BinaryExpression b1: + { + var b2 = e2 as BinaryExpression; + return this.Equals(b1.Left, b2.Left) && this.Equals(b1.Right, b2.Right); + } + + case UnaryExpression u1: + { + var u2 = e2 as UnaryExpression; + return this.Equals(u1.Operand, u2.Operand); + } + + case ConditionalExpression conditional1: + { + var conditional2 = e2 as ConditionalExpression; + return this.Equals(conditional1.Test, conditional2.Test) && this.Equals(conditional1.IfTrue, conditional2.IfTrue) && this.Equals(conditional1.IfFalse, conditional2.IfFalse); + } + + case ConstantExpression constant1: + { + var constant2 = e2 as ConstantExpression; + return constant1.Value == null ? constant2.Value == null : constant1.Value.Equals(constant2.Value); + } + + case ParameterExpression param1: + { + var param2 = e2 as ParameterExpression; + return this.parameterMap[param1] == this.parameterMap[param2]; + } + + case IndexExpression index1: + { + var index2 = e2 as IndexExpression; + return this.Equals(index1.Object, index2.Object) && this.Equals(index1.Arguments, index2.Arguments); + } + + case InvocationExpression invoke1: + { + var invoke2 = e2 as InvocationExpression; + return this.Equals(invoke1.Expression, invoke2.Expression) && this.Equals(invoke1.Arguments, invoke2.Arguments); + } + + case LambdaExpression lambda1: + { + var lambda2 = e2 as LambdaExpression; + if (!lambda1.ReturnType.Equals(lambda2.ReturnType)) return false; + if (lambda1.Parameters.Count != lambda2.Parameters.Count) return false; + for (int i = 0; i < lambda1.Parameters.Count; i++) + { + var v1 = lambda1.Parameters[i]; + var v2 = lambda2.Parameters[i]; + this.parameterMap.Add(v1, this.uniqueParameterNumber); + if (v1 != v2) this.parameterMap.Add(v2, this.uniqueParameterNumber); + this.uniqueParameterNumber++; + } + var result = this.Equals(lambda1.Body, lambda2.Body); + for (int i = 0; i < lambda1.Parameters.Count; i++) + { + this.parameterMap.Remove(lambda1.Parameters[i]); + this.parameterMap.Remove(lambda2.Parameters[i]); + } + return result; + } + + case MemberExpression member1: + { + var member2 = e2 as MemberExpression; + return member1.Member.Equals(member2.Member) && this.Equals(member1.Expression, member2.Expression); + } + + case MethodCallExpression mc1: + { + var mc2 = e2 as MethodCallExpression; + return mc1.Method.Equals(mc2.Method) && this.Equals(mc1.Arguments, mc2.Arguments); + } + + case NewExpression new1: + { + var new2 = e2 as NewExpression; + return new1.Constructor == null + ? new2.Constructor == null + : new1.Constructor.Equals(new2.Constructor) && this.Equals(new1.Arguments, new2.Arguments); + } + + case NewArrayExpression newarr1: + { + var newarr2 = e2 as NewArrayExpression; + return newarr1.Type.Equals(newarr2.Type) && this.Equals(newarr1.Expressions, newarr2.Expressions); + } + + case MemberInitExpression memInit1: + { + var memInit2 = e2 as MemberInitExpression; + return this.Equals(memInit1.NewExpression, memInit2.NewExpression) && memInit1.Bindings.Count == memInit2.Bindings.Count + && memInit1.Bindings.Zip(memInit2.Bindings, (a, b) => Tuple.Create(a, b)).All(r => this.Equals(r.Item1, r.Item2)); + } + + case BlockExpression block1: + { + var block2 = e2 as BlockExpression; + return this.Equals(block1.Expressions, block2.Expressions); + } + + case LoopExpression loop1: + { + var loop2 = e2 as LoopExpression; + return this.Equals(loop1.Body, loop2.Body) + && loop1.BreakLabel.Name == loop2.BreakLabel.Name + && loop1.ContinueLabel.Name == loop2.ContinueLabel.Name; + } + + case LabelExpression label1: + { + var label2 = e2 as LabelExpression; + return this.Equals(label1.DefaultValue, label2.DefaultValue) && label1.Target.Name == label2.Target.Name; + } + + default: + return false; } - return false; } private bool Equals(ReadOnlyCollection list1, ReadOnlyCollection list2) @@ -313,7 +340,7 @@ private bool Equals(ReadOnlyCollection list1, ReadOnlyCollection l1.Initializers[o].AddMethod == l2.Initializers[o].AddMethod && Equals(l1.Initializers[o].Arguments, l2.Initializers[o].Arguments)); + && Enumerable.Range(0, l1.Initializers.Count).All(o => l1.Initializers[o].AddMethod == l2.Initializers[o].AddMethod && this.Equals(l1.Initializers[o].Arguments, l2.Initializers[o].Arguments)); } case MemberBindingType.MemberBinding: { @@ -344,7 +371,7 @@ private bool Equals(MemberBinding mb1, MemberBinding mb2) var v1 = mb1 as MemberMemberBinding; var v2 = mb2 as MemberMemberBinding; return v1.Bindings.Count == v2.Bindings.Count - && Enumerable.Range(0, v1.Bindings.Count).All(o => Equals(v1.Bindings[o], v2.Bindings[o])); + && Enumerable.Range(0, v1.Bindings.Count).All(o => this.Equals(v1.Bindings[o], v2.Bindings[o])); } default: throw new InvalidOperationException("Switch statement meant to be exhaustive."); } @@ -353,7 +380,7 @@ private bool Equals(MemberBinding mb1, MemberBinding mb2) internal sealed class VariableFinder : ExpressionVisitor { - private readonly List foundVariables = new List(); + private readonly List foundVariables = []; public static List Find(Expression exp) { @@ -367,11 +394,11 @@ protected override Expression VisitMember(MemberExpression node) // Looking for pattern Constant.Member, where Constant is not a primitive if (node.Expression != null && node.Expression.NodeType == ExpressionType.Constant - && node.Member is FieldInfo - && !node.Expression.Type.GetTypeInfo().IsPrimitive) + && node.Member is FieldInfo info + && !node.Expression.Type.IsPrimitive) { var c = (ConstantExpression)node.Expression; - var f = (FieldInfo)node.Member; + var f = info; this.foundVariables.Add(f.GetValue(c.Value)); } return node; @@ -384,7 +411,7 @@ internal sealed class ParameterSubstituter : ExpressionVisitor public static Expression InlineInvocation(InvocationExpression invokeExpression) { - if (!(invokeExpression.Expression is LambdaExpression lambda)) return invokeExpression; + if (invokeExpression.Expression is not LambdaExpression lambda) return invokeExpression; var map = new Dictionary(invokeExpression.Arguments.Count); for (int i = 0; i < invokeExpression.Arguments.Count; i++) { @@ -428,11 +455,11 @@ protected override Expression VisitParameter(ParameterExpression node) internal class ConvertToCSharp : ExpressionVisitor { public readonly TextWriter writer; - private readonly HashSet nonExpressionFeatures = new HashSet - { + private readonly HashSet nonExpressionFeatures = + [ ExpressionType.Loop, ExpressionType.Block - }; + ]; public ConvertToCSharp(TextWriter writer) => this.writer = writer ?? throw new ArgumentNullException(nameof(writer)); @@ -444,7 +471,7 @@ internal class ConvertToCSharp : ExpressionVisitor { if (!first) this.writer.Write(", "); first = false; - Visit(e); + this.Visit(e); } this.writer.Write(")"); @@ -470,9 +497,9 @@ protected override Expression VisitBinary(BinaryExpression node) { this.writer.Write("("); } - Visit(node.Left); - Visit(node.NodeType); - Visit(node.Right); + this.Visit(node.Left); + this.Visit(node.NodeType); + this.Visit(node.Right); if (!node.NodeType.ToString().Contains("Assign")) { this.writer.Write(")"); @@ -483,10 +510,10 @@ protected override Expression VisitBinary(BinaryExpression node) protected override Expression VisitBlock(BlockExpression node) { this.writer.WriteLine("{"); - Visit(node.Variables); + this.Visit(node.Variables); foreach (var e in node.Expressions) { - Visit(e); + this.Visit(e); this.writer.WriteLine(";"); } @@ -546,16 +573,15 @@ protected override Expression VisitConstant(ConstantExpression node) this.writer.Write(string.Format(CultureInfo.InvariantCulture, "'{0}'", v)); return null; } - var typeInfo = t.GetTypeInfo(); - if (typeof(Type).GetTypeInfo().IsAssignableFrom(typeInfo)) + if (typeof(Type).IsAssignableFrom(t)) { this.writer.Write("typeof({0})", GetTypeName((Type)v)); return null; } - if (node.Type.GetTypeInfo().IsEnum) + if (node.Type.IsEnum) { var remainingFlags = (Enum)v; - WriteDelimitedList( + this.WriteDelimitedList( from name in Enum.GetNames(t) let y = (Enum)Enum.Parse(t, name, false) where remainingFlags.HasFlag(y) @@ -564,7 +590,7 @@ select GetTypeName(t) + "." + name, return null; } - if (!typeInfo.IsPrimitive && typeInfo.IsValueType && Nullable.GetUnderlyingType(t) == null && v.Equals(Activator.CreateInstance(t))) + if (!t.IsPrimitive && t.IsValueType && Nullable.GetUnderlyingType(t) == null && v.Equals(Activator.CreateInstance(t))) { // A constant of a non-primitive struct type must be a default value for that type // At least, that is what is assumed here. @@ -632,14 +658,14 @@ protected override Expression VisitGoto(GotoExpression node) protected override Expression VisitIndex(IndexExpression node) { - Visit(node.Object); + this.Visit(node.Object); this.writer.Write("["); var first = true; foreach (var arg in node.Arguments) { if (!first) this.writer.Write(", "); first = false; - Visit(arg); + this.Visit(arg); } this.writer.Write("]"); @@ -649,16 +675,16 @@ protected override Expression VisitIndex(IndexExpression node) protected override Expression VisitInvocation(InvocationExpression node) { var inlinedLambda = ParameterSubstituter.InlineInvocation(node); - if (!(inlinedLambda is InvocationExpression)) + if (inlinedLambda is not InvocationExpression) { - Visit(inlinedLambda); + this.Visit(inlinedLambda); return null; } this.writer.Write("Invoke("); base.Visit(node.Expression); this.writer.Write(","); - Visit(node.Arguments); + this.Visit(node.Arguments); this.writer.Write(")"); return null; } @@ -701,7 +727,7 @@ protected override Expression VisitLambda(Expression node) protected override Expression VisitListInit(ListInitExpression node) { - Visit(node.NewExpression); + this.Visit(node.NewExpression); this.writer.Write("{"); int j = 0; foreach (var i in node.Initializers) @@ -709,7 +735,7 @@ protected override Expression VisitListInit(ListInitExpression node) if (j++ > 0) this.writer.Write(", "); if (i.Arguments.Count > 1) this.writer.Write(" {"); this.writer.Write(" "); - VisitCommaDelimitedList(i.Arguments); + this.VisitCommaDelimitedList(i.Arguments); if (i.Arguments.Count > 1) this.writer.Write(" }"); } @@ -732,7 +758,7 @@ protected override Expression VisitLoop(LoopExpression node) protected override Expression VisitMember(MemberExpression node) { - if (node.Expression != null) Visit(node.Expression); + if (node.Expression != null) this.Visit(node.Expression); else this.writer.Write(GetTypeName(node.Member.DeclaringType)); this.writer.Write("."); @@ -744,7 +770,7 @@ protected override MemberAssignment VisitMemberAssignment(MemberAssignment node) { this.writer.Write(node.Member.Name); this.writer.Write(" = "); - Visit(node.Expression); + this.Visit(node.Expression); return null; } @@ -753,13 +779,13 @@ protected override MemberBinding VisitMemberBinding(MemberBinding node) protected override Expression VisitMemberInit(MemberInitExpression node) { - Visit(node.NewExpression); + this.Visit(node.NewExpression); var first = true; this.writer.Write("{"); foreach (var b in node.Bindings) { if (!first) this.writer.Write(", "); - VisitMemberBinding(b); + this.VisitMemberBinding(b); first = false; } @@ -784,7 +810,7 @@ protected override Expression VisitMethodCall(MethodCallExpression node) var isIndexer = node.Method.IsSpecialName && node.Method.Name.Equals("get_Item"); if (node.Object != null) { - Visit(node.Object); + this.Visit(node.Object); if (!isIndexer) this.writer.Write("."); } else @@ -815,7 +841,7 @@ protected override Expression VisitMethodCall(MethodCallExpression node) first = false; if (byRef[iter]) this.writer.Write("ref "); iter++; - Visit(arg); + this.Visit(arg); } if (isIndexer) @@ -846,7 +872,7 @@ protected override Expression VisitNew(NewExpression node) { if (i > 0) this.writer.Write(", "); if (isAnon) this.writer.Write("{0} = ", anonymousTypePropertyNames[i]); - Visit(arg); + this.Visit(arg); i++; } @@ -860,7 +886,7 @@ protected override Expression VisitNew(NewExpression node) protected override Expression VisitNewArray(NewArrayExpression node) { this.writer.Write("new {0} {{ ", GetTypeName(node.Type)); - VisitCommaDelimitedList(node.Expressions); + this.VisitCommaDelimitedList(node.Expressions); if (node.Expressions.Count > 0) this.writer.Write(" "); @@ -913,12 +939,12 @@ protected override Expression VisitUnary(UnaryExpression node) this.writer.Write("("); this.writer.Write(GetTypeName(node.Type)); this.writer.Write(")"); - Visit(node.Operand); + this.Visit(node.Operand); } else { - Visit(node.NodeType); - Visit(node.Operand); + this.Visit(node.NodeType); + this.Visit(node.Operand); } this.writer.Write(")"); @@ -1180,7 +1206,7 @@ private void Visit(ExpressionType expressionType) this.writer.Write(" "); } - private void VisitCommaDelimitedList(IEnumerable es) => VisitDelimitedList(es, ", "); + private void VisitCommaDelimitedList(IEnumerable es) => this.VisitDelimitedList(es, ", "); private void VisitDelimitedList(IEnumerable es, string delimiter) { @@ -1189,7 +1215,7 @@ private void VisitDelimitedList(IEnumerable es, string delimiter) { if (!first) this.writer.Write(delimiter); first = false; - Visit(e); + this.Visit(e); } } @@ -1260,14 +1286,14 @@ private ColumnOriented() { } /// Null if the body could not be transformed public static LambdaExpression/*?*/ Transform(LambdaExpression rowOrientedLambda, IDictionary substitutionInformation) { - Contract.Requires(rowOrientedLambda != null); - Contract.Requires(substitutionInformation != null); + ArgumentNullException.ThrowIfNull(rowOrientedLambda); + ArgumentNullException.ThrowIfNull(substitutionInformation); Contract.Requires(Contract.ForAll(substitutionInformation.Keys, k => rowOrientedLambda.Parameters.Contains(k))); var me = new ColumnOriented { - parameterTableForDecomposableTypes = new Dictionary, ParameterInformation>(), - parameterTableForAtomicTypes = new Dictionary() + parameterTableForDecomposableTypes = [], + parameterTableForAtomicTypes = [] }; var parameterMapping = new Dictionary(); var i = 0; @@ -1292,9 +1318,9 @@ private ColumnOriented() { } if (cr.noFields) { var columnarField = cr.PseudoField; - var batchField = batchType.GetTypeInfo().GetField(columnarField.Name); + var batchField = batchType.GetField(columnarField.Name); var columnBatch = Expression.MakeMemberAccess(batchVariable, batchField); - var colArrayOfColumnBatch = Expression.MakeMemberAccess(columnBatch, batchField.FieldType.GetTypeInfo().GetField("col")); + var colArrayOfColumnBatch = Expression.MakeMemberAccess(columnBatch, batchField.FieldType.GetField("col")); me.parameterTableForAtomicTypes.Add( parameter, new ParameterInformation { ArrayVariable = colArrayOfColumnBatch, IndexVariable = indexExpression, }); @@ -1304,13 +1330,13 @@ private ColumnOriented() { } foreach (var f in cr.Fields.Values) { Expression arrayToUse; - var batchField = batchType.GetTypeInfo().GetField(f.Name); + var batchField = batchType.GetField(f.Name); var batchFieldType = batchField.FieldType; - if (batchFieldType.GetTypeInfo().IsGenericType && batchFieldType.GetGenericTypeDefinition().Equals(typeof(ColumnBatch<>))) + if (batchFieldType.IsGenericType && batchFieldType.GetGenericTypeDefinition().Equals(typeof(ColumnBatch<>))) { // ColumBatch for some T var columnBatch = Expression.MakeMemberAccess(batchVariable, batchField); - var colArrayOfColumnBatch = Expression.MakeMemberAccess(columnBatch, batchField.FieldType.GetTypeInfo().GetField("col")); + var colArrayOfColumnBatch = Expression.MakeMemberAccess(columnBatch, batchField.FieldType.GetField("col")); arrayToUse = colArrayOfColumnBatch; } else if (batchFieldType.Equals(typeof(MultiString))) @@ -1346,7 +1372,7 @@ protected override Expression VisitParameter(ParameterExpression node) // decomposed into a columnar representation. // So its value must be reconstructed from its columnar representation. // Flag that this is happening so clients can decide what to do about it. - return ReconstructValue(node); + return this.ReconstructValue(node); } return base.VisitParameter(node); } @@ -1369,8 +1395,7 @@ private Expression ReconstructValue(ParameterExpression p) fieldsDictionary .Select(kv => { - var memberInfo = t.GetTypeInfo().GetField(kv.Key.Item2) as MemberInfo; - if (memberInfo == null) memberInfo = t.GetTypeInfo().GetProperty(kv.Key.Item2) as MemberInfo; + var memberInfo = t.GetField(kv.Key.Item2) as MemberInfo ?? t.GetProperty(kv.Key.Item2); return Expression.Bind(memberInfo, MakeIndexedAccessExpression(kv.Value)); })); return memberInitExpression; @@ -1459,7 +1484,7 @@ private IntroduceArrayVariables() { } /// public static LambdaExpression Transform(LambdaExpression inputLambda, IDictionary parameterSubstitutionNames = null) { - Contract.Requires(inputLambda != null); + ArgumentNullException.ThrowIfNull(inputLambda); Contract.Requires(parameterSubstitutionNames == null || Contract.ForAll(parameterSubstitutionNames.Keys, p => inputLambda.Parameters.Contains(p))); var me = new IntroduceArrayVariables @@ -1479,7 +1504,7 @@ public static LambdaExpression Transform(LambdaExpression inputLambda, IDictiona protected override Expression VisitIndex(IndexExpression node) { - if (!(node.Object is MemberExpression colFieldAccess)) goto JustVisit; + if (node.Object is not MemberExpression colFieldAccess) goto JustVisit; var colMember = colFieldAccess.Member as FieldInfo; if (colMember == null) goto JustVisit; ParameterExpression batchVariable; @@ -1488,7 +1513,7 @@ protected override Expression VisitIndex(IndexExpression node) { // then the colMember should be "col" in the expression "b.f.col" if (!colMember.Name.Equals("col")) goto JustVisit; - if (!(colFieldAccess.Expression is MemberExpression FAccess)) goto JustVisit; + if (colFieldAccess.Expression is not MemberExpression FAccess) goto JustVisit; fieldInfo = FAccess.Member as FieldInfo; if (fieldInfo == null) goto JustVisit; batchVariable = FAccess.Expression as ParameterExpression; @@ -1596,7 +1621,7 @@ internal sealed class ParameterInstanceFinder : ExpressionVisitor public static bool FoundInstance(LambdaExpression function) { - Contract.Requires(function != null); + ArgumentNullException.ThrowIfNull(function); var hashSet = new HashSet(function.Parameters); var me = new ParameterInstanceFinder(hashSet); @@ -1609,12 +1634,12 @@ protected override Expression VisitMethodCall(MethodCallExpression node) if (node.Object != null) { if (node.Object is ParameterExpression p && this.parameters.Contains(p)) this.foundInstance = true; - Visit(node.Object); + this.Visit(node.Object); } foreach (var arg in node.Arguments) { if (arg is ParameterExpression p && this.parameters.Contains(p)) this.foundInstance = true; - Visit(arg); + this.Visit(arg); } return node; } @@ -1622,11 +1647,11 @@ protected override Expression VisitMethodCall(MethodCallExpression node) protected override Expression VisitBinary(BinaryExpression node) { if (node.Left is ParameterExpression p && this.parameters.Contains(p)) this.foundInstance = true; - Visit(node.Left); + this.Visit(node.Left); p = node.Right as ParameterExpression; if (p != null && this.parameters.Contains(p)) this.foundInstance = true; - Visit(node.Right); + this.Visit(node.Right); return node; } @@ -1634,7 +1659,7 @@ protected override Expression VisitBinary(BinaryExpression node) protected override Expression VisitUnary(UnaryExpression node) { if (node.Operand is ParameterExpression p && this.parameters.Contains(p)) this.foundInstance = true; - Visit(node.Operand); + this.Visit(node.Operand); return node; } @@ -1642,15 +1667,15 @@ protected override Expression VisitUnary(UnaryExpression node) protected override Expression VisitConditional(ConditionalExpression node) { if (node.Test is ParameterExpression p && this.parameters.Contains(p)) this.foundInstance = true; - Visit(node.Test); + this.Visit(node.Test); p = node.IfTrue as ParameterExpression; if (p != null && this.parameters.Contains(p)) this.foundInstance = true; - Visit(node.IfTrue); + this.Visit(node.IfTrue); p = node.IfFalse as ParameterExpression; if (p != null && this.parameters.Contains(p)) this.foundInstance = true; - Visit(node.IfFalse); + this.Visit(node.IfFalse); return node; } diff --git a/Sources/Core/Microsoft.StreamProcessing/Utilities/Native32.cs b/Sources/Core/Microsoft.StreamProcessing/Utilities/Native32.cs index f2924c0e7..d19a7ca57 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Utilities/Native32.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Utilities/Native32.cs @@ -74,8 +74,16 @@ internal static void AffinitizeThread(int processor) { if (utid == pt.Id) { - long AffinityMask = 1 << processor; - pt.ProcessorAffinity = (IntPtr)(AffinityMask); // Set affinity for this + if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) + { + pt.IdealProcessor = processor; + } + + if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + { + long AffinityMask = 1 << processor; + pt.ProcessorAffinity = (IntPtr)(AffinityMask); // Set affinity for this + } } } } diff --git a/Sources/Core/Microsoft.StreamProcessing/Utilities/RxReplacements.cs b/Sources/Core/Microsoft.StreamProcessing/Utilities/RxReplacements.cs index 124147476..f87675dea 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Utilities/RxReplacements.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Utilities/RxReplacements.cs @@ -3,8 +3,7 @@ // Licensed under the MIT License // ********************************************************************* using System; -using System.Diagnostics.Contracts; -using System.Threading; +using System.Threading.Tasks; namespace Microsoft.StreamProcessing { @@ -15,58 +14,37 @@ public static void SynchronousForEach(this IObservable source, Action a SynchronousForEachWorker.DoIt(source, action); } - private sealed class SynchronousForEachWorker : IObserver, IDisposable + private sealed class SynchronousForEachWorker(Action action) : IObserver { - private Action action; - private AutoResetEvent mutex; - private Exception exception = null; - - private SynchronousForEachWorker() { } + private readonly TaskCompletionSource tcs = new(TaskCreationOptions.RunContinuationsAsynchronously); public static void DoIt(IObservable observable, Action action) { - Contract.Requires(observable != null); - Contract.Requires(action != null); + ArgumentNullException.ThrowIfNull(observable); + ArgumentNullException.ThrowIfNull(action); - var me = new SynchronousForEachWorker + SynchronousForEachWorker worker = new(action); + using (observable.Subscribe(worker)) { - action = action, - mutex = new AutoResetEvent(false) - }; - - IDisposable disp = observable.Subscribe(me); - me.mutex.WaitOne(); - if (disp != null) disp.Dispose(); - if (me.exception != null) throw me.exception; - return; + worker.tcs.Task.GetAwaiter().GetResult(); + } } - public void OnCompleted() => this.mutex.Set(); - - public void OnError(Exception error) - { - this.exception = error; - this.mutex.Set(); - } + public void OnCompleted() => this.tcs.TrySetResult(); + public void OnError(Exception error) => this.tcs.TrySetException(error); public void OnNext(T value) { - if (this.exception != null) - { - OnCompleted(); - return; - } + if (this.tcs.Task.IsCompleted) return; try { - this.action(value); + action(value); } catch (Exception e) { - OnError(e); + this.OnError(e); } } - - public void Dispose() => this.mutex?.Dispose(); } } diff --git a/Sources/Core/Microsoft.StreamProcessing/Utilities/StructTupleTemplate.cs b/Sources/Core/Microsoft.StreamProcessing/Utilities/StructTupleTemplate.cs index 5470b7d25..c0b95fd13 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Utilities/StructTupleTemplate.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Utilities/StructTupleTemplate.cs @@ -96,13 +96,13 @@ public struct StructTuple : IDisposable /// Prints a string representation of the StructTuple. /// [EditorBrowsable(EditorBrowsableState.Never)] - public override string ToString() => new { this.Item1 }.ToString(); + public override readonly string ToString() => new { this.Item1 }.ToString(); /// /// Disposes the struct by testing each constituent component for disposability. /// [EditorBrowsable(EditorBrowsableState.Never)] - public void Dispose() + public readonly void Dispose() { (this.Item1 as IDisposable)?.Dispose(); } @@ -135,13 +135,13 @@ public struct StructTuple : IDisposable /// Prints a string representation of the StructTuple. /// [EditorBrowsable(EditorBrowsableState.Never)] - public override string ToString() => new { this.Item1, this.Item2 }.ToString(); + public override readonly string ToString() => new { this.Item1, this.Item2 }.ToString(); /// /// Disposes the struct by testing each constituent component for disposability. /// [EditorBrowsable(EditorBrowsableState.Never)] - public void Dispose() + public readonly void Dispose() { (this.Item1 as IDisposable)?.Dispose(); (this.Item2 as IDisposable)?.Dispose(); @@ -183,13 +183,13 @@ public struct StructTuple : IDisposable /// Prints a string representation of the StructTuple. /// [EditorBrowsable(EditorBrowsableState.Never)] - public override string ToString() => new { this.Item1, this.Item2, this.Item3 }.ToString(); + public override readonly string ToString() => new { this.Item1, this.Item2, this.Item3 }.ToString(); /// /// Disposes the struct by testing each constituent component for disposability. /// [EditorBrowsable(EditorBrowsableState.Never)] - public void Dispose() + public readonly void Dispose() { (this.Item1 as IDisposable)?.Dispose(); (this.Item2 as IDisposable)?.Dispose(); @@ -240,13 +240,13 @@ public struct StructTuple : IDisposable /// Prints a string representation of the StructTuple. /// [EditorBrowsable(EditorBrowsableState.Never)] - public override string ToString() => new { this.Item1, this.Item2, this.Item3, this.Item4 }.ToString(); + public override readonly string ToString() => new { this.Item1, this.Item2, this.Item3, this.Item4 }.ToString(); /// /// Disposes the struct by testing each constituent component for disposability. /// [EditorBrowsable(EditorBrowsableState.Never)] - public void Dispose() + public readonly void Dispose() { (this.Item1 as IDisposable)?.Dispose(); (this.Item2 as IDisposable)?.Dispose(); @@ -306,13 +306,13 @@ public struct StructTuple : IDisposable /// Prints a string representation of the StructTuple. /// [EditorBrowsable(EditorBrowsableState.Never)] - public override string ToString() => new { this.Item1, this.Item2, this.Item3, this.Item4, this.Item5 }.ToString(); + public override readonly string ToString() => new { this.Item1, this.Item2, this.Item3, this.Item4, this.Item5 }.ToString(); /// /// Disposes the struct by testing each constituent component for disposability. /// [EditorBrowsable(EditorBrowsableState.Never)] - public void Dispose() + public readonly void Dispose() { (this.Item1 as IDisposable)?.Dispose(); (this.Item2 as IDisposable)?.Dispose(); @@ -381,13 +381,13 @@ public struct StructTuple : IDisposable /// Prints a string representation of the StructTuple. /// [EditorBrowsable(EditorBrowsableState.Never)] - public override string ToString() => new { this.Item1, this.Item2, this.Item3, this.Item4, this.Item5, this.Item6 }.ToString(); + public override readonly string ToString() => new { this.Item1, this.Item2, this.Item3, this.Item4, this.Item5, this.Item6 }.ToString(); /// /// Disposes the struct by testing each constituent component for disposability. /// [EditorBrowsable(EditorBrowsableState.Never)] - public void Dispose() + public readonly void Dispose() { (this.Item1 as IDisposable)?.Dispose(); (this.Item2 as IDisposable)?.Dispose(); @@ -465,13 +465,13 @@ public struct StructTuple : IDisposable /// Prints a string representation of the StructTuple. /// [EditorBrowsable(EditorBrowsableState.Never)] - public override string ToString() => new { this.Item1, this.Item2, this.Item3, this.Item4, this.Item5, this.Item6, this.Item7 }.ToString(); + public override readonly string ToString() => new { this.Item1, this.Item2, this.Item3, this.Item4, this.Item5, this.Item6, this.Item7 }.ToString(); /// /// Disposes the struct by testing each constituent component for disposability. /// [EditorBrowsable(EditorBrowsableState.Never)] - public void Dispose() + public readonly void Dispose() { (this.Item1 as IDisposable)?.Dispose(); (this.Item2 as IDisposable)?.Dispose(); @@ -558,13 +558,13 @@ public struct StructTuple : IDisposable /// Prints a string representation of the StructTuple. /// [EditorBrowsable(EditorBrowsableState.Never)] - public override string ToString() => new { this.Item1, this.Item2, this.Item3, this.Item4, this.Item5, this.Item6, this.Item7, this.Item8 }.ToString(); + public override readonly string ToString() => new { this.Item1, this.Item2, this.Item3, this.Item4, this.Item5, this.Item6, this.Item7, this.Item8 }.ToString(); /// /// Disposes the struct by testing each constituent component for disposability. /// [EditorBrowsable(EditorBrowsableState.Never)] - public void Dispose() + public readonly void Dispose() { (this.Item1 as IDisposable)?.Dispose(); (this.Item2 as IDisposable)?.Dispose(); @@ -660,13 +660,13 @@ public struct StructTuple : IDisposable /// Prints a string representation of the StructTuple. /// [EditorBrowsable(EditorBrowsableState.Never)] - public override string ToString() => new { this.Item1, this.Item2, this.Item3, this.Item4, this.Item5, this.Item6, this.Item7, this.Item8, this.Item9 }.ToString(); + public override readonly string ToString() => new { this.Item1, this.Item2, this.Item3, this.Item4, this.Item5, this.Item6, this.Item7, this.Item8, this.Item9 }.ToString(); /// /// Disposes the struct by testing each constituent component for disposability. /// [EditorBrowsable(EditorBrowsableState.Never)] - public void Dispose() + public readonly void Dispose() { (this.Item1 as IDisposable)?.Dispose(); (this.Item2 as IDisposable)?.Dispose(); @@ -771,13 +771,13 @@ public struct StructTuple : IDisposable /// Prints a string representation of the StructTuple. /// [EditorBrowsable(EditorBrowsableState.Never)] - public override string ToString() => new { this.Item1, this.Item2, this.Item3, this.Item4, this.Item5, this.Item6, this.Item7, this.Item8, this.Item9, this.Item10 }.ToString(); + public override readonly string ToString() => new { this.Item1, this.Item2, this.Item3, this.Item4, this.Item5, this.Item6, this.Item7, this.Item8, this.Item9, this.Item10 }.ToString(); /// /// Disposes the struct by testing each constituent component for disposability. /// [EditorBrowsable(EditorBrowsableState.Never)] - public void Dispose() + public readonly void Dispose() { (this.Item1 as IDisposable)?.Dispose(); (this.Item2 as IDisposable)?.Dispose(); @@ -891,13 +891,13 @@ public struct StructTuple : IDispo /// Prints a string representation of the StructTuple. /// [EditorBrowsable(EditorBrowsableState.Never)] - public override string ToString() => new { this.Item1, this.Item2, this.Item3, this.Item4, this.Item5, this.Item6, this.Item7, this.Item8, this.Item9, this.Item10, this.Item11 }.ToString(); + public override readonly string ToString() => new { this.Item1, this.Item2, this.Item3, this.Item4, this.Item5, this.Item6, this.Item7, this.Item8, this.Item9, this.Item10, this.Item11 }.ToString(); /// /// Disposes the struct by testing each constituent component for disposability. /// [EditorBrowsable(EditorBrowsableState.Never)] - public void Dispose() + public readonly void Dispose() { (this.Item1 as IDisposable)?.Dispose(); (this.Item2 as IDisposable)?.Dispose(); @@ -1020,13 +1020,13 @@ public struct StructTuple : I /// Prints a string representation of the StructTuple. /// [EditorBrowsable(EditorBrowsableState.Never)] - public override string ToString() => new { this.Item1, this.Item2, this.Item3, this.Item4, this.Item5, this.Item6, this.Item7, this.Item8, this.Item9, this.Item10, this.Item11, this.Item12 }.ToString(); + public override readonly string ToString() => new { this.Item1, this.Item2, this.Item3, this.Item4, this.Item5, this.Item6, this.Item7, this.Item8, this.Item9, this.Item10, this.Item11, this.Item12 }.ToString(); /// /// Disposes the struct by testing each constituent component for disposability. /// [EditorBrowsable(EditorBrowsableState.Never)] - public void Dispose() + public readonly void Dispose() { (this.Item1 as IDisposable)?.Dispose(); (this.Item2 as IDisposable)?.Dispose(); @@ -1158,13 +1158,13 @@ public struct StructTuple [EditorBrowsable(EditorBrowsableState.Never)] - public override string ToString() => new { this.Item1, this.Item2, this.Item3, this.Item4, this.Item5, this.Item6, this.Item7, this.Item8, this.Item9, this.Item10, this.Item11, this.Item12, this.Item13 }.ToString(); + public override readonly string ToString() => new { this.Item1, this.Item2, this.Item3, this.Item4, this.Item5, this.Item6, this.Item7, this.Item8, this.Item9, this.Item10, this.Item11, this.Item12, this.Item13 }.ToString(); /// /// Disposes the struct by testing each constituent component for disposability. /// [EditorBrowsable(EditorBrowsableState.Never)] - public void Dispose() + public readonly void Dispose() { (this.Item1 as IDisposable)?.Dispose(); (this.Item2 as IDisposable)?.Dispose(); @@ -1305,13 +1305,13 @@ public struct StructTuple [EditorBrowsable(EditorBrowsableState.Never)] - public override string ToString() => new { this.Item1, this.Item2, this.Item3, this.Item4, this.Item5, this.Item6, this.Item7, this.Item8, this.Item9, this.Item10, this.Item11, this.Item12, this.Item13, this.Item14 }.ToString(); + public override readonly string ToString() => new { this.Item1, this.Item2, this.Item3, this.Item4, this.Item5, this.Item6, this.Item7, this.Item8, this.Item9, this.Item10, this.Item11, this.Item12, this.Item13, this.Item14 }.ToString(); /// /// Disposes the struct by testing each constituent component for disposability. /// [EditorBrowsable(EditorBrowsableState.Never)] - public void Dispose() + public readonly void Dispose() { (this.Item1 as IDisposable)?.Dispose(); (this.Item2 as IDisposable)?.Dispose(); @@ -1461,13 +1461,13 @@ public struct StructTuple [EditorBrowsable(EditorBrowsableState.Never)] - public override string ToString() => new { this.Item1, this.Item2, this.Item3, this.Item4, this.Item5, this.Item6, this.Item7, this.Item8, this.Item9, this.Item10, this.Item11, this.Item12, this.Item13, this.Item14, this.Item15 }.ToString(); + public override readonly string ToString() => new { this.Item1, this.Item2, this.Item3, this.Item4, this.Item5, this.Item6, this.Item7, this.Item8, this.Item9, this.Item10, this.Item11, this.Item12, this.Item13, this.Item14, this.Item15 }.ToString(); /// /// Disposes the struct by testing each constituent component for disposability. /// [EditorBrowsable(EditorBrowsableState.Never)] - public void Dispose() + public readonly void Dispose() { (this.Item1 as IDisposable)?.Dispose(); (this.Item2 as IDisposable)?.Dispose(); @@ -1626,13 +1626,13 @@ public struct StructTuple [EditorBrowsable(EditorBrowsableState.Never)] - public override string ToString() => new { this.Item1, this.Item2, this.Item3, this.Item4, this.Item5, this.Item6, this.Item7, this.Item8, this.Item9, this.Item10, this.Item11, this.Item12, this.Item13, this.Item14, this.Item15, this.Item16 }.ToString(); + public override readonly string ToString() => new { this.Item1, this.Item2, this.Item3, this.Item4, this.Item5, this.Item6, this.Item7, this.Item8, this.Item9, this.Item10, this.Item11, this.Item12, this.Item13, this.Item14, this.Item15, this.Item16 }.ToString(); /// /// Disposes the struct by testing each constituent component for disposability. /// [EditorBrowsable(EditorBrowsableState.Never)] - public void Dispose() + public readonly void Dispose() { (this.Item1 as IDisposable)?.Dispose(); (this.Item2 as IDisposable)?.Dispose(); diff --git a/Sources/Core/Microsoft.StreamProcessing/Utilities/TransformerExtensions.cs b/Sources/Core/Microsoft.StreamProcessing/Utilities/TransformerExtensions.cs index ff88f7684..58591935e 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Utilities/TransformerExtensions.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Utilities/TransformerExtensions.cs @@ -17,14 +17,14 @@ internal static class Extensions { public static string CleanUpIdentifierName(this string s) { - Contract.Requires(s != null); + ArgumentNullException.ThrowIfNull(s); return s.Replace('`', '_').Replace('.', '_').Replace('<', '_').Replace('>', '_').Replace(',', '_').Replace(' ', '_').Replace('`', '_').Replace('[', '_').Replace(']', '_').Replace('=', '_').Replace('+', '_'); } public static string AddNumberOfNecessaryGenericArguments(this string s, params Type[] types) { - Contract.Requires(types != null); + ArgumentNullException.ThrowIfNull(types); var i = types.Count(t => t.IsAnonymousType()); return i > 0 ? s + "`" + i.ToString(CultureInfo.InvariantCulture) @@ -48,7 +48,7 @@ public static bool CanUsePayloadEquality(this IEqualityComparerExpression // If T is a struct, then even if the user defined equality function calls a method on the struct, // it can still be used because the active events will have a field of type T. - if (typeofT.GetTypeInfo().IsValueType) return true; + if (typeofT.IsValueType) return true; // If T is a type for which the columnar representation is just a pseudo-field, e.g., string, // then the payload is not really represented as a set of its fields, but is an instance of T diff --git a/Sources/Core/Microsoft.StreamProcessing/Utilities/TypeExtensions.cs b/Sources/Core/Microsoft.StreamProcessing/Utilities/TypeExtensions.cs index ff24319a2..2be0be936 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Utilities/TypeExtensions.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Utilities/TypeExtensions.cs @@ -32,20 +32,20 @@ static TypeExtensions() foreach (var pair in OperatorNameLookup) { KnownSupportedOperators.TryAdd( - pair.Key, new HashSet { typeof(long), typeof(ulong), typeof(int), typeof(uint), typeof(short), typeof(ushort), typeof(double), typeof(float), typeof(decimal), typeof(byte), typeof(sbyte) }); + pair.Key, [typeof(long), typeof(ulong), typeof(int), typeof(uint), typeof(short), typeof(ushort), typeof(double), typeof(float), typeof(decimal), typeof(byte), typeof(sbyte)]); } } public static PropertyInfo GetPropertyByName(this Type type, string name) - => type.GetTypeInfo().GetProperty(name, BindingFlags.Public | BindingFlags.Instance); + => type.GetProperty(name, BindingFlags.Public | BindingFlags.Instance); public static MethodInfo GetMethodByName(this Type type, string shortName, params Type[] arguments) { - var result = type.GetTypeInfo() + var result = type .GetMethods(BindingFlags.Instance | BindingFlags.Public) .SingleOrDefault(m => m.Name == shortName && m.GetParameters().Select(p => p.ParameterType).SequenceEqual(arguments)); - return result ?? type.GetTypeInfo() + return result ?? type .GetMethods(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public) .FirstOrDefault(m => (m.Name.EndsWith(shortName, StringComparison.Ordinal) || m.Name.EndsWith("." + shortName, StringComparison.Ordinal)) @@ -53,44 +53,41 @@ public static MethodInfo GetMethodByName(this Type type, string shortName, param } public static bool CanContainNull(this Type type) - => !type.GetTypeInfo().IsValueType || Nullable.GetUnderlyingType(type) != null; + => !type.IsValueType || Nullable.GetUnderlyingType(type) != null; public static bool CanBeKnownTypeOf(this Type type, Type baseType) { - var typeInfo = type.GetTypeInfo(); - var baseTypeInfo = baseType.GetTypeInfo(); - - return !typeInfo.IsAbstract + return !type.IsAbstract && !type.IsUnsupported() - && (typeInfo.IsSubclassOf(baseType) + && (type.IsSubclassOf(baseType) || type == baseType - || (baseTypeInfo.IsInterface && baseTypeInfo.IsAssignableFrom(type)) - || (baseTypeInfo.IsGenericType && baseTypeInfo.IsInterface && baseType.GenericIsAssignable(type) - && typeInfo.GetGenericArguments() - .Zip(baseTypeInfo.GetGenericArguments(), (type1, type2) => new Tuple(type1, type2)) + || (baseType.IsInterface && baseType.IsAssignableFrom(type)) + || (baseType.IsGenericType && baseType.IsInterface && baseType.GenericIsAssignable(type) + && type.GetGenericArguments() + .Zip(baseType.GetGenericArguments(), (type1, type2) => new Tuple(type1, type2)) .ToList() .TrueForAll(tuple => CanBeKnownTypeOf(tuple.Item1, tuple.Item2)))); } private static bool GenericIsAssignable(this Type type, Type instanceType) { - if (!type.GetTypeInfo().IsGenericType || !instanceType.GetTypeInfo().IsGenericType) return false; + if (!type.IsGenericType || !instanceType.IsGenericType) return false; - var args = type.GetTypeInfo().GetGenericArguments(); + var args = type.GetGenericArguments(); var typeDefinition = instanceType.GetGenericTypeDefinition(); - var args2 = typeDefinition.GetTypeInfo().GetGenericArguments(); - return args.Any() && args.Length == args2.Length && type.GetTypeInfo().IsAssignableFrom(typeDefinition.MakeGenericType(args)); + var args2 = typeDefinition.GetGenericArguments(); + return args.Length != 0 && args.Length == args2.Length && type.IsAssignableFrom(typeDefinition.MakeGenericType(args)); } public static IEnumerable GetAllKnownTypes(this Type t) { - var types = t.GetTypeInfo().GetCustomAttributes(true) + var types = t.GetCustomAttributes(true) .OfType() .SelectMany(a => a.Type != null ? new Type[] { a.Type } - : (IEnumerable)t.GetTypeInfo().GetMethod(a.MethodName, BindingFlags.NonPublic | BindingFlags.Static).Invoke(null, Array.Empty())); - if (t.GetTypeInfo().BaseType != null) types = types.Concat(GetAllKnownTypes(t.GetTypeInfo().BaseType)); + : (IEnumerable)t.GetMethod(a.MethodName, BindingFlags.NonPublic | BindingFlags.Static).Invoke(null, [])); + if (t.BaseType != null) types = types.Concat(GetAllKnownTypes(t.BaseType)); return types; } @@ -98,17 +95,24 @@ public static IEnumerable GetAllKnownTypes(this Type t) public static int ReadAllRequiredBytes(this Stream stream, byte[] buffer, int offset, int count) { - int toRead = count; - int currentOffset = offset; - int currentRead; - do + return ReadAllRequiredBytes(stream, buffer.AsSpan(offset, count)); + } + + /// + /// Reads up to .Length bytes into ; returns total bytes read. + /// + public static int ReadAllRequiredBytes(this Stream stream, Span buffer) + { + int totalRead = 0; + while (totalRead < buffer.Length) { - currentRead = stream.Read(buffer, currentOffset, toRead); - currentOffset += currentRead; - toRead -= currentRead; + int n = stream.Read(buffer[totalRead..]); + if (n == 0) + break; + totalRead += n; } - while (toRead > 0 && currentRead != 0); - return currentOffset - offset; + + return totalRead; } public static Tuple, bool> GetAnnotatedFields(this Type t) @@ -119,9 +123,9 @@ public static Tuple, bool> GetAnnotatedFields(this Type : Tuple.Create(new MyFieldInfo(t).Yield(), true); } - private static readonly ConcurrentDictionary OperatorNameLookup = new ConcurrentDictionary(); + private static readonly ConcurrentDictionary OperatorNameLookup = new(); - private static readonly ConcurrentDictionary> KnownSupportedOperators = new ConcurrentDictionary>(); + private static readonly ConcurrentDictionary> KnownSupportedOperators = new(); public static bool SupportsOperator(this Type t, string @operator) { @@ -130,8 +134,8 @@ public static bool SupportsOperator(this Type t, string @operator) if (KnownSupportedOperators[@operator].Contains(t)) return true; // Get all operator methods that have the correct name for the given operator and have the given type as the first parameter and return type. - var secondParameter = @operator.EndsWith("d", StringComparison.Ordinal) ? typeof(double) : t; - var operatorMethods = t.GetTypeInfo().GetMethods(BindingFlags.Static | BindingFlags.Public) + var secondParameter = @operator.EndsWith('d') ? typeof(double) : t; + var operatorMethods = t.GetMethods(BindingFlags.Static | BindingFlags.Public) .Where(o => o.CallingConvention == CallingConventions.Standard && o.IsSpecialName && o.Name == methodName @@ -153,13 +157,13 @@ public static bool SupportsOperator(this Type t, string @operator) public static Type InstantiateAsNecessary(this Type type, params Type[] types) { - Contract.Requires(type != null); - Contract.Requires(types != null); + ArgumentNullException.ThrowIfNull(type); + ArgumentNullException.ThrowIfNull(types); if (type == null) throw new NullReferenceException(nameof(type)); var genericArgs = types .Distinct() - .Where(g => IsAnonymousType(g)); + .Where(IsAnonymousType); return !genericArgs.Any() ? type : type.MakeGenericType(genericArgs.ToArray()); @@ -167,13 +171,13 @@ public static Type InstantiateAsNecessary(this Type type, params Type[] types) public static bool IsAnonymousTypeName(this Type type) { - Contract.Requires(type != null); + ArgumentNullException.ThrowIfNull(type); - return type.GetTypeInfo().IsClass - && type.GetTypeInfo().IsDefined(typeof(CompilerGeneratedAttribute)) + return type.IsClass + && type.IsDefined(typeof(CompilerGeneratedAttribute)) && !type.IsNested && type.Name.StartsWith("<>", StringComparison.Ordinal) - && type.Name.Contains("__Anonymous"); + && type.Name.Contains("__Anonymous", StringComparison.Ordinal); } /// @@ -184,11 +188,11 @@ public static bool IsAnonymousTypeName(this Type type) [Pure] public static bool IsAnonymousType(this Type type) { - Contract.Requires(type != null); + ArgumentNullException.ThrowIfNull(type); return type.IsAnonymousTypeName() - || type.GetTypeInfo().Assembly.IsDynamic - || (type.GetTypeInfo().IsGenericType && type.GenericTypeArguments.Any(t => t.IsAnonymousType())); + || type.Assembly.IsDynamic + || (type.IsGenericType && type.GenericTypeArguments.Any(IsAnonymousType)); } public static bool HasSupportedParameterizedConstructor(this Type type) @@ -201,11 +205,11 @@ public static bool HasSupportedParameterizedConstructor(this Type type) if (type.IsAnonymousTypeName()) return true; // Case 2: Key-Value pairs - if (type.GetTypeInfo().IsGenericType + if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(KeyValuePair<,>)) return true; // Case 3: Tuples - if (type.GetTypeInfo().IsGenericType) + if (type.IsGenericType) { var baseType = type.GetGenericTypeDefinition(); if ( @@ -219,6 +223,14 @@ public static bool HasSupportedParameterizedConstructor(this Type type) baseType == typeof(Tuple<,,,,,,,>)) return true; } + // Case 4: StreamEvent and PartitionedStreamEvent — readonly structs deserialized via constructor + if (type.IsGenericType) + { + var baseType = type.GetGenericTypeDefinition(); + if (baseType == typeof(StreamEvent<>) || + baseType == typeof(PartitionedStreamEvent<,>)) return true; + } + return false; } @@ -229,7 +241,7 @@ public static bool HasSupportedParameterizedConstructor(this Type type) /// Collection of fields. public static IEnumerable GetAllFields(this Type t) { - if (t == null) return Enumerable.Empty(); + if (t == null) return []; const BindingFlags Flags = BindingFlags.Public | @@ -237,10 +249,10 @@ public static IEnumerable GetAllFields(this Type t) BindingFlags.Instance | BindingFlags.DeclaredOnly; var returnValue = t - .GetTypeInfo() + .GetFields(Flags) .Where(f => !f.IsDefined(typeof(CompilerGeneratedAttribute), false)) - .Concat(GetAllFields(t.GetTypeInfo().BaseType)); + .Concat(GetAllFields(t.BaseType)); if (!t.HasSupportedParameterizedConstructor()) returnValue = returnValue.OrderBy(o => o.Name); return returnValue; } @@ -252,7 +264,7 @@ public static IEnumerable GetAllFields(this Type t) /// Collection of properties. public static IEnumerable GetAllProperties(this Type t) { - if (t == null) return Enumerable.Empty(); + if (t == null) return []; const BindingFlags Flags = BindingFlags.Public | @@ -260,13 +272,13 @@ public static IEnumerable GetAllProperties(this Type t) BindingFlags.Instance | BindingFlags.DeclaredOnly; var returnValue = t - .GetTypeInfo() + .GetProperties(Flags) .Where(p => !p.IsDefined(typeof(CompilerGeneratedAttribute), false) && p.GetIndexParameters().Length == 0 && !p.IsSpecialName && p.CanRead && p.CanWrite) - .Concat(GetAllProperties(t.GetTypeInfo().BaseType)); + .Concat(GetAllProperties(t.BaseType)); if (!t.HasSupportedParameterizedConstructor()) returnValue = returnValue.OrderBy(o => o.Name); return returnValue; } @@ -274,7 +286,7 @@ public static IEnumerable GetAllProperties(this Type t) private static void GetAnonymousTypes(Type t, List partialList) { if (t.IsAnonymousTypeName()) partialList.Add(t); - else if (t.GetTypeInfo().IsGenericType) + else if (t.IsGenericType) { foreach (var genericArgument in t.GenericTypeArguments) { @@ -285,7 +297,7 @@ private static void GetAnonymousTypes(Type t, List partialList) public static List GetAnonymousTypes(this Type t) { - Contract.Requires(t != null); + ArgumentNullException.ThrowIfNull(t); var list = new List(); GetAnonymousTypes(t, list); @@ -306,13 +318,13 @@ public static List GetAnonymousTypes(this Type t) public static bool KeyTypeNeedsGeneratedMemoryPool(this Type keyType) { if (keyType == typeof(Empty)) return false; - if (keyType.GetTypeInfo().IsGenericType) + if (keyType.IsGenericType) { if (keyType.GetGenericTypeDefinition() != typeof(CompoundGroupKey<,>)) return true; else { - var outerKeyType = keyType.GetTypeInfo().GetField("outerGroup").FieldType; - var innerKeyType = keyType.GetTypeInfo().GetField("innerGroup").FieldType; + var outerKeyType = keyType.GetField("outerGroup").FieldType; + var innerKeyType = keyType.GetField("innerGroup").FieldType; return outerKeyType.KeyTypeNeedsGeneratedMemoryPool() || innerKeyType.KeyTypeNeedsGeneratedMemoryPool(); } } @@ -329,13 +341,13 @@ public static bool KeyTypeNeedsGeneratedMemoryPool(this Type keyType) /// private static bool NeedGeneratedMemoryPool(this Type type) { - Contract.Requires(type != null); + ArgumentNullException.ThrowIfNull(type); if (type.MemoryPoolHasGetMethodFor()) return false; if (type.HasSupportedParameterizedConstructor()) { - foreach (var p in type.GetTypeInfo().GetProperties(BindingFlags.Public | BindingFlags.Instance)) + foreach (var p in type.GetProperties(BindingFlags.Public | BindingFlags.Instance)) { var t = p.PropertyType; if (t != typeof(int) && t != typeof(long) && t != typeof(string)) @@ -344,7 +356,7 @@ private static bool NeedGeneratedMemoryPool(this Type type) } else { - foreach (var f in type.GetTypeInfo().GetFields(BindingFlags.Public | BindingFlags.Instance)) + foreach (var f in type.GetFields(BindingFlags.Public | BindingFlags.Instance)) { var t = f.FieldType; if (t != typeof(int) && t != typeof(long) && t != typeof(string)) @@ -361,19 +373,18 @@ private static bool NeedGeneratedMemoryPool(this Type type) /// public static bool CanRepresentAsColumnar(this Type type) { - Contract.Requires(type != null); + ArgumentNullException.ThrowIfNull(type); // If any public instance fields are anonymous types, then they // cannot be represented as columns. - var typeInfo = type.GetTypeInfo(); - var fields = typeInfo.GetFields(BindingFlags.Public | BindingFlags.Instance); + var fields = type.GetFields(BindingFlags.Public | BindingFlags.Instance); if (fields.Any(f => f.FieldType.IsAnonymousTypeName())) return false; // However, an anonymous type can be decomposed into its "fields" (NOTE: anonymous types // have public properties, not fields) as long as they themselves are not anonymous types. if (type.IsAnonymousTypeName()) { - var props = typeInfo.GetProperties(BindingFlags.Public | BindingFlags.Instance); + var props = type.GetProperties(BindingFlags.Public | BindingFlags.Instance); return props.All(p => !p.PropertyType.IsAnonymousTypeName()); } @@ -390,7 +401,7 @@ public static bool CanRepresentAsColumnar(this Type type) { var allFields = type .GetFields(BindingFlags.NonPublic | BindingFlags.Instance) - .Where(f => !(f.Name.StartsWith("<", StringComparison.Ordinal) && f.Name.EndsWith(">k__BackingField", StringComparison.Ordinal))) // ignore backing fields for autoprops + .Where(f => !(f.Name.StartsWith('<') && f.Name.EndsWith(">k__BackingField", StringComparison.Ordinal))) // ignore backing fields for autoprops ; if (allFields.Any()) return false; @@ -439,8 +450,8 @@ public static Type GetPartitionType(this Type type) private static string TurnTypeIntoCSharpSource(Type t, ref List introducedGenericTypeParameters) { - Contract.Requires(t != null); - Contract.Requires(introducedGenericTypeParameters != null); + ArgumentNullException.ThrowIfNull(t); + ArgumentNullException.ThrowIfNull(introducedGenericTypeParameters); var typeName = t.FullName.Replace('#', '_').Replace('+', '.'); if (t.IsAnonymousTypeName()) @@ -449,14 +460,14 @@ private static string TurnTypeIntoCSharpSource(Type t, ref List introduc introducedGenericTypeParameters.Add(newGenericTypeParameter); return newGenericTypeParameter; } - if (!t.GetTypeInfo().IsGenericType) // need to test after anonymous because deserialized anonymous types are *not* generic (but unserialized anonymous types *are* generic) + if (!t.IsGenericType) // need to test after anonymous because deserialized anonymous types are *not* generic (but unserialized anonymous types *are* generic) return typeName; - var isDynamic = t.GetTypeInfo().Assembly.IsDynamic; + var isDynamic = t.Assembly.IsDynamic; var sb = new StringBuilder(); if (!string.IsNullOrWhiteSpace(t.Namespace)) { sb.Append(t.Namespace); - sb.Append("."); + sb.Append('.'); } var genericArgs = new List(); foreach (var genericArgument in t.GenericTypeArguments) @@ -483,14 +494,14 @@ private static string TurnTypeIntoCSharpSource(Type t, ref List introduc var currentName = currentType.Name; var indexOfBackTick = currentType.Name.IndexOf('`'); - if (typeIndex > 0) sb.Append("."); - sb.Append(indexOfBackTick > 0 ? currentName.Substring(0, indexOfBackTick) : currentName); + if (typeIndex > 0) sb.Append('.'); + sb.Append(indexOfBackTick > 0 ? currentName[..indexOfBackTick] : currentName); if (indexOfBackTick > 0) { var j = indexOfBackTick + 1; while (j < currentName.Length && char.IsDigit(currentName[j])) j++; - var numberOfGenerics = int.Parse(currentName.Substring(indexOfBackTick + 1, j - (indexOfBackTick + 1))); - sb.Append("<"); + var numberOfGenerics = int.Parse(currentName[(indexOfBackTick + 1)..j]); + sb.Append('<'); if (!isDynamic) { for (int i = 0; i < numberOfGenerics; i++) @@ -501,7 +512,7 @@ private static string TurnTypeIntoCSharpSource(Type t, ref List introduc } } else indexIntoGenericArguments += numberOfGenerics; - sb.Append(">"); + sb.Append('>'); } } @@ -518,7 +529,7 @@ public static string GetCSharpSourceSyntax(this Type t) public static string GetCSharpSourceSyntax(this Type t, ref List introducedGenericTypeParameters) { - if (introducedGenericTypeParameters == null) introducedGenericTypeParameters = new List(); + if (introducedGenericTypeParameters == null) introducedGenericTypeParameters = []; string ret = TurnTypeIntoCSharpSource(t, ref introducedGenericTypeParameters); return ret; } @@ -532,7 +543,7 @@ public static bool CanBeFixed(this Type t) return b; } - public static bool IsCompoundGroupKey(this TypeInfo t, out Type outerType, out Type innerType) + public static bool IsCompoundGroupKey(this Type t, out Type outerType, out Type innerType) { if (t.IsGenericType && t.GenericTypeArguments.Length == 2 && t.GetGenericTypeDefinition() == typeof(CompoundGroupKey<,>)) { @@ -548,25 +559,35 @@ public static bool IsCompoundGroupKey(this TypeInfo t, out Type outerType, out T } } - public static bool ImplementsIEqualityComparerExpression(this TypeInfo t) - => t.GetInterfaces() - .Any(i => i.Namespace.Equals("Microsoft.StreamProcessing") && i.Name.Equals("IEqualityComparerExpression`1") && i.GetTypeInfo().GetGenericArguments().Length == 1 && i.GetTypeInfo().GetGenericArguments()[0] == t); - - public static bool ImplementsIEqualityComparer(this TypeInfo t) - => t.GetInterfaces() - .Any(i => i.Namespace.Equals("System.Collections.Generic") && i.Name.Equals("IEqualityComparer`1") && i.GetTypeInfo().GetGenericArguments().Length == 1 && i.GetTypeInfo().GetGenericArguments()[0] == t); - - public static bool ImplementsIComparer(this TypeInfo t) - => t.GetInterfaces() - .Any(i => i.Namespace.Equals("System.Collections.Generic") && i.Name.Equals("IComparer`1") && i.GetTypeInfo().GetGenericArguments().Length == 1 && i.GetTypeInfo().GetGenericArguments()[0] == t); - - public static bool ImplementsIEquatable(this TypeInfo t) - => t.GetInterfaces() - .Any(i => i.Namespace.Equals("System") && i.Name.Equals("IEquatable`1") && i.GetTypeInfo().GetGenericArguments().Length == 1 && i.GetTypeInfo().GetGenericArguments()[0] == t); - - public static bool ImplementsIComparable(this TypeInfo t) - => t.GetInterfaces() - .Any(i => i.Namespace.Equals("System") && i.Name.Equals("IComparable`1") && i.GetTypeInfo().GetGenericArguments().Length == 1 && i.GetTypeInfo().GetGenericArguments()[0] == t); + public static bool ImplementsIEqualityComparerExpression(this Type t) + => t.ContainsGenericParameters + ? t.GetInterfaces() + .Any(i => i.Namespace.Equals("Microsoft.StreamProcessing") && i.Name.Equals("IEqualityComparerExpression`1") && i.GetGenericArguments().Length == 1 && i.GetGenericArguments()[0] == t) + : typeof(IEqualityComparerExpression<>).MakeGenericType(t).IsAssignableFrom(t); + + public static bool ImplementsIEqualityComparer(this Type t) + => t.ContainsGenericParameters + ? t.GetInterfaces() + .Any(i => i.Namespace.Equals("System.Collections.Generic") && i.Name.Equals("IEqualityComparer`1") && i.GetGenericArguments().Length == 1 && i.GetGenericArguments()[0] == t) + : typeof(IEqualityComparer<>).MakeGenericType(t).IsAssignableFrom(t); + + public static bool ImplementsIComparer(this Type t) + => t.ContainsGenericParameters + ? t.GetInterfaces() + .Any(i => i.Namespace.Equals("System.Collections.Generic") && i.Name.Equals("IComparer`1") && i.GetGenericArguments().Length == 1 && i.GetGenericArguments()[0] == t) + : typeof(IComparer<>).MakeGenericType(t).IsAssignableFrom(t); + + public static bool ImplementsIEquatable(this Type t) + => t.ContainsGenericParameters + ? t.GetInterfaces() + .Any(i => i.Namespace.Equals("System") && i.Name.Equals("IEquatable`1") && i.GetGenericArguments().Length == 1 && i.GetGenericArguments()[0] == t) + : typeof(IEquatable<>).MakeGenericType(t).IsAssignableFrom(t); + + public static bool ImplementsIComparable(this Type t) + => t.ContainsGenericParameters + ? t.GetInterfaces() + .Any(i => i.Namespace.Equals("System") && i.Name.Equals("IComparable`1") && i.GetGenericArguments().Length == 1 && i.GetGenericArguments()[0] == t) + : typeof(IComparable<>).MakeGenericType(t).IsAssignableFrom(t); #region Borrowed from Roslyn @@ -602,13 +623,13 @@ public static bool IsManagedType(Type type) private static bool DependsOnDefinitelyManagedType(Type type, HashSet partialClosure) { - Contract.Requires(type != null); + ArgumentNullException.ThrowIfNull(type); // NOTE: unlike in StructDependsClosure, we don't have to check for expanding cycles, // because as soon as we see something with non-zero arity we kick out (generic => managed). if (partialClosure.Add(type)) { - foreach (var field in type.GetTypeInfo().GetFields(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance)) + foreach (var field in type.GetFields(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance)) { // Only instance fields (including field-like events) affect the outcome. if (field.IsStatic) continue; @@ -637,12 +658,12 @@ private static bool DependsOnDefinitelyManagedType(Type type, HashSet part private static bool? IsManagedTypeHelper(Type type) { // To match dev10, we treat enums as their underlying types. - if (type.GetTypeInfo().IsEnum) type = Enum.GetUnderlyingType(type); + if (type.IsEnum) type = Enum.GetUnderlyingType(type); - if (type.GetTypeInfo().IsEnum) return false; - if (type.GetTypeInfo().IsPrimitive) return false; - if (type.GetTypeInfo().IsGenericType) return true; - if (type.GetTypeInfo().IsValueType) return null; + if (type.IsEnum) return false; + if (type.IsPrimitive) return false; + if (type.IsGenericType) return true; + if (type.IsValueType) return null; return true; } @@ -654,7 +675,7 @@ private static bool DependsOnDefinitelyManagedType(Type type, HashSet part /// The type. /// True if type t has a public parameter-less constructor, false otherwise. private static bool HasParameterlessConstructor(this Type type) - => type.GetTypeInfo().GetConstructors(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic).Any(c => c.GetParameters().Length == 0); + => type.GetConstructors(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic).Any(c => c.GetParameters().Length == 0); /// /// Determines whether the type is definitely unsupported for schema generation. @@ -667,22 +688,22 @@ public static bool IsUnsupported(this Type type) => type == typeof(IntPtr) || type == typeof(UIntPtr) || type == typeof(object) - || type.GetTypeInfo().ContainsGenericParameters + || type.ContainsGenericParameters || (!type.IsArray - && !type.GetTypeInfo().IsValueType + && !type.IsValueType && !type.HasSupportedParameterizedConstructor() && !type.HasParameterlessConstructor() && type != typeof(string) && type != typeof(Uri) - && !type.GetTypeInfo().IsAbstract - && !type.GetTypeInfo().IsInterface - && !(type.GetTypeInfo().IsGenericType && SupportedInterfaces.Contains(type.GetGenericTypeDefinition()))); + && !type.IsAbstract + && !type.IsInterface + && !(type.IsGenericType && SupportedInterfaces.Contains(type.GetGenericTypeDefinition()))); - private static readonly HashSet SupportedInterfaces = new HashSet - { + private static readonly HashSet SupportedInterfaces = + [ typeof(IList<>), typeof(IDictionary<,>) - }; + ]; /// /// Validates that a type can be serialized. @@ -693,7 +714,7 @@ public static bool IsUnsupported(this Type type) /// public static Type ValidateTypeForSerializer(this Type type) { - if (type == null) throw new ArgumentNullException(nameof(type)); + ArgumentNullException.ThrowIfNull(type); Contract.EndContractBlock(); if (type.IsUnsupported()) @@ -711,21 +732,24 @@ public static Type ValidateTypeForSerializer(this Type type) /// public static IEnumerable ResolveMembers(this Type type) { - if (type == null) throw new ArgumentNullException(nameof(type)); + ArgumentNullException.ThrowIfNull(type); Contract.EndContractBlock(); - if (type.GetTypeInfo().IsPrimitive) return Enumerable.Empty(); - else if (type.HasSupportedParameterizedConstructor()) + if (type.IsPrimitive) return []; + else if (type.IsDefined(typeof(DataContractAttribute))) { - return type.GetTypeInfo().GetProperties().Where(p => p.GetIndexParameters().Length == 0).Select(o => new MyFieldInfo(o)); - } - else if (type.GetTypeInfo().IsDefined(typeof(DataContractAttribute))) - { - // In DataContract context, return all fields and properties marked with DataMember + // In DataContract context, return all fields and properties marked with DataMember. + // This takes priority over HasSupportedParameterizedConstructor so that types like + // StreamEvent (readonly struct with [DataContract]) use their [DataMember] fields + // as constructor arguments rather than their unrelated public getter properties. var fields = type.GetAllFields().Where(m => m.IsDefined(typeof(DataMemberAttribute))).Select(o => new MyFieldInfo(o)); var properties = type.GetAllProperties().Where(m => m.IsDefined(typeof(DataMemberAttribute))).Select(o => new MyFieldInfo(o)); return fields.Concat(properties); } + else if (type.HasSupportedParameterizedConstructor()) + { + return type.GetProperties().Where(p => p.GetIndexParameters().Length == 0).Select(o => new MyFieldInfo(o)); + } else { // Otherwise, return all fields, as well as all autoproperties diff --git a/Sources/Core/Microsoft.StreamProcessing/Utilities/Utility.cs b/Sources/Core/Microsoft.StreamProcessing/Utilities/Utility.cs index 7dc5c98d5..38f805055 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Utilities/Utility.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Utilities/Utility.cs @@ -4,6 +4,7 @@ // ********************************************************************* using System; using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using System.Diagnostics.Contracts; using System.Linq; using System.Linq.Expressions; @@ -77,7 +78,7 @@ public static bool TryGetFirst(this SortedSet source, out TKey key) internal static IDisposable CreateDisposable(params IDisposable[] disposables) => new CompoundDisposable(disposables); - internal static Dictionary Clone(this Dictionary source) => new Dictionary(source); + internal static Dictionary Clone(this Dictionary source) => new(source); /// /// With a dictionary of lists, add a single element to a particular list. Create a new list if none exists at that key location. @@ -91,7 +92,7 @@ public static void Add(this IDictionary> dict, { if (!dict.TryGetValue(key, out var list)) { - list = new List(); + list = []; dict.Add(key, list); } list.Add(value); @@ -133,28 +134,15 @@ internal static Expression> CreateCompoundComparer(Expres return Expression.Lambda>(result, newParam1, newParam2); } - private sealed class CompoundDisposable : IDisposable + private sealed class CompoundDisposable(IDisposable[] disposables) : IDisposable { - private readonly IDisposable[] disposables; - - public CompoundDisposable(IDisposable[] disposables) - { - Contract.Requires(disposables != null); - - this.disposables = disposables; - } - - #region IDisposable Members - public void Dispose() { - foreach (IDisposable disposable in this.disposables.Where(d => d != null)) + foreach (IDisposable disposable in disposables) { - disposable.Dispose(); + disposable?.Dispose(); } } - - #endregion } private sealed class NullDisposable : IDisposable @@ -184,42 +172,4 @@ internal static int GetSizeOf(this Type type) throw new InvalidOperationException("Only primitive types supported, unknown structural type " + type.FullName); } } - - internal static class Invariant - { - public static T IsNotNull(this T arg, string argName) where T : class - { - if (arg == null) throw new ArgumentNullException(argName); - return arg; - } - - public static int IsPositive(this int arg, string argName) - { - if (arg <= 0) throw new ArgumentException("Value must be positive.", argName); - return arg; - } - - public static long IsPositive(this long arg, string argName) - { - if (arg <= 0L) throw new ArgumentException("Value must be positive.", argName); - return arg; - } - - public static int IsNonNegative(this int arg, string argName) - { - if (arg < 0) throw new ArgumentException("Value must be positive or 0.", argName); - return arg; - } - - public static long IsNonNegative(this long arg, string argName) - { - if (arg < 0L) throw new ArgumentException("Value must be positive or 0.", argName); - return arg; - } - - public static void IsTrue(bool assertion, string message) - { - if (!assertion) throw new ArgumentException(message); - } - } } \ No newline at end of file diff --git a/Sources/Core/Microsoft.StreamProcessing/Windows/FilteredWindowTemplate.cs b/Sources/Core/Microsoft.StreamProcessing/Windows/FilteredWindowTemplate.cs index 53bd84b9c..d506bbf71 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Windows/FilteredWindowTemplate.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Windows/FilteredWindowTemplate.cs @@ -27,7 +27,7 @@ internal FilteredWindow(Expression> filter, StreamProperties /// public new IAggregate, double?> Average(Expression> selector) { - Invariant.IsNotNull(selector, "selector"); + ArgumentNullException.ThrowIfNull(selector); var aggregate = new AverageFilterableSByteAggregate(); return aggregate.Wrap(selector).ApplyFilter(this.Filter); } @@ -38,7 +38,7 @@ internal FilteredWindow(Expression> filter, StreamProperties /// public new IAggregate, double?> Average(Expression> selector) { - Invariant.IsNotNull(selector, "selector"); + ArgumentNullException.ThrowIfNull(selector); var aggregate = new AverageFilterableShortAggregate(); return aggregate.Wrap(selector).ApplyFilter(this.Filter); } @@ -49,7 +49,7 @@ internal FilteredWindow(Expression> filter, StreamProperties /// public new IAggregate, double?> Average(Expression> selector) { - Invariant.IsNotNull(selector, "selector"); + ArgumentNullException.ThrowIfNull(selector); var aggregate = new AverageFilterableIntAggregate(); return aggregate.Wrap(selector).ApplyFilter(this.Filter); } @@ -60,7 +60,7 @@ internal FilteredWindow(Expression> filter, StreamProperties /// public new IAggregate, double?> Average(Expression> selector) { - Invariant.IsNotNull(selector, "selector"); + ArgumentNullException.ThrowIfNull(selector); var aggregate = new AverageFilterableLongAggregate(); return aggregate.Wrap(selector).ApplyFilter(this.Filter); } @@ -71,7 +71,7 @@ internal FilteredWindow(Expression> filter, StreamProperties /// public new IAggregate, double?> Average(Expression> selector) { - Invariant.IsNotNull(selector, "selector"); + ArgumentNullException.ThrowIfNull(selector); var aggregate = new AverageFilterableByteAggregate(); return aggregate.Wrap(selector).ApplyFilter(this.Filter); } @@ -82,7 +82,7 @@ internal FilteredWindow(Expression> filter, StreamProperties /// public new IAggregate, double?> Average(Expression> selector) { - Invariant.IsNotNull(selector, "selector"); + ArgumentNullException.ThrowIfNull(selector); var aggregate = new AverageFilterableUShortAggregate(); return aggregate.Wrap(selector).ApplyFilter(this.Filter); } @@ -93,7 +93,7 @@ internal FilteredWindow(Expression> filter, StreamProperties /// public new IAggregate, double?> Average(Expression> selector) { - Invariant.IsNotNull(selector, "selector"); + ArgumentNullException.ThrowIfNull(selector); var aggregate = new AverageFilterableUIntAggregate(); return aggregate.Wrap(selector).ApplyFilter(this.Filter); } @@ -104,7 +104,7 @@ internal FilteredWindow(Expression> filter, StreamProperties /// public new IAggregate, double?> Average(Expression> selector) { - Invariant.IsNotNull(selector, "selector"); + ArgumentNullException.ThrowIfNull(selector); var aggregate = new AverageFilterableULongAggregate(); return aggregate.Wrap(selector).ApplyFilter(this.Filter); } @@ -115,7 +115,7 @@ internal FilteredWindow(Expression> filter, StreamProperties /// public new IAggregate, float?> Average(Expression> selector) { - Invariant.IsNotNull(selector, "selector"); + ArgumentNullException.ThrowIfNull(selector); var aggregate = new AverageFilterableFloatAggregate(); return aggregate.Wrap(selector).ApplyFilter(this.Filter); } @@ -126,7 +126,7 @@ internal FilteredWindow(Expression> filter, StreamProperties /// public new IAggregate, double?> Average(Expression> selector) { - Invariant.IsNotNull(selector, "selector"); + ArgumentNullException.ThrowIfNull(selector); var aggregate = new AverageFilterableDoubleAggregate(); return aggregate.Wrap(selector).ApplyFilter(this.Filter); } @@ -137,7 +137,7 @@ internal FilteredWindow(Expression> filter, StreamProperties /// public new IAggregate, decimal?> Average(Expression> selector) { - Invariant.IsNotNull(selector, "selector"); + ArgumentNullException.ThrowIfNull(selector); var aggregate = new AverageFilterableDecimalAggregate(); return aggregate.Wrap(selector).ApplyFilter(this.Filter); } @@ -148,7 +148,7 @@ internal FilteredWindow(Expression> filter, StreamProperties /// public new IAggregate, double?> Average(Expression> selector) { - Invariant.IsNotNull(selector, "selector"); + ArgumentNullException.ThrowIfNull(selector); var aggregate = new AverageFilterableBigIntegerAggregate(); return aggregate.Wrap(selector).ApplyFilter(this.Filter); } @@ -159,7 +159,7 @@ internal FilteredWindow(Expression> filter, StreamProperties /// public new IAggregate, Complex?> Average(Expression> selector) { - Invariant.IsNotNull(selector, "selector"); + ArgumentNullException.ThrowIfNull(selector); var aggregate = new AverageFilterableComplexAggregate(); return aggregate.Wrap(selector).ApplyFilter(this.Filter); } @@ -170,7 +170,7 @@ internal FilteredWindow(Expression> filter, StreamProperties /// public new IAggregate, double?> AverageSquares(Expression> selector) { - Invariant.IsNotNull(selector, "selector"); + ArgumentNullException.ThrowIfNull(selector); var aggregate = new AverageSquareFilterableSByteAggregate(); return aggregate.Wrap(selector).ApplyFilter(this.Filter); } @@ -181,7 +181,7 @@ internal FilteredWindow(Expression> filter, StreamProperties /// public new IAggregate, double?> AverageSquares(Expression> selector) { - Invariant.IsNotNull(selector, "selector"); + ArgumentNullException.ThrowIfNull(selector); var aggregate = new AverageSquareFilterableShortAggregate(); return aggregate.Wrap(selector).ApplyFilter(this.Filter); } @@ -192,7 +192,7 @@ internal FilteredWindow(Expression> filter, StreamProperties /// public new IAggregate, double?> AverageSquares(Expression> selector) { - Invariant.IsNotNull(selector, "selector"); + ArgumentNullException.ThrowIfNull(selector); var aggregate = new AverageSquareFilterableIntAggregate(); return aggregate.Wrap(selector).ApplyFilter(this.Filter); } @@ -203,7 +203,7 @@ internal FilteredWindow(Expression> filter, StreamProperties /// public new IAggregate, double?> AverageSquares(Expression> selector) { - Invariant.IsNotNull(selector, "selector"); + ArgumentNullException.ThrowIfNull(selector); var aggregate = new AverageSquareFilterableLongAggregate(); return aggregate.Wrap(selector).ApplyFilter(this.Filter); } @@ -214,7 +214,7 @@ internal FilteredWindow(Expression> filter, StreamProperties /// public new IAggregate, double?> AverageSquares(Expression> selector) { - Invariant.IsNotNull(selector, "selector"); + ArgumentNullException.ThrowIfNull(selector); var aggregate = new AverageSquareFilterableByteAggregate(); return aggregate.Wrap(selector).ApplyFilter(this.Filter); } @@ -225,7 +225,7 @@ internal FilteredWindow(Expression> filter, StreamProperties /// public new IAggregate, double?> AverageSquares(Expression> selector) { - Invariant.IsNotNull(selector, "selector"); + ArgumentNullException.ThrowIfNull(selector); var aggregate = new AverageSquareFilterableUShortAggregate(); return aggregate.Wrap(selector).ApplyFilter(this.Filter); } @@ -236,7 +236,7 @@ internal FilteredWindow(Expression> filter, StreamProperties /// public new IAggregate, double?> AverageSquares(Expression> selector) { - Invariant.IsNotNull(selector, "selector"); + ArgumentNullException.ThrowIfNull(selector); var aggregate = new AverageSquareFilterableUIntAggregate(); return aggregate.Wrap(selector).ApplyFilter(this.Filter); } @@ -247,7 +247,7 @@ internal FilteredWindow(Expression> filter, StreamProperties /// public new IAggregate, double?> AverageSquares(Expression> selector) { - Invariant.IsNotNull(selector, "selector"); + ArgumentNullException.ThrowIfNull(selector); var aggregate = new AverageSquareFilterableULongAggregate(); return aggregate.Wrap(selector).ApplyFilter(this.Filter); } @@ -258,7 +258,7 @@ internal FilteredWindow(Expression> filter, StreamProperties /// public new IAggregate, float?> AverageSquares(Expression> selector) { - Invariant.IsNotNull(selector, "selector"); + ArgumentNullException.ThrowIfNull(selector); var aggregate = new AverageSquareFilterableFloatAggregate(); return aggregate.Wrap(selector).ApplyFilter(this.Filter); } @@ -269,7 +269,7 @@ internal FilteredWindow(Expression> filter, StreamProperties /// public new IAggregate, double?> AverageSquares(Expression> selector) { - Invariant.IsNotNull(selector, "selector"); + ArgumentNullException.ThrowIfNull(selector); var aggregate = new AverageSquareFilterableDoubleAggregate(); return aggregate.Wrap(selector).ApplyFilter(this.Filter); } @@ -280,7 +280,7 @@ internal FilteredWindow(Expression> filter, StreamProperties /// public new IAggregate, decimal?> AverageSquares(Expression> selector) { - Invariant.IsNotNull(selector, "selector"); + ArgumentNullException.ThrowIfNull(selector); var aggregate = new AverageSquareFilterableDecimalAggregate(); return aggregate.Wrap(selector).ApplyFilter(this.Filter); } @@ -291,7 +291,7 @@ internal FilteredWindow(Expression> filter, StreamProperties /// public new IAggregate, double?> AverageSquares(Expression> selector) { - Invariant.IsNotNull(selector, "selector"); + ArgumentNullException.ThrowIfNull(selector); var aggregate = new AverageSquareFilterableBigIntegerAggregate(); return aggregate.Wrap(selector).ApplyFilter(this.Filter); } @@ -302,7 +302,7 @@ internal FilteredWindow(Expression> filter, StreamProperties /// public new IAggregate, Complex?> AverageSquares(Expression> selector) { - Invariant.IsNotNull(selector, "selector"); + ArgumentNullException.ThrowIfNull(selector); var aggregate = new AverageSquareFilterableComplexAggregate(); return aggregate.Wrap(selector).ApplyFilter(this.Filter); } diff --git a/Sources/Core/Microsoft.StreamProcessing/Windows/FilteredWindowTemplate.tt b/Sources/Core/Microsoft.StreamProcessing/Windows/FilteredWindowTemplate.tt index 7dbd6b1e6..71aae58a9 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Windows/FilteredWindowTemplate.tt +++ b/Sources/Core/Microsoft.StreamProcessing/Windows/FilteredWindowTemplate.tt @@ -38,7 +38,7 @@ namespace Microsoft.StreamProcessing /// public new IAggregate>, <#= returnTypeName#>?> Average(Expression>> selector) { - Invariant.IsNotNull(selector, "selector"); + ArgumentNullException.ThrowIfNull(selector); var aggregate = new AverageFilterable<#= typeFriendlyName #>Aggregate(); return aggregate.Wrap(selector).ApplyFilter(this.Filter); } @@ -60,7 +60,7 @@ namespace Microsoft.StreamProcessing /// public new IAggregate>, <#= returnTypeName#>?> AverageSquares(Expression>> selector) { - Invariant.IsNotNull(selector, "selector"); + ArgumentNullException.ThrowIfNull(selector); var aggregate = new AverageSquareFilterable<#= typeFriendlyName #>Aggregate(); return aggregate.Wrap(selector).ApplyFilter(this.Filter); } diff --git a/Sources/Core/Microsoft.StreamProcessing/Windows/Window.cs b/Sources/Core/Microsoft.StreamProcessing/Windows/Window.cs index 198521763..8a77981f4 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Windows/Window.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Windows/Window.cs @@ -34,7 +34,7 @@ internal Window(StreamProperties properties) /// protected Window(Expression> filter, StreamProperties properties) { - Invariant.IsNotNull(filter, nameof(filter)); + ArgumentNullException.ThrowIfNull(filter); this.Filter = filter; this.Properties = properties; } @@ -44,7 +44,7 @@ protected Window(Expression> filter, StreamProperties public FilteredWindow Where(Expression> predicate) { - Invariant.IsNotNull(predicate, nameof(predicate)); + ArgumentNullException.ThrowIfNull(predicate); if (this.Filter == null) return new FilteredWindow(predicate, this.Properties); Expression> andedExpressionTemplate = input => CallInliner.Call(this.Filter, input) && CallInliner.Call(predicate, input); @@ -75,7 +75,7 @@ public IAggregate, TSource> SingleOrDefault() /// public IAggregate CountNotNull(Expression> selector) { - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(selector); var aggregate = new CountAggregate(); return aggregate.SkipNulls().Wrap(selector).ApplyFilter(this.Filter); } @@ -85,7 +85,7 @@ public IAggregate CountNotNull(Expression public IAggregate, TValue> Min(Expression> selector) { - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(selector); var aggregate = this.Properties.IsTumbling ? new TumblingMinAggregate() @@ -102,8 +102,8 @@ public IAggregate, TValue> Min(Expression, TValue> Min( Expression> selector, IComparerExpression comparer) { - Invariant.IsNotNull(selector, nameof(selector)); - Invariant.IsNotNull(comparer, nameof(comparer)); + ArgumentNullException.ThrowIfNull(selector); + ArgumentNullException.ThrowIfNull(comparer); var aggregate = this.Properties.IsTumbling ? new TumblingMinAggregate(comparer) @@ -118,14 +118,14 @@ public IAggregate, TValue> Min( /// Computes a time-sensitive minimum aggregate using snapshot semantics with the provided ordering comparer. /// public IAggregate, TValue> Min(Expression> selector, Expression> comparer) - => Min(selector, new ComparerExpression(comparer)); + => this.Min(selector, new ComparerExpression(comparer)); /// /// Computes a time-sensitive maximum aggregate using snapshot semantics. /// public IAggregate, TValue> Max(Expression> selector) { - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(selector); var aggregate = this.Properties.IsTumbling ? new TumblingMaxAggregate() @@ -141,8 +141,8 @@ public IAggregate, TValue> Max(Expression public IAggregate, TValue> Max(Expression> selector, IComparerExpression comparer) { - Invariant.IsNotNull(selector, nameof(selector)); - Invariant.IsNotNull(comparer, nameof(comparer)); + ArgumentNullException.ThrowIfNull(selector); + ArgumentNullException.ThrowIfNull(comparer); var aggregate = this.Properties.IsTumbling ? new TumblingMaxAggregate(comparer) @@ -157,15 +157,15 @@ public IAggregate, TValue> Max(Expression public IAggregate, TValue> Max(Expression> selector, Expression> comparer) - => Max(selector, new ComparerExpression(comparer)); + => this.Max(selector, new ComparerExpression(comparer)); /// /// Computes a time-sensitive top-k aggregate using snapshot semantics based on a key selector. /// public IAggregate, List>> TopK(Expression> orderer, int k) { - Invariant.IsNotNull(orderer, nameof(orderer)); - Invariant.IsPositive(k, nameof(k)); + ArgumentNullException.ThrowIfNull(orderer); + ArgumentOutOfRangeException.ThrowIfNegativeOrZero(k); var orderComparer = ComparerExpression.Default.TransformInput(orderer); var aggregate = new TopKAggregate(k, orderComparer, this.Properties.QueryContainer); return aggregate.SkipNulls().ApplyFilter(this.Filter); @@ -176,9 +176,9 @@ public IAggregate, List>> /// public IAggregate, List>> TopK(Expression> orderer, IComparerExpression comparer, int k) { - Invariant.IsNotNull(orderer, nameof(orderer)); - Invariant.IsNotNull(comparer, nameof(comparer)); - Invariant.IsPositive(k, nameof(k)); + ArgumentNullException.ThrowIfNull(orderer); + ArgumentNullException.ThrowIfNull(comparer); + ArgumentOutOfRangeException.ThrowIfNegativeOrZero(k); var orderComparer = comparer.TransformInput(orderer); var aggregate = new TopKAggregate(k, orderComparer, this.Properties.QueryContainer); return aggregate.SkipNulls().ApplyFilter(this.Filter); @@ -191,9 +191,10 @@ public IAggregate, double> PercentileContinuous( double percentile, Expression> selector) { - Invariant.IsNotNull(selector, nameof(selector)); - Invariant.IsTrue(percentile >= 0.0 && percentile <= 1.0, "percentile must be within [0.0 .. 1.0]."); - var aggregate = new PercentileContinuousDoubleAggregate(percentile, this.Properties.QueryContainer); + ArgumentNullException.ThrowIfNull(selector); + ArgumentOutOfRangeException.ThrowIfNegative(percentile); + ArgumentOutOfRangeException.ThrowIfGreaterThan(percentile, 1.0); + var aggregate = new PercentileContinuousDoubleAggregate(percentile, this.Properties.QueryContainer); return aggregate.SkipNulls().Wrap(selector).ApplyFilter(this.Filter); } @@ -205,9 +206,10 @@ public IAggregate, double> PercentileContinuous( double percentile, Expression> selector) { - Invariant.IsNotNull(comparer, nameof(comparer)); - Invariant.IsNotNull(selector, nameof(selector)); - Invariant.IsTrue(percentile >= 0.0 && percentile <= 1.0, "percentile must be within [0.0 .. 1.0]."); + ArgumentNullException.ThrowIfNull(comparer); + ArgumentNullException.ThrowIfNull(selector); + ArgumentOutOfRangeException.ThrowIfNegative(percentile); + ArgumentOutOfRangeException.ThrowIfGreaterThan(percentile, 1.0); var aggregate = new PercentileContinuousDoubleAggregate(percentile, new ComparerExpression(comparer), this.Properties.QueryContainer); return aggregate.SkipNulls().Wrap(selector).ApplyFilter(this.Filter); } @@ -219,9 +221,10 @@ public IAggregate, double> PercentileDiscrete( double percentile, Expression> selector) { - Invariant.IsNotNull(selector, nameof(selector)); - Invariant.IsTrue(percentile >= 0.0 && percentile <= 1.0, "percentile must be within [0.0 .. 1.0]."); - var aggregate = new PercentileDiscreteDoubleAggregate(percentile, this.Properties.QueryContainer); + ArgumentNullException.ThrowIfNull(selector); + ArgumentOutOfRangeException.ThrowIfNegative(percentile); + ArgumentOutOfRangeException.ThrowIfGreaterThan(percentile, 1.0); + var aggregate = new PercentileDiscreteDoubleAggregate(percentile, this.Properties.QueryContainer); return aggregate.SkipNulls().Wrap(selector).ApplyFilter(this.Filter); } @@ -233,10 +236,11 @@ public IAggregate, double> PercentileDiscrete( double percentile, Expression> selector) { - Invariant.IsNotNull(comparer, nameof(comparer)); - Invariant.IsNotNull(selector, nameof(selector)); - Invariant.IsTrue(percentile >= 0.0 && percentile <= 1.0, "percentile must be within [0.0 .. 1.0]."); - var aggregate = new PercentileDiscreteDoubleAggregate(percentile, new ComparerExpression(comparer), this.Properties.QueryContainer); + ArgumentNullException.ThrowIfNull(comparer); + ArgumentNullException.ThrowIfNull(selector); + ArgumentOutOfRangeException.ThrowIfNegative(percentile); + ArgumentOutOfRangeException.ThrowIfGreaterThan(percentile, 1.0); + var aggregate = new PercentileDiscreteDoubleAggregate(percentile, new ComparerExpression(comparer), this.Properties.QueryContainer); return aggregate.SkipNulls().Wrap(selector).ApplyFilter(this.Filter); } diff --git a/Sources/Core/Microsoft.StreamProcessing/Windows/WindowTemplate.cs b/Sources/Core/Microsoft.StreamProcessing/Windows/WindowTemplate.cs index 282c59953..014be6a9c 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Windows/WindowTemplate.cs +++ b/Sources/Core/Microsoft.StreamProcessing/Windows/WindowTemplate.cs @@ -18,7 +18,7 @@ public partial class Window /// public IAggregate Sum(Expression> selector) { - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(selector); var aggregate = new SumSByteAggregate(); return aggregate.Wrap(selector).ApplyFilter(this.Filter); } @@ -28,7 +28,7 @@ public IAggregate Sum(Expression> se /// public IAggregate Sum(Expression> selector) { - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(selector); var aggregate = new SumByteAggregate(); return aggregate.Wrap(selector).ApplyFilter(this.Filter); } @@ -38,7 +38,7 @@ public IAggregate Sum(Expression> selec /// public IAggregate Sum(Expression> selector) { - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(selector); var aggregate = new SumShortAggregate(); return aggregate.Wrap(selector).ApplyFilter(this.Filter); } @@ -48,7 +48,7 @@ public IAggregate Sum(Expression> se /// public IAggregate Sum(Expression> selector) { - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(selector); var aggregate = new SumUShortAggregate(); return aggregate.Wrap(selector).ApplyFilter(this.Filter); } @@ -58,7 +58,7 @@ public IAggregate Sum(Expression> /// public IAggregate Sum(Expression> selector) { - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(selector); var aggregate = new SumIntAggregate(); return aggregate.Wrap(selector).ApplyFilter(this.Filter); } @@ -68,7 +68,7 @@ public IAggregate Sum(Expression> selector /// public IAggregate Sum(Expression> selector) { - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(selector); var aggregate = new SumUIntAggregate(); return aggregate.Wrap(selector).ApplyFilter(this.Filter); } @@ -78,7 +78,7 @@ public IAggregate Sum(Expression> selec /// public IAggregate Sum(Expression> selector) { - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(selector); var aggregate = new SumLongAggregate(); return aggregate.Wrap(selector).ApplyFilter(this.Filter); } @@ -88,7 +88,7 @@ public IAggregate Sum(Expression> selec /// public IAggregate Sum(Expression> selector) { - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(selector); var aggregate = new SumULongAggregate(); return aggregate.Wrap(selector).ApplyFilter(this.Filter); } @@ -98,7 +98,7 @@ public IAggregate Sum(Expression> se /// public IAggregate Sum(Expression> selector) { - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(selector); var aggregate = new SumFloatAggregate(); return aggregate.Wrap(selector).ApplyFilter(this.Filter); } @@ -108,7 +108,7 @@ public IAggregate Sum(Expression> se /// public IAggregate Sum(Expression> selector) { - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(selector); var aggregate = new SumDoubleAggregate(); return aggregate.Wrap(selector).ApplyFilter(this.Filter); } @@ -118,7 +118,7 @@ public IAggregate Sum(Expression> /// public IAggregate Sum(Expression> selector) { - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(selector); var aggregate = new SumDecimalAggregate(); return aggregate.Wrap(selector).ApplyFilter(this.Filter); } @@ -128,7 +128,7 @@ public IAggregate Sum(Expression public IAggregate Sum(Expression> selector) { - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(selector); var aggregate = new SumBigIntegerAggregate(); return aggregate.Wrap(selector).ApplyFilter(this.Filter); } @@ -138,7 +138,7 @@ public IAggregate Sum(Expression public IAggregate Sum(Expression> selector) { - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(selector); var aggregate = new SumComplexAggregate(); return aggregate.Wrap(selector).ApplyFilter(this.Filter); } @@ -149,7 +149,7 @@ public IAggregate Sum(Expression public IAggregate Sum(Expression> selector) { - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(selector); var aggregate = new SumSByteAggregate(); return aggregate.MakeInputNullableAndSkipNulls().Wrap(selector).ApplyFilter(this.Filter); } @@ -160,7 +160,7 @@ public IAggregate Sum(Expression> s /// public IAggregate Sum(Expression> selector) { - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(selector); var aggregate = new SumByteAggregate(); return aggregate.MakeInputNullableAndSkipNulls().Wrap(selector).ApplyFilter(this.Filter); } @@ -171,7 +171,7 @@ public IAggregate Sum(Expression> sele /// public IAggregate Sum(Expression> selector) { - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(selector); var aggregate = new SumShortAggregate(); return aggregate.MakeInputNullableAndSkipNulls().Wrap(selector).ApplyFilter(this.Filter); } @@ -182,7 +182,7 @@ public IAggregate Sum(Expression> s /// public IAggregate Sum(Expression> selector) { - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(selector); var aggregate = new SumUShortAggregate(); return aggregate.MakeInputNullableAndSkipNulls().Wrap(selector).ApplyFilter(this.Filter); } @@ -193,7 +193,7 @@ public IAggregate Sum(Expression /// public IAggregate Sum(Expression> selector) { - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(selector); var aggregate = new SumIntAggregate(); return aggregate.MakeInputNullableAndSkipNulls().Wrap(selector).ApplyFilter(this.Filter); } @@ -204,7 +204,7 @@ public IAggregate Sum(Expression> selecto /// public IAggregate Sum(Expression> selector) { - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(selector); var aggregate = new SumUIntAggregate(); return aggregate.MakeInputNullableAndSkipNulls().Wrap(selector).ApplyFilter(this.Filter); } @@ -215,7 +215,7 @@ public IAggregate Sum(Expression> sele /// public IAggregate Sum(Expression> selector) { - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(selector); var aggregate = new SumLongAggregate(); return aggregate.MakeInputNullableAndSkipNulls().Wrap(selector).ApplyFilter(this.Filter); } @@ -226,7 +226,7 @@ public IAggregate Sum(Expression> sele /// public IAggregate Sum(Expression> selector) { - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(selector); var aggregate = new SumULongAggregate(); return aggregate.MakeInputNullableAndSkipNulls().Wrap(selector).ApplyFilter(this.Filter); } @@ -237,7 +237,7 @@ public IAggregate Sum(Expression> s /// public IAggregate Sum(Expression> selector) { - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(selector); var aggregate = new SumFloatAggregate(); return aggregate.MakeInputNullableAndSkipNulls().Wrap(selector).ApplyFilter(this.Filter); } @@ -248,7 +248,7 @@ public IAggregate Sum(Expression> s /// public IAggregate Sum(Expression> selector) { - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(selector); var aggregate = new SumDoubleAggregate(); return aggregate.MakeInputNullableAndSkipNulls().Wrap(selector).ApplyFilter(this.Filter); } @@ -259,7 +259,7 @@ public IAggregate Sum(Expression /// public IAggregate Sum(Expression> selector) { - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(selector); var aggregate = new SumDecimalAggregate(); return aggregate.MakeInputNullableAndSkipNulls().Wrap(selector).ApplyFilter(this.Filter); } @@ -270,7 +270,7 @@ public IAggregate Sum(Expression public IAggregate Sum(Expression> selector) { - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(selector); var aggregate = new SumBigIntegerAggregate(); return aggregate.MakeInputNullableAndSkipNulls().Wrap(selector).ApplyFilter(this.Filter); } @@ -281,7 +281,7 @@ public IAggregate Sum(Expression public IAggregate Sum(Expression> selector) { - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(selector); var aggregate = new SumComplexAggregate(); return aggregate.MakeInputNullableAndSkipNulls().Wrap(selector).ApplyFilter(this.Filter); } @@ -291,7 +291,7 @@ public IAggregate Sum(Expression public IAggregate SumSquares(Expression> selector) { - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(selector); var aggregate = new SumSquareSByteAggregate(); return aggregate.Wrap(selector).ApplyFilter(this.Filter); } @@ -301,7 +301,7 @@ public IAggregate SumSquares(Expression public IAggregate SumSquares(Expression> selector) { - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(selector); var aggregate = new SumSquareByteAggregate(); return aggregate.Wrap(selector).ApplyFilter(this.Filter); } @@ -311,7 +311,7 @@ public IAggregate SumSquares(Expression /// public IAggregate SumSquares(Expression> selector) { - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(selector); var aggregate = new SumSquareShortAggregate(); return aggregate.Wrap(selector).ApplyFilter(this.Filter); } @@ -321,7 +321,7 @@ public IAggregate SumSquares(Expression public IAggregate SumSquares(Expression> selector) { - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(selector); var aggregate = new SumSquareUShortAggregate(); return aggregate.Wrap(selector).ApplyFilter(this.Filter); } @@ -331,7 +331,7 @@ public IAggregate SumSquares(Expression public IAggregate SumSquares(Expression> selector) { - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(selector); var aggregate = new SumSquareIntAggregate(); return aggregate.Wrap(selector).ApplyFilter(this.Filter); } @@ -341,7 +341,7 @@ public IAggregate SumSquares(Expression> s /// public IAggregate SumSquares(Expression> selector) { - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(selector); var aggregate = new SumSquareUIntAggregate(); return aggregate.Wrap(selector).ApplyFilter(this.Filter); } @@ -351,7 +351,7 @@ public IAggregate SumSquares(Expression /// public IAggregate SumSquares(Expression> selector) { - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(selector); var aggregate = new SumSquareLongAggregate(); return aggregate.Wrap(selector).ApplyFilter(this.Filter); } @@ -361,7 +361,7 @@ public IAggregate SumSquares(Expression /// public IAggregate SumSquares(Expression> selector) { - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(selector); var aggregate = new SumSquareULongAggregate(); return aggregate.Wrap(selector).ApplyFilter(this.Filter); } @@ -371,7 +371,7 @@ public IAggregate SumSquares(Expression public IAggregate SumSquares(Expression> selector) { - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(selector); var aggregate = new SumSquareFloatAggregate(); return aggregate.Wrap(selector).ApplyFilter(this.Filter); } @@ -381,7 +381,7 @@ public IAggregate SumSquares(Expression public IAggregate SumSquares(Expression> selector) { - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(selector); var aggregate = new SumSquareDoubleAggregate(); return aggregate.Wrap(selector).ApplyFilter(this.Filter); } @@ -391,7 +391,7 @@ public IAggregate SumSquares(Expression public IAggregate SumSquares(Expression> selector) { - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(selector); var aggregate = new SumSquareDecimalAggregate(); return aggregate.Wrap(selector).ApplyFilter(this.Filter); } @@ -401,7 +401,7 @@ public IAggregate SumSquares(Expression public IAggregate SumSquares(Expression> selector) { - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(selector); var aggregate = new SumSquareBigIntegerAggregate(); return aggregate.Wrap(selector).ApplyFilter(this.Filter); } @@ -411,7 +411,7 @@ public IAggregate SumSquares(Expression public IAggregate SumSquares(Expression> selector) { - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(selector); var aggregate = new SumSquareComplexAggregate(); return aggregate.Wrap(selector).ApplyFilter(this.Filter); } @@ -422,7 +422,7 @@ public IAggregate SumSquares(Expression public IAggregate SumSquares(Expression> selector) { - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(selector); var aggregate = new SumSquareSByteAggregate(); return aggregate.MakeInputNullableAndSkipNulls().Wrap(selector).ApplyFilter(this.Filter); } @@ -433,7 +433,7 @@ public IAggregate SumSquares(Expression public IAggregate SumSquares(Expression> selector) { - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(selector); var aggregate = new SumSquareByteAggregate(); return aggregate.MakeInputNullableAndSkipNulls().Wrap(selector).ApplyFilter(this.Filter); } @@ -444,7 +444,7 @@ public IAggregate SumSquares(Expression public IAggregate SumSquares(Expression> selector) { - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(selector); var aggregate = new SumSquareShortAggregate(); return aggregate.MakeInputNullableAndSkipNulls().Wrap(selector).ApplyFilter(this.Filter); } @@ -455,7 +455,7 @@ public IAggregate SumSquares(Expression public IAggregate SumSquares(Expression> selector) { - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(selector); var aggregate = new SumSquareUShortAggregate(); return aggregate.MakeInputNullableAndSkipNulls().Wrap(selector).ApplyFilter(this.Filter); } @@ -466,7 +466,7 @@ public IAggregate SumSquares(Expression public IAggregate SumSquares(Expression> selector) { - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(selector); var aggregate = new SumSquareIntAggregate(); return aggregate.MakeInputNullableAndSkipNulls().Wrap(selector).ApplyFilter(this.Filter); } @@ -477,7 +477,7 @@ public IAggregate SumSquares(Expression> /// public IAggregate SumSquares(Expression> selector) { - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(selector); var aggregate = new SumSquareUIntAggregate(); return aggregate.MakeInputNullableAndSkipNulls().Wrap(selector).ApplyFilter(this.Filter); } @@ -488,7 +488,7 @@ public IAggregate SumSquares(Expression public IAggregate SumSquares(Expression> selector) { - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(selector); var aggregate = new SumSquareLongAggregate(); return aggregate.MakeInputNullableAndSkipNulls().Wrap(selector).ApplyFilter(this.Filter); } @@ -499,7 +499,7 @@ public IAggregate SumSquares(Expression public IAggregate SumSquares(Expression> selector) { - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(selector); var aggregate = new SumSquareULongAggregate(); return aggregate.MakeInputNullableAndSkipNulls().Wrap(selector).ApplyFilter(this.Filter); } @@ -510,7 +510,7 @@ public IAggregate SumSquares(Expression public IAggregate SumSquares(Expression> selector) { - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(selector); var aggregate = new SumSquareFloatAggregate(); return aggregate.MakeInputNullableAndSkipNulls().Wrap(selector).ApplyFilter(this.Filter); } @@ -521,7 +521,7 @@ public IAggregate SumSquares(Expression public IAggregate SumSquares(Expression> selector) { - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(selector); var aggregate = new SumSquareDoubleAggregate(); return aggregate.MakeInputNullableAndSkipNulls().Wrap(selector).ApplyFilter(this.Filter); } @@ -532,7 +532,7 @@ public IAggregate SumSquares(Expression public IAggregate SumSquares(Expression> selector) { - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(selector); var aggregate = new SumSquareDecimalAggregate(); return aggregate.MakeInputNullableAndSkipNulls().Wrap(selector).ApplyFilter(this.Filter); } @@ -543,7 +543,7 @@ public IAggregate SumSquares(Expression public IAggregate SumSquares(Expression> selector) { - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(selector); var aggregate = new SumSquareBigIntegerAggregate(); return aggregate.MakeInputNullableAndSkipNulls().Wrap(selector).ApplyFilter(this.Filter); } @@ -554,7 +554,7 @@ public IAggregate SumSquares(Expression public IAggregate SumSquares(Expression> selector) { - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(selector); var aggregate = new SumSquareComplexAggregate(); return aggregate.MakeInputNullableAndSkipNulls().Wrap(selector).ApplyFilter(this.Filter); } @@ -564,7 +564,7 @@ public IAggregate SumSquares(Expression public IAggregate Product(Expression> selector) { - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(selector); var aggregate = new ProductSByteAggregate(); return aggregate.Wrap(selector).ApplyFilter(this.Filter); } @@ -574,7 +574,7 @@ public IAggregate Product(Expression /// public IAggregate Product(Expression> selector) { - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(selector); var aggregate = new ProductByteAggregate(); return aggregate.Wrap(selector).ApplyFilter(this.Filter); } @@ -584,7 +584,7 @@ public IAggregate Product(Expression> s /// public IAggregate Product(Expression> selector) { - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(selector); var aggregate = new ProductShortAggregate(); return aggregate.Wrap(selector).ApplyFilter(this.Filter); } @@ -594,7 +594,7 @@ public IAggregate Product(Expression /// public IAggregate Product(Expression> selector) { - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(selector); var aggregate = new ProductUShortAggregate(); return aggregate.Wrap(selector).ApplyFilter(this.Filter); } @@ -604,7 +604,7 @@ public IAggregate Product(Expression public IAggregate Product(Expression> selector) { - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(selector); var aggregate = new ProductIntAggregate(); return aggregate.Wrap(selector).ApplyFilter(this.Filter); } @@ -614,7 +614,7 @@ public IAggregate Product(Expression> sele /// public IAggregate Product(Expression> selector) { - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(selector); var aggregate = new ProductUIntAggregate(); return aggregate.Wrap(selector).ApplyFilter(this.Filter); } @@ -624,7 +624,7 @@ public IAggregate Product(Expression> s /// public IAggregate Product(Expression> selector) { - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(selector); var aggregate = new ProductLongAggregate(); return aggregate.Wrap(selector).ApplyFilter(this.Filter); } @@ -634,7 +634,7 @@ public IAggregate Product(Expression> s /// public IAggregate Product(Expression> selector) { - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(selector); var aggregate = new ProductULongAggregate(); return aggregate.Wrap(selector).ApplyFilter(this.Filter); } @@ -644,7 +644,7 @@ public IAggregate Product(Expression /// public IAggregate Product(Expression> selector) { - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(selector); var aggregate = new ProductFloatAggregate(); return aggregate.Wrap(selector).ApplyFilter(this.Filter); } @@ -654,7 +654,7 @@ public IAggregate Product(Expression /// public IAggregate Product(Expression> selector) { - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(selector); var aggregate = new ProductDoubleAggregate(); return aggregate.Wrap(selector).ApplyFilter(this.Filter); } @@ -664,7 +664,7 @@ public IAggregate Product(Expression public IAggregate Product(Expression> selector) { - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(selector); var aggregate = new ProductDecimalAggregate(); return aggregate.Wrap(selector).ApplyFilter(this.Filter); } @@ -674,7 +674,7 @@ public IAggregate Product(Expression public IAggregate Product(Expression> selector) { - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(selector); var aggregate = new ProductBigIntegerAggregate(); return aggregate.Wrap(selector).ApplyFilter(this.Filter); } @@ -684,7 +684,7 @@ public IAggregate Product(Expression public IAggregate Product(Expression> selector) { - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(selector); var aggregate = new ProductComplexAggregate(); return aggregate.Wrap(selector).ApplyFilter(this.Filter); } @@ -695,7 +695,7 @@ public IAggregate Product(Expression public IAggregate Product(Expression> selector) { - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(selector); var aggregate = new ProductSByteAggregate(); return aggregate.MakeInputNullableAndSkipNulls().Wrap(selector).ApplyFilter(this.Filter); } @@ -706,7 +706,7 @@ public IAggregate Product(Expression public IAggregate Product(Expression> selector) { - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(selector); var aggregate = new ProductByteAggregate(); return aggregate.MakeInputNullableAndSkipNulls().Wrap(selector).ApplyFilter(this.Filter); } @@ -717,7 +717,7 @@ public IAggregate Product(Expression> /// public IAggregate Product(Expression> selector) { - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(selector); var aggregate = new ProductShortAggregate(); return aggregate.MakeInputNullableAndSkipNulls().Wrap(selector).ApplyFilter(this.Filter); } @@ -728,7 +728,7 @@ public IAggregate Product(Expression public IAggregate Product(Expression> selector) { - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(selector); var aggregate = new ProductUShortAggregate(); return aggregate.MakeInputNullableAndSkipNulls().Wrap(selector).ApplyFilter(this.Filter); } @@ -739,7 +739,7 @@ public IAggregate Product(Expression public IAggregate Product(Expression> selector) { - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(selector); var aggregate = new ProductIntAggregate(); return aggregate.MakeInputNullableAndSkipNulls().Wrap(selector).ApplyFilter(this.Filter); } @@ -750,7 +750,7 @@ public IAggregate Product(Expression> sel /// public IAggregate Product(Expression> selector) { - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(selector); var aggregate = new ProductUIntAggregate(); return aggregate.MakeInputNullableAndSkipNulls().Wrap(selector).ApplyFilter(this.Filter); } @@ -761,7 +761,7 @@ public IAggregate Product(Expression> /// public IAggregate Product(Expression> selector) { - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(selector); var aggregate = new ProductLongAggregate(); return aggregate.MakeInputNullableAndSkipNulls().Wrap(selector).ApplyFilter(this.Filter); } @@ -772,7 +772,7 @@ public IAggregate Product(Expression> /// public IAggregate Product(Expression> selector) { - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(selector); var aggregate = new ProductULongAggregate(); return aggregate.MakeInputNullableAndSkipNulls().Wrap(selector).ApplyFilter(this.Filter); } @@ -783,7 +783,7 @@ public IAggregate Product(Expression public IAggregate Product(Expression> selector) { - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(selector); var aggregate = new ProductFloatAggregate(); return aggregate.MakeInputNullableAndSkipNulls().Wrap(selector).ApplyFilter(this.Filter); } @@ -794,7 +794,7 @@ public IAggregate Product(Expression public IAggregate Product(Expression> selector) { - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(selector); var aggregate = new ProductDoubleAggregate(); return aggregate.MakeInputNullableAndSkipNulls().Wrap(selector).ApplyFilter(this.Filter); } @@ -805,7 +805,7 @@ public IAggregate Product(Expression public IAggregate Product(Expression> selector) { - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(selector); var aggregate = new ProductDecimalAggregate(); return aggregate.MakeInputNullableAndSkipNulls().Wrap(selector).ApplyFilter(this.Filter); } @@ -816,7 +816,7 @@ public IAggregate Product(Expression public IAggregate Product(Expression> selector) { - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(selector); var aggregate = new ProductBigIntegerAggregate(); return aggregate.MakeInputNullableAndSkipNulls().Wrap(selector).ApplyFilter(this.Filter); } @@ -827,7 +827,7 @@ public IAggregate Product(Expression public IAggregate Product(Expression> selector) { - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(selector); var aggregate = new ProductComplexAggregate(); return aggregate.MakeInputNullableAndSkipNulls().Wrap(selector).ApplyFilter(this.Filter); } @@ -838,7 +838,7 @@ public IAggregate Product(Expression public IAggregate, double> Average(Expression> selector) { - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(selector); var aggregate = new AverageSByteAggregate(); return aggregate.Wrap(selector).ApplyFilter(this.Filter); } @@ -849,7 +849,7 @@ public IAggregate, double> Average(Expression public IAggregate, double> Average(Expression> selector) { - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(selector); var aggregate = new AverageShortAggregate(); return aggregate.Wrap(selector).ApplyFilter(this.Filter); } @@ -860,7 +860,7 @@ public IAggregate, double> Average(Expression public IAggregate, double> Average(Expression> selector) { - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(selector); var aggregate = new AverageIntAggregate(); return aggregate.Wrap(selector).ApplyFilter(this.Filter); } @@ -871,7 +871,7 @@ public IAggregate, double> Average(Expression public IAggregate, double> Average(Expression> selector) { - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(selector); var aggregate = new AverageLongAggregate(); return aggregate.Wrap(selector).ApplyFilter(this.Filter); } @@ -882,7 +882,7 @@ public IAggregate, double> Average(Expression public IAggregate, double> Average(Expression> selector) { - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(selector); var aggregate = new AverageByteAggregate(); return aggregate.Wrap(selector).ApplyFilter(this.Filter); } @@ -893,7 +893,7 @@ public IAggregate, double> Average(Expression public IAggregate, double> Average(Expression> selector) { - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(selector); var aggregate = new AverageUShortAggregate(); return aggregate.Wrap(selector).ApplyFilter(this.Filter); } @@ -904,7 +904,7 @@ public IAggregate, double> Average(Expression public IAggregate, double> Average(Expression> selector) { - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(selector); var aggregate = new AverageUIntAggregate(); return aggregate.Wrap(selector).ApplyFilter(this.Filter); } @@ -915,7 +915,7 @@ public IAggregate, double> Average(Expression public IAggregate, double> Average(Expression> selector) { - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(selector); var aggregate = new AverageULongAggregate(); return aggregate.Wrap(selector).ApplyFilter(this.Filter); } @@ -926,7 +926,7 @@ public IAggregate, double> Average(Expression public IAggregate, float> Average(Expression> selector) { - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(selector); var aggregate = new AverageFloatAggregate(); return aggregate.Wrap(selector).ApplyFilter(this.Filter); } @@ -937,7 +937,7 @@ public IAggregate, float> Average(Expression public IAggregate, double> Average(Expression> selector) { - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(selector); var aggregate = new AverageDoubleAggregate(); return aggregate.Wrap(selector).ApplyFilter(this.Filter); } @@ -948,7 +948,7 @@ public IAggregate, double> Average(Expression public IAggregate, decimal> Average(Expression> selector) { - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(selector); var aggregate = new AverageDecimalAggregate(); return aggregate.Wrap(selector).ApplyFilter(this.Filter); } @@ -959,7 +959,7 @@ public IAggregate, decimal> Average(Expression public IAggregate, double> Average(Expression> selector) { - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(selector); var aggregate = new AverageBigIntegerAggregate(); return aggregate.Wrap(selector).ApplyFilter(this.Filter); } @@ -970,7 +970,7 @@ public IAggregate, double> Average(Expression< /// public IAggregate, Complex> Average(Expression> selector) { - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(selector); var aggregate = new AverageComplexAggregate(); return aggregate.Wrap(selector).ApplyFilter(this.Filter); } @@ -981,7 +981,7 @@ public IAggregate, Complex> Average(Expression public IAggregate, double?> Average(Expression> selector) { - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(selector); var aggregate = new AverageNullableSByteAggregate(); return aggregate.Wrap(selector).ApplyFilter(this.Filter); } @@ -992,7 +992,7 @@ public IAggregate, Complex> Average(Expression public IAggregate, double?> Average(Expression> selector) { - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(selector); var aggregate = new AverageNullableShortAggregate(); return aggregate.Wrap(selector).ApplyFilter(this.Filter); } @@ -1003,7 +1003,7 @@ public IAggregate, Complex> Average(Expression public IAggregate, double?> Average(Expression> selector) { - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(selector); var aggregate = new AverageNullableIntAggregate(); return aggregate.Wrap(selector).ApplyFilter(this.Filter); } @@ -1014,7 +1014,7 @@ public IAggregate, Complex> Average(Expression public IAggregate, double?> Average(Expression> selector) { - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(selector); var aggregate = new AverageNullableLongAggregate(); return aggregate.Wrap(selector).ApplyFilter(this.Filter); } @@ -1025,7 +1025,7 @@ public IAggregate, Complex> Average(Expression public IAggregate, double?> Average(Expression> selector) { - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(selector); var aggregate = new AverageNullableByteAggregate(); return aggregate.Wrap(selector).ApplyFilter(this.Filter); } @@ -1036,7 +1036,7 @@ public IAggregate, Complex> Average(Expression public IAggregate, double?> Average(Expression> selector) { - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(selector); var aggregate = new AverageNullableUShortAggregate(); return aggregate.Wrap(selector).ApplyFilter(this.Filter); } @@ -1047,7 +1047,7 @@ public IAggregate, Complex> Average(Expression public IAggregate, double?> Average(Expression> selector) { - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(selector); var aggregate = new AverageNullableUIntAggregate(); return aggregate.Wrap(selector).ApplyFilter(this.Filter); } @@ -1058,7 +1058,7 @@ public IAggregate, Complex> Average(Expression public IAggregate, double?> Average(Expression> selector) { - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(selector); var aggregate = new AverageNullableULongAggregate(); return aggregate.Wrap(selector).ApplyFilter(this.Filter); } @@ -1069,7 +1069,7 @@ public IAggregate, Complex> Average(Expression public IAggregate, float?> Average(Expression> selector) { - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(selector); var aggregate = new AverageNullableFloatAggregate(); return aggregate.Wrap(selector).ApplyFilter(this.Filter); } @@ -1080,7 +1080,7 @@ public IAggregate, Complex> Average(Expression public IAggregate, double?> Average(Expression> selector) { - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(selector); var aggregate = new AverageNullableDoubleAggregate(); return aggregate.Wrap(selector).ApplyFilter(this.Filter); } @@ -1091,7 +1091,7 @@ public IAggregate, Complex> Average(Expression public IAggregate, decimal?> Average(Expression> selector) { - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(selector); var aggregate = new AverageNullableDecimalAggregate(); return aggregate.Wrap(selector).ApplyFilter(this.Filter); } @@ -1102,7 +1102,7 @@ public IAggregate, Complex> Average(Expression public IAggregate, double?> Average(Expression> selector) { - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(selector); var aggregate = new AverageNullableBigIntegerAggregate(); return aggregate.Wrap(selector).ApplyFilter(this.Filter); } @@ -1113,7 +1113,7 @@ public IAggregate, Complex> Average(Expression public IAggregate, Complex?> Average(Expression> selector) { - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(selector); var aggregate = new AverageNullableComplexAggregate(); return aggregate.Wrap(selector).ApplyFilter(this.Filter); } @@ -1124,7 +1124,7 @@ public IAggregate, Complex> Average(Expression public IAggregate, double> AverageSquares(Expression> selector) { - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(selector); var aggregate = new AverageSquareSByteAggregate(); return aggregate.Wrap(selector).ApplyFilter(this.Filter); } @@ -1135,7 +1135,7 @@ public IAggregate, double> AverageSquares(Expression /// public IAggregate, double> AverageSquares(Expression> selector) { - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(selector); var aggregate = new AverageSquareShortAggregate(); return aggregate.Wrap(selector).ApplyFilter(this.Filter); } @@ -1146,7 +1146,7 @@ public IAggregate, double> AverageSquares(Expression /// public IAggregate, double> AverageSquares(Expression> selector) { - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(selector); var aggregate = new AverageSquareIntAggregate(); return aggregate.Wrap(selector).ApplyFilter(this.Filter); } @@ -1157,7 +1157,7 @@ public IAggregate, double> AverageSquares(Expression /// public IAggregate, double> AverageSquares(Expression> selector) { - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(selector); var aggregate = new AverageSquareLongAggregate(); return aggregate.Wrap(selector).ApplyFilter(this.Filter); } @@ -1168,7 +1168,7 @@ public IAggregate, double> AverageSquares(Expression /// public IAggregate, double> AverageSquares(Expression> selector) { - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(selector); var aggregate = new AverageSquareByteAggregate(); return aggregate.Wrap(selector).ApplyFilter(this.Filter); } @@ -1179,7 +1179,7 @@ public IAggregate, double> AverageSquares(Expressio /// public IAggregate, double> AverageSquares(Expression> selector) { - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(selector); var aggregate = new AverageSquareUShortAggregate(); return aggregate.Wrap(selector).ApplyFilter(this.Filter); } @@ -1190,7 +1190,7 @@ public IAggregate, double> AverageSquares(Expressio /// public IAggregate, double> AverageSquares(Expression> selector) { - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(selector); var aggregate = new AverageSquareUIntAggregate(); return aggregate.Wrap(selector).ApplyFilter(this.Filter); } @@ -1201,7 +1201,7 @@ public IAggregate, double> AverageSquares(Expressio /// public IAggregate, double> AverageSquares(Expression> selector) { - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(selector); var aggregate = new AverageSquareULongAggregate(); return aggregate.Wrap(selector).ApplyFilter(this.Filter); } @@ -1212,7 +1212,7 @@ public IAggregate, double> AverageSquares(Expressio /// public IAggregate, float> AverageSquares(Expression> selector) { - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(selector); var aggregate = new AverageSquareFloatAggregate(); return aggregate.Wrap(selector).ApplyFilter(this.Filter); } @@ -1223,7 +1223,7 @@ public IAggregate, float> AverageSquares(Expression /// public IAggregate, double> AverageSquares(Expression> selector) { - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(selector); var aggregate = new AverageSquareDoubleAggregate(); return aggregate.Wrap(selector).ApplyFilter(this.Filter); } @@ -1234,7 +1234,7 @@ public IAggregate, double> AverageSquares(Expressi /// public IAggregate, decimal> AverageSquares(Expression> selector) { - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(selector); var aggregate = new AverageSquareDecimalAggregate(); return aggregate.Wrap(selector).ApplyFilter(this.Filter); } @@ -1245,7 +1245,7 @@ public IAggregate, decimal> AverageSquares(Expres /// public IAggregate, double> AverageSquares(Expression> selector) { - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(selector); var aggregate = new AverageSquareBigIntegerAggregate(); return aggregate.Wrap(selector).ApplyFilter(this.Filter); } @@ -1256,7 +1256,7 @@ public IAggregate, double> AverageSquares(Expr /// public IAggregate, Complex> AverageSquares(Expression> selector) { - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(selector); var aggregate = new AverageSquareComplexAggregate(); return aggregate.Wrap(selector).ApplyFilter(this.Filter); } @@ -1267,7 +1267,7 @@ public IAggregate, Complex> AverageSquares(Expres /// public IAggregate, double?> AverageSquares(Expression> selector) { - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(selector); var aggregate = new AverageSquareNullableSByteAggregate(); return aggregate.Wrap(selector).ApplyFilter(this.Filter); } @@ -1278,7 +1278,7 @@ public IAggregate, Complex> AverageSquares(Expres /// public IAggregate, double?> AverageSquares(Expression> selector) { - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(selector); var aggregate = new AverageSquareNullableShortAggregate(); return aggregate.Wrap(selector).ApplyFilter(this.Filter); } @@ -1289,7 +1289,7 @@ public IAggregate, Complex> AverageSquares(Expres /// public IAggregate, double?> AverageSquares(Expression> selector) { - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(selector); var aggregate = new AverageSquareNullableIntAggregate(); return aggregate.Wrap(selector).ApplyFilter(this.Filter); } @@ -1300,7 +1300,7 @@ public IAggregate, Complex> AverageSquares(Expres /// public IAggregate, double?> AverageSquares(Expression> selector) { - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(selector); var aggregate = new AverageSquareNullableLongAggregate(); return aggregate.Wrap(selector).ApplyFilter(this.Filter); } @@ -1311,7 +1311,7 @@ public IAggregate, Complex> AverageSquares(Expres /// public IAggregate, double?> AverageSquares(Expression> selector) { - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(selector); var aggregate = new AverageSquareNullableByteAggregate(); return aggregate.Wrap(selector).ApplyFilter(this.Filter); } @@ -1322,7 +1322,7 @@ public IAggregate, Complex> AverageSquares(Expres /// public IAggregate, double?> AverageSquares(Expression> selector) { - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(selector); var aggregate = new AverageSquareNullableUShortAggregate(); return aggregate.Wrap(selector).ApplyFilter(this.Filter); } @@ -1333,7 +1333,7 @@ public IAggregate, Complex> AverageSquares(Expres /// public IAggregate, double?> AverageSquares(Expression> selector) { - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(selector); var aggregate = new AverageSquareNullableUIntAggregate(); return aggregate.Wrap(selector).ApplyFilter(this.Filter); } @@ -1344,7 +1344,7 @@ public IAggregate, Complex> AverageSquares(Expres /// public IAggregate, double?> AverageSquares(Expression> selector) { - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(selector); var aggregate = new AverageSquareNullableULongAggregate(); return aggregate.Wrap(selector).ApplyFilter(this.Filter); } @@ -1355,7 +1355,7 @@ public IAggregate, Complex> AverageSquares(Expres /// public IAggregate, float?> AverageSquares(Expression> selector) { - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(selector); var aggregate = new AverageSquareNullableFloatAggregate(); return aggregate.Wrap(selector).ApplyFilter(this.Filter); } @@ -1366,7 +1366,7 @@ public IAggregate, Complex> AverageSquares(Expres /// public IAggregate, double?> AverageSquares(Expression> selector) { - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(selector); var aggregate = new AverageSquareNullableDoubleAggregate(); return aggregate.Wrap(selector).ApplyFilter(this.Filter); } @@ -1377,7 +1377,7 @@ public IAggregate, Complex> AverageSquares(Expres /// public IAggregate, decimal?> AverageSquares(Expression> selector) { - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(selector); var aggregate = new AverageSquareNullableDecimalAggregate(); return aggregate.Wrap(selector).ApplyFilter(this.Filter); } @@ -1388,7 +1388,7 @@ public IAggregate, Complex> AverageSquares(Expres /// public IAggregate, double?> AverageSquares(Expression> selector) { - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(selector); var aggregate = new AverageSquareNullableBigIntegerAggregate(); return aggregate.Wrap(selector).ApplyFilter(this.Filter); } @@ -1399,7 +1399,7 @@ public IAggregate, Complex> AverageSquares(Expres /// public IAggregate, Complex?> AverageSquares(Expression> selector) { - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(selector); var aggregate = new AverageSquareNullableComplexAggregate(); return aggregate.Wrap(selector).ApplyFilter(this.Filter); } diff --git a/Sources/Core/Microsoft.StreamProcessing/Windows/WindowTemplate.tt b/Sources/Core/Microsoft.StreamProcessing/Windows/WindowTemplate.tt index 478c954f9..d009c0bc9 100644 --- a/Sources/Core/Microsoft.StreamProcessing/Windows/WindowTemplate.tt +++ b/Sources/Core/Microsoft.StreamProcessing/Windows/WindowTemplate.tt @@ -27,7 +27,7 @@ namespace Microsoft.StreamProcessing /// public IAggregate, <#= typeName #>> Sum(Expression>> selector) { - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(selector); var aggregate = new Sum<#= typeFriendlyName #>Aggregate(); return aggregate.Wrap(selector).ApplyFilter(this.Filter); } @@ -47,7 +47,7 @@ namespace Microsoft.StreamProcessing /// public IAggregate, <#= typeName #>> Sum(Expression?>> selector) { - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(selector); var aggregate = new Sum<#= typeFriendlyName #>Aggregate(); return aggregate.MakeInputNullableAndSkipNulls().Wrap(selector).ApplyFilter(this.Filter); } @@ -66,7 +66,7 @@ namespace Microsoft.StreamProcessing /// public IAggregate, <#= typeName #>> SumSquares(Expression>> selector) { - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(selector); var aggregate = new SumSquare<#= typeFriendlyName #>Aggregate(); return aggregate.Wrap(selector).ApplyFilter(this.Filter); } @@ -86,7 +86,7 @@ namespace Microsoft.StreamProcessing /// public IAggregate, <#= typeName #>> SumSquares(Expression?>> selector) { - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(selector); var aggregate = new SumSquare<#= typeFriendlyName #>Aggregate(); return aggregate.MakeInputNullableAndSkipNulls().Wrap(selector).ApplyFilter(this.Filter); } @@ -105,7 +105,7 @@ namespace Microsoft.StreamProcessing /// public IAggregate, <#= typeName #>> Product(Expression>> selector) { - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(selector); var aggregate = new Product<#= typeFriendlyName #>Aggregate(); return aggregate.Wrap(selector).ApplyFilter(this.Filter); } @@ -125,7 +125,7 @@ namespace Microsoft.StreamProcessing /// public IAggregate, <#= typeName #>> Product(Expression?>> selector) { - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(selector); var aggregate = new Product<#= typeFriendlyName #>Aggregate(); return aggregate.MakeInputNullableAndSkipNulls().Wrap(selector).ApplyFilter(this.Filter); } @@ -147,7 +147,7 @@ namespace Microsoft.StreamProcessing /// public IAggregate>, <#= returnTypeName#>> Average(Expression>> selector) { - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(selector); var aggregate = new Average<#= typeFriendlyName #>Aggregate(); return aggregate.Wrap(selector).ApplyFilter(this.Filter); } @@ -169,7 +169,7 @@ namespace Microsoft.StreamProcessing /// public IAggregate>, <#= returnTypeName#>?> Average(Expression?>> selector) { - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(selector); var aggregate = new AverageNullable<#= typeFriendlyName #>Aggregate(); return aggregate.Wrap(selector).ApplyFilter(this.Filter); } @@ -191,7 +191,7 @@ namespace Microsoft.StreamProcessing /// public IAggregate>, <#= returnTypeName#>> AverageSquares(Expression>> selector) { - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(selector); var aggregate = new AverageSquare<#= typeFriendlyName #>Aggregate(); return aggregate.Wrap(selector).ApplyFilter(this.Filter); } @@ -213,7 +213,7 @@ namespace Microsoft.StreamProcessing /// public IAggregate>, <#= returnTypeName#>?> AverageSquares(Expression?>> selector) { - Invariant.IsNotNull(selector, nameof(selector)); + ArgumentNullException.ThrowIfNull(selector); var aggregate = new AverageSquareNullable<#= typeFriendlyName #>Aggregate(); return aggregate.Wrap(selector).ApplyFilter(this.Filter); } diff --git a/Sources/Microsoft.StreamProcessing.ruleset b/Sources/Microsoft.StreamProcessing.ruleset deleted file mode 100644 index b9cb6cefc..000000000 --- a/Sources/Microsoft.StreamProcessing.ruleset +++ /dev/null @@ -1,198 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/Sources/Test/Directory.Build.props b/Sources/Test/Directory.Build.props index 588c632b2..b046b9e77 100644 --- a/Sources/Test/Directory.Build.props +++ b/Sources/Test/Directory.Build.props @@ -7,7 +7,6 @@ false - $(MSBuildThisFileDirectory)Microsoft.StreamProcessing.Test.ruleset prompt 4 true @@ -27,8 +26,4 @@ - - - - diff --git a/Sources/Test/Microsoft.StreamProcessing.Test.ruleset b/Sources/Test/Microsoft.StreamProcessing.Test.ruleset deleted file mode 100644 index ca4f78706..000000000 --- a/Sources/Test/Microsoft.StreamProcessing.Test.ruleset +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - - \ No newline at end of file diff --git a/Sources/Test/SimpleTesting/AdHocTests.cs b/Sources/Test/SimpleTesting/AdHocTests.cs index 41c0cca20..66e3b1ed8 100644 --- a/Sources/Test/SimpleTesting/AdHocTests.cs +++ b/Sources/Test/SimpleTesting/AdHocTests.cs @@ -37,14 +37,14 @@ public void Properties() { var inputs = new List { - new MyPropertiesContainer { A = 1, B = true, C = 3M, D = "4", E = new Nested() }, + new() { A = 1, B = true, C = 3M, D = "4", E = new Nested() }, }; var q1 = inputs.Select(x => StreamEvent.CreatePoint(10, x)) .ToObservable() .ToStreamable(DisorderPolicy.Throw(), FlushPolicy.FlushOnPunctuation, PeriodicPunctuationPolicy.None(), OnCompletedPolicy.None); - var q2 = q1.Select(x => string.Join(",", x.A, x.B, x.C, x.D, x.E)); + var q2 = q1.Select(x => string.Join(",", new object[] { x.A, x.B, x.C, x.D, x.E })); int count = 0; q2.ToStreamEventObservable().ForEachAsync(x => count++).Wait(); @@ -60,14 +60,14 @@ public void Fields() { var inputs = new List { - new MyFieldsContainer { A = 1, B = true, C = 3M, D = "4", E = new Nested() }, + new() { A = 1, B = true, C = 3M, D = "4", E = new Nested() }, }; var q1 = inputs.Select(x => StreamEvent.CreatePoint(10, x)) .ToObservable() .ToStreamable(DisorderPolicy.Throw(), FlushPolicy.FlushOnPunctuation, PeriodicPunctuationPolicy.None(), OnCompletedPolicy.None); - var q2 = q1.Select(x => string.Join(",", x.A, x.B, x.C, x.D, x.E)); + var q2 = q1.Select(x => string.Join(",", new object[] { x.A, x.B, x.C, x.D, x.E })); int count = 0; q2.ToStreamEventObservable().ForEachAsync(x => count++).Wait(); @@ -83,7 +83,7 @@ public void Initializer() { var inputs = new List { - new MyFieldsContainer { A = 1, B = true, C = 3M, D = "4", E = new Nested() { Value = "five" } }, + new() { A = 1, B = true, C = 3M, D = "4", E = new Nested() { Value = "five" } }, }; var q1 = inputs.Select(x => StreamEvent.CreatePoint(10, x)) @@ -141,11 +141,11 @@ private void TestSerialization() ms.Position = 0; ColumnBatch resultStr = s.Deserialize(ms); - Assert.IsTrue(resultStr.UsedLength == inputStr.UsedLength); + Assert.AreEqual(inputStr.UsedLength, resultStr.UsedLength); for (int j = 0; j < inputStr.UsedLength; j++) { - Assert.IsTrue(inputStr.col[j] == resultStr.col[j]); + Assert.AreEqual(resultStr.col[j], inputStr.col[j]); } resultStr.ReturnClear(); inputStr.ReturnClear(); @@ -155,19 +155,21 @@ private void TestSerialization() [TestMethod, TestCategory("Gated")] public void StreamEventArrayIngress1() { - // Test where full array can fit into one batch + // Test where full array can fit into one batch — pin DataBatchSize so the + // assertion on batch count is not sensitive to Config state set by other tests. + using var _ = new ConfigModifier().DataBatchSize(80000).Modify(); var startTime = 0; var length = 100; var a = Enumerable.Range(0, length) .Select(i => StreamEvent.CreateStart(startTime++ / 80000, i)) .ToArray(); - var input = new ArraySegment>[] { new ArraySegment>(a), }; + var input = new ArraySegment>[] { new(a), }; var s = input.ToObservable(); var str = s.ToStreamable(); var output = str.ToStreamMessageObservable().ToEnumerable().ToArray(); - Assert.IsTrue(output.Length == 1); // first batch with all data and one punctuation - Assert.IsTrue(output[0].Count == length + 1); - Assert.IsTrue(output[0].vother.col[output[0].Count - 1] == StreamEvent.PunctuationOtherTime); + Assert.HasCount(1, output); // first batch with all data and one punctuation + Assert.AreEqual(length + 1, output[0].Count); + Assert.AreEqual(StreamEvent.PunctuationOtherTime, output[0].vother.col[output[0].Count - 1]); for (int i = 0; i < output.Length; i++) output[i].Free(); } @@ -181,15 +183,15 @@ public void StreamEventArrayIngress2() var a = Enumerable.Range(0, length) .Select(i => StreamEvent.CreateStart(startTime++ / 80000, i)) .ToArray(); - var input = new ArraySegment>[] { new ArraySegment>(a) }; + var input = new ArraySegment>[] { new(a) }; var s = input.ToObservable(); var str = s.ToStreamable(); var output = str.ToStreamMessageObservable().ToEnumerable().ToArray(); - Assert.IsTrue(output.Length == 4); // four data batches - Assert.IsTrue(output[0].Count + output[1].Count + output[2].Count + output[3].Count == length + 1); + Assert.HasCount(4, output); // four data batches + Assert.AreEqual(length + 1, output[0].Count + output[1].Count + output[2].Count + output[3].Count); // fourth data batch should have a punctuation at the end - Assert.IsTrue(output[3].vother.col[output[3].Count - 1] == StreamEvent.PunctuationOtherTime); + Assert.AreEqual(StreamEvent.PunctuationOtherTime, output[3].vother.col[output[3].Count - 1]); for (int i = 0; i < output.Length; i++) output[i].Free(); } @@ -204,22 +206,22 @@ public void StreamEventArrayIngress3() StreamEvent.CreatePunctuation(i) : StreamEvent.CreateStart(i, i)) .ToArray(); - var input = new ArraySegment>[] { new ArraySegment>(a) }; + var input = new ArraySegment>[] { new(a) }; var s = input.ToObservable(); var str = s.ToStreamable(); var output = str.ToStreamMessageObservable().ToEnumerable().ToArray(); // 10 pairs of data and punc, then one with just a punctuation at infinity int expectedDataBatches = 11; - Assert.IsTrue(output.Length == expectedDataBatches); + Assert.HasCount(expectedDataBatches, output); var dataEventCount = 0; for (int i = 0; i < output.Length; i++) { // Data batch should end with a punctuation - Assert.IsTrue(output[i].vother.col[output[i].Count - 1] == StreamEvent.PunctuationOtherTime); + Assert.AreEqual(StreamEvent.PunctuationOtherTime, output[i].vother.col[output[i].Count - 1]); dataEventCount += output[i].Count - 1; // exclude punctuation } - Assert.IsTrue(dataEventCount == length - 10); // because every 10th row was a punctuation, not a data row + Assert.AreEqual(length - 10, dataEventCount); // because every 10th row was a punctuation, not a data row for (int i = 0; i < output.Length; i++) output[i].Free(); } @@ -255,7 +257,7 @@ public void PartitionedStreamAdjustIngressPolicy() egress.Wait(); output = output.Where(o => o.IsData).ToList(); - Assert.AreEqual(2, output.Count); + Assert.HasCount(2, output); Assert.AreEqual(70, output[0].SyncTime); Assert.AreEqual(22, output[1].SyncTime); } @@ -405,7 +407,7 @@ public void UnderFlowFalseFlush() OnCompletedPolicy.None); var output = new List>(); - var egress = qc.RegisterOutput(ingress).ForEachAsync(o => output.Add(o)); + var egress = qc.RegisterOutput(ingress).ForEachAsync(output.Add); var process = qc.Restore(); process.Flush(); egress.Wait(); @@ -507,7 +509,7 @@ public void InactiveAndNewPartitions() OnCompletedPolicy.EndOfStream); var output = new List>(); - var egress = qc.RegisterOutput(ingress).ForEachAsync(o => output.Add(o)); + var egress = qc.RegisterOutput(ingress).ForEachAsync(output.Add); var process = qc.Restore(); process.Flush(); egress.Wait(); @@ -547,7 +549,7 @@ public void FileStreamPassthrough() // Stream from file var fromFile = filePath.ToStreamableFromFile(readPropertiesFromStream: serializeStreamProperties); var output = new List>(); - fromFile.ToStreamEventObservable().Where(e => e.IsData).ForEachAsync(r => output.Add(r)).Wait(); + fromFile.ToStreamEventObservable().Where(e => e.IsData).ForEachAsync(output.Add).Wait(); Assert.IsTrue(inputData.SequenceEqual(output)); } @@ -579,7 +581,7 @@ public void FileStreamDoubleQuery() for (int i = 0; i < 2; i++) { var output = new List>(); - streamable.ToStreamEventObservable().Where(e => e.IsData).ForEachAsync(e => output.Add(e)).Wait(); + streamable.ToStreamEventObservable().Where(e => e.IsData).ForEachAsync(output.Add).Wait(); Assert.IsTrue(inputData.SequenceEqual(output)); } } @@ -651,7 +653,7 @@ public void ExplicitAndGeneratedLowWatermarks() var output = new List>(); input.ToStreamEventObservable() - .ForEachAsync(x => output.Add(x)) + .ForEachAsync(output.Add) .Wait(); var expected = new List> @@ -863,7 +865,7 @@ public void LASJ_OutOfOrderLWM() e => e); var output = new List>(); - var egress = qc.RegisterOutput(query).ForEachAsync(o => output.Add(o)); + var egress = qc.RegisterOutput(query).ForEachAsync(output.Add); var process = qc.Restore(); process.Flush(); egress.Wait(); @@ -898,7 +900,7 @@ public void SimpleShardTest() .Unshard() .ToStreamEventObservable() .Where(e => e.IsData) - .ForEachAsync(e => output.Add(e)); + .ForEachAsync(output.Add); Assert.IsTrue(output.SequenceEqual(input)); } @@ -920,11 +922,11 @@ public void SinglePunctuationBatchTimestamps() batch => { var min = batch.MinTimestamp; - Assert.IsTrue(min >= currentMin); + Assert.IsGreaterThanOrEqualTo(currentMin, min); currentMin = min; var max = batch.MaxTimestamp; - Assert.IsTrue(max >= currentMax); + Assert.IsGreaterThanOrEqualTo(currentMax, max); currentMax = max; batch.Free(); @@ -957,7 +959,7 @@ public void AggressivePartitionCleanup_LASJ() e => e); var output = new List>(); - qc.RegisterOutput(query).ForEachAsync(o => output.Add(o)); + qc.RegisterOutput(query).ForEachAsync(output.Add); var process = qc.Restore(); // Set up state so that the left has an "invisible" (i.e. unmatched on the right) interval. @@ -1045,7 +1047,7 @@ public void AggressivePartitionCleanup_EquiJoin() (l, r) => l); var output = new List>(); - qc.RegisterOutput(query).ForEachAsync(o => output.Add(o)); + qc.RegisterOutput(query).ForEachAsync(output.Add); var process = qc.Restore(); // Set up state so that there is outstanding start edges/intervals @@ -1129,7 +1131,7 @@ public void AggressivePartitionCleanup_Clip() e => e); var output = new List>(); - qc.RegisterOutput(query).ForEachAsync(o => output.Add(o)); + qc.RegisterOutput(query).ForEachAsync(output.Add); var process = qc.Restore(); // Set up state so that there is outstanding start edges/intervals @@ -1190,7 +1192,7 @@ public void OutOfOrderRepro() var input = new Subject>(); var ingress = qc.RegisterInput(input, DisorderPolicy.Drop(reorderLatency: 500)); var output = new List>(); - var egress = qc.RegisterOutput(ingress).ForEachAsync(o => output.Add(o)); + var egress = qc.RegisterOutput(ingress).ForEachAsync(output.Add); var process = qc.Restore(); // These will be buffered due to reorderLatency @@ -1247,7 +1249,7 @@ public void ColumnarUngroupNullRefRepro() (g, byNamePayload) => new Payload { GroupId = g.Key, Name = byNamePayload.Name, Reading = byNamePayload.Reading }) .ToStreamEventObservable()); var output = new List>(); - var egress = qc.RegisterOutput(ingress).Where(e => e.IsData).ForEachAsync(o => output.Add(o)); + var egress = qc.RegisterOutput(ingress).Where(e => e.IsData).ForEachAsync(output.Add); var process = qc.Restore(); process.Flush(); egress.Wait(); @@ -1311,8 +1313,10 @@ public async Task DisposeTest1() await inputTask; // Make sure we really got an output data event. - Assert.IsTrue(lastSeenSubscription > 0); + Assert.IsGreaterThan(0, lastSeenSubscription); } + + public TestContext TestContext { get; set; } } [TestClass] @@ -1347,16 +1351,16 @@ public void PublishTest1() var input = inputSubject.ToStreamable().SetProperty().IsConstantDuration(true, StreamEvent.InfinitySyncTime).Publish(); - var output1 = input.ToStreamEventObservable().Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(x => outputList1.Add(x)); + var output1 = input.ToStreamEventObservable().Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(outputList1.Add); input.Connect(); - preConnectData.ForEachAsync(x => inputSubject.OnNext(x)).Wait(); + preConnectData.ForEachAsync(inputSubject.OnNext).Wait(); inputSubject.OnNext(StreamEvent.CreatePunctuation(1)); - var output2 = input.ToStreamEventObservable().Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(x => outputList2.Add(x)); + var output2 = input.ToStreamEventObservable().Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(outputList2.Add); - postConnectData.ForEachAsync(x => inputSubject.OnNext(x)).Wait(); + postConnectData.ForEachAsync(inputSubject.OnNext).Wait(); inputSubject.OnCompleted(); @@ -1412,7 +1416,7 @@ public struct NormalizedHttpEvent countedNE = countedNE.AlterEventDuration(1); var output2 = countedNE.ToStreamEventObservable(ReshapingPolicy.CoalesceEndEdges).ToEnumerable().ToArray(); - Assert.IsTrue(output2.Count() == 9); + Assert.AreEqual(9, output2.Count()); } } @@ -1737,8 +1741,8 @@ private class QueryProcessor : IDisposable { private IObserver> observer; private readonly Process process = null; - private readonly Queue> results = new Queue>(); - private readonly QueryContainer container = new QueryContainer(); + private readonly Queue> results = new(); + private readonly QueryContainer container = new(); private void CommonInitialize() { @@ -1748,10 +1752,7 @@ private void CommonInitialize() var result = Query(inputEvents); var resultObs = this.container.RegisterOutput(result); - resultObs.Subscribe(x => - { - this.results.Enqueue(x); - }); + resultObs.Subscribe(this.results.Enqueue); } internal QueryProcessor() @@ -1842,7 +1843,7 @@ public void LeftJoinOutOfOrder() s => s, s => s, e1 => e1, - (e1, e2) => null)).ForEachAsync(o => output.Add(o)); + (e1, e2) => null)).ForEachAsync(output.Add); var process = qc.Restore(); // This test used to rely on lagAllowance=50 and (Global)PeriodicPunctuationPolicy=10 to generate global punctuations and flush contents. @@ -1871,7 +1872,7 @@ public void LeftJoinOutOfOrder() process.Flush(); var outputData = output.Where(o => o.IsData).ToList(); - Assert.IsTrue(outputData.Count == 2); + Assert.HasCount(2, outputData); } [TestMethod, TestCategory("Gated")] @@ -1949,7 +1950,7 @@ public void StartEdge1() .ToArray(); var x = events.Length; - Assert.IsTrue(x == inputEnumerable.Count()); + Assert.AreEqual(inputEnumerable.Count(), x); } } @@ -2133,12 +2134,14 @@ public void JoinClipTest() }); var result = successes.ToStreamEventObservable().ToEnumerable().ToArray(); - Assert.IsTrue(false); // should never reach here. + Assert.Fail(); // should never reach here. } - catch (Exception e) + catch (InvalidOperationException) { - Assert.IsTrue(e is InvalidOperationException); + // expected, because the Join should not be able to match the clipped events with the finishing events, since the clipped events have had their lifetime shifted by 1 tick, and thus should not overlap with the finishing events. + return; } + Assert.Fail(); // should never reach here. } /// @@ -2170,7 +2173,7 @@ public void UnionWithOneColumnarAndOneNot01() .ToStreamEventObservable() .Where(e => e.IsData) .Select(e => e.Payload) - .ForEachAsync(x => outputList.Add(x)); + .ForEachAsync(outputList.Add); streamResult.Connect(); @@ -2208,7 +2211,7 @@ public void UnionWithOneColumnarAndOneNot02() .ToStreamEventObservable() .Where(e => e.IsData) .Select(e => e.Payload) - .ForEachAsync(x => outputList.Add(x)); + .ForEachAsync(outputList.Add); streamResult.Connect(); @@ -2249,7 +2252,7 @@ public void Select8() .ToEnumerable() .ToArray() ; - Assert.IsTrue(expected.Count() == output.Length); + Assert.AreEqual(output.Length, expected.Count()); for (int i = 0; i < output.Length; i++) Assert.IsTrue(expected.ElementAt(i).Equals(output[i])); } @@ -2316,10 +2319,32 @@ public void UnionWithBatchEndingInPastPunctuation() } [TestClass] + [DoNotParallelize] public class LeftComparerPayload_WithCodegen : TestWithConfigSettingsAndMemoryLeakDetection { public LeftComparerPayload_WithCodegen() - : base(new ConfigModifier().DontFallBackToRowBasedExecution(true)) { } + : base(new ConfigModifier() + .ForceRowBasedExecution(false) + .DontFallBackToRowBasedExecution(true)) { } + + // Named result type so the full closed generic EquiJoinStreamable<,,,,> can be + // referenced at compile time (anonymous types cannot be named in typeof/generic arguments). + public struct JoinResult { public int LeftX; public int RightX; } + + /// + /// Apply gated config first, then clear the join codegen cache. Ordering is important: + /// multiple test initializer methods do not have a guaranteed run order, so a separate + /// initializer could clear the cache before base setup applied + /// DontFallBackToRowBasedExecution, letting another test repopulate the cache. + /// + [TestInitialize] + public override void Setup() + { + base.Setup(); + // The join is built via Map+Reduce, so the inner EquiJoinStreamable uses TKey=CompoundGroupKey. + EquiJoinStreamable, ClassOverridingEquals, int, JoinResult> + .cachedPipes.Clear(); + } public class ClassOverridingEquals { @@ -2330,9 +2355,10 @@ public class ClassOverridingEquals } /// - /// This test has a left comparer which has a reference to the left - /// payload instead of just to its fields. This causes the streamable - /// to thrown an exception. + /// This test has a left comparer which has a reference to the left payload instead of + /// just to its fields. Codegen should always throw StreamProcessingException when + /// compiling this join fresh. The [TestInitialize] method clears the codegen cache + /// before this test runs to ensure deterministic behavior in the full test suite. /// [TestMethod] public void JoinTestWithException() @@ -2349,20 +2375,17 @@ public void JoinTestWithException() .ToStreamable() ; - bool exceptionHappened = false; + bool threw = false; try { - var result = stream1 - .Join(stream2, e => e.x, e => e, (left, right) => new { LeftX = left.x, RightX = right, }) - .ToStreamEventObservable() - .ToEnumerable() - .ToArray(); - } - catch (StreamProcessingException) - { - exceptionHappened = true; + stream1 + .Join(stream2, e => e.x, e => e, (left, right) => new JoinResult { LeftX = left.x, RightX = right }) + .ToStreamEventObservable() + .ToEnumerable() + .ToArray(); } - Assert.IsTrue(exceptionHappened); + catch (StreamProcessingException) { threw = true; } + Assert.IsTrue(threw, "Expected StreamProcessingException from codegen failure on ClassOverridingEquals"); } } @@ -2404,18 +2427,15 @@ public void JoinTestWithoutException() .ToStreamable() ; - try - { - var result = stream1 + + var result = stream1 .Join(stream2, e => e.x, e => e, (left, right) => new { LeftX = left.x, RightX = right, }) .ToStreamEventObservable() .ToEnumerable() .ToArray(); - Assert.IsTrue(true); // just test that no exception happened - } - catch (Exception) + if (object.ReferenceEquals(result, null)) { - Assert.IsTrue(false); // should never reach here. + // just to use the result and avoid "unused variable" warning } } @@ -2505,9 +2525,9 @@ public void ToEndEdgeFreeTest5() var expectedOutput = new StreamEvent>>[] { - StreamEvent.CreateInterval(1, 2, new List> { new RankedEvent(1, 'a') }), - StreamEvent.CreateInterval(2, 3, new List> { new RankedEvent(1, 'a') }), - StreamEvent.CreateInterval(3, 4, new List> { new RankedEvent(1, 'b') }), + StreamEvent.CreateInterval(1, 2, new List> { new(1, 'a') }), + StreamEvent.CreateInterval(2, 3, new List> { new(1, 'a') }), + StreamEvent.CreateInterval(3, 4, new List> { new(1, 'b') }), StreamEvent.CreatePunctuation>>(StreamEvent.InfinitySyncTime), }; var str = input.ToObservable().ToStreamable(null, FlushPolicy.FlushOnPunctuation, null, OnCompletedPolicy.None).Cache(); @@ -2554,7 +2574,7 @@ public void WhereWithClosure() // BUG? Should codegen be able to handle this? var s = "string"; var t = "another string"; - TestWhere(e => e.field2.mystring.Contains(s + t)); + this.TestWhere(e => e.field2.mystring.Contains(s + t)); } } diff --git a/Sources/Test/SimpleTesting/Aggregates/PerKeyAggregate.cs b/Sources/Test/SimpleTesting/Aggregates/PerKeyAggregate.cs index c3acc3535..5998c5884 100644 --- a/Sources/Test/SimpleTesting/Aggregates/PerKeyAggregate.cs +++ b/Sources/Test/SimpleTesting/Aggregates/PerKeyAggregate.cs @@ -4,7 +4,6 @@ // ********************************************************************* using System; using System.Collections.Generic; -using System.Diagnostics.CodeAnalysis; using System.Linq; using System.Reactive.Linq; using Microsoft.StreamProcessing; @@ -13,7 +12,6 @@ namespace SimpleTesting { - [SuppressMessage("StyleCop.CSharp.SpacingRules", "SA1009", Justification = "Reviewed.")] [TestClass] public class AggregateByKey : TestWithConfigSettingsAndMemoryLeakDetection { @@ -149,7 +147,7 @@ public void TestAggregateByKeyTupleDecomposition() input .GroupAggregate(s => true, w => w.Count(), (g, c) => ValueTuple.Create(g.Key, c)) .ToStreamEventObservable() - .ForEachAsync(e => output.Add(e)) + .ForEachAsync(output.Add) .Wait(); var correct = new[] diff --git a/Sources/Test/SimpleTesting/CheckpointRestoreTests.cs b/Sources/Test/SimpleTesting/CheckpointRestoreTests.cs index 02483aca7..2cae343d3 100644 --- a/Sources/Test/SimpleTesting/CheckpointRestoreTests.cs +++ b/Sources/Test/SimpleTesting/CheckpointRestoreTests.cs @@ -71,9 +71,9 @@ public void BasicUnaryCheckpointHoppingWindowSumRow() var output1 = container1.RegisterOutput(query1); - var outputAsync1 = output1.Where(e => e.IsData).ForEachAsync(o => outputListWithCheckpoint.Add(o)); + var outputAsync1 = output1.Where(e => e.IsData).ForEachAsync(outputListWithCheckpoint.Add); var pipe1 = container1.Restore(null); - preCheckpointData.ForEachAsync(e => preCheckpointSubject.OnNext(e)).Wait(); + preCheckpointData.ForEachAsync(preCheckpointSubject.OnNext).Wait(); pipe1.Checkpoint(state); state.Seek(0, SeekOrigin.Begin); @@ -83,10 +83,10 @@ public void BasicUnaryCheckpointHoppingWindowSumRow() var query2 = input2.HoppingWindowLifetime(window, period).Sum(e => (ulong)e); var output2 = container2.RegisterOutput(query2); - var outputAsync2 = output2.Where(e => e.IsData).ForEachAsync(o => outputListWithCheckpoint.Add(o)); + var outputAsync2 = output2.Where(e => e.IsData).ForEachAsync(outputListWithCheckpoint.Add); var pipe2 = container2.Restore(state); - postCheckpointData.ForEachAsync(e => postCheckpointSubject.OnNext(e)).Wait(); + postCheckpointData.ForEachAsync(postCheckpointSubject.OnNext).Wait(); postCheckpointSubject.OnCompleted(); outputAsync2.Wait(); outputListWithCheckpoint.Sort((x, y) => @@ -104,7 +104,7 @@ public void BasicUnaryCheckpointHoppingWindowSumRow() var query3 = input3.HoppingWindowLifetime(window, period).Sum(e => (ulong)e); var output3 = container3.RegisterOutput(query3); - var outputAsync3 = output3.Where(e => e.IsData).ForEachAsync(o => outputListWithoutCheckpoint.Add(o)); + var outputAsync3 = output3.Where(e => e.IsData).ForEachAsync(outputListWithoutCheckpoint.Add); container3.Restore(null); outputAsync3.Wait(); outputListWithoutCheckpoint.Sort((x, y) => @@ -200,9 +200,9 @@ public void BasicUnaryCheckpoint0Row() var query1 = CreateBasicQuery(input1); var output1 = container1.RegisterOutput(query1); - var outputAsync1 = output1.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(o => outputListWithCheckpoint.Add(o)); + var outputAsync1 = output1.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(outputListWithCheckpoint.Add); var pipe1 = container1.Restore(null); - preCheckpointData.ForEachAsync(e => preCheckpointSubject.OnNext(e)).Wait(); + preCheckpointData.ForEachAsync(preCheckpointSubject.OnNext).Wait(); pipe1.Checkpoint(state); state.Seek(0, SeekOrigin.Begin); @@ -212,9 +212,9 @@ public void BasicUnaryCheckpoint0Row() var query2 = CreateBasicQuery(input2); var output2 = container2.RegisterOutput(query2); - var outputAsync2 = output2.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(o => outputListWithCheckpoint.Add(o)); + var outputAsync2 = output2.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(outputListWithCheckpoint.Add); var pipe2 = container2.Restore(state); - postCheckpointData.ForEachAsync(e => postCheckpointSubject.OnNext(e)).Wait(); + postCheckpointData.ForEachAsync(postCheckpointSubject.OnNext).Wait(); postCheckpointSubject.OnCompleted(); outputAsync2.Wait(); outputListWithCheckpoint.Sort(); @@ -224,7 +224,7 @@ public void BasicUnaryCheckpoint0Row() var query3 = CreateBasicQuery(input3); var output3 = container3.RegisterOutput(query3); - var outputAsync3 = output3.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(o => outputListWithoutCheckpoint.Add(o)); + var outputAsync3 = output3.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(outputListWithoutCheckpoint.Add); container3.Restore(null); outputAsync3.Wait(); @@ -265,9 +265,9 @@ public void BasicUnaryCheckpointDisorderPolicyRow() var query1 = CreateBasicQuery(input1); var output1 = container1.RegisterOutput(query1); - var outputAsync1 = output1.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(o => outputListWithCheckpoint.Add(o)); + var outputAsync1 = output1.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(outputListWithCheckpoint.Add); var pipe1 = container1.Restore(null); - preCheckpointData.ForEachAsync(e => preCheckpointSubject.OnNext(e)).Wait(); + preCheckpointData.ForEachAsync(preCheckpointSubject.OnNext).Wait(); pipe1.Checkpoint(state); state.Seek(0, SeekOrigin.Begin); @@ -277,9 +277,9 @@ public void BasicUnaryCheckpointDisorderPolicyRow() var query2 = CreateBasicQuery(input2); var output2 = container2.RegisterOutput(query2); - var outputAsync2 = output2.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(o => outputListWithCheckpoint.Add(o)); + var outputAsync2 = output2.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(outputListWithCheckpoint.Add); var pipe2 = container2.Restore(state); - postCheckpointData.ForEachAsync(e => postCheckpointSubject.OnNext(e)).Wait(); + postCheckpointData.ForEachAsync(postCheckpointSubject.OnNext).Wait(); postCheckpointSubject.OnCompleted(); outputAsync2.Wait(); outputListWithCheckpoint.Sort(); @@ -289,7 +289,7 @@ public void BasicUnaryCheckpointDisorderPolicyRow() var query3 = CreateBasicQuery(input3); var output3 = container3.RegisterOutput(query3); - var outputAsync3 = output3.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(o => outputListWithoutCheckpoint.Add(o)); + var outputAsync3 = output3.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(outputListWithoutCheckpoint.Add); container3.Restore(null); outputAsync3.Wait(); @@ -333,9 +333,9 @@ public void BasicMulticastCheckpoint0Row() var query1 = query1_left.Union(query1right); var output1 = container1.RegisterOutput(query1); - var outputAsync1 = output1.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(o => outputListWithCheckpoint.Add(o)); + var outputAsync1 = output1.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(outputListWithCheckpoint.Add); var pipe1 = container1.Restore(null); - preCheckpointData.ForEachAsync(e => preCheckpointSubject.OnNext(e)).Wait(); + preCheckpointData.ForEachAsync(preCheckpointSubject.OnNext).Wait(); pipe1.Checkpoint(state); state.Seek(0, SeekOrigin.Begin); @@ -348,9 +348,9 @@ public void BasicMulticastCheckpoint0Row() var query2 = query2_left.Union(query2right); var output2 = container2.RegisterOutput(query2); - var outputAsync2 = output2.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(o => outputListWithCheckpoint.Add(o)); + var outputAsync2 = output2.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(outputListWithCheckpoint.Add); var pipe2 = container2.Restore(state); - postCheckpointData.ForEachAsync(e => postCheckpointSubject.OnNext(e)).Wait(); + postCheckpointData.ForEachAsync(postCheckpointSubject.OnNext).Wait(); postCheckpointSubject.OnCompleted(); outputAsync2.Wait(); outputListWithCheckpoint.Sort(); @@ -363,7 +363,7 @@ public void BasicMulticastCheckpoint0Row() var query3 = query3_left.Union(query3right); var output3 = container3.RegisterOutput(query3); - var outputAsync3 = output3.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(o => outputListWithoutCheckpoint.Add(o)); + var outputAsync3 = output3.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(outputListWithoutCheckpoint.Add); container3.Restore(null); outputAsync3.Wait(); outputListWithoutCheckpoint.Sort(); @@ -408,7 +408,7 @@ public void BasicUnaryCheckpointAnonTypeSelectManyRow() var outputAsync1 = output1.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(o => outputListWithCheckpoint.Add(o.p)); var pipe1 = container1.Restore(null); - preCheckpointData.ForEachAsync(e => preCheckpointSubject.OnNext(e)).Wait(); + preCheckpointData.ForEachAsync(preCheckpointSubject.OnNext).Wait(); pipe1.Checkpoint(state); state.Seek(0, SeekOrigin.Begin); @@ -420,7 +420,7 @@ public void BasicUnaryCheckpointAnonTypeSelectManyRow() var outputAsync2 = output2.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(o => outputListWithCheckpoint.Add(o.p)); var pipe2 = container2.Restore(state); - postCheckpointData.ForEachAsync(e => postCheckpointSubject.OnNext(e)).Wait(); + postCheckpointData.ForEachAsync(postCheckpointSubject.OnNext).Wait(); postCheckpointSubject.OnCompleted(); outputAsync2.Wait(); outputListWithCheckpoint.Sort(); @@ -472,9 +472,9 @@ public void BasicUnaryCheckpointCountRow() var output1 = container1.RegisterOutput(query1); - var outputAsync1 = output1.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(o => outputListWithCheckpoint.Add(o)); + var outputAsync1 = output1.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(outputListWithCheckpoint.Add); var pipe1 = container1.Restore(null); - preCheckpointData.ForEachAsync(e => preCheckpointSubject.OnNext(e)).Wait(); + preCheckpointData.ForEachAsync(preCheckpointSubject.OnNext).Wait(); pipe1.Checkpoint(state); state.Seek(0, SeekOrigin.Begin); @@ -484,9 +484,9 @@ public void BasicUnaryCheckpointCountRow() var query2 = input2.Count(); var output2 = container2.RegisterOutput(query2); - var outputAsync2 = output2.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(o => outputListWithCheckpoint.Add(o)); + var outputAsync2 = output2.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(outputListWithCheckpoint.Add); var pipe2 = container2.Restore(state); - postCheckpointData.ForEachAsync(e => postCheckpointSubject.OnNext(e)).Wait(); + postCheckpointData.ForEachAsync(postCheckpointSubject.OnNext).Wait(); postCheckpointSubject.OnCompleted(); outputAsync2.Wait(); outputListWithCheckpoint.Sort(); @@ -496,7 +496,7 @@ public void BasicUnaryCheckpointCountRow() var query3 = input3.Count(); var output3 = container3.RegisterOutput(query3); - var outputAsync3 = output3.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(o => outputListWithoutCheckpoint.Add(o)); + var outputAsync3 = output3.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(outputListWithoutCheckpoint.Add); container3.Restore(null); outputAsync3.Wait(); @@ -538,9 +538,9 @@ public void BasicUnaryCheckpointGroupedSumRow() var output1 = container1.RegisterOutput(query1); - var outputAsync1 = output1.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(o => outputListWithCheckpoint.Add(o)); + var outputAsync1 = output1.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(outputListWithCheckpoint.Add); var pipe1 = container1.Restore(null); - preCheckpointData.ForEachAsync(e => preCheckpointSubject.OnNext(e)).Wait(); + preCheckpointData.ForEachAsync(preCheckpointSubject.OnNext).Wait(); pipe1.Checkpoint(state); state.Seek(0, SeekOrigin.Begin); @@ -550,9 +550,9 @@ public void BasicUnaryCheckpointGroupedSumRow() var query2 = input2.GroupApply(e => e.Item1, str => str.Sum(e => (ulong)e.Item2), (g, c) => new StructTuple { Item1 = g.Key, Item2 = c }); var output2 = container2.RegisterOutput(query2); - var outputAsync2 = output2.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(o => outputListWithCheckpoint.Add(o)); + var outputAsync2 = output2.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(outputListWithCheckpoint.Add); var pipe2 = container2.Restore(state); - postCheckpointData.ForEachAsync(e => postCheckpointSubject.OnNext(e)).Wait(); + postCheckpointData.ForEachAsync(postCheckpointSubject.OnNext).Wait(); postCheckpointSubject.OnCompleted(); outputAsync2.Wait(); outputListWithCheckpoint.Sort((a, b) => a.Item1.CompareTo(b.Item1) == 0 ? a.Item2.CompareTo(b.Item2) : a.Item1.CompareTo(b.Item1)); @@ -562,7 +562,7 @@ public void BasicUnaryCheckpointGroupedSumRow() var query3 = input3.GroupApply(e => e.Item1, str => str.Sum(e => (ulong)e.Item2), (g, c) => new StructTuple { Item1 = g.Key, Item2 = c }); var output3 = container3.RegisterOutput(query3); - var outputAsync3 = output3.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(o => outputListWithoutCheckpoint.Add(o)); + var outputAsync3 = output3.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(outputListWithoutCheckpoint.Add); container3.Restore(null); outputAsync3.Wait(); @@ -620,11 +620,11 @@ public void BasicUnaryCheckpointEquiJoinRow() var output1 = container1.RegisterOutput(query1); - var outputAsync1 = output1.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(o => outputListWithCheckpoint.Add(o)); + var outputAsync1 = output1.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(outputListWithCheckpoint.Add); var pipe1 = container1.Restore(null); - preCheckpointData1.ForEachAsync(e => preCheckpointSubject1.OnNext(e)).Wait(); - preCheckpointData2.ForEachAsync(e => preCheckpointSubject2.OnNext(e)).Wait(); + preCheckpointData1.ForEachAsync(preCheckpointSubject1.OnNext).Wait(); + preCheckpointData2.ForEachAsync(preCheckpointSubject2.OnNext).Wait(); pipe1.Checkpoint(state); @@ -636,11 +636,11 @@ public void BasicUnaryCheckpointEquiJoinRow() var query2 = input21.Join(input22, e => e.Item1, e => e.Item1, (l, r) => new StructTuple { Item1 = l.Item1, Item2 = r.Item2 }); var output2 = container2.RegisterOutput(query2); - var outputAsync2 = output2.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(o => outputListWithCheckpoint.Add(o)); + var outputAsync2 = output2.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(outputListWithCheckpoint.Add); var pipe2 = container2.Restore(state); - postCheckpointData1.ForEachAsync(e => postCheckpointSubject1.OnNext(e)).Wait(); - postCheckpointData2.ForEachAsync(e => postCheckpointSubject2.OnNext(e)).Wait(); + postCheckpointData1.ForEachAsync(postCheckpointSubject1.OnNext).Wait(); + postCheckpointData2.ForEachAsync(postCheckpointSubject2.OnNext).Wait(); postCheckpointSubject1.OnCompleted(); postCheckpointSubject2.OnCompleted(); outputAsync2.Wait(); @@ -652,7 +652,7 @@ public void BasicUnaryCheckpointEquiJoinRow() var query3 = input31.Join(input32, e => e.Item1, e => e.Item1, (l, r) => new StructTuple { Item1 = l.Item1, Item2 = r.Item2 }); var output3 = container3.RegisterOutput(query3); - var outputAsync3 = output3.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(o => outputListWithoutCheckpoint.Add(o)); + var outputAsync3 = output3.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(outputListWithoutCheckpoint.Add); container3.Restore(null); outputAsync3.Wait(); @@ -713,11 +713,11 @@ public void BasicUnaryCheckpointLASJRow() var output1 = container1.RegisterOutput(query1); - var outputAsync1 = output1.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(o => outputListWithCheckpoint.Add(o)); + var outputAsync1 = output1.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(outputListWithCheckpoint.Add); var pipe1 = container1.Restore(null); - preCheckpointData1.ForEachAsync(e => preCheckpointSubject1.OnNext(e)).Wait(); - preCheckpointData2.ForEachAsync(e => preCheckpointSubject2.OnNext(e)).Wait(); + preCheckpointData1.ForEachAsync(preCheckpointSubject1.OnNext).Wait(); + preCheckpointData2.ForEachAsync(preCheckpointSubject2.OnNext).Wait(); pipe1.Checkpoint(state); @@ -729,11 +729,11 @@ public void BasicUnaryCheckpointLASJRow() var query2 = input21.WhereNotExists(input22, e => e.Item1, e => e.Item1); var output2 = container2.RegisterOutput(query2); - var outputAsync2 = output2.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(o => outputListWithCheckpoint.Add(o)); + var outputAsync2 = output2.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(outputListWithCheckpoint.Add); var pipe2 = container2.Restore(state); - postCheckpointData1.ForEachAsync(e => postCheckpointSubject1.OnNext(e)).Wait(); - postCheckpointData2.ForEachAsync(e => postCheckpointSubject2.OnNext(e)).Wait(); + postCheckpointData1.ForEachAsync(postCheckpointSubject1.OnNext).Wait(); + postCheckpointData2.ForEachAsync(postCheckpointSubject2.OnNext).Wait(); postCheckpointSubject1.OnCompleted(); postCheckpointSubject2.OnCompleted(); outputAsync2.Wait(); @@ -745,7 +745,7 @@ public void BasicUnaryCheckpointLASJRow() var query3 = input31.WhereNotExists(input32, e => e.Item1, e => e.Item1); var output3 = container3.RegisterOutput(query3); - var outputAsync3 = output3.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(o => outputListWithoutCheckpoint.Add(o)); + var outputAsync3 = output3.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(outputListWithoutCheckpoint.Add); container3.Restore(null); outputAsync3.Wait(); @@ -806,11 +806,11 @@ public void LeftUnaryCheckpointLASJRow() var output1 = container1.RegisterOutput(query1); - var outputAsync1 = output1.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(o => outputListWithCheckpoint.Add(o)); + var outputAsync1 = output1.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(outputListWithCheckpoint.Add); var pipe1 = container1.Restore(null); - preCheckpointData1.ForEachAsync(e => preCheckpointSubject1.OnNext(e)).Wait(); - preCheckpointData2.ForEachAsync(e => preCheckpointSubject2.OnNext(e)).Wait(); + preCheckpointData1.ForEachAsync(preCheckpointSubject1.OnNext).Wait(); + preCheckpointData2.ForEachAsync(preCheckpointSubject2.OnNext).Wait(); pipe1.Checkpoint(state); @@ -822,11 +822,11 @@ public void LeftUnaryCheckpointLASJRow() var query2 = input21.WhereNotExists(input22, e => e.Item1, e => e.Item1); var output2 = container2.RegisterOutput(query2); - var outputAsync2 = output2.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(o => outputListWithCheckpoint.Add(o)); + var outputAsync2 = output2.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(outputListWithCheckpoint.Add); var pipe2 = container2.Restore(state); - postCheckpointData1.ForEachAsync(e => postCheckpointSubject1.OnNext(e)).Wait(); - postCheckpointData2.ForEachAsync(e => postCheckpointSubject2.OnNext(e)).Wait(); + postCheckpointData1.ForEachAsync(postCheckpointSubject1.OnNext).Wait(); + postCheckpointData2.ForEachAsync(postCheckpointSubject2.OnNext).Wait(); postCheckpointSubject1.OnCompleted(); postCheckpointSubject2.OnCompleted(); outputAsync2.Wait(); @@ -838,7 +838,7 @@ public void LeftUnaryCheckpointLASJRow() var query3 = input31.WhereNotExists(input32, e => e.Item1, e => e.Item1); var output3 = container3.RegisterOutput(query3); - var outputAsync3 = output3.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(o => outputListWithoutCheckpoint.Add(o)); + var outputAsync3 = output3.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(outputListWithoutCheckpoint.Add); container3.Restore(null); outputAsync3.Wait(); @@ -899,11 +899,11 @@ public void RightUnaryCheckpointLASJRow() var output1 = container1.RegisterOutput(query1); - var outputAsync1 = output1.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(o => outputListWithCheckpoint.Add(o)); + var outputAsync1 = output1.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(outputListWithCheckpoint.Add); var pipe1 = container1.Restore(null); - preCheckpointData1.ForEachAsync(e => preCheckpointSubject1.OnNext(e)).Wait(); - preCheckpointData2.ForEachAsync(e => preCheckpointSubject2.OnNext(e)).Wait(); + preCheckpointData1.ForEachAsync(preCheckpointSubject1.OnNext).Wait(); + preCheckpointData2.ForEachAsync(preCheckpointSubject2.OnNext).Wait(); pipe1.Checkpoint(state); @@ -915,11 +915,11 @@ public void RightUnaryCheckpointLASJRow() var query2 = input21.WhereNotExists(input22, e => e.Item1, e => e.Item1); var output2 = container2.RegisterOutput(query2); - var outputAsync2 = output2.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(o => outputListWithCheckpoint.Add(o)); + var outputAsync2 = output2.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(outputListWithCheckpoint.Add); var pipe2 = container2.Restore(state); - postCheckpointData1.ForEachAsync(e => postCheckpointSubject1.OnNext(e)).Wait(); - postCheckpointData2.ForEachAsync(e => postCheckpointSubject2.OnNext(e)).Wait(); + postCheckpointData1.ForEachAsync(postCheckpointSubject1.OnNext).Wait(); + postCheckpointData2.ForEachAsync(postCheckpointSubject2.OnNext).Wait(); postCheckpointSubject1.OnCompleted(); postCheckpointSubject2.OnCompleted(); outputAsync2.Wait(); @@ -931,7 +931,7 @@ public void RightUnaryCheckpointLASJRow() var query3 = input31.WhereNotExists(input32, e => e.Item1, e => e.Item1); var output3 = container3.RegisterOutput(query3); - var outputAsync3 = output3.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(o => outputListWithoutCheckpoint.Add(o)); + var outputAsync3 = output3.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(outputListWithoutCheckpoint.Add); container3.Restore(null); outputAsync3.Wait(); @@ -977,10 +977,10 @@ public void SelfUnaryCheckpointLASJRow() var output1 = container1.RegisterOutput(query1); - var outputAsync1 = output1.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(o => outputListWithCheckpoint.Add(o)); + var outputAsync1 = output1.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(outputListWithCheckpoint.Add); var pipe1 = container1.Restore(null); - preCheckpointData.ForEachAsync(e => preCheckpointSubject.OnNext(e)).Wait(); + preCheckpointData.ForEachAsync(preCheckpointSubject.OnNext).Wait(); pipe1.Checkpoint(state); @@ -991,10 +991,10 @@ public void SelfUnaryCheckpointLASJRow() var query2 = input2.GroupApply(o => 1, s => s.Multicast(p => p.WhereNotExists(p.Where(i => false), e => e.Item1, e => e.Item1))); var output2 = container2.RegisterOutput(query2); - var outputAsync2 = output2.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(o => outputListWithCheckpoint.Add(o)); + var outputAsync2 = output2.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(outputListWithCheckpoint.Add); var pipe2 = container2.Restore(state); - postCheckpointData.ForEachAsync(e => postCheckpointSubject.OnNext(e)).Wait(); + postCheckpointData.ForEachAsync(postCheckpointSubject.OnNext).Wait(); postCheckpointSubject.OnCompleted(); outputAsync2.Wait(); outputListWithCheckpoint.Sort((a, b) => a.Item1.CompareTo(b.Item1) == 0 ? a.Item2.CompareTo(b.Item2) : a.Item1.CompareTo(b.Item1)); @@ -1004,7 +1004,7 @@ public void SelfUnaryCheckpointLASJRow() var query3 = input3.GroupApply(o => 1, s => s.Multicast(p => p.WhereNotExists(p.Where(i => false), e => e.Item1, e => e.Item1))); var output3 = container3.RegisterOutput(query3); - var outputAsync3 = output3.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(o => outputListWithoutCheckpoint.Add(o)); + var outputAsync3 = output3.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(outputListWithoutCheckpoint.Add); container3.Restore(null); outputAsync3.Wait(); @@ -1064,11 +1064,11 @@ public void BasicUnaryCheckpointClipRow() var output1 = container1.RegisterOutput(query1); - var outputAsync1 = output1.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(o => outputListWithCheckpoint.Add(o)); + var outputAsync1 = output1.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(outputListWithCheckpoint.Add); var pipe1 = container1.Restore(null); - preCheckpointData1.ForEachAsync(e => preCheckpointSubject1.OnNext(e)).Wait(); - preCheckpointData2.ForEachAsync(e => preCheckpointSubject2.OnNext(e)).Wait(); + preCheckpointData1.ForEachAsync(preCheckpointSubject1.OnNext).Wait(); + preCheckpointData2.ForEachAsync(preCheckpointSubject2.OnNext).Wait(); pipe1.Checkpoint(state); @@ -1080,11 +1080,11 @@ public void BasicUnaryCheckpointClipRow() var query2 = input21.ClipEventDuration(input22, e => e.Item1, e => e.Item1); var output2 = container2.RegisterOutput(query2); - var outputAsync2 = output2.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(o => outputListWithCheckpoint.Add(o)); + var outputAsync2 = output2.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(outputListWithCheckpoint.Add); var pipe2 = container2.Restore(state); - postCheckpointData1.ForEachAsync(e => postCheckpointSubject1.OnNext(e)).Wait(); - postCheckpointData2.ForEachAsync(e => postCheckpointSubject2.OnNext(e)).Wait(); + postCheckpointData1.ForEachAsync(postCheckpointSubject1.OnNext).Wait(); + postCheckpointData2.ForEachAsync(postCheckpointSubject2.OnNext).Wait(); postCheckpointSubject1.OnCompleted(); postCheckpointSubject2.OnCompleted(); outputAsync2.Wait(); @@ -1096,7 +1096,7 @@ public void BasicUnaryCheckpointClipRow() var query3 = input31.ClipEventDuration(input32, e => e.Item1, e => e.Item1); var output3 = container3.RegisterOutput(query3); - var outputAsync3 = output3.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(o => outputListWithoutCheckpoint.Add(o)); + var outputAsync3 = output3.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(outputListWithoutCheckpoint.Add); container3.Restore(null); outputAsync3.Wait(); @@ -1139,7 +1139,7 @@ public void BasicEmptyCheckpointErrorRow() var query1 = query1_left.Union(query1right); var output1 = container1.RegisterOutput(query1); - var outputAsync1 = output1.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(o => outputListWithCheckpoint.Add(o)); + var outputAsync1 = output1.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(outputListWithCheckpoint.Add); try { @@ -1185,9 +1185,9 @@ public void BasicUnaryCheckpointErrorRow() var query1 = CreateBasicQuery(input1); var output1 = container1.RegisterOutput(query1); - var outputAsync1 = output1.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(o => outputList.Add(o)); + var outputAsync1 = output1.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(outputList.Add); var pipe1 = container1.Restore(null); - preCheckpointData.ForEachAsync(e => preCheckpointSubject.OnNext(e)).Wait(); + preCheckpointData.ForEachAsync(preCheckpointSubject.OnNext).Wait(); pipe1.Checkpoint(state); state.Seek(0, SeekOrigin.Begin); @@ -1197,9 +1197,9 @@ public void BasicUnaryCheckpointErrorRow() var query2 = CreateBasicQuery(input2); var output2 = container2.RegisterOutput(query2); - var outputAsync2 = output2.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(o => outputList.Add(o)); + var outputAsync2 = output2.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(outputList.Add); var pipe2 = container2.Restore(state); - postCheckpointData.ForEachAsync(e => postCheckpointSubject.OnNext(e)).Wait(); + postCheckpointData.ForEachAsync(postCheckpointSubject.OnNext).Wait(); outputAsync2.Wait(); } catch (AggregateException e) @@ -1243,9 +1243,9 @@ public void BasicDisorderPolicyErrorRow() var query1 = CreateBasicQuery(input1); var output1 = container1.RegisterOutput(query1); - var outputAsync1 = output1.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(o => outputList.Add(o)); + var outputAsync1 = output1.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(outputList.Add); var pipe1 = container1.Restore(null); - preCheckpointData.ForEachAsync(e => preCheckpointSubject.OnNext(e)).Wait(); + preCheckpointData.ForEachAsync(preCheckpointSubject.OnNext).Wait(); pipe1.Checkpoint(state); state.Seek(0, SeekOrigin.Begin); @@ -1257,9 +1257,9 @@ public void BasicDisorderPolicyErrorRow() var query2 = CreateBasicQuery(input2); var output2 = container2.RegisterOutput(query2); - var outputAsync2 = output2.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(o => outputList.Add(o)); + var outputAsync2 = output2.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(outputList.Add); var pipe2 = container2.Restore(state); - postCheckpointData.ForEachAsync(e => postCheckpointSubject.OnNext(e)).Wait(); + postCheckpointData.ForEachAsync(postCheckpointSubject.OnNext).Wait(); postCheckpointSubject.OnCompleted(); outputAsync2.Wait(); } @@ -1300,9 +1300,9 @@ public void BasicDisorderAdjustPolicyRow() var query1 = CreateBasicQuery(input1); var output1 = container1.RegisterOutput(query1); - var outputAsync1 = output1.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(o => outputList.Add(o)); + var outputAsync1 = output1.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(outputList.Add); var pipe1 = container1.Restore(null); - preCheckpointData.ForEachAsync(e => preCheckpointSubject.OnNext(e)).Wait(); + preCheckpointData.ForEachAsync(preCheckpointSubject.OnNext).Wait(); pipe1.Checkpoint(state); state.Seek(0, SeekOrigin.Begin); @@ -1312,13 +1312,13 @@ public void BasicDisorderAdjustPolicyRow() var query2 = CreateBasicQuery(input2); var output2 = container2.RegisterOutput(query2); - var outputAsync2 = output2.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(o => outputList.Add(o)); + var outputAsync2 = output2.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(outputList.Add); var pipe2 = container2.Restore(state); - postCheckpointData.ForEachAsync(e => postCheckpointSubject.OnNext(e)).Wait(); + postCheckpointData.ForEachAsync(postCheckpointSubject.OnNext).Wait(); postCheckpointSubject.OnCompleted(); outputAsync2.Wait(); - Assert.IsTrue(outputList.Count == 10000); + Assert.HasCount(10000, outputList); preCheckpointSubject.OnCompleted(); } @@ -1542,9 +1542,9 @@ public void BasicUnaryCheckpointHoppingWindowSumRowSmallBatch() var output1 = container1.RegisterOutput(query1); - var outputAsync1 = output1.Where(e => e.IsData).ForEachAsync(o => outputListWithCheckpoint.Add(o)); + var outputAsync1 = output1.Where(e => e.IsData).ForEachAsync(outputListWithCheckpoint.Add); var pipe1 = container1.Restore(null); - preCheckpointData.ForEachAsync(e => preCheckpointSubject.OnNext(e)).Wait(); + preCheckpointData.ForEachAsync(preCheckpointSubject.OnNext).Wait(); pipe1.Checkpoint(state); state.Seek(0, SeekOrigin.Begin); @@ -1554,10 +1554,10 @@ public void BasicUnaryCheckpointHoppingWindowSumRowSmallBatch() var query2 = input2.HoppingWindowLifetime(window, period).Sum(e => (ulong)e); var output2 = container2.RegisterOutput(query2); - var outputAsync2 = output2.Where(e => e.IsData).ForEachAsync(o => outputListWithCheckpoint.Add(o)); + var outputAsync2 = output2.Where(e => e.IsData).ForEachAsync(outputListWithCheckpoint.Add); var pipe2 = container2.Restore(state); - postCheckpointData.ForEachAsync(e => postCheckpointSubject.OnNext(e)).Wait(); + postCheckpointData.ForEachAsync(postCheckpointSubject.OnNext).Wait(); postCheckpointSubject.OnCompleted(); outputAsync2.Wait(); outputListWithCheckpoint.Sort((x, y) => @@ -1575,7 +1575,7 @@ public void BasicUnaryCheckpointHoppingWindowSumRowSmallBatch() var query3 = input3.HoppingWindowLifetime(window, period).Sum(e => (ulong)e); var output3 = container3.RegisterOutput(query3); - var outputAsync3 = output3.Where(e => e.IsData).ForEachAsync(o => outputListWithoutCheckpoint.Add(o)); + var outputAsync3 = output3.Where(e => e.IsData).ForEachAsync(outputListWithoutCheckpoint.Add); container3.Restore(null); outputAsync3.Wait(); outputListWithoutCheckpoint.Sort((x, y) => @@ -1672,9 +1672,9 @@ public void BasicUnaryCheckpoint0RowSmallBatch() var query1 = CreateBasicQuery(input1); var output1 = container1.RegisterOutput(query1); - var outputAsync1 = output1.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(o => outputListWithCheckpoint.Add(o)); + var outputAsync1 = output1.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(outputListWithCheckpoint.Add); var pipe1 = container1.Restore(null); - preCheckpointData.ForEachAsync(e => preCheckpointSubject.OnNext(e)).Wait(); + preCheckpointData.ForEachAsync(preCheckpointSubject.OnNext).Wait(); pipe1.Checkpoint(state); state.Seek(0, SeekOrigin.Begin); @@ -1684,9 +1684,9 @@ public void BasicUnaryCheckpoint0RowSmallBatch() var query2 = CreateBasicQuery(input2); var output2 = container2.RegisterOutput(query2); - var outputAsync2 = output2.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(o => outputListWithCheckpoint.Add(o)); + var outputAsync2 = output2.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(outputListWithCheckpoint.Add); var pipe2 = container2.Restore(state); - postCheckpointData.ForEachAsync(e => postCheckpointSubject.OnNext(e)).Wait(); + postCheckpointData.ForEachAsync(postCheckpointSubject.OnNext).Wait(); postCheckpointSubject.OnCompleted(); outputAsync2.Wait(); outputListWithCheckpoint.Sort(); @@ -1696,7 +1696,7 @@ public void BasicUnaryCheckpoint0RowSmallBatch() var query3 = CreateBasicQuery(input3); var output3 = container3.RegisterOutput(query3); - var outputAsync3 = output3.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(o => outputListWithoutCheckpoint.Add(o)); + var outputAsync3 = output3.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(outputListWithoutCheckpoint.Add); container3.Restore(null); outputAsync3.Wait(); @@ -1737,9 +1737,9 @@ public void BasicUnaryCheckpointDisorderPolicyRowSmallBatch() var query1 = CreateBasicQuery(input1); var output1 = container1.RegisterOutput(query1); - var outputAsync1 = output1.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(o => outputListWithCheckpoint.Add(o)); + var outputAsync1 = output1.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(outputListWithCheckpoint.Add); var pipe1 = container1.Restore(null); - preCheckpointData.ForEachAsync(e => preCheckpointSubject.OnNext(e)).Wait(); + preCheckpointData.ForEachAsync(preCheckpointSubject.OnNext).Wait(); pipe1.Checkpoint(state); state.Seek(0, SeekOrigin.Begin); @@ -1749,9 +1749,9 @@ public void BasicUnaryCheckpointDisorderPolicyRowSmallBatch() var query2 = CreateBasicQuery(input2); var output2 = container2.RegisterOutput(query2); - var outputAsync2 = output2.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(o => outputListWithCheckpoint.Add(o)); + var outputAsync2 = output2.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(outputListWithCheckpoint.Add); var pipe2 = container2.Restore(state); - postCheckpointData.ForEachAsync(e => postCheckpointSubject.OnNext(e)).Wait(); + postCheckpointData.ForEachAsync(postCheckpointSubject.OnNext).Wait(); postCheckpointSubject.OnCompleted(); outputAsync2.Wait(); outputListWithCheckpoint.Sort(); @@ -1761,7 +1761,7 @@ public void BasicUnaryCheckpointDisorderPolicyRowSmallBatch() var query3 = CreateBasicQuery(input3); var output3 = container3.RegisterOutput(query3); - var outputAsync3 = output3.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(o => outputListWithoutCheckpoint.Add(o)); + var outputAsync3 = output3.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(outputListWithoutCheckpoint.Add); container3.Restore(null); outputAsync3.Wait(); @@ -1805,9 +1805,9 @@ public void BasicMulticastCheckpoint0RowSmallBatch() var query1 = query1_left.Union(query1right); var output1 = container1.RegisterOutput(query1); - var outputAsync1 = output1.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(o => outputListWithCheckpoint.Add(o)); + var outputAsync1 = output1.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(outputListWithCheckpoint.Add); var pipe1 = container1.Restore(null); - preCheckpointData.ForEachAsync(e => preCheckpointSubject.OnNext(e)).Wait(); + preCheckpointData.ForEachAsync(preCheckpointSubject.OnNext).Wait(); pipe1.Checkpoint(state); state.Seek(0, SeekOrigin.Begin); @@ -1820,9 +1820,9 @@ public void BasicMulticastCheckpoint0RowSmallBatch() var query2 = query2_left.Union(query2right); var output2 = container2.RegisterOutput(query2); - var outputAsync2 = output2.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(o => outputListWithCheckpoint.Add(o)); + var outputAsync2 = output2.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(outputListWithCheckpoint.Add); var pipe2 = container2.Restore(state); - postCheckpointData.ForEachAsync(e => postCheckpointSubject.OnNext(e)).Wait(); + postCheckpointData.ForEachAsync(postCheckpointSubject.OnNext).Wait(); postCheckpointSubject.OnCompleted(); outputAsync2.Wait(); outputListWithCheckpoint.Sort(); @@ -1835,7 +1835,7 @@ public void BasicMulticastCheckpoint0RowSmallBatch() var query3 = query3_left.Union(query3right); var output3 = container3.RegisterOutput(query3); - var outputAsync3 = output3.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(o => outputListWithoutCheckpoint.Add(o)); + var outputAsync3 = output3.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(outputListWithoutCheckpoint.Add); container3.Restore(null); outputAsync3.Wait(); outputListWithoutCheckpoint.Sort(); @@ -1880,7 +1880,7 @@ public void BasicUnaryCheckpointAnonTypeSelectManyRowSmallBatch() var outputAsync1 = output1.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(o => outputListWithCheckpoint.Add(o.p)); var pipe1 = container1.Restore(null); - preCheckpointData.ForEachAsync(e => preCheckpointSubject.OnNext(e)).Wait(); + preCheckpointData.ForEachAsync(preCheckpointSubject.OnNext).Wait(); pipe1.Checkpoint(state); state.Seek(0, SeekOrigin.Begin); @@ -1892,7 +1892,7 @@ public void BasicUnaryCheckpointAnonTypeSelectManyRowSmallBatch() var outputAsync2 = output2.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(o => outputListWithCheckpoint.Add(o.p)); var pipe2 = container2.Restore(state); - postCheckpointData.ForEachAsync(e => postCheckpointSubject.OnNext(e)).Wait(); + postCheckpointData.ForEachAsync(postCheckpointSubject.OnNext).Wait(); postCheckpointSubject.OnCompleted(); outputAsync2.Wait(); outputListWithCheckpoint.Sort(); @@ -1944,9 +1944,9 @@ public void BasicUnaryCheckpointCountRowSmallBatch() var output1 = container1.RegisterOutput(query1); - var outputAsync1 = output1.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(o => outputListWithCheckpoint.Add(o)); + var outputAsync1 = output1.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(outputListWithCheckpoint.Add); var pipe1 = container1.Restore(null); - preCheckpointData.ForEachAsync(e => preCheckpointSubject.OnNext(e)).Wait(); + preCheckpointData.ForEachAsync(preCheckpointSubject.OnNext).Wait(); pipe1.Checkpoint(state); state.Seek(0, SeekOrigin.Begin); @@ -1956,9 +1956,9 @@ public void BasicUnaryCheckpointCountRowSmallBatch() var query2 = input2.Count(); var output2 = container2.RegisterOutput(query2); - var outputAsync2 = output2.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(o => outputListWithCheckpoint.Add(o)); + var outputAsync2 = output2.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(outputListWithCheckpoint.Add); var pipe2 = container2.Restore(state); - postCheckpointData.ForEachAsync(e => postCheckpointSubject.OnNext(e)).Wait(); + postCheckpointData.ForEachAsync(postCheckpointSubject.OnNext).Wait(); postCheckpointSubject.OnCompleted(); outputAsync2.Wait(); outputListWithCheckpoint.Sort(); @@ -1968,7 +1968,7 @@ public void BasicUnaryCheckpointCountRowSmallBatch() var query3 = input3.Count(); var output3 = container3.RegisterOutput(query3); - var outputAsync3 = output3.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(o => outputListWithoutCheckpoint.Add(o)); + var outputAsync3 = output3.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(outputListWithoutCheckpoint.Add); container3.Restore(null); outputAsync3.Wait(); @@ -2010,9 +2010,9 @@ public void BasicUnaryCheckpointGroupedSumRowSmallBatch() var output1 = container1.RegisterOutput(query1); - var outputAsync1 = output1.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(o => outputListWithCheckpoint.Add(o)); + var outputAsync1 = output1.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(outputListWithCheckpoint.Add); var pipe1 = container1.Restore(null); - preCheckpointData.ForEachAsync(e => preCheckpointSubject.OnNext(e)).Wait(); + preCheckpointData.ForEachAsync(preCheckpointSubject.OnNext).Wait(); pipe1.Checkpoint(state); state.Seek(0, SeekOrigin.Begin); @@ -2022,9 +2022,9 @@ public void BasicUnaryCheckpointGroupedSumRowSmallBatch() var query2 = input2.GroupApply(e => e.Item1, str => str.Sum(e => (ulong)e.Item2), (g, c) => new StructTuple { Item1 = g.Key, Item2 = c }); var output2 = container2.RegisterOutput(query2); - var outputAsync2 = output2.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(o => outputListWithCheckpoint.Add(o)); + var outputAsync2 = output2.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(outputListWithCheckpoint.Add); var pipe2 = container2.Restore(state); - postCheckpointData.ForEachAsync(e => postCheckpointSubject.OnNext(e)).Wait(); + postCheckpointData.ForEachAsync(postCheckpointSubject.OnNext).Wait(); postCheckpointSubject.OnCompleted(); outputAsync2.Wait(); outputListWithCheckpoint.Sort((a, b) => a.Item1.CompareTo(b.Item1) == 0 ? a.Item2.CompareTo(b.Item2) : a.Item1.CompareTo(b.Item1)); @@ -2034,7 +2034,7 @@ public void BasicUnaryCheckpointGroupedSumRowSmallBatch() var query3 = input3.GroupApply(e => e.Item1, str => str.Sum(e => (ulong)e.Item2), (g, c) => new StructTuple { Item1 = g.Key, Item2 = c }); var output3 = container3.RegisterOutput(query3); - var outputAsync3 = output3.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(o => outputListWithoutCheckpoint.Add(o)); + var outputAsync3 = output3.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(outputListWithoutCheckpoint.Add); container3.Restore(null); outputAsync3.Wait(); @@ -2092,11 +2092,11 @@ public void BasicUnaryCheckpointEquiJoinRowSmallBatch() var output1 = container1.RegisterOutput(query1); - var outputAsync1 = output1.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(o => outputListWithCheckpoint.Add(o)); + var outputAsync1 = output1.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(outputListWithCheckpoint.Add); var pipe1 = container1.Restore(null); - preCheckpointData1.ForEachAsync(e => preCheckpointSubject1.OnNext(e)).Wait(); - preCheckpointData2.ForEachAsync(e => preCheckpointSubject2.OnNext(e)).Wait(); + preCheckpointData1.ForEachAsync(preCheckpointSubject1.OnNext).Wait(); + preCheckpointData2.ForEachAsync(preCheckpointSubject2.OnNext).Wait(); pipe1.Checkpoint(state); @@ -2108,11 +2108,11 @@ public void BasicUnaryCheckpointEquiJoinRowSmallBatch() var query2 = input21.Join(input22, e => e.Item1, e => e.Item1, (l, r) => new StructTuple { Item1 = l.Item1, Item2 = r.Item2 }); var output2 = container2.RegisterOutput(query2); - var outputAsync2 = output2.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(o => outputListWithCheckpoint.Add(o)); + var outputAsync2 = output2.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(outputListWithCheckpoint.Add); var pipe2 = container2.Restore(state); - postCheckpointData1.ForEachAsync(e => postCheckpointSubject1.OnNext(e)).Wait(); - postCheckpointData2.ForEachAsync(e => postCheckpointSubject2.OnNext(e)).Wait(); + postCheckpointData1.ForEachAsync(postCheckpointSubject1.OnNext).Wait(); + postCheckpointData2.ForEachAsync(postCheckpointSubject2.OnNext).Wait(); postCheckpointSubject1.OnCompleted(); postCheckpointSubject2.OnCompleted(); outputAsync2.Wait(); @@ -2124,7 +2124,7 @@ public void BasicUnaryCheckpointEquiJoinRowSmallBatch() var query3 = input31.Join(input32, e => e.Item1, e => e.Item1, (l, r) => new StructTuple { Item1 = l.Item1, Item2 = r.Item2 }); var output3 = container3.RegisterOutput(query3); - var outputAsync3 = output3.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(o => outputListWithoutCheckpoint.Add(o)); + var outputAsync3 = output3.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(outputListWithoutCheckpoint.Add); container3.Restore(null); outputAsync3.Wait(); @@ -2185,11 +2185,11 @@ public void BasicUnaryCheckpointLASJRowSmallBatch() var output1 = container1.RegisterOutput(query1); - var outputAsync1 = output1.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(o => outputListWithCheckpoint.Add(o)); + var outputAsync1 = output1.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(outputListWithCheckpoint.Add); var pipe1 = container1.Restore(null); - preCheckpointData1.ForEachAsync(e => preCheckpointSubject1.OnNext(e)).Wait(); - preCheckpointData2.ForEachAsync(e => preCheckpointSubject2.OnNext(e)).Wait(); + preCheckpointData1.ForEachAsync(preCheckpointSubject1.OnNext).Wait(); + preCheckpointData2.ForEachAsync(preCheckpointSubject2.OnNext).Wait(); pipe1.Checkpoint(state); @@ -2201,11 +2201,11 @@ public void BasicUnaryCheckpointLASJRowSmallBatch() var query2 = input21.WhereNotExists(input22, e => e.Item1, e => e.Item1); var output2 = container2.RegisterOutput(query2); - var outputAsync2 = output2.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(o => outputListWithCheckpoint.Add(o)); + var outputAsync2 = output2.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(outputListWithCheckpoint.Add); var pipe2 = container2.Restore(state); - postCheckpointData1.ForEachAsync(e => postCheckpointSubject1.OnNext(e)).Wait(); - postCheckpointData2.ForEachAsync(e => postCheckpointSubject2.OnNext(e)).Wait(); + postCheckpointData1.ForEachAsync(postCheckpointSubject1.OnNext).Wait(); + postCheckpointData2.ForEachAsync(postCheckpointSubject2.OnNext).Wait(); postCheckpointSubject1.OnCompleted(); postCheckpointSubject2.OnCompleted(); outputAsync2.Wait(); @@ -2217,7 +2217,7 @@ public void BasicUnaryCheckpointLASJRowSmallBatch() var query3 = input31.WhereNotExists(input32, e => e.Item1, e => e.Item1); var output3 = container3.RegisterOutput(query3); - var outputAsync3 = output3.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(o => outputListWithoutCheckpoint.Add(o)); + var outputAsync3 = output3.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(outputListWithoutCheckpoint.Add); container3.Restore(null); outputAsync3.Wait(); @@ -2278,11 +2278,11 @@ public void LeftUnaryCheckpointLASJRowSmallBatch() var output1 = container1.RegisterOutput(query1); - var outputAsync1 = output1.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(o => outputListWithCheckpoint.Add(o)); + var outputAsync1 = output1.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(outputListWithCheckpoint.Add); var pipe1 = container1.Restore(null); - preCheckpointData1.ForEachAsync(e => preCheckpointSubject1.OnNext(e)).Wait(); - preCheckpointData2.ForEachAsync(e => preCheckpointSubject2.OnNext(e)).Wait(); + preCheckpointData1.ForEachAsync(preCheckpointSubject1.OnNext).Wait(); + preCheckpointData2.ForEachAsync(preCheckpointSubject2.OnNext).Wait(); pipe1.Checkpoint(state); @@ -2294,11 +2294,11 @@ public void LeftUnaryCheckpointLASJRowSmallBatch() var query2 = input21.WhereNotExists(input22, e => e.Item1, e => e.Item1); var output2 = container2.RegisterOutput(query2); - var outputAsync2 = output2.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(o => outputListWithCheckpoint.Add(o)); + var outputAsync2 = output2.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(outputListWithCheckpoint.Add); var pipe2 = container2.Restore(state); - postCheckpointData1.ForEachAsync(e => postCheckpointSubject1.OnNext(e)).Wait(); - postCheckpointData2.ForEachAsync(e => postCheckpointSubject2.OnNext(e)).Wait(); + postCheckpointData1.ForEachAsync(postCheckpointSubject1.OnNext).Wait(); + postCheckpointData2.ForEachAsync(postCheckpointSubject2.OnNext).Wait(); postCheckpointSubject1.OnCompleted(); postCheckpointSubject2.OnCompleted(); outputAsync2.Wait(); @@ -2310,7 +2310,7 @@ public void LeftUnaryCheckpointLASJRowSmallBatch() var query3 = input31.WhereNotExists(input32, e => e.Item1, e => e.Item1); var output3 = container3.RegisterOutput(query3); - var outputAsync3 = output3.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(o => outputListWithoutCheckpoint.Add(o)); + var outputAsync3 = output3.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(outputListWithoutCheckpoint.Add); container3.Restore(null); outputAsync3.Wait(); @@ -2371,11 +2371,11 @@ public void RightUnaryCheckpointLASJRowSmallBatch() var output1 = container1.RegisterOutput(query1); - var outputAsync1 = output1.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(o => outputListWithCheckpoint.Add(o)); + var outputAsync1 = output1.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(outputListWithCheckpoint.Add); var pipe1 = container1.Restore(null); - preCheckpointData1.ForEachAsync(e => preCheckpointSubject1.OnNext(e)).Wait(); - preCheckpointData2.ForEachAsync(e => preCheckpointSubject2.OnNext(e)).Wait(); + preCheckpointData1.ForEachAsync(preCheckpointSubject1.OnNext).Wait(); + preCheckpointData2.ForEachAsync(preCheckpointSubject2.OnNext).Wait(); pipe1.Checkpoint(state); @@ -2387,11 +2387,11 @@ public void RightUnaryCheckpointLASJRowSmallBatch() var query2 = input21.WhereNotExists(input22, e => e.Item1, e => e.Item1); var output2 = container2.RegisterOutput(query2); - var outputAsync2 = output2.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(o => outputListWithCheckpoint.Add(o)); + var outputAsync2 = output2.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(outputListWithCheckpoint.Add); var pipe2 = container2.Restore(state); - postCheckpointData1.ForEachAsync(e => postCheckpointSubject1.OnNext(e)).Wait(); - postCheckpointData2.ForEachAsync(e => postCheckpointSubject2.OnNext(e)).Wait(); + postCheckpointData1.ForEachAsync(postCheckpointSubject1.OnNext).Wait(); + postCheckpointData2.ForEachAsync(postCheckpointSubject2.OnNext).Wait(); postCheckpointSubject1.OnCompleted(); postCheckpointSubject2.OnCompleted(); outputAsync2.Wait(); @@ -2403,7 +2403,7 @@ public void RightUnaryCheckpointLASJRowSmallBatch() var query3 = input31.WhereNotExists(input32, e => e.Item1, e => e.Item1); var output3 = container3.RegisterOutput(query3); - var outputAsync3 = output3.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(o => outputListWithoutCheckpoint.Add(o)); + var outputAsync3 = output3.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(outputListWithoutCheckpoint.Add); container3.Restore(null); outputAsync3.Wait(); @@ -2449,10 +2449,10 @@ public void SelfUnaryCheckpointLASJRowSmallBatch() var output1 = container1.RegisterOutput(query1); - var outputAsync1 = output1.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(o => outputListWithCheckpoint.Add(o)); + var outputAsync1 = output1.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(outputListWithCheckpoint.Add); var pipe1 = container1.Restore(null); - preCheckpointData.ForEachAsync(e => preCheckpointSubject.OnNext(e)).Wait(); + preCheckpointData.ForEachAsync(preCheckpointSubject.OnNext).Wait(); pipe1.Checkpoint(state); @@ -2463,10 +2463,10 @@ public void SelfUnaryCheckpointLASJRowSmallBatch() var query2 = input2.GroupApply(o => 1, s => s.Multicast(p => p.WhereNotExists(p.Where(i => false), e => e.Item1, e => e.Item1))); var output2 = container2.RegisterOutput(query2); - var outputAsync2 = output2.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(o => outputListWithCheckpoint.Add(o)); + var outputAsync2 = output2.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(outputListWithCheckpoint.Add); var pipe2 = container2.Restore(state); - postCheckpointData.ForEachAsync(e => postCheckpointSubject.OnNext(e)).Wait(); + postCheckpointData.ForEachAsync(postCheckpointSubject.OnNext).Wait(); postCheckpointSubject.OnCompleted(); outputAsync2.Wait(); outputListWithCheckpoint.Sort((a, b) => a.Item1.CompareTo(b.Item1) == 0 ? a.Item2.CompareTo(b.Item2) : a.Item1.CompareTo(b.Item1)); @@ -2476,7 +2476,7 @@ public void SelfUnaryCheckpointLASJRowSmallBatch() var query3 = input3.GroupApply(o => 1, s => s.Multicast(p => p.WhereNotExists(p.Where(i => false), e => e.Item1, e => e.Item1))); var output3 = container3.RegisterOutput(query3); - var outputAsync3 = output3.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(o => outputListWithoutCheckpoint.Add(o)); + var outputAsync3 = output3.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(outputListWithoutCheckpoint.Add); container3.Restore(null); outputAsync3.Wait(); @@ -2536,11 +2536,11 @@ public void BasicUnaryCheckpointClipRowSmallBatch() var output1 = container1.RegisterOutput(query1); - var outputAsync1 = output1.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(o => outputListWithCheckpoint.Add(o)); + var outputAsync1 = output1.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(outputListWithCheckpoint.Add); var pipe1 = container1.Restore(null); - preCheckpointData1.ForEachAsync(e => preCheckpointSubject1.OnNext(e)).Wait(); - preCheckpointData2.ForEachAsync(e => preCheckpointSubject2.OnNext(e)).Wait(); + preCheckpointData1.ForEachAsync(preCheckpointSubject1.OnNext).Wait(); + preCheckpointData2.ForEachAsync(preCheckpointSubject2.OnNext).Wait(); pipe1.Checkpoint(state); @@ -2552,11 +2552,11 @@ public void BasicUnaryCheckpointClipRowSmallBatch() var query2 = input21.ClipEventDuration(input22, e => e.Item1, e => e.Item1); var output2 = container2.RegisterOutput(query2); - var outputAsync2 = output2.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(o => outputListWithCheckpoint.Add(o)); + var outputAsync2 = output2.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(outputListWithCheckpoint.Add); var pipe2 = container2.Restore(state); - postCheckpointData1.ForEachAsync(e => postCheckpointSubject1.OnNext(e)).Wait(); - postCheckpointData2.ForEachAsync(e => postCheckpointSubject2.OnNext(e)).Wait(); + postCheckpointData1.ForEachAsync(postCheckpointSubject1.OnNext).Wait(); + postCheckpointData2.ForEachAsync(postCheckpointSubject2.OnNext).Wait(); postCheckpointSubject1.OnCompleted(); postCheckpointSubject2.OnCompleted(); outputAsync2.Wait(); @@ -2568,7 +2568,7 @@ public void BasicUnaryCheckpointClipRowSmallBatch() var query3 = input31.ClipEventDuration(input32, e => e.Item1, e => e.Item1); var output3 = container3.RegisterOutput(query3); - var outputAsync3 = output3.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(o => outputListWithoutCheckpoint.Add(o)); + var outputAsync3 = output3.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(outputListWithoutCheckpoint.Add); container3.Restore(null); outputAsync3.Wait(); @@ -2611,7 +2611,7 @@ public void BasicEmptyCheckpointErrorRowSmallBatch() var query1 = query1_left.Union(query1right); var output1 = container1.RegisterOutput(query1); - var outputAsync1 = output1.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(o => outputListWithCheckpoint.Add(o)); + var outputAsync1 = output1.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(outputListWithCheckpoint.Add); try { @@ -2657,9 +2657,9 @@ public void BasicUnaryCheckpointErrorRowSmallBatch() var query1 = CreateBasicQuery(input1); var output1 = container1.RegisterOutput(query1); - var outputAsync1 = output1.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(o => outputList.Add(o)); + var outputAsync1 = output1.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(outputList.Add); var pipe1 = container1.Restore(null); - preCheckpointData.ForEachAsync(e => preCheckpointSubject.OnNext(e)).Wait(); + preCheckpointData.ForEachAsync(preCheckpointSubject.OnNext).Wait(); pipe1.Checkpoint(state); state.Seek(0, SeekOrigin.Begin); @@ -2669,9 +2669,9 @@ public void BasicUnaryCheckpointErrorRowSmallBatch() var query2 = CreateBasicQuery(input2); var output2 = container2.RegisterOutput(query2); - var outputAsync2 = output2.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(o => outputList.Add(o)); + var outputAsync2 = output2.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(outputList.Add); var pipe2 = container2.Restore(state); - postCheckpointData.ForEachAsync(e => postCheckpointSubject.OnNext(e)).Wait(); + postCheckpointData.ForEachAsync(postCheckpointSubject.OnNext).Wait(); outputAsync2.Wait(); } catch (AggregateException e) @@ -2715,9 +2715,9 @@ public void BasicDisorderPolicyErrorRowSmallBatch() var query1 = CreateBasicQuery(input1); var output1 = container1.RegisterOutput(query1); - var outputAsync1 = output1.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(o => outputList.Add(o)); + var outputAsync1 = output1.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(outputList.Add); var pipe1 = container1.Restore(null); - preCheckpointData.ForEachAsync(e => preCheckpointSubject.OnNext(e)).Wait(); + preCheckpointData.ForEachAsync(preCheckpointSubject.OnNext).Wait(); pipe1.Checkpoint(state); state.Seek(0, SeekOrigin.Begin); @@ -2729,9 +2729,9 @@ public void BasicDisorderPolicyErrorRowSmallBatch() var query2 = CreateBasicQuery(input2); var output2 = container2.RegisterOutput(query2); - var outputAsync2 = output2.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(o => outputList.Add(o)); + var outputAsync2 = output2.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(outputList.Add); var pipe2 = container2.Restore(state); - postCheckpointData.ForEachAsync(e => postCheckpointSubject.OnNext(e)).Wait(); + postCheckpointData.ForEachAsync(postCheckpointSubject.OnNext).Wait(); postCheckpointSubject.OnCompleted(); outputAsync2.Wait(); } @@ -2772,9 +2772,9 @@ public void BasicDisorderAdjustPolicyRowSmallBatch() var query1 = CreateBasicQuery(input1); var output1 = container1.RegisterOutput(query1); - var outputAsync1 = output1.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(o => outputList.Add(o)); + var outputAsync1 = output1.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(outputList.Add); var pipe1 = container1.Restore(null); - preCheckpointData.ForEachAsync(e => preCheckpointSubject.OnNext(e)).Wait(); + preCheckpointData.ForEachAsync(preCheckpointSubject.OnNext).Wait(); pipe1.Checkpoint(state); state.Seek(0, SeekOrigin.Begin); @@ -2784,13 +2784,13 @@ public void BasicDisorderAdjustPolicyRowSmallBatch() var query2 = CreateBasicQuery(input2); var output2 = container2.RegisterOutput(query2); - var outputAsync2 = output2.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(o => outputList.Add(o)); + var outputAsync2 = output2.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(outputList.Add); var pipe2 = container2.Restore(state); - postCheckpointData.ForEachAsync(e => postCheckpointSubject.OnNext(e)).Wait(); + postCheckpointData.ForEachAsync(postCheckpointSubject.OnNext).Wait(); postCheckpointSubject.OnCompleted(); outputAsync2.Wait(); - Assert.IsTrue(outputList.Count == 10000); + Assert.HasCount(10000, outputList); preCheckpointSubject.OnCompleted(); } @@ -3013,9 +3013,9 @@ public void BasicUnaryCheckpointHoppingWindowSumColumnar() var output1 = container1.RegisterOutput(query1); - var outputAsync1 = output1.Where(e => e.IsData).ForEachAsync(o => outputListWithCheckpoint.Add(o)); + var outputAsync1 = output1.Where(e => e.IsData).ForEachAsync(outputListWithCheckpoint.Add); var pipe1 = container1.Restore(null); - preCheckpointData.ForEachAsync(e => preCheckpointSubject.OnNext(e)).Wait(); + preCheckpointData.ForEachAsync(preCheckpointSubject.OnNext).Wait(); pipe1.Checkpoint(state); state.Seek(0, SeekOrigin.Begin); @@ -3025,10 +3025,10 @@ public void BasicUnaryCheckpointHoppingWindowSumColumnar() var query2 = input2.HoppingWindowLifetime(window, period).Sum(e => (ulong)e); var output2 = container2.RegisterOutput(query2); - var outputAsync2 = output2.Where(e => e.IsData).ForEachAsync(o => outputListWithCheckpoint.Add(o)); + var outputAsync2 = output2.Where(e => e.IsData).ForEachAsync(outputListWithCheckpoint.Add); var pipe2 = container2.Restore(state); - postCheckpointData.ForEachAsync(e => postCheckpointSubject.OnNext(e)).Wait(); + postCheckpointData.ForEachAsync(postCheckpointSubject.OnNext).Wait(); postCheckpointSubject.OnCompleted(); outputAsync2.Wait(); outputListWithCheckpoint.Sort((x, y) => @@ -3046,7 +3046,7 @@ public void BasicUnaryCheckpointHoppingWindowSumColumnar() var query3 = input3.HoppingWindowLifetime(window, period).Sum(e => (ulong)e); var output3 = container3.RegisterOutput(query3); - var outputAsync3 = output3.Where(e => e.IsData).ForEachAsync(o => outputListWithoutCheckpoint.Add(o)); + var outputAsync3 = output3.Where(e => e.IsData).ForEachAsync(outputListWithoutCheckpoint.Add); container3.Restore(null); outputAsync3.Wait(); outputListWithoutCheckpoint.Sort((x, y) => @@ -3142,9 +3142,9 @@ public void BasicUnaryCheckpoint0Columnar() var query1 = CreateBasicQuery(input1); var output1 = container1.RegisterOutput(query1); - var outputAsync1 = output1.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(o => outputListWithCheckpoint.Add(o)); + var outputAsync1 = output1.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(outputListWithCheckpoint.Add); var pipe1 = container1.Restore(null); - preCheckpointData.ForEachAsync(e => preCheckpointSubject.OnNext(e)).Wait(); + preCheckpointData.ForEachAsync(preCheckpointSubject.OnNext).Wait(); pipe1.Checkpoint(state); state.Seek(0, SeekOrigin.Begin); @@ -3154,9 +3154,9 @@ public void BasicUnaryCheckpoint0Columnar() var query2 = CreateBasicQuery(input2); var output2 = container2.RegisterOutput(query2); - var outputAsync2 = output2.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(o => outputListWithCheckpoint.Add(o)); + var outputAsync2 = output2.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(outputListWithCheckpoint.Add); var pipe2 = container2.Restore(state); - postCheckpointData.ForEachAsync(e => postCheckpointSubject.OnNext(e)).Wait(); + postCheckpointData.ForEachAsync(postCheckpointSubject.OnNext).Wait(); postCheckpointSubject.OnCompleted(); outputAsync2.Wait(); outputListWithCheckpoint.Sort(); @@ -3166,7 +3166,7 @@ public void BasicUnaryCheckpoint0Columnar() var query3 = CreateBasicQuery(input3); var output3 = container3.RegisterOutput(query3); - var outputAsync3 = output3.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(o => outputListWithoutCheckpoint.Add(o)); + var outputAsync3 = output3.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(outputListWithoutCheckpoint.Add); container3.Restore(null); outputAsync3.Wait(); @@ -3207,9 +3207,9 @@ public void BasicUnaryCheckpointDisorderPolicyColumnar() var query1 = CreateBasicQuery(input1); var output1 = container1.RegisterOutput(query1); - var outputAsync1 = output1.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(o => outputListWithCheckpoint.Add(o)); + var outputAsync1 = output1.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(outputListWithCheckpoint.Add); var pipe1 = container1.Restore(null); - preCheckpointData.ForEachAsync(e => preCheckpointSubject.OnNext(e)).Wait(); + preCheckpointData.ForEachAsync(preCheckpointSubject.OnNext).Wait(); pipe1.Checkpoint(state); state.Seek(0, SeekOrigin.Begin); @@ -3219,9 +3219,9 @@ public void BasicUnaryCheckpointDisorderPolicyColumnar() var query2 = CreateBasicQuery(input2); var output2 = container2.RegisterOutput(query2); - var outputAsync2 = output2.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(o => outputListWithCheckpoint.Add(o)); + var outputAsync2 = output2.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(outputListWithCheckpoint.Add); var pipe2 = container2.Restore(state); - postCheckpointData.ForEachAsync(e => postCheckpointSubject.OnNext(e)).Wait(); + postCheckpointData.ForEachAsync(postCheckpointSubject.OnNext).Wait(); postCheckpointSubject.OnCompleted(); outputAsync2.Wait(); outputListWithCheckpoint.Sort(); @@ -3231,7 +3231,7 @@ public void BasicUnaryCheckpointDisorderPolicyColumnar() var query3 = CreateBasicQuery(input3); var output3 = container3.RegisterOutput(query3); - var outputAsync3 = output3.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(o => outputListWithoutCheckpoint.Add(o)); + var outputAsync3 = output3.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(outputListWithoutCheckpoint.Add); container3.Restore(null); outputAsync3.Wait(); @@ -3275,9 +3275,9 @@ public void BasicMulticastCheckpoint0Columnar() var query1 = query1_left.Union(query1right); var output1 = container1.RegisterOutput(query1); - var outputAsync1 = output1.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(o => outputListWithCheckpoint.Add(o)); + var outputAsync1 = output1.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(outputListWithCheckpoint.Add); var pipe1 = container1.Restore(null); - preCheckpointData.ForEachAsync(e => preCheckpointSubject.OnNext(e)).Wait(); + preCheckpointData.ForEachAsync(preCheckpointSubject.OnNext).Wait(); pipe1.Checkpoint(state); state.Seek(0, SeekOrigin.Begin); @@ -3290,9 +3290,9 @@ public void BasicMulticastCheckpoint0Columnar() var query2 = query2_left.Union(query2right); var output2 = container2.RegisterOutput(query2); - var outputAsync2 = output2.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(o => outputListWithCheckpoint.Add(o)); + var outputAsync2 = output2.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(outputListWithCheckpoint.Add); var pipe2 = container2.Restore(state); - postCheckpointData.ForEachAsync(e => postCheckpointSubject.OnNext(e)).Wait(); + postCheckpointData.ForEachAsync(postCheckpointSubject.OnNext).Wait(); postCheckpointSubject.OnCompleted(); outputAsync2.Wait(); outputListWithCheckpoint.Sort(); @@ -3305,7 +3305,7 @@ public void BasicMulticastCheckpoint0Columnar() var query3 = query3_left.Union(query3right); var output3 = container3.RegisterOutput(query3); - var outputAsync3 = output3.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(o => outputListWithoutCheckpoint.Add(o)); + var outputAsync3 = output3.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(outputListWithoutCheckpoint.Add); container3.Restore(null); outputAsync3.Wait(); outputListWithoutCheckpoint.Sort(); @@ -3350,7 +3350,7 @@ public void BasicUnaryCheckpointAnonTypeSelectManyColumnar() var outputAsync1 = output1.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(o => outputListWithCheckpoint.Add(o.p)); var pipe1 = container1.Restore(null); - preCheckpointData.ForEachAsync(e => preCheckpointSubject.OnNext(e)).Wait(); + preCheckpointData.ForEachAsync(preCheckpointSubject.OnNext).Wait(); pipe1.Checkpoint(state); state.Seek(0, SeekOrigin.Begin); @@ -3362,7 +3362,7 @@ public void BasicUnaryCheckpointAnonTypeSelectManyColumnar() var outputAsync2 = output2.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(o => outputListWithCheckpoint.Add(o.p)); var pipe2 = container2.Restore(state); - postCheckpointData.ForEachAsync(e => postCheckpointSubject.OnNext(e)).Wait(); + postCheckpointData.ForEachAsync(postCheckpointSubject.OnNext).Wait(); postCheckpointSubject.OnCompleted(); outputAsync2.Wait(); outputListWithCheckpoint.Sort(); @@ -3414,9 +3414,9 @@ public void BasicUnaryCheckpointCountColumnar() var output1 = container1.RegisterOutput(query1); - var outputAsync1 = output1.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(o => outputListWithCheckpoint.Add(o)); + var outputAsync1 = output1.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(outputListWithCheckpoint.Add); var pipe1 = container1.Restore(null); - preCheckpointData.ForEachAsync(e => preCheckpointSubject.OnNext(e)).Wait(); + preCheckpointData.ForEachAsync(preCheckpointSubject.OnNext).Wait(); pipe1.Checkpoint(state); state.Seek(0, SeekOrigin.Begin); @@ -3426,9 +3426,9 @@ public void BasicUnaryCheckpointCountColumnar() var query2 = input2.Count(); var output2 = container2.RegisterOutput(query2); - var outputAsync2 = output2.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(o => outputListWithCheckpoint.Add(o)); + var outputAsync2 = output2.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(outputListWithCheckpoint.Add); var pipe2 = container2.Restore(state); - postCheckpointData.ForEachAsync(e => postCheckpointSubject.OnNext(e)).Wait(); + postCheckpointData.ForEachAsync(postCheckpointSubject.OnNext).Wait(); postCheckpointSubject.OnCompleted(); outputAsync2.Wait(); outputListWithCheckpoint.Sort(); @@ -3438,7 +3438,7 @@ public void BasicUnaryCheckpointCountColumnar() var query3 = input3.Count(); var output3 = container3.RegisterOutput(query3); - var outputAsync3 = output3.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(o => outputListWithoutCheckpoint.Add(o)); + var outputAsync3 = output3.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(outputListWithoutCheckpoint.Add); container3.Restore(null); outputAsync3.Wait(); @@ -3480,9 +3480,9 @@ public void BasicUnaryCheckpointGroupedSumColumnar() var output1 = container1.RegisterOutput(query1); - var outputAsync1 = output1.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(o => outputListWithCheckpoint.Add(o)); + var outputAsync1 = output1.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(outputListWithCheckpoint.Add); var pipe1 = container1.Restore(null); - preCheckpointData.ForEachAsync(e => preCheckpointSubject.OnNext(e)).Wait(); + preCheckpointData.ForEachAsync(preCheckpointSubject.OnNext).Wait(); pipe1.Checkpoint(state); state.Seek(0, SeekOrigin.Begin); @@ -3492,9 +3492,9 @@ public void BasicUnaryCheckpointGroupedSumColumnar() var query2 = input2.GroupApply(e => e.Item1, str => str.Sum(e => (ulong)e.Item2), (g, c) => new StructTuple { Item1 = g.Key, Item2 = c }); var output2 = container2.RegisterOutput(query2); - var outputAsync2 = output2.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(o => outputListWithCheckpoint.Add(o)); + var outputAsync2 = output2.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(outputListWithCheckpoint.Add); var pipe2 = container2.Restore(state); - postCheckpointData.ForEachAsync(e => postCheckpointSubject.OnNext(e)).Wait(); + postCheckpointData.ForEachAsync(postCheckpointSubject.OnNext).Wait(); postCheckpointSubject.OnCompleted(); outputAsync2.Wait(); outputListWithCheckpoint.Sort((a, b) => a.Item1.CompareTo(b.Item1) == 0 ? a.Item2.CompareTo(b.Item2) : a.Item1.CompareTo(b.Item1)); @@ -3504,7 +3504,7 @@ public void BasicUnaryCheckpointGroupedSumColumnar() var query3 = input3.GroupApply(e => e.Item1, str => str.Sum(e => (ulong)e.Item2), (g, c) => new StructTuple { Item1 = g.Key, Item2 = c }); var output3 = container3.RegisterOutput(query3); - var outputAsync3 = output3.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(o => outputListWithoutCheckpoint.Add(o)); + var outputAsync3 = output3.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(outputListWithoutCheckpoint.Add); container3.Restore(null); outputAsync3.Wait(); @@ -3562,11 +3562,11 @@ public void BasicUnaryCheckpointEquiJoinColumnar() var output1 = container1.RegisterOutput(query1); - var outputAsync1 = output1.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(o => outputListWithCheckpoint.Add(o)); + var outputAsync1 = output1.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(outputListWithCheckpoint.Add); var pipe1 = container1.Restore(null); - preCheckpointData1.ForEachAsync(e => preCheckpointSubject1.OnNext(e)).Wait(); - preCheckpointData2.ForEachAsync(e => preCheckpointSubject2.OnNext(e)).Wait(); + preCheckpointData1.ForEachAsync(preCheckpointSubject1.OnNext).Wait(); + preCheckpointData2.ForEachAsync(preCheckpointSubject2.OnNext).Wait(); pipe1.Checkpoint(state); @@ -3578,11 +3578,11 @@ public void BasicUnaryCheckpointEquiJoinColumnar() var query2 = input21.Join(input22, e => e.Item1, e => e.Item1, (l, r) => new StructTuple { Item1 = l.Item1, Item2 = r.Item2 }); var output2 = container2.RegisterOutput(query2); - var outputAsync2 = output2.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(o => outputListWithCheckpoint.Add(o)); + var outputAsync2 = output2.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(outputListWithCheckpoint.Add); var pipe2 = container2.Restore(state); - postCheckpointData1.ForEachAsync(e => postCheckpointSubject1.OnNext(e)).Wait(); - postCheckpointData2.ForEachAsync(e => postCheckpointSubject2.OnNext(e)).Wait(); + postCheckpointData1.ForEachAsync(postCheckpointSubject1.OnNext).Wait(); + postCheckpointData2.ForEachAsync(postCheckpointSubject2.OnNext).Wait(); postCheckpointSubject1.OnCompleted(); postCheckpointSubject2.OnCompleted(); outputAsync2.Wait(); @@ -3594,7 +3594,7 @@ public void BasicUnaryCheckpointEquiJoinColumnar() var query3 = input31.Join(input32, e => e.Item1, e => e.Item1, (l, r) => new StructTuple { Item1 = l.Item1, Item2 = r.Item2 }); var output3 = container3.RegisterOutput(query3); - var outputAsync3 = output3.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(o => outputListWithoutCheckpoint.Add(o)); + var outputAsync3 = output3.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(outputListWithoutCheckpoint.Add); container3.Restore(null); outputAsync3.Wait(); @@ -3655,11 +3655,11 @@ public void BasicUnaryCheckpointLASJColumnar() var output1 = container1.RegisterOutput(query1); - var outputAsync1 = output1.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(o => outputListWithCheckpoint.Add(o)); + var outputAsync1 = output1.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(outputListWithCheckpoint.Add); var pipe1 = container1.Restore(null); - preCheckpointData1.ForEachAsync(e => preCheckpointSubject1.OnNext(e)).Wait(); - preCheckpointData2.ForEachAsync(e => preCheckpointSubject2.OnNext(e)).Wait(); + preCheckpointData1.ForEachAsync(preCheckpointSubject1.OnNext).Wait(); + preCheckpointData2.ForEachAsync(preCheckpointSubject2.OnNext).Wait(); pipe1.Checkpoint(state); @@ -3671,11 +3671,11 @@ public void BasicUnaryCheckpointLASJColumnar() var query2 = input21.WhereNotExists(input22, e => e.Item1, e => e.Item1); var output2 = container2.RegisterOutput(query2); - var outputAsync2 = output2.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(o => outputListWithCheckpoint.Add(o)); + var outputAsync2 = output2.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(outputListWithCheckpoint.Add); var pipe2 = container2.Restore(state); - postCheckpointData1.ForEachAsync(e => postCheckpointSubject1.OnNext(e)).Wait(); - postCheckpointData2.ForEachAsync(e => postCheckpointSubject2.OnNext(e)).Wait(); + postCheckpointData1.ForEachAsync(postCheckpointSubject1.OnNext).Wait(); + postCheckpointData2.ForEachAsync(postCheckpointSubject2.OnNext).Wait(); postCheckpointSubject1.OnCompleted(); postCheckpointSubject2.OnCompleted(); outputAsync2.Wait(); @@ -3687,7 +3687,7 @@ public void BasicUnaryCheckpointLASJColumnar() var query3 = input31.WhereNotExists(input32, e => e.Item1, e => e.Item1); var output3 = container3.RegisterOutput(query3); - var outputAsync3 = output3.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(o => outputListWithoutCheckpoint.Add(o)); + var outputAsync3 = output3.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(outputListWithoutCheckpoint.Add); container3.Restore(null); outputAsync3.Wait(); @@ -3748,11 +3748,11 @@ public void LeftUnaryCheckpointLASJColumnar() var output1 = container1.RegisterOutput(query1); - var outputAsync1 = output1.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(o => outputListWithCheckpoint.Add(o)); + var outputAsync1 = output1.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(outputListWithCheckpoint.Add); var pipe1 = container1.Restore(null); - preCheckpointData1.ForEachAsync(e => preCheckpointSubject1.OnNext(e)).Wait(); - preCheckpointData2.ForEachAsync(e => preCheckpointSubject2.OnNext(e)).Wait(); + preCheckpointData1.ForEachAsync(preCheckpointSubject1.OnNext).Wait(); + preCheckpointData2.ForEachAsync(preCheckpointSubject2.OnNext).Wait(); pipe1.Checkpoint(state); @@ -3764,11 +3764,11 @@ public void LeftUnaryCheckpointLASJColumnar() var query2 = input21.WhereNotExists(input22, e => e.Item1, e => e.Item1); var output2 = container2.RegisterOutput(query2); - var outputAsync2 = output2.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(o => outputListWithCheckpoint.Add(o)); + var outputAsync2 = output2.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(outputListWithCheckpoint.Add); var pipe2 = container2.Restore(state); - postCheckpointData1.ForEachAsync(e => postCheckpointSubject1.OnNext(e)).Wait(); - postCheckpointData2.ForEachAsync(e => postCheckpointSubject2.OnNext(e)).Wait(); + postCheckpointData1.ForEachAsync(postCheckpointSubject1.OnNext).Wait(); + postCheckpointData2.ForEachAsync(postCheckpointSubject2.OnNext).Wait(); postCheckpointSubject1.OnCompleted(); postCheckpointSubject2.OnCompleted(); outputAsync2.Wait(); @@ -3780,7 +3780,7 @@ public void LeftUnaryCheckpointLASJColumnar() var query3 = input31.WhereNotExists(input32, e => e.Item1, e => e.Item1); var output3 = container3.RegisterOutput(query3); - var outputAsync3 = output3.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(o => outputListWithoutCheckpoint.Add(o)); + var outputAsync3 = output3.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(outputListWithoutCheckpoint.Add); container3.Restore(null); outputAsync3.Wait(); @@ -3841,11 +3841,11 @@ public void RightUnaryCheckpointLASJColumnar() var output1 = container1.RegisterOutput(query1); - var outputAsync1 = output1.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(o => outputListWithCheckpoint.Add(o)); + var outputAsync1 = output1.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(outputListWithCheckpoint.Add); var pipe1 = container1.Restore(null); - preCheckpointData1.ForEachAsync(e => preCheckpointSubject1.OnNext(e)).Wait(); - preCheckpointData2.ForEachAsync(e => preCheckpointSubject2.OnNext(e)).Wait(); + preCheckpointData1.ForEachAsync(preCheckpointSubject1.OnNext).Wait(); + preCheckpointData2.ForEachAsync(preCheckpointSubject2.OnNext).Wait(); pipe1.Checkpoint(state); @@ -3857,11 +3857,11 @@ public void RightUnaryCheckpointLASJColumnar() var query2 = input21.WhereNotExists(input22, e => e.Item1, e => e.Item1); var output2 = container2.RegisterOutput(query2); - var outputAsync2 = output2.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(o => outputListWithCheckpoint.Add(o)); + var outputAsync2 = output2.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(outputListWithCheckpoint.Add); var pipe2 = container2.Restore(state); - postCheckpointData1.ForEachAsync(e => postCheckpointSubject1.OnNext(e)).Wait(); - postCheckpointData2.ForEachAsync(e => postCheckpointSubject2.OnNext(e)).Wait(); + postCheckpointData1.ForEachAsync(postCheckpointSubject1.OnNext).Wait(); + postCheckpointData2.ForEachAsync(postCheckpointSubject2.OnNext).Wait(); postCheckpointSubject1.OnCompleted(); postCheckpointSubject2.OnCompleted(); outputAsync2.Wait(); @@ -3873,7 +3873,7 @@ public void RightUnaryCheckpointLASJColumnar() var query3 = input31.WhereNotExists(input32, e => e.Item1, e => e.Item1); var output3 = container3.RegisterOutput(query3); - var outputAsync3 = output3.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(o => outputListWithoutCheckpoint.Add(o)); + var outputAsync3 = output3.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(outputListWithoutCheckpoint.Add); container3.Restore(null); outputAsync3.Wait(); @@ -3919,10 +3919,10 @@ public void SelfUnaryCheckpointLASJColumnar() var output1 = container1.RegisterOutput(query1); - var outputAsync1 = output1.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(o => outputListWithCheckpoint.Add(o)); + var outputAsync1 = output1.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(outputListWithCheckpoint.Add); var pipe1 = container1.Restore(null); - preCheckpointData.ForEachAsync(e => preCheckpointSubject.OnNext(e)).Wait(); + preCheckpointData.ForEachAsync(preCheckpointSubject.OnNext).Wait(); pipe1.Checkpoint(state); @@ -3933,10 +3933,10 @@ public void SelfUnaryCheckpointLASJColumnar() var query2 = input2.GroupApply(o => 1, s => s.Multicast(p => p.WhereNotExists(p.Where(i => false), e => e.Item1, e => e.Item1))); var output2 = container2.RegisterOutput(query2); - var outputAsync2 = output2.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(o => outputListWithCheckpoint.Add(o)); + var outputAsync2 = output2.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(outputListWithCheckpoint.Add); var pipe2 = container2.Restore(state); - postCheckpointData.ForEachAsync(e => postCheckpointSubject.OnNext(e)).Wait(); + postCheckpointData.ForEachAsync(postCheckpointSubject.OnNext).Wait(); postCheckpointSubject.OnCompleted(); outputAsync2.Wait(); outputListWithCheckpoint.Sort((a, b) => a.Item1.CompareTo(b.Item1) == 0 ? a.Item2.CompareTo(b.Item2) : a.Item1.CompareTo(b.Item1)); @@ -3946,7 +3946,7 @@ public void SelfUnaryCheckpointLASJColumnar() var query3 = input3.GroupApply(o => 1, s => s.Multicast(p => p.WhereNotExists(p.Where(i => false), e => e.Item1, e => e.Item1))); var output3 = container3.RegisterOutput(query3); - var outputAsync3 = output3.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(o => outputListWithoutCheckpoint.Add(o)); + var outputAsync3 = output3.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(outputListWithoutCheckpoint.Add); container3.Restore(null); outputAsync3.Wait(); @@ -4006,11 +4006,11 @@ public void BasicUnaryCheckpointClipColumnar() var output1 = container1.RegisterOutput(query1); - var outputAsync1 = output1.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(o => outputListWithCheckpoint.Add(o)); + var outputAsync1 = output1.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(outputListWithCheckpoint.Add); var pipe1 = container1.Restore(null); - preCheckpointData1.ForEachAsync(e => preCheckpointSubject1.OnNext(e)).Wait(); - preCheckpointData2.ForEachAsync(e => preCheckpointSubject2.OnNext(e)).Wait(); + preCheckpointData1.ForEachAsync(preCheckpointSubject1.OnNext).Wait(); + preCheckpointData2.ForEachAsync(preCheckpointSubject2.OnNext).Wait(); pipe1.Checkpoint(state); @@ -4022,11 +4022,11 @@ public void BasicUnaryCheckpointClipColumnar() var query2 = input21.ClipEventDuration(input22, e => e.Item1, e => e.Item1); var output2 = container2.RegisterOutput(query2); - var outputAsync2 = output2.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(o => outputListWithCheckpoint.Add(o)); + var outputAsync2 = output2.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(outputListWithCheckpoint.Add); var pipe2 = container2.Restore(state); - postCheckpointData1.ForEachAsync(e => postCheckpointSubject1.OnNext(e)).Wait(); - postCheckpointData2.ForEachAsync(e => postCheckpointSubject2.OnNext(e)).Wait(); + postCheckpointData1.ForEachAsync(postCheckpointSubject1.OnNext).Wait(); + postCheckpointData2.ForEachAsync(postCheckpointSubject2.OnNext).Wait(); postCheckpointSubject1.OnCompleted(); postCheckpointSubject2.OnCompleted(); outputAsync2.Wait(); @@ -4038,7 +4038,7 @@ public void BasicUnaryCheckpointClipColumnar() var query3 = input31.ClipEventDuration(input32, e => e.Item1, e => e.Item1); var output3 = container3.RegisterOutput(query3); - var outputAsync3 = output3.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(o => outputListWithoutCheckpoint.Add(o)); + var outputAsync3 = output3.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(outputListWithoutCheckpoint.Add); container3.Restore(null); outputAsync3.Wait(); @@ -4081,7 +4081,7 @@ public void BasicEmptyCheckpointErrorColumnar() var query1 = query1_left.Union(query1right); var output1 = container1.RegisterOutput(query1); - var outputAsync1 = output1.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(o => outputListWithCheckpoint.Add(o)); + var outputAsync1 = output1.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(outputListWithCheckpoint.Add); try { @@ -4127,9 +4127,9 @@ public void BasicUnaryCheckpointErrorColumnar() var query1 = CreateBasicQuery(input1); var output1 = container1.RegisterOutput(query1); - var outputAsync1 = output1.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(o => outputList.Add(o)); + var outputAsync1 = output1.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(outputList.Add); var pipe1 = container1.Restore(null); - preCheckpointData.ForEachAsync(e => preCheckpointSubject.OnNext(e)).Wait(); + preCheckpointData.ForEachAsync(preCheckpointSubject.OnNext).Wait(); pipe1.Checkpoint(state); state.Seek(0, SeekOrigin.Begin); @@ -4139,9 +4139,9 @@ public void BasicUnaryCheckpointErrorColumnar() var query2 = CreateBasicQuery(input2); var output2 = container2.RegisterOutput(query2); - var outputAsync2 = output2.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(o => outputList.Add(o)); + var outputAsync2 = output2.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(outputList.Add); var pipe2 = container2.Restore(state); - postCheckpointData.ForEachAsync(e => postCheckpointSubject.OnNext(e)).Wait(); + postCheckpointData.ForEachAsync(postCheckpointSubject.OnNext).Wait(); outputAsync2.Wait(); } catch (AggregateException e) @@ -4185,9 +4185,9 @@ public void BasicDisorderPolicyErrorColumnar() var query1 = CreateBasicQuery(input1); var output1 = container1.RegisterOutput(query1); - var outputAsync1 = output1.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(o => outputList.Add(o)); + var outputAsync1 = output1.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(outputList.Add); var pipe1 = container1.Restore(null); - preCheckpointData.ForEachAsync(e => preCheckpointSubject.OnNext(e)).Wait(); + preCheckpointData.ForEachAsync(preCheckpointSubject.OnNext).Wait(); pipe1.Checkpoint(state); state.Seek(0, SeekOrigin.Begin); @@ -4199,9 +4199,9 @@ public void BasicDisorderPolicyErrorColumnar() var query2 = CreateBasicQuery(input2); var output2 = container2.RegisterOutput(query2); - var outputAsync2 = output2.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(o => outputList.Add(o)); + var outputAsync2 = output2.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(outputList.Add); var pipe2 = container2.Restore(state); - postCheckpointData.ForEachAsync(e => postCheckpointSubject.OnNext(e)).Wait(); + postCheckpointData.ForEachAsync(postCheckpointSubject.OnNext).Wait(); postCheckpointSubject.OnCompleted(); outputAsync2.Wait(); } @@ -4242,9 +4242,9 @@ public void BasicDisorderAdjustPolicyColumnar() var query1 = CreateBasicQuery(input1); var output1 = container1.RegisterOutput(query1); - var outputAsync1 = output1.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(o => outputList.Add(o)); + var outputAsync1 = output1.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(outputList.Add); var pipe1 = container1.Restore(null); - preCheckpointData.ForEachAsync(e => preCheckpointSubject.OnNext(e)).Wait(); + preCheckpointData.ForEachAsync(preCheckpointSubject.OnNext).Wait(); pipe1.Checkpoint(state); state.Seek(0, SeekOrigin.Begin); @@ -4254,13 +4254,13 @@ public void BasicDisorderAdjustPolicyColumnar() var query2 = CreateBasicQuery(input2); var output2 = container2.RegisterOutput(query2); - var outputAsync2 = output2.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(o => outputList.Add(o)); + var outputAsync2 = output2.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(outputList.Add); var pipe2 = container2.Restore(state); - postCheckpointData.ForEachAsync(e => postCheckpointSubject.OnNext(e)).Wait(); + postCheckpointData.ForEachAsync(postCheckpointSubject.OnNext).Wait(); postCheckpointSubject.OnCompleted(); outputAsync2.Wait(); - Assert.IsTrue(outputList.Count == 10000); + Assert.HasCount(10000, outputList); preCheckpointSubject.OnCompleted(); } @@ -4484,9 +4484,9 @@ public void BasicUnaryCheckpointHoppingWindowSumColumnarSmallBatch() var output1 = container1.RegisterOutput(query1); - var outputAsync1 = output1.Where(e => e.IsData).ForEachAsync(o => outputListWithCheckpoint.Add(o)); + var outputAsync1 = output1.Where(e => e.IsData).ForEachAsync(outputListWithCheckpoint.Add); var pipe1 = container1.Restore(null); - preCheckpointData.ForEachAsync(e => preCheckpointSubject.OnNext(e)).Wait(); + preCheckpointData.ForEachAsync(preCheckpointSubject.OnNext).Wait(); pipe1.Checkpoint(state); state.Seek(0, SeekOrigin.Begin); @@ -4496,10 +4496,10 @@ public void BasicUnaryCheckpointHoppingWindowSumColumnarSmallBatch() var query2 = input2.HoppingWindowLifetime(window, period).Sum(e => (ulong)e); var output2 = container2.RegisterOutput(query2); - var outputAsync2 = output2.Where(e => e.IsData).ForEachAsync(o => outputListWithCheckpoint.Add(o)); + var outputAsync2 = output2.Where(e => e.IsData).ForEachAsync(outputListWithCheckpoint.Add); var pipe2 = container2.Restore(state); - postCheckpointData.ForEachAsync(e => postCheckpointSubject.OnNext(e)).Wait(); + postCheckpointData.ForEachAsync(postCheckpointSubject.OnNext).Wait(); postCheckpointSubject.OnCompleted(); outputAsync2.Wait(); outputListWithCheckpoint.Sort((x, y) => @@ -4517,7 +4517,7 @@ public void BasicUnaryCheckpointHoppingWindowSumColumnarSmallBatch() var query3 = input3.HoppingWindowLifetime(window, period).Sum(e => (ulong)e); var output3 = container3.RegisterOutput(query3); - var outputAsync3 = output3.Where(e => e.IsData).ForEachAsync(o => outputListWithoutCheckpoint.Add(o)); + var outputAsync3 = output3.Where(e => e.IsData).ForEachAsync(outputListWithoutCheckpoint.Add); container3.Restore(null); outputAsync3.Wait(); outputListWithoutCheckpoint.Sort((x, y) => @@ -4614,9 +4614,9 @@ public void BasicUnaryCheckpoint0ColumnarSmallBatch() var query1 = CreateBasicQuery(input1); var output1 = container1.RegisterOutput(query1); - var outputAsync1 = output1.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(o => outputListWithCheckpoint.Add(o)); + var outputAsync1 = output1.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(outputListWithCheckpoint.Add); var pipe1 = container1.Restore(null); - preCheckpointData.ForEachAsync(e => preCheckpointSubject.OnNext(e)).Wait(); + preCheckpointData.ForEachAsync(preCheckpointSubject.OnNext).Wait(); pipe1.Checkpoint(state); state.Seek(0, SeekOrigin.Begin); @@ -4626,9 +4626,9 @@ public void BasicUnaryCheckpoint0ColumnarSmallBatch() var query2 = CreateBasicQuery(input2); var output2 = container2.RegisterOutput(query2); - var outputAsync2 = output2.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(o => outputListWithCheckpoint.Add(o)); + var outputAsync2 = output2.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(outputListWithCheckpoint.Add); var pipe2 = container2.Restore(state); - postCheckpointData.ForEachAsync(e => postCheckpointSubject.OnNext(e)).Wait(); + postCheckpointData.ForEachAsync(postCheckpointSubject.OnNext).Wait(); postCheckpointSubject.OnCompleted(); outputAsync2.Wait(); outputListWithCheckpoint.Sort(); @@ -4638,7 +4638,7 @@ public void BasicUnaryCheckpoint0ColumnarSmallBatch() var query3 = CreateBasicQuery(input3); var output3 = container3.RegisterOutput(query3); - var outputAsync3 = output3.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(o => outputListWithoutCheckpoint.Add(o)); + var outputAsync3 = output3.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(outputListWithoutCheckpoint.Add); container3.Restore(null); outputAsync3.Wait(); @@ -4679,9 +4679,9 @@ public void BasicUnaryCheckpointDisorderPolicyColumnarSmallBatch() var query1 = CreateBasicQuery(input1); var output1 = container1.RegisterOutput(query1); - var outputAsync1 = output1.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(o => outputListWithCheckpoint.Add(o)); + var outputAsync1 = output1.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(outputListWithCheckpoint.Add); var pipe1 = container1.Restore(null); - preCheckpointData.ForEachAsync(e => preCheckpointSubject.OnNext(e)).Wait(); + preCheckpointData.ForEachAsync(preCheckpointSubject.OnNext).Wait(); pipe1.Checkpoint(state); state.Seek(0, SeekOrigin.Begin); @@ -4691,9 +4691,9 @@ public void BasicUnaryCheckpointDisorderPolicyColumnarSmallBatch() var query2 = CreateBasicQuery(input2); var output2 = container2.RegisterOutput(query2); - var outputAsync2 = output2.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(o => outputListWithCheckpoint.Add(o)); + var outputAsync2 = output2.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(outputListWithCheckpoint.Add); var pipe2 = container2.Restore(state); - postCheckpointData.ForEachAsync(e => postCheckpointSubject.OnNext(e)).Wait(); + postCheckpointData.ForEachAsync(postCheckpointSubject.OnNext).Wait(); postCheckpointSubject.OnCompleted(); outputAsync2.Wait(); outputListWithCheckpoint.Sort(); @@ -4703,7 +4703,7 @@ public void BasicUnaryCheckpointDisorderPolicyColumnarSmallBatch() var query3 = CreateBasicQuery(input3); var output3 = container3.RegisterOutput(query3); - var outputAsync3 = output3.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(o => outputListWithoutCheckpoint.Add(o)); + var outputAsync3 = output3.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(outputListWithoutCheckpoint.Add); container3.Restore(null); outputAsync3.Wait(); @@ -4747,9 +4747,9 @@ public void BasicMulticastCheckpoint0ColumnarSmallBatch() var query1 = query1_left.Union(query1right); var output1 = container1.RegisterOutput(query1); - var outputAsync1 = output1.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(o => outputListWithCheckpoint.Add(o)); + var outputAsync1 = output1.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(outputListWithCheckpoint.Add); var pipe1 = container1.Restore(null); - preCheckpointData.ForEachAsync(e => preCheckpointSubject.OnNext(e)).Wait(); + preCheckpointData.ForEachAsync(preCheckpointSubject.OnNext).Wait(); pipe1.Checkpoint(state); state.Seek(0, SeekOrigin.Begin); @@ -4762,9 +4762,9 @@ public void BasicMulticastCheckpoint0ColumnarSmallBatch() var query2 = query2_left.Union(query2right); var output2 = container2.RegisterOutput(query2); - var outputAsync2 = output2.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(o => outputListWithCheckpoint.Add(o)); + var outputAsync2 = output2.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(outputListWithCheckpoint.Add); var pipe2 = container2.Restore(state); - postCheckpointData.ForEachAsync(e => postCheckpointSubject.OnNext(e)).Wait(); + postCheckpointData.ForEachAsync(postCheckpointSubject.OnNext).Wait(); postCheckpointSubject.OnCompleted(); outputAsync2.Wait(); outputListWithCheckpoint.Sort(); @@ -4777,7 +4777,7 @@ public void BasicMulticastCheckpoint0ColumnarSmallBatch() var query3 = query3_left.Union(query3right); var output3 = container3.RegisterOutput(query3); - var outputAsync3 = output3.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(o => outputListWithoutCheckpoint.Add(o)); + var outputAsync3 = output3.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(outputListWithoutCheckpoint.Add); container3.Restore(null); outputAsync3.Wait(); outputListWithoutCheckpoint.Sort(); @@ -4822,7 +4822,7 @@ public void BasicUnaryCheckpointAnonTypeSelectManyColumnarSmallBatch() var outputAsync1 = output1.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(o => outputListWithCheckpoint.Add(o.p)); var pipe1 = container1.Restore(null); - preCheckpointData.ForEachAsync(e => preCheckpointSubject.OnNext(e)).Wait(); + preCheckpointData.ForEachAsync(preCheckpointSubject.OnNext).Wait(); pipe1.Checkpoint(state); state.Seek(0, SeekOrigin.Begin); @@ -4834,7 +4834,7 @@ public void BasicUnaryCheckpointAnonTypeSelectManyColumnarSmallBatch() var outputAsync2 = output2.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(o => outputListWithCheckpoint.Add(o.p)); var pipe2 = container2.Restore(state); - postCheckpointData.ForEachAsync(e => postCheckpointSubject.OnNext(e)).Wait(); + postCheckpointData.ForEachAsync(postCheckpointSubject.OnNext).Wait(); postCheckpointSubject.OnCompleted(); outputAsync2.Wait(); outputListWithCheckpoint.Sort(); @@ -4886,9 +4886,9 @@ public void BasicUnaryCheckpointCountColumnarSmallBatch() var output1 = container1.RegisterOutput(query1); - var outputAsync1 = output1.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(o => outputListWithCheckpoint.Add(o)); + var outputAsync1 = output1.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(outputListWithCheckpoint.Add); var pipe1 = container1.Restore(null); - preCheckpointData.ForEachAsync(e => preCheckpointSubject.OnNext(e)).Wait(); + preCheckpointData.ForEachAsync(preCheckpointSubject.OnNext).Wait(); pipe1.Checkpoint(state); state.Seek(0, SeekOrigin.Begin); @@ -4898,9 +4898,9 @@ public void BasicUnaryCheckpointCountColumnarSmallBatch() var query2 = input2.Count(); var output2 = container2.RegisterOutput(query2); - var outputAsync2 = output2.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(o => outputListWithCheckpoint.Add(o)); + var outputAsync2 = output2.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(outputListWithCheckpoint.Add); var pipe2 = container2.Restore(state); - postCheckpointData.ForEachAsync(e => postCheckpointSubject.OnNext(e)).Wait(); + postCheckpointData.ForEachAsync(postCheckpointSubject.OnNext).Wait(); postCheckpointSubject.OnCompleted(); outputAsync2.Wait(); outputListWithCheckpoint.Sort(); @@ -4910,7 +4910,7 @@ public void BasicUnaryCheckpointCountColumnarSmallBatch() var query3 = input3.Count(); var output3 = container3.RegisterOutput(query3); - var outputAsync3 = output3.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(o => outputListWithoutCheckpoint.Add(o)); + var outputAsync3 = output3.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(outputListWithoutCheckpoint.Add); container3.Restore(null); outputAsync3.Wait(); @@ -4952,9 +4952,9 @@ public void BasicUnaryCheckpointGroupedSumColumnarSmallBatch() var output1 = container1.RegisterOutput(query1); - var outputAsync1 = output1.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(o => outputListWithCheckpoint.Add(o)); + var outputAsync1 = output1.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(outputListWithCheckpoint.Add); var pipe1 = container1.Restore(null); - preCheckpointData.ForEachAsync(e => preCheckpointSubject.OnNext(e)).Wait(); + preCheckpointData.ForEachAsync(preCheckpointSubject.OnNext).Wait(); pipe1.Checkpoint(state); state.Seek(0, SeekOrigin.Begin); @@ -4964,9 +4964,9 @@ public void BasicUnaryCheckpointGroupedSumColumnarSmallBatch() var query2 = input2.GroupApply(e => e.Item1, str => str.Sum(e => (ulong)e.Item2), (g, c) => new StructTuple { Item1 = g.Key, Item2 = c }); var output2 = container2.RegisterOutput(query2); - var outputAsync2 = output2.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(o => outputListWithCheckpoint.Add(o)); + var outputAsync2 = output2.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(outputListWithCheckpoint.Add); var pipe2 = container2.Restore(state); - postCheckpointData.ForEachAsync(e => postCheckpointSubject.OnNext(e)).Wait(); + postCheckpointData.ForEachAsync(postCheckpointSubject.OnNext).Wait(); postCheckpointSubject.OnCompleted(); outputAsync2.Wait(); outputListWithCheckpoint.Sort((a, b) => a.Item1.CompareTo(b.Item1) == 0 ? a.Item2.CompareTo(b.Item2) : a.Item1.CompareTo(b.Item1)); @@ -4976,7 +4976,7 @@ public void BasicUnaryCheckpointGroupedSumColumnarSmallBatch() var query3 = input3.GroupApply(e => e.Item1, str => str.Sum(e => (ulong)e.Item2), (g, c) => new StructTuple { Item1 = g.Key, Item2 = c }); var output3 = container3.RegisterOutput(query3); - var outputAsync3 = output3.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(o => outputListWithoutCheckpoint.Add(o)); + var outputAsync3 = output3.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(outputListWithoutCheckpoint.Add); container3.Restore(null); outputAsync3.Wait(); @@ -5034,11 +5034,11 @@ public void BasicUnaryCheckpointEquiJoinColumnarSmallBatch() var output1 = container1.RegisterOutput(query1); - var outputAsync1 = output1.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(o => outputListWithCheckpoint.Add(o)); + var outputAsync1 = output1.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(outputListWithCheckpoint.Add); var pipe1 = container1.Restore(null); - preCheckpointData1.ForEachAsync(e => preCheckpointSubject1.OnNext(e)).Wait(); - preCheckpointData2.ForEachAsync(e => preCheckpointSubject2.OnNext(e)).Wait(); + preCheckpointData1.ForEachAsync(preCheckpointSubject1.OnNext).Wait(); + preCheckpointData2.ForEachAsync(preCheckpointSubject2.OnNext).Wait(); pipe1.Checkpoint(state); @@ -5050,11 +5050,11 @@ public void BasicUnaryCheckpointEquiJoinColumnarSmallBatch() var query2 = input21.Join(input22, e => e.Item1, e => e.Item1, (l, r) => new StructTuple { Item1 = l.Item1, Item2 = r.Item2 }); var output2 = container2.RegisterOutput(query2); - var outputAsync2 = output2.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(o => outputListWithCheckpoint.Add(o)); + var outputAsync2 = output2.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(outputListWithCheckpoint.Add); var pipe2 = container2.Restore(state); - postCheckpointData1.ForEachAsync(e => postCheckpointSubject1.OnNext(e)).Wait(); - postCheckpointData2.ForEachAsync(e => postCheckpointSubject2.OnNext(e)).Wait(); + postCheckpointData1.ForEachAsync(postCheckpointSubject1.OnNext).Wait(); + postCheckpointData2.ForEachAsync(postCheckpointSubject2.OnNext).Wait(); postCheckpointSubject1.OnCompleted(); postCheckpointSubject2.OnCompleted(); outputAsync2.Wait(); @@ -5066,7 +5066,7 @@ public void BasicUnaryCheckpointEquiJoinColumnarSmallBatch() var query3 = input31.Join(input32, e => e.Item1, e => e.Item1, (l, r) => new StructTuple { Item1 = l.Item1, Item2 = r.Item2 }); var output3 = container3.RegisterOutput(query3); - var outputAsync3 = output3.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(o => outputListWithoutCheckpoint.Add(o)); + var outputAsync3 = output3.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(outputListWithoutCheckpoint.Add); container3.Restore(null); outputAsync3.Wait(); @@ -5127,11 +5127,11 @@ public void BasicUnaryCheckpointLASJColumnarSmallBatch() var output1 = container1.RegisterOutput(query1); - var outputAsync1 = output1.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(o => outputListWithCheckpoint.Add(o)); + var outputAsync1 = output1.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(outputListWithCheckpoint.Add); var pipe1 = container1.Restore(null); - preCheckpointData1.ForEachAsync(e => preCheckpointSubject1.OnNext(e)).Wait(); - preCheckpointData2.ForEachAsync(e => preCheckpointSubject2.OnNext(e)).Wait(); + preCheckpointData1.ForEachAsync(preCheckpointSubject1.OnNext).Wait(); + preCheckpointData2.ForEachAsync(preCheckpointSubject2.OnNext).Wait(); pipe1.Checkpoint(state); @@ -5143,11 +5143,11 @@ public void BasicUnaryCheckpointLASJColumnarSmallBatch() var query2 = input21.WhereNotExists(input22, e => e.Item1, e => e.Item1); var output2 = container2.RegisterOutput(query2); - var outputAsync2 = output2.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(o => outputListWithCheckpoint.Add(o)); + var outputAsync2 = output2.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(outputListWithCheckpoint.Add); var pipe2 = container2.Restore(state); - postCheckpointData1.ForEachAsync(e => postCheckpointSubject1.OnNext(e)).Wait(); - postCheckpointData2.ForEachAsync(e => postCheckpointSubject2.OnNext(e)).Wait(); + postCheckpointData1.ForEachAsync(postCheckpointSubject1.OnNext).Wait(); + postCheckpointData2.ForEachAsync(postCheckpointSubject2.OnNext).Wait(); postCheckpointSubject1.OnCompleted(); postCheckpointSubject2.OnCompleted(); outputAsync2.Wait(); @@ -5159,7 +5159,7 @@ public void BasicUnaryCheckpointLASJColumnarSmallBatch() var query3 = input31.WhereNotExists(input32, e => e.Item1, e => e.Item1); var output3 = container3.RegisterOutput(query3); - var outputAsync3 = output3.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(o => outputListWithoutCheckpoint.Add(o)); + var outputAsync3 = output3.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(outputListWithoutCheckpoint.Add); container3.Restore(null); outputAsync3.Wait(); @@ -5220,11 +5220,11 @@ public void LeftUnaryCheckpointLASJColumnarSmallBatch() var output1 = container1.RegisterOutput(query1); - var outputAsync1 = output1.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(o => outputListWithCheckpoint.Add(o)); + var outputAsync1 = output1.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(outputListWithCheckpoint.Add); var pipe1 = container1.Restore(null); - preCheckpointData1.ForEachAsync(e => preCheckpointSubject1.OnNext(e)).Wait(); - preCheckpointData2.ForEachAsync(e => preCheckpointSubject2.OnNext(e)).Wait(); + preCheckpointData1.ForEachAsync(preCheckpointSubject1.OnNext).Wait(); + preCheckpointData2.ForEachAsync(preCheckpointSubject2.OnNext).Wait(); pipe1.Checkpoint(state); @@ -5236,11 +5236,11 @@ public void LeftUnaryCheckpointLASJColumnarSmallBatch() var query2 = input21.WhereNotExists(input22, e => e.Item1, e => e.Item1); var output2 = container2.RegisterOutput(query2); - var outputAsync2 = output2.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(o => outputListWithCheckpoint.Add(o)); + var outputAsync2 = output2.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(outputListWithCheckpoint.Add); var pipe2 = container2.Restore(state); - postCheckpointData1.ForEachAsync(e => postCheckpointSubject1.OnNext(e)).Wait(); - postCheckpointData2.ForEachAsync(e => postCheckpointSubject2.OnNext(e)).Wait(); + postCheckpointData1.ForEachAsync(postCheckpointSubject1.OnNext).Wait(); + postCheckpointData2.ForEachAsync(postCheckpointSubject2.OnNext).Wait(); postCheckpointSubject1.OnCompleted(); postCheckpointSubject2.OnCompleted(); outputAsync2.Wait(); @@ -5252,7 +5252,7 @@ public void LeftUnaryCheckpointLASJColumnarSmallBatch() var query3 = input31.WhereNotExists(input32, e => e.Item1, e => e.Item1); var output3 = container3.RegisterOutput(query3); - var outputAsync3 = output3.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(o => outputListWithoutCheckpoint.Add(o)); + var outputAsync3 = output3.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(outputListWithoutCheckpoint.Add); container3.Restore(null); outputAsync3.Wait(); @@ -5313,11 +5313,11 @@ public void RightUnaryCheckpointLASJColumnarSmallBatch() var output1 = container1.RegisterOutput(query1); - var outputAsync1 = output1.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(o => outputListWithCheckpoint.Add(o)); + var outputAsync1 = output1.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(outputListWithCheckpoint.Add); var pipe1 = container1.Restore(null); - preCheckpointData1.ForEachAsync(e => preCheckpointSubject1.OnNext(e)).Wait(); - preCheckpointData2.ForEachAsync(e => preCheckpointSubject2.OnNext(e)).Wait(); + preCheckpointData1.ForEachAsync(preCheckpointSubject1.OnNext).Wait(); + preCheckpointData2.ForEachAsync(preCheckpointSubject2.OnNext).Wait(); pipe1.Checkpoint(state); @@ -5329,11 +5329,11 @@ public void RightUnaryCheckpointLASJColumnarSmallBatch() var query2 = input21.WhereNotExists(input22, e => e.Item1, e => e.Item1); var output2 = container2.RegisterOutput(query2); - var outputAsync2 = output2.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(o => outputListWithCheckpoint.Add(o)); + var outputAsync2 = output2.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(outputListWithCheckpoint.Add); var pipe2 = container2.Restore(state); - postCheckpointData1.ForEachAsync(e => postCheckpointSubject1.OnNext(e)).Wait(); - postCheckpointData2.ForEachAsync(e => postCheckpointSubject2.OnNext(e)).Wait(); + postCheckpointData1.ForEachAsync(postCheckpointSubject1.OnNext).Wait(); + postCheckpointData2.ForEachAsync(postCheckpointSubject2.OnNext).Wait(); postCheckpointSubject1.OnCompleted(); postCheckpointSubject2.OnCompleted(); outputAsync2.Wait(); @@ -5345,7 +5345,7 @@ public void RightUnaryCheckpointLASJColumnarSmallBatch() var query3 = input31.WhereNotExists(input32, e => e.Item1, e => e.Item1); var output3 = container3.RegisterOutput(query3); - var outputAsync3 = output3.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(o => outputListWithoutCheckpoint.Add(o)); + var outputAsync3 = output3.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(outputListWithoutCheckpoint.Add); container3.Restore(null); outputAsync3.Wait(); @@ -5391,10 +5391,10 @@ public void SelfUnaryCheckpointLASJColumnarSmallBatch() var output1 = container1.RegisterOutput(query1); - var outputAsync1 = output1.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(o => outputListWithCheckpoint.Add(o)); + var outputAsync1 = output1.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(outputListWithCheckpoint.Add); var pipe1 = container1.Restore(null); - preCheckpointData.ForEachAsync(e => preCheckpointSubject.OnNext(e)).Wait(); + preCheckpointData.ForEachAsync(preCheckpointSubject.OnNext).Wait(); pipe1.Checkpoint(state); @@ -5405,10 +5405,10 @@ public void SelfUnaryCheckpointLASJColumnarSmallBatch() var query2 = input2.GroupApply(o => 1, s => s.Multicast(p => p.WhereNotExists(p.Where(i => false), e => e.Item1, e => e.Item1))); var output2 = container2.RegisterOutput(query2); - var outputAsync2 = output2.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(o => outputListWithCheckpoint.Add(o)); + var outputAsync2 = output2.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(outputListWithCheckpoint.Add); var pipe2 = container2.Restore(state); - postCheckpointData.ForEachAsync(e => postCheckpointSubject.OnNext(e)).Wait(); + postCheckpointData.ForEachAsync(postCheckpointSubject.OnNext).Wait(); postCheckpointSubject.OnCompleted(); outputAsync2.Wait(); outputListWithCheckpoint.Sort((a, b) => a.Item1.CompareTo(b.Item1) == 0 ? a.Item2.CompareTo(b.Item2) : a.Item1.CompareTo(b.Item1)); @@ -5418,7 +5418,7 @@ public void SelfUnaryCheckpointLASJColumnarSmallBatch() var query3 = input3.GroupApply(o => 1, s => s.Multicast(p => p.WhereNotExists(p.Where(i => false), e => e.Item1, e => e.Item1))); var output3 = container3.RegisterOutput(query3); - var outputAsync3 = output3.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(o => outputListWithoutCheckpoint.Add(o)); + var outputAsync3 = output3.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(outputListWithoutCheckpoint.Add); container3.Restore(null); outputAsync3.Wait(); @@ -5478,11 +5478,11 @@ public void BasicUnaryCheckpointClipColumnarSmallBatch() var output1 = container1.RegisterOutput(query1); - var outputAsync1 = output1.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(o => outputListWithCheckpoint.Add(o)); + var outputAsync1 = output1.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(outputListWithCheckpoint.Add); var pipe1 = container1.Restore(null); - preCheckpointData1.ForEachAsync(e => preCheckpointSubject1.OnNext(e)).Wait(); - preCheckpointData2.ForEachAsync(e => preCheckpointSubject2.OnNext(e)).Wait(); + preCheckpointData1.ForEachAsync(preCheckpointSubject1.OnNext).Wait(); + preCheckpointData2.ForEachAsync(preCheckpointSubject2.OnNext).Wait(); pipe1.Checkpoint(state); @@ -5494,11 +5494,11 @@ public void BasicUnaryCheckpointClipColumnarSmallBatch() var query2 = input21.ClipEventDuration(input22, e => e.Item1, e => e.Item1); var output2 = container2.RegisterOutput(query2); - var outputAsync2 = output2.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(o => outputListWithCheckpoint.Add(o)); + var outputAsync2 = output2.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(outputListWithCheckpoint.Add); var pipe2 = container2.Restore(state); - postCheckpointData1.ForEachAsync(e => postCheckpointSubject1.OnNext(e)).Wait(); - postCheckpointData2.ForEachAsync(e => postCheckpointSubject2.OnNext(e)).Wait(); + postCheckpointData1.ForEachAsync(postCheckpointSubject1.OnNext).Wait(); + postCheckpointData2.ForEachAsync(postCheckpointSubject2.OnNext).Wait(); postCheckpointSubject1.OnCompleted(); postCheckpointSubject2.OnCompleted(); outputAsync2.Wait(); @@ -5510,7 +5510,7 @@ public void BasicUnaryCheckpointClipColumnarSmallBatch() var query3 = input31.ClipEventDuration(input32, e => e.Item1, e => e.Item1); var output3 = container3.RegisterOutput(query3); - var outputAsync3 = output3.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(o => outputListWithoutCheckpoint.Add(o)); + var outputAsync3 = output3.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(outputListWithoutCheckpoint.Add); container3.Restore(null); outputAsync3.Wait(); @@ -5553,7 +5553,7 @@ public void BasicEmptyCheckpointErrorColumnarSmallBatch() var query1 = query1_left.Union(query1right); var output1 = container1.RegisterOutput(query1); - var outputAsync1 = output1.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(o => outputListWithCheckpoint.Add(o)); + var outputAsync1 = output1.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(outputListWithCheckpoint.Add); try { @@ -5599,9 +5599,9 @@ public void BasicUnaryCheckpointErrorColumnarSmallBatch() var query1 = CreateBasicQuery(input1); var output1 = container1.RegisterOutput(query1); - var outputAsync1 = output1.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(o => outputList.Add(o)); + var outputAsync1 = output1.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(outputList.Add); var pipe1 = container1.Restore(null); - preCheckpointData.ForEachAsync(e => preCheckpointSubject.OnNext(e)).Wait(); + preCheckpointData.ForEachAsync(preCheckpointSubject.OnNext).Wait(); pipe1.Checkpoint(state); state.Seek(0, SeekOrigin.Begin); @@ -5611,9 +5611,9 @@ public void BasicUnaryCheckpointErrorColumnarSmallBatch() var query2 = CreateBasicQuery(input2); var output2 = container2.RegisterOutput(query2); - var outputAsync2 = output2.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(o => outputList.Add(o)); + var outputAsync2 = output2.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(outputList.Add); var pipe2 = container2.Restore(state); - postCheckpointData.ForEachAsync(e => postCheckpointSubject.OnNext(e)).Wait(); + postCheckpointData.ForEachAsync(postCheckpointSubject.OnNext).Wait(); outputAsync2.Wait(); } catch (AggregateException e) @@ -5657,9 +5657,9 @@ public void BasicDisorderPolicyErrorColumnarSmallBatch() var query1 = CreateBasicQuery(input1); var output1 = container1.RegisterOutput(query1); - var outputAsync1 = output1.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(o => outputList.Add(o)); + var outputAsync1 = output1.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(outputList.Add); var pipe1 = container1.Restore(null); - preCheckpointData.ForEachAsync(e => preCheckpointSubject.OnNext(e)).Wait(); + preCheckpointData.ForEachAsync(preCheckpointSubject.OnNext).Wait(); pipe1.Checkpoint(state); state.Seek(0, SeekOrigin.Begin); @@ -5671,9 +5671,9 @@ public void BasicDisorderPolicyErrorColumnarSmallBatch() var query2 = CreateBasicQuery(input2); var output2 = container2.RegisterOutput(query2); - var outputAsync2 = output2.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(o => outputList.Add(o)); + var outputAsync2 = output2.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(outputList.Add); var pipe2 = container2.Restore(state); - postCheckpointData.ForEachAsync(e => postCheckpointSubject.OnNext(e)).Wait(); + postCheckpointData.ForEachAsync(postCheckpointSubject.OnNext).Wait(); postCheckpointSubject.OnCompleted(); outputAsync2.Wait(); } @@ -5714,9 +5714,9 @@ public void BasicDisorderAdjustPolicyColumnarSmallBatch() var query1 = CreateBasicQuery(input1); var output1 = container1.RegisterOutput(query1); - var outputAsync1 = output1.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(o => outputList.Add(o)); + var outputAsync1 = output1.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(outputList.Add); var pipe1 = container1.Restore(null); - preCheckpointData.ForEachAsync(e => preCheckpointSubject.OnNext(e)).Wait(); + preCheckpointData.ForEachAsync(preCheckpointSubject.OnNext).Wait(); pipe1.Checkpoint(state); state.Seek(0, SeekOrigin.Begin); @@ -5726,13 +5726,13 @@ public void BasicDisorderAdjustPolicyColumnarSmallBatch() var query2 = CreateBasicQuery(input2); var output2 = container2.RegisterOutput(query2); - var outputAsync2 = output2.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(o => outputList.Add(o)); + var outputAsync2 = output2.Where(e => e.IsData).Select(e => e.Payload).ForEachAsync(outputList.Add); var pipe2 = container2.Restore(state); - postCheckpointData.ForEachAsync(e => postCheckpointSubject.OnNext(e)).Wait(); + postCheckpointData.ForEachAsync(postCheckpointSubject.OnNext).Wait(); postCheckpointSubject.OnCompleted(); outputAsync2.Wait(); - Assert.IsTrue(outputList.Count == 10000); + Assert.HasCount(10000, outputList); preCheckpointSubject.OnCompleted(); } diff --git a/Sources/Test/SimpleTesting/CodegenAssemblyCacheTests.cs b/Sources/Test/SimpleTesting/CodegenAssemblyCacheTests.cs new file mode 100644 index 000000000..247f40f7a --- /dev/null +++ b/Sources/Test/SimpleTesting/CodegenAssemblyCacheTests.cs @@ -0,0 +1,271 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Reflection; +using System.Text; +using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis.CSharp; +using Microsoft.StreamProcessing; +using Microsoft.VisualStudio.TestTools.UnitTesting; + +namespace SimpleTesting +{ + /// + /// Disk cache settings are applied with inside a using; dispose restores prior + /// and so other tests see default Trill behavior. + /// clears the cache path and counters in case a future test forgets the modifier. + /// + [TestClass] + public sealed class CodegenAssemblyCacheTests + { + private const string ValidSource = + "namespace Microsoft.StreamProcessing { public static class CodegenCacheProbe { public static int F() => 42; } }"; + + private static string UniqueProbeSource(string tag) + => $"namespace Microsoft.StreamProcessing {{ public static class CodegenCacheProbe_{tag} {{ public static int F() => 42; }} }}"; + + private static string UniqueProbeTypeName(string tag) => $"Microsoft.StreamProcessing.CodegenCacheProbe_{tag}"; + + private static Assembly CompileForTest(string source, string typeFullName, out string errorMessages) + { + Type resolved = Transformer.CompileSourceCode(source, Array.Empty(), a => a.GetType(typeFullName), out errorMessages); + return resolved?.Assembly; + } + + [TestCleanup] + public void TestCleanup() + { + Config.CodegenAssemblyCachePath = null; + Transformer.CodegenAssemblyCacheHits = 0; + Transformer.CodegenAssemblyCacheMisses = 0; + } + + [TestMethod] + public void ConfigModifier_restores_codegen_cache_path_and_generate_debug_info() + { + string priorPath = Config.CodegenAssemblyCachePath; + bool priorGenerateDebugInfo = Config.CodegenOptions.GenerateDebugInfo; + string dir = Path.Combine(Path.GetTempPath(), "TrillCodegenRestore_" + Guid.NewGuid().ToString("N")); + Directory.CreateDirectory(dir); + try + { + using (new ConfigModifier().CodegenAssemblyCachePath(dir).GenerateDebugInfo(false).Modify()) + { + Assert.AreEqual(dir, Config.CodegenAssemblyCachePath); + Assert.IsFalse(Config.CodegenOptions.GenerateDebugInfo); + } + + Assert.AreEqual(priorPath, Config.CodegenAssemblyCachePath); + Assert.AreEqual(priorGenerateDebugInfo, Config.CodegenOptions.GenerateDebugInfo); + } + finally + { + TryDeleteDirectory(dir); + } + } + + [TestMethod] + public void Second_compile_with_same_source_hits_disk_cache() + { + string dir = Path.Combine(Path.GetTempPath(), "TrillCodegenTest_" + Guid.NewGuid().ToString("N")); + Directory.CreateDirectory(dir); + try + { + using (new ConfigModifier().CodegenAssemblyCachePath(dir).GenerateDebugInfo(false).Modify()) + { + Transformer.CodegenAssemblyCacheHits = 0; + Transformer.CodegenAssemblyCacheMisses = 0; + + Assembly a1 = CompileForTest(ValidSource, "Microsoft.StreamProcessing.CodegenCacheProbe", out string err1); + Assert.IsNotNull(a1, err1); + Assert.IsTrue(string.IsNullOrEmpty(err1), err1); + Assert.IsTrue(Transformer.CodegenAssemblyCacheMisses >= 1, "first compile should emit"); + long hitsAfterFirst = Transformer.CodegenAssemblyCacheHits; + + Assembly a2 = CompileForTest(ValidSource, "Microsoft.StreamProcessing.CodegenCacheProbe", out string err2); + Assert.IsNotNull(a2, err2); + Assert.IsTrue(string.IsNullOrEmpty(err2), err2); + Assert.IsTrue(Transformer.CodegenAssemblyCacheHits > hitsAfterFirst, "second compile should load from disk"); + } + } + finally + { + TryDeleteDirectory(dir); + } + } + + [TestMethod] + public void Second_compile_with_same_source_hits_disk_cache_when_generate_debug_info_enabled() + { + string dir = Path.Combine(Path.GetTempPath(), "TrillCodegenDebug_" + Guid.NewGuid().ToString("N")); + Directory.CreateDirectory(dir); + try + { + using (new ConfigModifier().CodegenAssemblyCachePath(dir).GenerateDebugInfo(true).Modify()) + { + Transformer.CodegenAssemblyCacheHits = 0; + Transformer.CodegenAssemblyCacheMisses = 0; + + Assembly a1 = CompileForTest(ValidSource, "Microsoft.StreamProcessing.CodegenCacheProbe", out string err1); + Assert.IsNotNull(a1, err1); + Assert.IsTrue(string.IsNullOrEmpty(err1), err1); + Assert.IsTrue(Transformer.CodegenAssemblyCacheMisses >= 1, "first compile should emit"); + long hitsAfterFirst = Transformer.CodegenAssemblyCacheHits; + + Assembly a2 = CompileForTest(ValidSource, "Microsoft.StreamProcessing.CodegenCacheProbe", out string err2); + Assert.IsNotNull(a2, err2); + Assert.IsTrue(string.IsNullOrEmpty(err2), err2); + Assert.IsTrue(Transformer.CodegenAssemblyCacheHits > hitsAfterFirst, "second compile should load from disk"); + } + } + finally + { + TryDeleteDirectory(dir); + } + } + + [TestMethod] + public void Corrupt_preseeded_disk_cache_entry_is_replaced_by_fresh_emit() + { + string tag = Guid.NewGuid().ToString("N"); + string source = UniqueProbeSource(tag); + string typeName = UniqueProbeTypeName(tag); + + string dir = Path.Combine(Path.GetTempPath(), "TrillCodegenCorrupt_" + Guid.NewGuid().ToString("N")); + Directory.CreateDirectory(dir); + try + { + using (new ConfigModifier().CodegenAssemblyCachePath(dir).GenerateDebugInfo(false).Modify()) + { + Transformer.PrepareCompileSourceCodeFingerprintInputs( + source, + Array.Empty(), + includeIgnoreAccessChecksAssembly: true, + includeDebugInfo: false, + out List refs, + out CSharpCompilationOptions options, + out SyntaxTree tree); + Assert.IsTrue( + Transformer.TryComputeFingerprint( + tree.GetRoot().ToFullString(), + tree.Options, + refs, + options, + includeIgnoreAccessChecksAssembly: true, + emitPortablePdb: false, + out _, + out string fingerprint), + "fingerprint inputs should match CompileSourceCode (debug off)"); + + string cacheDll = Path.Combine(dir, fingerprint + ".dll"); + File.WriteAllBytes(cacheDll, Encoding.UTF8.GetBytes("not a PE – corrupt cache seed")); + + Assembly asm = CompileForTest(source, typeName, out string err); + Assert.IsNotNull(asm, err); + Assert.IsTrue(string.IsNullOrEmpty(err), err); + + byte[] pe = File.ReadAllBytes(cacheDll); + Assert.IsTrue(pe.Length > 64, "emit should overwrite corrupt file with a real assembly"); + Assert.AreEqual((byte)'M', pe[0]); + Assert.AreEqual((byte)'Z', pe[1]); + } + } + finally + { + TryDeleteDirectory(dir); + } + } + + [TestMethod] + public void TypeLoadException_from_resolveType_on_cached_assembly_triggers_retry_emit() + { + string tag = Guid.NewGuid().ToString("N"); + string source = UniqueProbeSource(tag); + string typeName = UniqueProbeTypeName(tag); + + string dir = Path.Combine(Path.GetTempPath(), "TrillCodegenRetry_" + Guid.NewGuid().ToString("N")); + Directory.CreateDirectory(dir); + try + { + using (new ConfigModifier().CodegenAssemblyCachePath(dir).GenerateDebugInfo(false).Modify()) + { + Assembly seed = CompileForTest(source, typeName, out string seedErr); + Assert.IsNotNull(seed, seedErr); + Assert.IsTrue(string.IsNullOrEmpty(seedErr), seedErr); + + int resolveInvocations = 0; + Type resolved = Transformer.CompileSourceCode( + source, + Array.Empty(), + a => + { + resolveInvocations++; + if (resolveInvocations == 1) + { + throw new TypeLoadException("simulated: resolveType fails on assembly loaded from disk cache"); + } + + return a.GetType(typeName); + }, + out string err, + includeIgnoreAccessChecksAssembly: true); + + Assert.IsNotNull(resolved, err); + Assert.AreEqual(2, resolveInvocations, "resolveType should run once for cached load and again after cache discard + emit"); + } + } + finally + { + TryDeleteDirectory(dir); + } + } + + [TestMethod] + public void Different_source_produces_distinct_cache_files() + { + string dir = Path.Combine(Path.GetTempPath(), "TrillCodegenTest_" + Guid.NewGuid().ToString("N")); + Directory.CreateDirectory(dir); + try + { + using (new ConfigModifier().CodegenAssemblyCachePath(dir).GenerateDebugInfo(false).Modify()) + { + const string srcA = + "namespace Microsoft.StreamProcessing { public static class A { public static int F() => 1; } }"; + const string srcB = + "namespace Microsoft.StreamProcessing { public static class B { public static int F() => 2; } }"; + + CompileForTest(srcA, "Microsoft.StreamProcessing.A", out string errA); + Assert.IsTrue(string.IsNullOrEmpty(errA), errA); + int countAfterA = Directory.GetFiles(dir, "*.dll").Length; + + CompileForTest(srcB, "Microsoft.StreamProcessing.B", out string errB); + Assert.IsTrue(string.IsNullOrEmpty(errB), errB); + int countAfterB = Directory.GetFiles(dir, "*.dll").Length; + + Assert.IsTrue(countAfterB > countAfterA, "second distinct source should add another cached assembly"); + } + } + finally + { + TryDeleteDirectory(dir); + } + } + + private static void TryDeleteDirectory(string dir) + { + try + { + if (Directory.Exists(dir)) + { + Directory.Delete(dir, recursive: true); + } + } + catch (IOException) + { + } + catch (UnauthorizedAccessException) + { + } + } + } +} diff --git a/Sources/Test/SimpleTesting/Collections/AbstractEventBatch.cs b/Sources/Test/SimpleTesting/Collections/AbstractEventBatch.cs index 28e73fb35..c07b95977 100644 --- a/Sources/Test/SimpleTesting/Collections/AbstractEventBatch.cs +++ b/Sources/Test/SimpleTesting/Collections/AbstractEventBatch.cs @@ -43,21 +43,21 @@ public void ComputeMinMax_Basic() // (a) message.Count = 0; - Assert.IsTrue(message.MinTimestamp == StreamEvent.MinSyncTime, "Empty message with Count=0 has MinTimestamp <> 0."); - Assert.IsTrue(message.MaxTimestamp == StreamEvent.MaxSyncTime, "Empty message with Count=0 has MaxTimestamp <> inf-1."); + Assert.AreEqual(StreamEvent.MinSyncTime, message.MinTimestamp, "Empty message with Count=0 has MinTimestamp <> 0."); + Assert.AreEqual(StreamEvent.MaxSyncTime, message.MaxTimestamp, "Empty message with Count=0 has MaxTimestamp <> inf-1."); // (b) message.Count = 1; message.vsync.col[0] = TESTVALUE; - Assert.IsTrue(message.MinTimestamp == StreamEvent.MinSyncTime, "Empty message with Count=1 has MinTimestamp <> 0."); - Assert.IsTrue(message.MaxTimestamp == StreamEvent.MaxSyncTime, "Empty message with Count=1 has MaxTimestamp <> inf-1."); + Assert.AreEqual(StreamEvent.MinSyncTime, message.MinTimestamp, "Empty message with Count=1 has MinTimestamp <> 0."); + Assert.AreEqual(StreamEvent.MaxSyncTime, message.MaxTimestamp, "Empty message with Count=1 has MaxTimestamp <> inf-1."); // (c) message.Count = 1; message.vsync.col[0] = TESTVALUE; OccupyAt(message, 0); - Assert.IsTrue(message.MinTimestamp == TESTVALUE, "Empty message with Count=1 has MinTimestamp <> TESTVALUE."); - Assert.IsTrue(message.MaxTimestamp == TESTVALUE, "Empty message with Count=1 has MaxTimestamp <> TESTVALUE"); + Assert.AreEqual(TESTVALUE, message.MinTimestamp, "Empty message with Count=1 has MinTimestamp <> TESTVALUE."); + Assert.AreEqual(TESTVALUE, message.MaxTimestamp, "Empty message with Count=1 has MaxTimestamp <> TESTVALUE"); VacateAt(message, 0); message.vsync.col[0] = 0; @@ -65,14 +65,14 @@ public void ComputeMinMax_Basic() message.Count = 100; message.vsync.col[5] = TESTVALUE - 1; message.vsync.col[42] = TESTVALUE; - Assert.IsTrue(message.MinTimestamp == StreamEvent.MinSyncTime, "Empty message with Count>1 has MinTimestamp <> 0."); - Assert.IsTrue(message.MaxTimestamp == StreamEvent.MaxSyncTime, "Empty message with Count>1 has MaxTimestamp <> inf-1"); + Assert.AreEqual(StreamEvent.MinSyncTime, message.MinTimestamp, "Empty message with Count>1 has MinTimestamp <> 0."); + Assert.AreEqual(StreamEvent.MaxSyncTime, message.MaxTimestamp, "Empty message with Count>1 has MaxTimestamp <> inf-1"); // (e) OccupyAt(message, 5); OccupyAt(message, 42); - Assert.IsTrue(message.MinTimestamp == TESTVALUE - 1, "Non-empty message with Count>1 has MinTimestamp <> TESTVALUE-1."); - Assert.IsTrue(message.MaxTimestamp == TESTVALUE, "Non-empty message with Count>1 has MaxTimestamp <> TESTVALUE"); + Assert.AreEqual(TESTVALUE - 1, message.MinTimestamp, "Non-empty message with Count>1 has MinTimestamp <> TESTVALUE-1."); + Assert.AreEqual(TESTVALUE, message.MaxTimestamp, "Non-empty message with Count>1 has MaxTimestamp <> TESTVALUE"); VacateAt(message, 5); VacateAt(message, 42); message.vsync.col[5] = 0; @@ -161,21 +161,21 @@ public void ComputeMinMax_Partitioned_Basic() // (a) message.Count = 0; - Assert.IsTrue(message.MinTimestamp == StreamEvent.MinSyncTime, "Empty message with Count=0 has MinTimestamp <> 0."); - Assert.IsTrue(message.MaxTimestamp == StreamEvent.MaxSyncTime, "Empty message with Count=0 has MaxTimestamp <> inf-1."); + Assert.AreEqual(StreamEvent.MinSyncTime, message.MinTimestamp, "Empty message with Count=0 has MinTimestamp <> 0."); + Assert.AreEqual(StreamEvent.MaxSyncTime, message.MaxTimestamp, "Empty message with Count=0 has MaxTimestamp <> inf-1."); // (b) message.Count = 1; message.vsync.col[0] = TESTVALUE; - Assert.IsTrue(message.MinTimestamp == StreamEvent.MinSyncTime, "Empty message with Count=1 has MinTimestamp <> 0."); - Assert.IsTrue(message.MaxTimestamp == StreamEvent.MaxSyncTime, "Empty message with Count=1 has MaxTimestamp <> inf-1."); + Assert.AreEqual(StreamEvent.MinSyncTime, message.MinTimestamp, "Empty message with Count=1 has MinTimestamp <> 0."); + Assert.AreEqual(StreamEvent.MaxSyncTime, message.MaxTimestamp, "Empty message with Count=1 has MaxTimestamp <> inf-1."); // (c) message.Count = 1; message.vsync.col[0] = TESTVALUE; OccupyAt(message, 0); - Assert.IsTrue(message.MinTimestamp == TESTVALUE, "Empty message with Count=1 has MinTimestamp <> TESTVALUE."); - Assert.IsTrue(message.MaxTimestamp == TESTVALUE, "Empty message with Count=1 has MaxTimestamp <> TESTVALUE"); + Assert.AreEqual(TESTVALUE, message.MinTimestamp, "Empty message with Count=1 has MinTimestamp <> TESTVALUE."); + Assert.AreEqual(TESTVALUE, message.MaxTimestamp, "Empty message with Count=1 has MaxTimestamp <> TESTVALUE"); VacateAt(message, 0); message.vsync.col[0] = 0; @@ -183,14 +183,14 @@ public void ComputeMinMax_Partitioned_Basic() message.Count = 100; message.vsync.col[5] = TESTVALUE - 1; message.vsync.col[42] = TESTVALUE; - Assert.IsTrue(message.MinTimestamp == StreamEvent.MinSyncTime, "Empty message with Count>1 has MinTimestamp <> 0."); - Assert.IsTrue(message.MaxTimestamp == StreamEvent.MaxSyncTime, "Empty message with Count>1 has MaxTimestamp <> inf-1"); + Assert.AreEqual(StreamEvent.MinSyncTime, message.MinTimestamp, "Empty message with Count>1 has MinTimestamp <> 0."); + Assert.AreEqual(StreamEvent.MaxSyncTime, message.MaxTimestamp, "Empty message with Count>1 has MaxTimestamp <> inf-1"); // (e) OccupyAt(message, 5); OccupyAt(message, 42); - Assert.IsTrue(message.MinTimestamp == TESTVALUE - 1, "Non-empty message with Count>1 has MinTimestamp <> TESTVALUE-1."); - Assert.IsTrue(message.MaxTimestamp == TESTVALUE, "Non-empty message with Count>1 has MaxTimestamp <> TESTVALUE"); + Assert.AreEqual(TESTVALUE - 1, message.MinTimestamp, "Non-empty message with Count>1 has MinTimestamp <> TESTVALUE-1."); + Assert.AreEqual(TESTVALUE, message.MaxTimestamp, "Non-empty message with Count>1 has MaxTimestamp <> TESTVALUE"); VacateAt(message, 5); VacateAt(message, 42); message.vsync.col[5] = 0; @@ -218,14 +218,14 @@ public void ComputeMinMax_Partitioned_Compound_Basic() message.Count = 100; message.vsync.col[5] = TESTVALUE; message.vsync.col[42] = TESTVALUE - 1; - Assert.IsTrue(message.MinTimestamp == StreamEvent.MinSyncTime, "Empty message with Count>1 has MinTimestamp <> 0."); - Assert.IsTrue(message.MaxTimestamp == StreamEvent.MaxSyncTime, "Empty message with Count>1 has MaxTimestamp <> inf-1"); + Assert.AreEqual(StreamEvent.MinSyncTime, message.MinTimestamp, "Empty message with Count>1 has MinTimestamp <> 0."); + Assert.AreEqual(StreamEvent.MaxSyncTime, message.MaxTimestamp, "Empty message with Count>1 has MaxTimestamp <> inf-1"); // (e) OccupyAt(message, 5); OccupyAt(message, 42); - Assert.IsTrue(message.MinTimestamp == TESTVALUE - 1, "Non-empty message with Count>1 has MinTimestamp <> TESTVALUE-1."); - Assert.IsTrue(message.MaxTimestamp == TESTVALUE, "Non-empty message with Count>1 has MaxTimestamp <> TESTVALUE"); + Assert.AreEqual(TESTVALUE - 1, message.MinTimestamp, "Non-empty message with Count>1 has MinTimestamp <> TESTVALUE-1."); + Assert.AreEqual(TESTVALUE, message.MaxTimestamp, "Non-empty message with Count>1 has MaxTimestamp <> TESTVALUE"); VacateAt(message, 5); VacateAt(message, 42); message.vsync.col[5] = 0; diff --git a/Sources/Test/SimpleTesting/Collections/FastListTest.cs b/Sources/Test/SimpleTesting/Collections/FastListTest.cs index 946f4c7c9..11c1957e0 100644 --- a/Sources/Test/SimpleTesting/Collections/FastListTest.cs +++ b/Sources/Test/SimpleTesting/Collections/FastListTest.cs @@ -39,9 +39,9 @@ private static void SimpleListTest() int indexA2 = list.Insert("a"); int indexB2 = list.Insert("b"); - Assert.IsTrue(indexA != indexA2); - Assert.IsTrue(indexA != indexB); - Assert.IsTrue(indexA2 != indexB2); + Assert.AreNotEqual(indexA2, indexA); + Assert.AreNotEqual(indexB, indexA); + Assert.AreNotEqual(indexB2, indexA2); Assert.IsFalse(list.IsEmpty); Assert.AreEqual(4, list.Count); @@ -131,7 +131,7 @@ private static void BetterListTest() { check += list.Values[index]; } - Assert.IsTrue(sum == check); + Assert.AreEqual(check, sum); } } } diff --git a/Sources/Test/SimpleTesting/Collections/FastMapTest.cs b/Sources/Test/SimpleTesting/Collections/FastMapTest.cs index 13cfb25c2..51750f2bf 100644 --- a/Sources/Test/SimpleTesting/Collections/FastMapTest.cs +++ b/Sources/Test/SimpleTesting/Collections/FastMapTest.cs @@ -40,9 +40,9 @@ private static void SimpleMapTest() int indexA5Two = map.Insert(5, "a"); int indexB5 = map.Insert(5, "b"); - Assert.IsTrue(indexA5 != indexA5Two); - Assert.IsTrue(indexA5 != indexB5); - Assert.IsTrue(indexA5Two != indexB5); + Assert.AreNotEqual(indexA5Two, indexA5); + Assert.AreNotEqual(indexB5, indexA5); + Assert.AreNotEqual(indexB5, indexA5Two); Assert.IsFalse(map.IsEmpty); Assert.AreEqual(4, map.Count); diff --git a/Sources/Test/SimpleTesting/ColumnarTests.cs b/Sources/Test/SimpleTesting/ColumnarTests.cs index ea06778aa..9e43a7627 100644 --- a/Sources/Test/SimpleTesting/ColumnarTests.cs +++ b/Sources/Test/SimpleTesting/ColumnarTests.cs @@ -4,7 +4,6 @@ // ********************************************************************* using System; using System.Collections.Generic; -using System.Diagnostics.CodeAnalysis; using System.Linq; using System.Linq.Expressions; using System.Reactive.Linq; @@ -29,8 +28,6 @@ public ColumnarTestBase() : base(new ConfigModifier() /// See SelectTransformer.Transform and SelectTransformer.ProjectionReturningResultInstance. /// This class covers all consumers of SelectTransformer.Transform /// - [SuppressMessage("StyleCop.CSharp.SpacingRules", "SA1008", Justification = "Reviewed.")] - [SuppressMessage("StyleCop.CSharp.SpacingRules", "SA1009", Justification = "Reviewed.")] [TestClass] public class GeneralProjectionFallbackTests : ColumnarTestBase { @@ -61,7 +58,7 @@ public class GeneralProjectionFallbackTests : ColumnarTestBase [TestMethod, TestCategory("Gated")] public void FixedIntervalEquiJoinTemplate() => EquiJoinWorker(constantDuration: 10); - private void EquiJoinWorker(long? constantDuration = null) + private static void EquiJoinWorker(long? constantDuration = null) { var left = new[] { @@ -86,7 +83,7 @@ private void EquiJoinWorker(long? constantDuration = null) var output = new List>(); left.Join(right, (l, r) => CreateValueTuple(l, r)) .ToStreamEventObservable() - .ForEachAsync(e => output.Add(e)) + .ForEachAsync(output.Add) .Wait(); var correct = new[] @@ -100,9 +97,7 @@ private void EquiJoinWorker(long? constantDuration = null) if (constantDuration.HasValue && constantDuration.Value != StreamEvent.InfinitySyncTime) { - correct = correct - .Select(e => e.IsPunctuation ? e : StreamEvent.CreateInterval(e.StartTime, e.StartTime + constantDuration.Value, e.Payload)) - .ToArray(); + correct = [.. correct.Select(e => e.IsPunctuation ? e : StreamEvent.CreateInterval(e.StartTime, e.StartTime + constantDuration.Value, e.Payload))]; } Assert.IsTrue(correct.SequenceEqual(output)); @@ -132,7 +127,7 @@ private void GroupWorker(bool group) input .GroupAggregate(s => true, w => w.Count(), (g, c) => CreateValueTuple(g.Key, c)) .ToStreamEventObservable() - .ForEachAsync(e => output.Add(e)) + .ForEachAsync(output.Add) .Wait(); var correct = new[] @@ -144,7 +139,7 @@ private void GroupWorker(bool group) Assert.IsTrue(correct.SequenceEqual(output)); } - private void SelectWorker(bool selectMany, bool fuse) + private static void SelectWorker(bool selectMany, bool fuse) { var input = new[] { @@ -175,7 +170,7 @@ private void SelectWorker(bool selectMany, bool fuse) selectStreamable .ToStreamEventObservable() - .ForEachAsync(e => output.Add(e)) + .ForEachAsync(output.Add) .Wait(); var correct = new[] diff --git a/Sources/Test/SimpleTesting/Common.cs b/Sources/Test/SimpleTesting/Common.cs index 29a080ad0..e85ac21eb 100644 --- a/Sources/Test/SimpleTesting/Common.cs +++ b/Sources/Test/SimpleTesting/Common.cs @@ -27,8 +27,8 @@ public static IStreamable ToStreamable( public static bool IsEquivalentTo(this IStreamable input, StreamEvent[] comparison) { - Invariant.IsNotNull(input, "input"); - Invariant.IsNotNull(comparison, "comparison"); + ArgumentNullException.ThrowIfNull(input); + ArgumentNullException.ThrowIfNull(comparison); var events = input.ToStreamEventArray(); var orderedEvents = events.OrderBy(e => e.SyncTime).ThenBy(e => e.OtherTime).ThenBy(e => e.Payload).ToArray(); var orderedComparison = comparison.OrderBy(e => e.SyncTime).ThenBy(e => e.OtherTime).ThenBy(e => e.Payload).ToArray(); @@ -38,19 +38,19 @@ public static bool IsEquivalentTo(this IStreamable in public static StreamEvent[] ToStreamEventArray(this IStreamable input) { - Invariant.IsNotNull(input, "input"); + ArgumentNullException.ThrowIfNull(input); return input.ToStreamEventObservable().ToEnumerable().ToArray(); } public static IStreamable ToCleanStreamable(this StreamEvent[] input) { - Invariant.IsNotNull(input, "input"); + ArgumentNullException.ThrowIfNull(input); return input.OrderBy(v => v.SyncTime).ToArray().ToStreamable(); } public static IStreamable ToStreamable(this StreamEvent[] input) { - Invariant.IsNotNull(input, "input"); + ArgumentNullException.ThrowIfNull(input); return input.ToObservable() .ToStreamable(null, FlushPolicy.FlushOnPunctuation); @@ -183,33 +183,28 @@ public static IEnumerable> ToEvents(this IEnumerable input, yield return StreamEvent.CreateInterval(vsSelector(e), veSelector(e), e); } } - -#if NET472 - // string.Split has different signatures across .NET Framework/Core, so use an extension so we can use a single signature - public static string[] Split(this string original, char separator, StringSplitOptions options) => original.Split(separator); -#endif } public static class Helpers { + /// + /// Runs the action in row mode then columnar mode. Uses + /// so toggles participate in the same gated swap/restore and global semaphore as tests, + /// instead of assigning static fields directly (which would bypass + /// that coordination and could race with parallel test workers). + /// public static void RunTwiceForRowAndColumnar(Action action) { - var savedForceRowBasedExecution = Config.ForceRowBasedExecution; - var savedRowFallback = Config.CodegenOptions.DontFallBackToRowBasedExecution; - try + foreach (var rowBased in new bool[] { true, false }) { - foreach (var rowBased in new bool[] { true, false }) + using (new ConfigModifier() + .ForceRowBasedExecution(rowBased) + .DontFallBackToRowBasedExecution(!rowBased) + .Modify()) { - Config.ForceRowBasedExecution = rowBased; - Config.CodegenOptions.DontFallBackToRowBasedExecution = !rowBased; action(); } } - finally - { - Config.ForceRowBasedExecution = savedForceRowBasedExecution; - Config.CodegenOptions.DontFallBackToRowBasedExecution = savedRowFallback; - } } } @@ -329,7 +324,7 @@ public struct MyStruct2 public double doubleField; public char[] charArrayField; public override string ToString() => string.Format("MyStruct({0}, {1}, {2}, {3})", this.field1, this.field2.mystring, this.field3.nestedField, this.doubleField); - public StructWithCtor ReturnStructWithCtor(int x) => new StructWithCtor(x); + public StructWithCtor ReturnStructWithCtor(int x) => new(x); } public struct StructWithCtor diff --git a/Sources/Test/SimpleTesting/IngressEgress/DisorderedIngressAndEgressTests.cs b/Sources/Test/SimpleTesting/IngressEgress/DisorderedIngressAndEgressTests.cs index a750c1dea..ea5153be0 100644 --- a/Sources/Test/SimpleTesting/IngressEgress/DisorderedIngressAndEgressTests.cs +++ b/Sources/Test/SimpleTesting/IngressEgress/DisorderedIngressAndEgressTests.cs @@ -145,7 +145,7 @@ public void DisorderedStartEdgeTestRowDrop105Diagnostic() var diagnosticStream = ingress.GetDroppedAdjustedEventsDiagnostic(); var outOfOrderEvents = new List>(); - diagnosticStream.Subscribe(o => outOfOrderEvents.Add(o)); + diagnosticStream.Subscribe(outOfOrderEvents.Add); var outevents = prog.ToEnumerable().ToList(); Assert.IsTrue(outevents.IsOrdered(t => t.SyncTime)); @@ -206,7 +206,7 @@ public void DisorderedIntervalTestRowDrop105Diagnostic() var diagnosticStream = ingress.GetDroppedAdjustedEventsDiagnostic(); var outOfOrderEvents = new List>(); - diagnosticStream.Subscribe(o => outOfOrderEvents.Add(o)); + diagnosticStream.Subscribe(outOfOrderEvents.Add); var outevents = prog.ToEnumerable().ToList(); Assert.IsTrue(outevents.IsOrdered(t => t.SyncTime)); @@ -361,7 +361,7 @@ public void DisorderedStartEdgeTestRowDrop1020Diagnostic() var diagnosticStream = ingress.GetDroppedAdjustedEventsDiagnostic(); var outOfOrderEvents = new List>(); - diagnosticStream.Subscribe(o => outOfOrderEvents.Add(o)); + diagnosticStream.Subscribe(outOfOrderEvents.Add); var outevents = prog.ToEnumerable().ToList(); Assert.IsTrue(outevents.IsOrdered(t => t.SyncTime)); @@ -416,7 +416,7 @@ public void DisorderedIntervalTestRowDrop1020Diagnostic() var diagnosticStream = ingress.GetDroppedAdjustedEventsDiagnostic(); var outOfOrderEvents = new List>(); - diagnosticStream.Subscribe(o => outOfOrderEvents.Add(o)); + diagnosticStream.Subscribe(outOfOrderEvents.Add); var outevents = prog.ToEnumerable().ToList(); Assert.IsTrue(outevents.IsOrdered(t => t.SyncTime)); @@ -643,7 +643,7 @@ public void DisorderedStartEdgeTestRowDrop105TimeDiagnostic() var diagnosticStream = ingress.GetDroppedAdjustedEventsDiagnostic(); var outOfOrderEvents = new List>(); - diagnosticStream.Subscribe(o => outOfOrderEvents.Add(o)); + diagnosticStream.Subscribe(outOfOrderEvents.Add); var outevents = prog.ToEnumerable().ToList(); Assert.IsTrue(outevents.IsOrdered(t => t.SyncTime)); @@ -737,7 +737,7 @@ public void DisorderedIntervalTestRowDrop105TimeDiagnostic() var diagnosticStream = ingress.GetDroppedAdjustedEventsDiagnostic(); var outOfOrderEvents = new List>(); - diagnosticStream.Subscribe(o => outOfOrderEvents.Add(o)); + diagnosticStream.Subscribe(outOfOrderEvents.Add); var outevents = prog.ToEnumerable().ToList(); Assert.IsTrue(outevents.IsOrdered(t => t.SyncTime)); @@ -991,7 +991,7 @@ public void DisorderedStartEdgeTestRowDrop1020TimeDiagnostic() var diagnosticStream = ingress.GetDroppedAdjustedEventsDiagnostic(); var outOfOrderEvents = new List>(); - diagnosticStream.Subscribe(o => outOfOrderEvents.Add(o)); + diagnosticStream.Subscribe(outOfOrderEvents.Add); var outevents = prog.ToEnumerable().ToList(); Assert.IsTrue(outevents.IsOrdered(t => t.SyncTime)); @@ -1079,7 +1079,7 @@ public void DisorderedIntervalTestRowDrop1020TimeDiagnostic() var diagnosticStream = ingress.GetDroppedAdjustedEventsDiagnostic(); var outOfOrderEvents = new List>(); - diagnosticStream.Subscribe(o => outOfOrderEvents.Add(o)); + diagnosticStream.Subscribe(outOfOrderEvents.Add); var outevents = prog.ToEnumerable().ToList(); Assert.IsTrue(outevents.IsOrdered(t => t.SyncTime)); @@ -1186,7 +1186,7 @@ public void DisorderedStartEdgeTestRowThrow105() } catch(Exception) { - Assert.IsTrue(true); // Todo. Verify if the ingress/egress before the exception was correct. + // Todo. Verify if the ingress/egress before the exception was correct. } } @@ -1229,7 +1229,7 @@ public void DisorderedIntervalTestRowThrow105() } catch(Exception) { - Assert.IsTrue(true); // Todo. Verify if the ingress/egress before the exception was correct. + // Todo. Verify if the ingress/egress before the exception was correct. } } } @@ -1273,7 +1273,7 @@ public void DisorderedStartEdgeTestRowThrow105Diagnostic() var diagnosticStream = ingress.GetDroppedAdjustedEventsDiagnostic(); var outOfOrderEvents = new List>(); - diagnosticStream.Subscribe(o => outOfOrderEvents.Add(o)); + diagnosticStream.Subscribe(outOfOrderEvents.Add); var outevents = prog.ToEnumerable().ToList(); Assert.IsTrue(outevents.IsOrdered(t => t.SyncTime)); @@ -1285,7 +1285,7 @@ public void DisorderedStartEdgeTestRowThrow105Diagnostic() } catch(Exception) { - Assert.IsTrue(true); // Todo. Verify if the ingress/egress before the exception was correct. + // Todo. Verify if the ingress/egress before the exception was correct. } } @@ -1320,7 +1320,7 @@ public void DisorderedIntervalTestRowThrow105Diagnostic() var diagnosticStream = ingress.GetDroppedAdjustedEventsDiagnostic(); var outOfOrderEvents = new List>(); - diagnosticStream.Subscribe(o => outOfOrderEvents.Add(o)); + diagnosticStream.Subscribe(outOfOrderEvents.Add); var outevents = prog.ToEnumerable().ToList(); Assert.IsTrue(outevents.IsOrdered(t => t.SyncTime)); @@ -1332,7 +1332,7 @@ public void DisorderedIntervalTestRowThrow105Diagnostic() } catch(Exception) { - Assert.IsTrue(true); // Todo. Verify if the ingress/egress before the exception was correct. + // Todo. Verify if the ingress/egress before the exception was correct. } } } @@ -1475,7 +1475,7 @@ public void DisorderedStartEdgeTestRowThrow1020Diagnostic() var diagnosticStream = ingress.GetDroppedAdjustedEventsDiagnostic(); var outOfOrderEvents = new List>(); - diagnosticStream.Subscribe(o => outOfOrderEvents.Add(o)); + diagnosticStream.Subscribe(outOfOrderEvents.Add); var outevents = prog.ToEnumerable().ToList(); Assert.IsTrue(outevents.IsOrdered(t => t.SyncTime)); @@ -1537,7 +1537,7 @@ public void DisorderedIntervalTestRowThrow1020Diagnostic() var diagnosticStream = ingress.GetDroppedAdjustedEventsDiagnostic(); var outOfOrderEvents = new List>(); - diagnosticStream.Subscribe(o => outOfOrderEvents.Add(o)); + diagnosticStream.Subscribe(outOfOrderEvents.Add); var outevents = prog.ToEnumerable().ToList(); Assert.IsTrue(outevents.IsOrdered(t => t.SyncTime)); @@ -1616,7 +1616,7 @@ public void DisorderedStartEdgeTestRowThrow105Time() } catch(Exception) { - Assert.IsTrue(true); // Todo. Verify if the ingress/egress before the exception was correct. + // Todo. Verify if the ingress/egress before the exception was correct. } } @@ -1659,7 +1659,7 @@ public void DisorderedIntervalTestRowThrow105Time() } catch(Exception) { - Assert.IsTrue(true); // Todo. Verify if the ingress/egress before the exception was correct. + // Todo. Verify if the ingress/egress before the exception was correct. } } } @@ -1703,7 +1703,7 @@ public void DisorderedStartEdgeTestRowThrow105TimeDiagnostic() var diagnosticStream = ingress.GetDroppedAdjustedEventsDiagnostic(); var outOfOrderEvents = new List>(); - diagnosticStream.Subscribe(o => outOfOrderEvents.Add(o)); + diagnosticStream.Subscribe(outOfOrderEvents.Add); var outevents = prog.ToEnumerable().ToList(); Assert.IsTrue(outevents.IsOrdered(t => t.SyncTime)); @@ -1715,7 +1715,7 @@ public void DisorderedStartEdgeTestRowThrow105TimeDiagnostic() } catch(Exception) { - Assert.IsTrue(true); // Todo. Verify if the ingress/egress before the exception was correct. + // Todo. Verify if the ingress/egress before the exception was correct. } } @@ -1750,7 +1750,7 @@ public void DisorderedIntervalTestRowThrow105TimeDiagnostic() var diagnosticStream = ingress.GetDroppedAdjustedEventsDiagnostic(); var outOfOrderEvents = new List>(); - diagnosticStream.Subscribe(o => outOfOrderEvents.Add(o)); + diagnosticStream.Subscribe(outOfOrderEvents.Add); var outevents = prog.ToEnumerable().ToList(); Assert.IsTrue(outevents.IsOrdered(t => t.SyncTime)); @@ -1762,7 +1762,7 @@ public void DisorderedIntervalTestRowThrow105TimeDiagnostic() } catch(Exception) { - Assert.IsTrue(true); // Todo. Verify if the ingress/egress before the exception was correct. + // Todo. Verify if the ingress/egress before the exception was correct. } } } @@ -1971,7 +1971,7 @@ public void DisorderedStartEdgeTestRowThrow1020TimeDiagnostic() var diagnosticStream = ingress.GetDroppedAdjustedEventsDiagnostic(); var outOfOrderEvents = new List>(); - diagnosticStream.Subscribe(o => outOfOrderEvents.Add(o)); + diagnosticStream.Subscribe(outOfOrderEvents.Add); var outevents = prog.ToEnumerable().ToList(); Assert.IsTrue(outevents.IsOrdered(t => t.SyncTime)); @@ -2066,7 +2066,7 @@ public void DisorderedIntervalTestRowThrow1020TimeDiagnostic() var diagnosticStream = ingress.GetDroppedAdjustedEventsDiagnostic(); var outOfOrderEvents = new List>(); - diagnosticStream.Subscribe(o => outOfOrderEvents.Add(o)); + diagnosticStream.Subscribe(outOfOrderEvents.Add); var outevents = prog.ToEnumerable().ToList(); Assert.IsTrue(outevents.IsOrdered(t => t.SyncTime)); @@ -2270,7 +2270,7 @@ public void DisorderedStartEdgeTestRowAdjust105Diagnostic() var diagnosticStream = ingress.GetDroppedAdjustedEventsDiagnostic(); var outOfOrderEvents = new List>(); - diagnosticStream.Subscribe(o => outOfOrderEvents.Add(o)); + diagnosticStream.Subscribe(outOfOrderEvents.Add); var outevents = prog.ToEnumerable().ToList(); Assert.IsTrue(outevents.IsOrdered(t => t.SyncTime)); @@ -2332,7 +2332,7 @@ public void DisorderedIntervalTestRowAdjust105Diagnostic() var diagnosticStream = ingress.GetDroppedAdjustedEventsDiagnostic(); var outOfOrderEvents = new List>(); - diagnosticStream.Subscribe(o => outOfOrderEvents.Add(o)); + diagnosticStream.Subscribe(outOfOrderEvents.Add); var outevents = prog.ToEnumerable().ToList(); Assert.IsTrue(outevents.IsOrdered(t => t.SyncTime)); @@ -2491,7 +2491,7 @@ public void DisorderedStartEdgeTestRowAdjust1020Diagnostic() var diagnosticStream = ingress.GetDroppedAdjustedEventsDiagnostic(); var outOfOrderEvents = new List>(); - diagnosticStream.Subscribe(o => outOfOrderEvents.Add(o)); + diagnosticStream.Subscribe(outOfOrderEvents.Add); var outevents = prog.ToEnumerable().ToList(); Assert.IsTrue(outevents.IsOrdered(t => t.SyncTime)); @@ -2546,7 +2546,7 @@ public void DisorderedIntervalTestRowAdjust1020Diagnostic() var diagnosticStream = ingress.GetDroppedAdjustedEventsDiagnostic(); var outOfOrderEvents = new List>(); - diagnosticStream.Subscribe(o => outOfOrderEvents.Add(o)); + diagnosticStream.Subscribe(outOfOrderEvents.Add); var outevents = prog.ToEnumerable().ToList(); Assert.IsTrue(outevents.IsOrdered(t => t.SyncTime)); @@ -2778,7 +2778,7 @@ public void DisorderedStartEdgeTestRowAdjust105TimeDiagnostic() var diagnosticStream = ingress.GetDroppedAdjustedEventsDiagnostic(); var outOfOrderEvents = new List>(); - diagnosticStream.Subscribe(o => outOfOrderEvents.Add(o)); + diagnosticStream.Subscribe(outOfOrderEvents.Add); var outevents = prog.ToEnumerable().ToList(); Assert.IsTrue(outevents.IsOrdered(t => t.SyncTime)); @@ -2873,7 +2873,7 @@ public void DisorderedIntervalTestRowAdjust105TimeDiagnostic() var diagnosticStream = ingress.GetDroppedAdjustedEventsDiagnostic(); var outOfOrderEvents = new List>(); - diagnosticStream.Subscribe(o => outOfOrderEvents.Add(o)); + diagnosticStream.Subscribe(outOfOrderEvents.Add); var outevents = prog.ToEnumerable().ToList(); Assert.IsTrue(outevents.IsOrdered(t => t.SyncTime)); @@ -3131,7 +3131,7 @@ public void DisorderedStartEdgeTestRowAdjust1020TimeDiagnostic() var diagnosticStream = ingress.GetDroppedAdjustedEventsDiagnostic(); var outOfOrderEvents = new List>(); - diagnosticStream.Subscribe(o => outOfOrderEvents.Add(o)); + diagnosticStream.Subscribe(outOfOrderEvents.Add); var outevents = prog.ToEnumerable().ToList(); Assert.IsTrue(outevents.IsOrdered(t => t.SyncTime)); @@ -3219,7 +3219,7 @@ public void DisorderedIntervalTestRowAdjust1020TimeDiagnostic() var diagnosticStream = ingress.GetDroppedAdjustedEventsDiagnostic(); var outOfOrderEvents = new List>(); - diagnosticStream.Subscribe(o => outOfOrderEvents.Add(o)); + diagnosticStream.Subscribe(outOfOrderEvents.Add); var outevents = prog.ToEnumerable().ToList(); Assert.IsTrue(outevents.IsOrdered(t => t.SyncTime)); @@ -3415,7 +3415,7 @@ public void DisorderedStartEdgeTestRowSmallBatchDrop105Diagnostic() var diagnosticStream = ingress.GetDroppedAdjustedEventsDiagnostic(); var outOfOrderEvents = new List>(); - diagnosticStream.Subscribe(o => outOfOrderEvents.Add(o)); + diagnosticStream.Subscribe(outOfOrderEvents.Add); var outevents = prog.ToEnumerable().ToList(); Assert.IsTrue(outevents.IsOrdered(t => t.SyncTime)); @@ -3476,7 +3476,7 @@ public void DisorderedIntervalTestRowSmallBatchDrop105Diagnostic() var diagnosticStream = ingress.GetDroppedAdjustedEventsDiagnostic(); var outOfOrderEvents = new List>(); - diagnosticStream.Subscribe(o => outOfOrderEvents.Add(o)); + diagnosticStream.Subscribe(outOfOrderEvents.Add); var outevents = prog.ToEnumerable().ToList(); Assert.IsTrue(outevents.IsOrdered(t => t.SyncTime)); @@ -3633,7 +3633,7 @@ public void DisorderedStartEdgeTestRowSmallBatchDrop1020Diagnostic() var diagnosticStream = ingress.GetDroppedAdjustedEventsDiagnostic(); var outOfOrderEvents = new List>(); - diagnosticStream.Subscribe(o => outOfOrderEvents.Add(o)); + diagnosticStream.Subscribe(outOfOrderEvents.Add); var outevents = prog.ToEnumerable().ToList(); Assert.IsTrue(outevents.IsOrdered(t => t.SyncTime)); @@ -3688,7 +3688,7 @@ public void DisorderedIntervalTestRowSmallBatchDrop1020Diagnostic() var diagnosticStream = ingress.GetDroppedAdjustedEventsDiagnostic(); var outOfOrderEvents = new List>(); - diagnosticStream.Subscribe(o => outOfOrderEvents.Add(o)); + diagnosticStream.Subscribe(outOfOrderEvents.Add); var outevents = prog.ToEnumerable().ToList(); Assert.IsTrue(outevents.IsOrdered(t => t.SyncTime)); @@ -3917,7 +3917,7 @@ public void DisorderedStartEdgeTestRowSmallBatchDrop105TimeDiagnostic() var diagnosticStream = ingress.GetDroppedAdjustedEventsDiagnostic(); var outOfOrderEvents = new List>(); - diagnosticStream.Subscribe(o => outOfOrderEvents.Add(o)); + diagnosticStream.Subscribe(outOfOrderEvents.Add); var outevents = prog.ToEnumerable().ToList(); Assert.IsTrue(outevents.IsOrdered(t => t.SyncTime)); @@ -4011,7 +4011,7 @@ public void DisorderedIntervalTestRowSmallBatchDrop105TimeDiagnostic() var diagnosticStream = ingress.GetDroppedAdjustedEventsDiagnostic(); var outOfOrderEvents = new List>(); - diagnosticStream.Subscribe(o => outOfOrderEvents.Add(o)); + diagnosticStream.Subscribe(outOfOrderEvents.Add); var outevents = prog.ToEnumerable().ToList(); Assert.IsTrue(outevents.IsOrdered(t => t.SyncTime)); @@ -4267,7 +4267,7 @@ public void DisorderedStartEdgeTestRowSmallBatchDrop1020TimeDiagnostic() var diagnosticStream = ingress.GetDroppedAdjustedEventsDiagnostic(); var outOfOrderEvents = new List>(); - diagnosticStream.Subscribe(o => outOfOrderEvents.Add(o)); + diagnosticStream.Subscribe(outOfOrderEvents.Add); var outevents = prog.ToEnumerable().ToList(); Assert.IsTrue(outevents.IsOrdered(t => t.SyncTime)); @@ -4355,7 +4355,7 @@ public void DisorderedIntervalTestRowSmallBatchDrop1020TimeDiagnostic() var diagnosticStream = ingress.GetDroppedAdjustedEventsDiagnostic(); var outOfOrderEvents = new List>(); - diagnosticStream.Subscribe(o => outOfOrderEvents.Add(o)); + diagnosticStream.Subscribe(outOfOrderEvents.Add); var outevents = prog.ToEnumerable().ToList(); Assert.IsTrue(outevents.IsOrdered(t => t.SyncTime)); @@ -4463,7 +4463,7 @@ public void DisorderedStartEdgeTestRowSmallBatchThrow105() } catch(Exception) { - Assert.IsTrue(true); // Todo. Verify if the ingress/egress before the exception was correct. + // Todo. Verify if the ingress/egress before the exception was correct. } } @@ -4506,7 +4506,7 @@ public void DisorderedIntervalTestRowSmallBatchThrow105() } catch(Exception) { - Assert.IsTrue(true); // Todo. Verify if the ingress/egress before the exception was correct. + // Todo. Verify if the ingress/egress before the exception was correct. } } } @@ -4551,7 +4551,7 @@ public void DisorderedStartEdgeTestRowSmallBatchThrow105Diagnostic() var diagnosticStream = ingress.GetDroppedAdjustedEventsDiagnostic(); var outOfOrderEvents = new List>(); - diagnosticStream.Subscribe(o => outOfOrderEvents.Add(o)); + diagnosticStream.Subscribe(outOfOrderEvents.Add); var outevents = prog.ToEnumerable().ToList(); Assert.IsTrue(outevents.IsOrdered(t => t.SyncTime)); @@ -4563,7 +4563,7 @@ public void DisorderedStartEdgeTestRowSmallBatchThrow105Diagnostic() } catch(Exception) { - Assert.IsTrue(true); // Todo. Verify if the ingress/egress before the exception was correct. + // Todo. Verify if the ingress/egress before the exception was correct. } } @@ -4598,7 +4598,7 @@ public void DisorderedIntervalTestRowSmallBatchThrow105Diagnostic() var diagnosticStream = ingress.GetDroppedAdjustedEventsDiagnostic(); var outOfOrderEvents = new List>(); - diagnosticStream.Subscribe(o => outOfOrderEvents.Add(o)); + diagnosticStream.Subscribe(outOfOrderEvents.Add); var outevents = prog.ToEnumerable().ToList(); Assert.IsTrue(outevents.IsOrdered(t => t.SyncTime)); @@ -4610,7 +4610,7 @@ public void DisorderedIntervalTestRowSmallBatchThrow105Diagnostic() } catch(Exception) { - Assert.IsTrue(true); // Todo. Verify if the ingress/egress before the exception was correct. + // Todo. Verify if the ingress/egress before the exception was correct. } } } @@ -4755,7 +4755,7 @@ public void DisorderedStartEdgeTestRowSmallBatchThrow1020Diagnostic() var diagnosticStream = ingress.GetDroppedAdjustedEventsDiagnostic(); var outOfOrderEvents = new List>(); - diagnosticStream.Subscribe(o => outOfOrderEvents.Add(o)); + diagnosticStream.Subscribe(outOfOrderEvents.Add); var outevents = prog.ToEnumerable().ToList(); Assert.IsTrue(outevents.IsOrdered(t => t.SyncTime)); @@ -4817,7 +4817,7 @@ public void DisorderedIntervalTestRowSmallBatchThrow1020Diagnostic() var diagnosticStream = ingress.GetDroppedAdjustedEventsDiagnostic(); var outOfOrderEvents = new List>(); - diagnosticStream.Subscribe(o => outOfOrderEvents.Add(o)); + diagnosticStream.Subscribe(outOfOrderEvents.Add); var outevents = prog.ToEnumerable().ToList(); Assert.IsTrue(outevents.IsOrdered(t => t.SyncTime)); @@ -4897,7 +4897,7 @@ public void DisorderedStartEdgeTestRowSmallBatchThrow105Time() } catch(Exception) { - Assert.IsTrue(true); // Todo. Verify if the ingress/egress before the exception was correct. + // Todo. Verify if the ingress/egress before the exception was correct. } } @@ -4940,7 +4940,7 @@ public void DisorderedIntervalTestRowSmallBatchThrow105Time() } catch(Exception) { - Assert.IsTrue(true); // Todo. Verify if the ingress/egress before the exception was correct. + // Todo. Verify if the ingress/egress before the exception was correct. } } } @@ -4985,7 +4985,7 @@ public void DisorderedStartEdgeTestRowSmallBatchThrow105TimeDiagnostic() var diagnosticStream = ingress.GetDroppedAdjustedEventsDiagnostic(); var outOfOrderEvents = new List>(); - diagnosticStream.Subscribe(o => outOfOrderEvents.Add(o)); + diagnosticStream.Subscribe(outOfOrderEvents.Add); var outevents = prog.ToEnumerable().ToList(); Assert.IsTrue(outevents.IsOrdered(t => t.SyncTime)); @@ -4997,7 +4997,7 @@ public void DisorderedStartEdgeTestRowSmallBatchThrow105TimeDiagnostic() } catch(Exception) { - Assert.IsTrue(true); // Todo. Verify if the ingress/egress before the exception was correct. + // Todo. Verify if the ingress/egress before the exception was correct. } } @@ -5032,7 +5032,7 @@ public void DisorderedIntervalTestRowSmallBatchThrow105TimeDiagnostic() var diagnosticStream = ingress.GetDroppedAdjustedEventsDiagnostic(); var outOfOrderEvents = new List>(); - diagnosticStream.Subscribe(o => outOfOrderEvents.Add(o)); + diagnosticStream.Subscribe(outOfOrderEvents.Add); var outevents = prog.ToEnumerable().ToList(); Assert.IsTrue(outevents.IsOrdered(t => t.SyncTime)); @@ -5044,7 +5044,7 @@ public void DisorderedIntervalTestRowSmallBatchThrow105TimeDiagnostic() } catch(Exception) { - Assert.IsTrue(true); // Todo. Verify if the ingress/egress before the exception was correct. + // Todo. Verify if the ingress/egress before the exception was correct. } } } @@ -5255,7 +5255,7 @@ public void DisorderedStartEdgeTestRowSmallBatchThrow1020TimeDiagnostic() var diagnosticStream = ingress.GetDroppedAdjustedEventsDiagnostic(); var outOfOrderEvents = new List>(); - diagnosticStream.Subscribe(o => outOfOrderEvents.Add(o)); + diagnosticStream.Subscribe(outOfOrderEvents.Add); var outevents = prog.ToEnumerable().ToList(); Assert.IsTrue(outevents.IsOrdered(t => t.SyncTime)); @@ -5350,7 +5350,7 @@ public void DisorderedIntervalTestRowSmallBatchThrow1020TimeDiagnostic() var diagnosticStream = ingress.GetDroppedAdjustedEventsDiagnostic(); var outOfOrderEvents = new List>(); - diagnosticStream.Subscribe(o => outOfOrderEvents.Add(o)); + diagnosticStream.Subscribe(outOfOrderEvents.Add); var outevents = prog.ToEnumerable().ToList(); Assert.IsTrue(outevents.IsOrdered(t => t.SyncTime)); @@ -5556,7 +5556,7 @@ public void DisorderedStartEdgeTestRowSmallBatchAdjust105Diagnostic() var diagnosticStream = ingress.GetDroppedAdjustedEventsDiagnostic(); var outOfOrderEvents = new List>(); - diagnosticStream.Subscribe(o => outOfOrderEvents.Add(o)); + diagnosticStream.Subscribe(outOfOrderEvents.Add); var outevents = prog.ToEnumerable().ToList(); Assert.IsTrue(outevents.IsOrdered(t => t.SyncTime)); @@ -5618,7 +5618,7 @@ public void DisorderedIntervalTestRowSmallBatchAdjust105Diagnostic() var diagnosticStream = ingress.GetDroppedAdjustedEventsDiagnostic(); var outOfOrderEvents = new List>(); - diagnosticStream.Subscribe(o => outOfOrderEvents.Add(o)); + diagnosticStream.Subscribe(outOfOrderEvents.Add); var outevents = prog.ToEnumerable().ToList(); Assert.IsTrue(outevents.IsOrdered(t => t.SyncTime)); @@ -5779,7 +5779,7 @@ public void DisorderedStartEdgeTestRowSmallBatchAdjust1020Diagnostic() var diagnosticStream = ingress.GetDroppedAdjustedEventsDiagnostic(); var outOfOrderEvents = new List>(); - diagnosticStream.Subscribe(o => outOfOrderEvents.Add(o)); + diagnosticStream.Subscribe(outOfOrderEvents.Add); var outevents = prog.ToEnumerable().ToList(); Assert.IsTrue(outevents.IsOrdered(t => t.SyncTime)); @@ -5834,7 +5834,7 @@ public void DisorderedIntervalTestRowSmallBatchAdjust1020Diagnostic() var diagnosticStream = ingress.GetDroppedAdjustedEventsDiagnostic(); var outOfOrderEvents = new List>(); - diagnosticStream.Subscribe(o => outOfOrderEvents.Add(o)); + diagnosticStream.Subscribe(outOfOrderEvents.Add); var outevents = prog.ToEnumerable().ToList(); Assert.IsTrue(outevents.IsOrdered(t => t.SyncTime)); @@ -6068,7 +6068,7 @@ public void DisorderedStartEdgeTestRowSmallBatchAdjust105TimeDiagnostic() var diagnosticStream = ingress.GetDroppedAdjustedEventsDiagnostic(); var outOfOrderEvents = new List>(); - diagnosticStream.Subscribe(o => outOfOrderEvents.Add(o)); + diagnosticStream.Subscribe(outOfOrderEvents.Add); var outevents = prog.ToEnumerable().ToList(); Assert.IsTrue(outevents.IsOrdered(t => t.SyncTime)); @@ -6163,7 +6163,7 @@ public void DisorderedIntervalTestRowSmallBatchAdjust105TimeDiagnostic() var diagnosticStream = ingress.GetDroppedAdjustedEventsDiagnostic(); var outOfOrderEvents = new List>(); - diagnosticStream.Subscribe(o => outOfOrderEvents.Add(o)); + diagnosticStream.Subscribe(outOfOrderEvents.Add); var outevents = prog.ToEnumerable().ToList(); Assert.IsTrue(outevents.IsOrdered(t => t.SyncTime)); @@ -6423,7 +6423,7 @@ public void DisorderedStartEdgeTestRowSmallBatchAdjust1020TimeDiagnostic() var diagnosticStream = ingress.GetDroppedAdjustedEventsDiagnostic(); var outOfOrderEvents = new List>(); - diagnosticStream.Subscribe(o => outOfOrderEvents.Add(o)); + diagnosticStream.Subscribe(outOfOrderEvents.Add); var outevents = prog.ToEnumerable().ToList(); Assert.IsTrue(outevents.IsOrdered(t => t.SyncTime)); @@ -6511,7 +6511,7 @@ public void DisorderedIntervalTestRowSmallBatchAdjust1020TimeDiagnostic() var diagnosticStream = ingress.GetDroppedAdjustedEventsDiagnostic(); var outOfOrderEvents = new List>(); - diagnosticStream.Subscribe(o => outOfOrderEvents.Add(o)); + diagnosticStream.Subscribe(outOfOrderEvents.Add); var outevents = prog.ToEnumerable().ToList(); Assert.IsTrue(outevents.IsOrdered(t => t.SyncTime)); @@ -6705,7 +6705,7 @@ public void DisorderedStartEdgeTestColumnarDrop105Diagnostic() var diagnosticStream = ingress.GetDroppedAdjustedEventsDiagnostic(); var outOfOrderEvents = new List>(); - diagnosticStream.Subscribe(o => outOfOrderEvents.Add(o)); + diagnosticStream.Subscribe(outOfOrderEvents.Add); var outevents = prog.ToEnumerable().ToList(); Assert.IsTrue(outevents.IsOrdered(t => t.SyncTime)); @@ -6766,7 +6766,7 @@ public void DisorderedIntervalTestColumnarDrop105Diagnostic() var diagnosticStream = ingress.GetDroppedAdjustedEventsDiagnostic(); var outOfOrderEvents = new List>(); - diagnosticStream.Subscribe(o => outOfOrderEvents.Add(o)); + diagnosticStream.Subscribe(outOfOrderEvents.Add); var outevents = prog.ToEnumerable().ToList(); Assert.IsTrue(outevents.IsOrdered(t => t.SyncTime)); @@ -6921,7 +6921,7 @@ public void DisorderedStartEdgeTestColumnarDrop1020Diagnostic() var diagnosticStream = ingress.GetDroppedAdjustedEventsDiagnostic(); var outOfOrderEvents = new List>(); - diagnosticStream.Subscribe(o => outOfOrderEvents.Add(o)); + diagnosticStream.Subscribe(outOfOrderEvents.Add); var outevents = prog.ToEnumerable().ToList(); Assert.IsTrue(outevents.IsOrdered(t => t.SyncTime)); @@ -6976,7 +6976,7 @@ public void DisorderedIntervalTestColumnarDrop1020Diagnostic() var diagnosticStream = ingress.GetDroppedAdjustedEventsDiagnostic(); var outOfOrderEvents = new List>(); - diagnosticStream.Subscribe(o => outOfOrderEvents.Add(o)); + diagnosticStream.Subscribe(outOfOrderEvents.Add); var outevents = prog.ToEnumerable().ToList(); Assert.IsTrue(outevents.IsOrdered(t => t.SyncTime)); @@ -7203,7 +7203,7 @@ public void DisorderedStartEdgeTestColumnarDrop105TimeDiagnostic() var diagnosticStream = ingress.GetDroppedAdjustedEventsDiagnostic(); var outOfOrderEvents = new List>(); - diagnosticStream.Subscribe(o => outOfOrderEvents.Add(o)); + diagnosticStream.Subscribe(outOfOrderEvents.Add); var outevents = prog.ToEnumerable().ToList(); Assert.IsTrue(outevents.IsOrdered(t => t.SyncTime)); @@ -7297,7 +7297,7 @@ public void DisorderedIntervalTestColumnarDrop105TimeDiagnostic() var diagnosticStream = ingress.GetDroppedAdjustedEventsDiagnostic(); var outOfOrderEvents = new List>(); - diagnosticStream.Subscribe(o => outOfOrderEvents.Add(o)); + diagnosticStream.Subscribe(outOfOrderEvents.Add); var outevents = prog.ToEnumerable().ToList(); Assert.IsTrue(outevents.IsOrdered(t => t.SyncTime)); @@ -7551,7 +7551,7 @@ public void DisorderedStartEdgeTestColumnarDrop1020TimeDiagnostic() var diagnosticStream = ingress.GetDroppedAdjustedEventsDiagnostic(); var outOfOrderEvents = new List>(); - diagnosticStream.Subscribe(o => outOfOrderEvents.Add(o)); + diagnosticStream.Subscribe(outOfOrderEvents.Add); var outevents = prog.ToEnumerable().ToList(); Assert.IsTrue(outevents.IsOrdered(t => t.SyncTime)); @@ -7639,7 +7639,7 @@ public void DisorderedIntervalTestColumnarDrop1020TimeDiagnostic() var diagnosticStream = ingress.GetDroppedAdjustedEventsDiagnostic(); var outOfOrderEvents = new List>(); - diagnosticStream.Subscribe(o => outOfOrderEvents.Add(o)); + diagnosticStream.Subscribe(outOfOrderEvents.Add); var outevents = prog.ToEnumerable().ToList(); Assert.IsTrue(outevents.IsOrdered(t => t.SyncTime)); @@ -7746,7 +7746,7 @@ public void DisorderedStartEdgeTestColumnarThrow105() } catch(Exception) { - Assert.IsTrue(true); // Todo. Verify if the ingress/egress before the exception was correct. + // Todo. Verify if the ingress/egress before the exception was correct. } } @@ -7789,7 +7789,7 @@ public void DisorderedIntervalTestColumnarThrow105() } catch(Exception) { - Assert.IsTrue(true); // Todo. Verify if the ingress/egress before the exception was correct. + // Todo. Verify if the ingress/egress before the exception was correct. } } } @@ -7833,7 +7833,7 @@ public void DisorderedStartEdgeTestColumnarThrow105Diagnostic() var diagnosticStream = ingress.GetDroppedAdjustedEventsDiagnostic(); var outOfOrderEvents = new List>(); - diagnosticStream.Subscribe(o => outOfOrderEvents.Add(o)); + diagnosticStream.Subscribe(outOfOrderEvents.Add); var outevents = prog.ToEnumerable().ToList(); Assert.IsTrue(outevents.IsOrdered(t => t.SyncTime)); @@ -7845,7 +7845,7 @@ public void DisorderedStartEdgeTestColumnarThrow105Diagnostic() } catch(Exception) { - Assert.IsTrue(true); // Todo. Verify if the ingress/egress before the exception was correct. + // Todo. Verify if the ingress/egress before the exception was correct. } } @@ -7880,7 +7880,7 @@ public void DisorderedIntervalTestColumnarThrow105Diagnostic() var diagnosticStream = ingress.GetDroppedAdjustedEventsDiagnostic(); var outOfOrderEvents = new List>(); - diagnosticStream.Subscribe(o => outOfOrderEvents.Add(o)); + diagnosticStream.Subscribe(outOfOrderEvents.Add); var outevents = prog.ToEnumerable().ToList(); Assert.IsTrue(outevents.IsOrdered(t => t.SyncTime)); @@ -7892,7 +7892,7 @@ public void DisorderedIntervalTestColumnarThrow105Diagnostic() } catch(Exception) { - Assert.IsTrue(true); // Todo. Verify if the ingress/egress before the exception was correct. + // Todo. Verify if the ingress/egress before the exception was correct. } } } @@ -8035,7 +8035,7 @@ public void DisorderedStartEdgeTestColumnarThrow1020Diagnostic() var diagnosticStream = ingress.GetDroppedAdjustedEventsDiagnostic(); var outOfOrderEvents = new List>(); - diagnosticStream.Subscribe(o => outOfOrderEvents.Add(o)); + diagnosticStream.Subscribe(outOfOrderEvents.Add); var outevents = prog.ToEnumerable().ToList(); Assert.IsTrue(outevents.IsOrdered(t => t.SyncTime)); @@ -8097,7 +8097,7 @@ public void DisorderedIntervalTestColumnarThrow1020Diagnostic() var diagnosticStream = ingress.GetDroppedAdjustedEventsDiagnostic(); var outOfOrderEvents = new List>(); - diagnosticStream.Subscribe(o => outOfOrderEvents.Add(o)); + diagnosticStream.Subscribe(outOfOrderEvents.Add); var outevents = prog.ToEnumerable().ToList(); Assert.IsTrue(outevents.IsOrdered(t => t.SyncTime)); @@ -8176,7 +8176,7 @@ public void DisorderedStartEdgeTestColumnarThrow105Time() } catch(Exception) { - Assert.IsTrue(true); // Todo. Verify if the ingress/egress before the exception was correct. + // Todo. Verify if the ingress/egress before the exception was correct. } } @@ -8219,7 +8219,7 @@ public void DisorderedIntervalTestColumnarThrow105Time() } catch(Exception) { - Assert.IsTrue(true); // Todo. Verify if the ingress/egress before the exception was correct. + // Todo. Verify if the ingress/egress before the exception was correct. } } } @@ -8263,7 +8263,7 @@ public void DisorderedStartEdgeTestColumnarThrow105TimeDiagnostic() var diagnosticStream = ingress.GetDroppedAdjustedEventsDiagnostic(); var outOfOrderEvents = new List>(); - diagnosticStream.Subscribe(o => outOfOrderEvents.Add(o)); + diagnosticStream.Subscribe(outOfOrderEvents.Add); var outevents = prog.ToEnumerable().ToList(); Assert.IsTrue(outevents.IsOrdered(t => t.SyncTime)); @@ -8275,7 +8275,7 @@ public void DisorderedStartEdgeTestColumnarThrow105TimeDiagnostic() } catch(Exception) { - Assert.IsTrue(true); // Todo. Verify if the ingress/egress before the exception was correct. + // Todo. Verify if the ingress/egress before the exception was correct. } } @@ -8310,7 +8310,7 @@ public void DisorderedIntervalTestColumnarThrow105TimeDiagnostic() var diagnosticStream = ingress.GetDroppedAdjustedEventsDiagnostic(); var outOfOrderEvents = new List>(); - diagnosticStream.Subscribe(o => outOfOrderEvents.Add(o)); + diagnosticStream.Subscribe(outOfOrderEvents.Add); var outevents = prog.ToEnumerable().ToList(); Assert.IsTrue(outevents.IsOrdered(t => t.SyncTime)); @@ -8322,7 +8322,7 @@ public void DisorderedIntervalTestColumnarThrow105TimeDiagnostic() } catch(Exception) { - Assert.IsTrue(true); // Todo. Verify if the ingress/egress before the exception was correct. + // Todo. Verify if the ingress/egress before the exception was correct. } } } @@ -8531,7 +8531,7 @@ public void DisorderedStartEdgeTestColumnarThrow1020TimeDiagnostic() var diagnosticStream = ingress.GetDroppedAdjustedEventsDiagnostic(); var outOfOrderEvents = new List>(); - diagnosticStream.Subscribe(o => outOfOrderEvents.Add(o)); + diagnosticStream.Subscribe(outOfOrderEvents.Add); var outevents = prog.ToEnumerable().ToList(); Assert.IsTrue(outevents.IsOrdered(t => t.SyncTime)); @@ -8626,7 +8626,7 @@ public void DisorderedIntervalTestColumnarThrow1020TimeDiagnostic() var diagnosticStream = ingress.GetDroppedAdjustedEventsDiagnostic(); var outOfOrderEvents = new List>(); - diagnosticStream.Subscribe(o => outOfOrderEvents.Add(o)); + diagnosticStream.Subscribe(outOfOrderEvents.Add); var outevents = prog.ToEnumerable().ToList(); Assert.IsTrue(outevents.IsOrdered(t => t.SyncTime)); @@ -8830,7 +8830,7 @@ public void DisorderedStartEdgeTestColumnarAdjust105Diagnostic() var diagnosticStream = ingress.GetDroppedAdjustedEventsDiagnostic(); var outOfOrderEvents = new List>(); - diagnosticStream.Subscribe(o => outOfOrderEvents.Add(o)); + diagnosticStream.Subscribe(outOfOrderEvents.Add); var outevents = prog.ToEnumerable().ToList(); Assert.IsTrue(outevents.IsOrdered(t => t.SyncTime)); @@ -8892,7 +8892,7 @@ public void DisorderedIntervalTestColumnarAdjust105Diagnostic() var diagnosticStream = ingress.GetDroppedAdjustedEventsDiagnostic(); var outOfOrderEvents = new List>(); - diagnosticStream.Subscribe(o => outOfOrderEvents.Add(o)); + diagnosticStream.Subscribe(outOfOrderEvents.Add); var outevents = prog.ToEnumerable().ToList(); Assert.IsTrue(outevents.IsOrdered(t => t.SyncTime)); @@ -9051,7 +9051,7 @@ public void DisorderedStartEdgeTestColumnarAdjust1020Diagnostic() var diagnosticStream = ingress.GetDroppedAdjustedEventsDiagnostic(); var outOfOrderEvents = new List>(); - diagnosticStream.Subscribe(o => outOfOrderEvents.Add(o)); + diagnosticStream.Subscribe(outOfOrderEvents.Add); var outevents = prog.ToEnumerable().ToList(); Assert.IsTrue(outevents.IsOrdered(t => t.SyncTime)); @@ -9106,7 +9106,7 @@ public void DisorderedIntervalTestColumnarAdjust1020Diagnostic() var diagnosticStream = ingress.GetDroppedAdjustedEventsDiagnostic(); var outOfOrderEvents = new List>(); - diagnosticStream.Subscribe(o => outOfOrderEvents.Add(o)); + diagnosticStream.Subscribe(outOfOrderEvents.Add); var outevents = prog.ToEnumerable().ToList(); Assert.IsTrue(outevents.IsOrdered(t => t.SyncTime)); @@ -9338,7 +9338,7 @@ public void DisorderedStartEdgeTestColumnarAdjust105TimeDiagnostic() var diagnosticStream = ingress.GetDroppedAdjustedEventsDiagnostic(); var outOfOrderEvents = new List>(); - diagnosticStream.Subscribe(o => outOfOrderEvents.Add(o)); + diagnosticStream.Subscribe(outOfOrderEvents.Add); var outevents = prog.ToEnumerable().ToList(); Assert.IsTrue(outevents.IsOrdered(t => t.SyncTime)); @@ -9433,7 +9433,7 @@ public void DisorderedIntervalTestColumnarAdjust105TimeDiagnostic() var diagnosticStream = ingress.GetDroppedAdjustedEventsDiagnostic(); var outOfOrderEvents = new List>(); - diagnosticStream.Subscribe(o => outOfOrderEvents.Add(o)); + diagnosticStream.Subscribe(outOfOrderEvents.Add); var outevents = prog.ToEnumerable().ToList(); Assert.IsTrue(outevents.IsOrdered(t => t.SyncTime)); @@ -9691,7 +9691,7 @@ public void DisorderedStartEdgeTestColumnarAdjust1020TimeDiagnostic() var diagnosticStream = ingress.GetDroppedAdjustedEventsDiagnostic(); var outOfOrderEvents = new List>(); - diagnosticStream.Subscribe(o => outOfOrderEvents.Add(o)); + diagnosticStream.Subscribe(outOfOrderEvents.Add); var outevents = prog.ToEnumerable().ToList(); Assert.IsTrue(outevents.IsOrdered(t => t.SyncTime)); @@ -9779,7 +9779,7 @@ public void DisorderedIntervalTestColumnarAdjust1020TimeDiagnostic() var diagnosticStream = ingress.GetDroppedAdjustedEventsDiagnostic(); var outOfOrderEvents = new List>(); - diagnosticStream.Subscribe(o => outOfOrderEvents.Add(o)); + diagnosticStream.Subscribe(outOfOrderEvents.Add); var outevents = prog.ToEnumerable().ToList(); Assert.IsTrue(outevents.IsOrdered(t => t.SyncTime)); @@ -9975,7 +9975,7 @@ public void DisorderedStartEdgeTestColumnarSmallBatchDrop105Diagnostic() var diagnosticStream = ingress.GetDroppedAdjustedEventsDiagnostic(); var outOfOrderEvents = new List>(); - diagnosticStream.Subscribe(o => outOfOrderEvents.Add(o)); + diagnosticStream.Subscribe(outOfOrderEvents.Add); var outevents = prog.ToEnumerable().ToList(); Assert.IsTrue(outevents.IsOrdered(t => t.SyncTime)); @@ -10036,7 +10036,7 @@ public void DisorderedIntervalTestColumnarSmallBatchDrop105Diagnostic() var diagnosticStream = ingress.GetDroppedAdjustedEventsDiagnostic(); var outOfOrderEvents = new List>(); - diagnosticStream.Subscribe(o => outOfOrderEvents.Add(o)); + diagnosticStream.Subscribe(outOfOrderEvents.Add); var outevents = prog.ToEnumerable().ToList(); Assert.IsTrue(outevents.IsOrdered(t => t.SyncTime)); @@ -10193,7 +10193,7 @@ public void DisorderedStartEdgeTestColumnarSmallBatchDrop1020Diagnostic() var diagnosticStream = ingress.GetDroppedAdjustedEventsDiagnostic(); var outOfOrderEvents = new List>(); - diagnosticStream.Subscribe(o => outOfOrderEvents.Add(o)); + diagnosticStream.Subscribe(outOfOrderEvents.Add); var outevents = prog.ToEnumerable().ToList(); Assert.IsTrue(outevents.IsOrdered(t => t.SyncTime)); @@ -10248,7 +10248,7 @@ public void DisorderedIntervalTestColumnarSmallBatchDrop1020Diagnostic() var diagnosticStream = ingress.GetDroppedAdjustedEventsDiagnostic(); var outOfOrderEvents = new List>(); - diagnosticStream.Subscribe(o => outOfOrderEvents.Add(o)); + diagnosticStream.Subscribe(outOfOrderEvents.Add); var outevents = prog.ToEnumerable().ToList(); Assert.IsTrue(outevents.IsOrdered(t => t.SyncTime)); @@ -10477,7 +10477,7 @@ public void DisorderedStartEdgeTestColumnarSmallBatchDrop105TimeDiagnostic() var diagnosticStream = ingress.GetDroppedAdjustedEventsDiagnostic(); var outOfOrderEvents = new List>(); - diagnosticStream.Subscribe(o => outOfOrderEvents.Add(o)); + diagnosticStream.Subscribe(outOfOrderEvents.Add); var outevents = prog.ToEnumerable().ToList(); Assert.IsTrue(outevents.IsOrdered(t => t.SyncTime)); @@ -10571,7 +10571,7 @@ public void DisorderedIntervalTestColumnarSmallBatchDrop105TimeDiagnostic() var diagnosticStream = ingress.GetDroppedAdjustedEventsDiagnostic(); var outOfOrderEvents = new List>(); - diagnosticStream.Subscribe(o => outOfOrderEvents.Add(o)); + diagnosticStream.Subscribe(outOfOrderEvents.Add); var outevents = prog.ToEnumerable().ToList(); Assert.IsTrue(outevents.IsOrdered(t => t.SyncTime)); @@ -10827,7 +10827,7 @@ public void DisorderedStartEdgeTestColumnarSmallBatchDrop1020TimeDiagnostic() var diagnosticStream = ingress.GetDroppedAdjustedEventsDiagnostic(); var outOfOrderEvents = new List>(); - diagnosticStream.Subscribe(o => outOfOrderEvents.Add(o)); + diagnosticStream.Subscribe(outOfOrderEvents.Add); var outevents = prog.ToEnumerable().ToList(); Assert.IsTrue(outevents.IsOrdered(t => t.SyncTime)); @@ -10915,7 +10915,7 @@ public void DisorderedIntervalTestColumnarSmallBatchDrop1020TimeDiagnostic() var diagnosticStream = ingress.GetDroppedAdjustedEventsDiagnostic(); var outOfOrderEvents = new List>(); - diagnosticStream.Subscribe(o => outOfOrderEvents.Add(o)); + diagnosticStream.Subscribe(outOfOrderEvents.Add); var outevents = prog.ToEnumerable().ToList(); Assert.IsTrue(outevents.IsOrdered(t => t.SyncTime)); @@ -11023,7 +11023,7 @@ public void DisorderedStartEdgeTestColumnarSmallBatchThrow105() } catch(Exception) { - Assert.IsTrue(true); // Todo. Verify if the ingress/egress before the exception was correct. + // Todo. Verify if the ingress/egress before the exception was correct. } } @@ -11066,7 +11066,7 @@ public void DisorderedIntervalTestColumnarSmallBatchThrow105() } catch(Exception) { - Assert.IsTrue(true); // Todo. Verify if the ingress/egress before the exception was correct. + // Todo. Verify if the ingress/egress before the exception was correct. } } } @@ -11111,7 +11111,7 @@ public void DisorderedStartEdgeTestColumnarSmallBatchThrow105Diagnostic() var diagnosticStream = ingress.GetDroppedAdjustedEventsDiagnostic(); var outOfOrderEvents = new List>(); - diagnosticStream.Subscribe(o => outOfOrderEvents.Add(o)); + diagnosticStream.Subscribe(outOfOrderEvents.Add); var outevents = prog.ToEnumerable().ToList(); Assert.IsTrue(outevents.IsOrdered(t => t.SyncTime)); @@ -11123,7 +11123,7 @@ public void DisorderedStartEdgeTestColumnarSmallBatchThrow105Diagnostic() } catch(Exception) { - Assert.IsTrue(true); // Todo. Verify if the ingress/egress before the exception was correct. + // Todo. Verify if the ingress/egress before the exception was correct. } } @@ -11158,7 +11158,7 @@ public void DisorderedIntervalTestColumnarSmallBatchThrow105Diagnostic() var diagnosticStream = ingress.GetDroppedAdjustedEventsDiagnostic(); var outOfOrderEvents = new List>(); - diagnosticStream.Subscribe(o => outOfOrderEvents.Add(o)); + diagnosticStream.Subscribe(outOfOrderEvents.Add); var outevents = prog.ToEnumerable().ToList(); Assert.IsTrue(outevents.IsOrdered(t => t.SyncTime)); @@ -11170,7 +11170,7 @@ public void DisorderedIntervalTestColumnarSmallBatchThrow105Diagnostic() } catch(Exception) { - Assert.IsTrue(true); // Todo. Verify if the ingress/egress before the exception was correct. + // Todo. Verify if the ingress/egress before the exception was correct. } } } @@ -11315,7 +11315,7 @@ public void DisorderedStartEdgeTestColumnarSmallBatchThrow1020Diagnostic() var diagnosticStream = ingress.GetDroppedAdjustedEventsDiagnostic(); var outOfOrderEvents = new List>(); - diagnosticStream.Subscribe(o => outOfOrderEvents.Add(o)); + diagnosticStream.Subscribe(outOfOrderEvents.Add); var outevents = prog.ToEnumerable().ToList(); Assert.IsTrue(outevents.IsOrdered(t => t.SyncTime)); @@ -11377,7 +11377,7 @@ public void DisorderedIntervalTestColumnarSmallBatchThrow1020Diagnostic() var diagnosticStream = ingress.GetDroppedAdjustedEventsDiagnostic(); var outOfOrderEvents = new List>(); - diagnosticStream.Subscribe(o => outOfOrderEvents.Add(o)); + diagnosticStream.Subscribe(outOfOrderEvents.Add); var outevents = prog.ToEnumerable().ToList(); Assert.IsTrue(outevents.IsOrdered(t => t.SyncTime)); @@ -11457,7 +11457,7 @@ public void DisorderedStartEdgeTestColumnarSmallBatchThrow105Time() } catch(Exception) { - Assert.IsTrue(true); // Todo. Verify if the ingress/egress before the exception was correct. + // Todo. Verify if the ingress/egress before the exception was correct. } } @@ -11500,7 +11500,7 @@ public void DisorderedIntervalTestColumnarSmallBatchThrow105Time() } catch(Exception) { - Assert.IsTrue(true); // Todo. Verify if the ingress/egress before the exception was correct. + // Todo. Verify if the ingress/egress before the exception was correct. } } } @@ -11545,7 +11545,7 @@ public void DisorderedStartEdgeTestColumnarSmallBatchThrow105TimeDiagnostic() var diagnosticStream = ingress.GetDroppedAdjustedEventsDiagnostic(); var outOfOrderEvents = new List>(); - diagnosticStream.Subscribe(o => outOfOrderEvents.Add(o)); + diagnosticStream.Subscribe(outOfOrderEvents.Add); var outevents = prog.ToEnumerable().ToList(); Assert.IsTrue(outevents.IsOrdered(t => t.SyncTime)); @@ -11557,7 +11557,7 @@ public void DisorderedStartEdgeTestColumnarSmallBatchThrow105TimeDiagnostic() } catch(Exception) { - Assert.IsTrue(true); // Todo. Verify if the ingress/egress before the exception was correct. + // Todo. Verify if the ingress/egress before the exception was correct. } } @@ -11592,7 +11592,7 @@ public void DisorderedIntervalTestColumnarSmallBatchThrow105TimeDiagnostic() var diagnosticStream = ingress.GetDroppedAdjustedEventsDiagnostic(); var outOfOrderEvents = new List>(); - diagnosticStream.Subscribe(o => outOfOrderEvents.Add(o)); + diagnosticStream.Subscribe(outOfOrderEvents.Add); var outevents = prog.ToEnumerable().ToList(); Assert.IsTrue(outevents.IsOrdered(t => t.SyncTime)); @@ -11604,7 +11604,7 @@ public void DisorderedIntervalTestColumnarSmallBatchThrow105TimeDiagnostic() } catch(Exception) { - Assert.IsTrue(true); // Todo. Verify if the ingress/egress before the exception was correct. + // Todo. Verify if the ingress/egress before the exception was correct. } } } @@ -11815,7 +11815,7 @@ public void DisorderedStartEdgeTestColumnarSmallBatchThrow1020TimeDiagnostic() var diagnosticStream = ingress.GetDroppedAdjustedEventsDiagnostic(); var outOfOrderEvents = new List>(); - diagnosticStream.Subscribe(o => outOfOrderEvents.Add(o)); + diagnosticStream.Subscribe(outOfOrderEvents.Add); var outevents = prog.ToEnumerable().ToList(); Assert.IsTrue(outevents.IsOrdered(t => t.SyncTime)); @@ -11910,7 +11910,7 @@ public void DisorderedIntervalTestColumnarSmallBatchThrow1020TimeDiagnostic() var diagnosticStream = ingress.GetDroppedAdjustedEventsDiagnostic(); var outOfOrderEvents = new List>(); - diagnosticStream.Subscribe(o => outOfOrderEvents.Add(o)); + diagnosticStream.Subscribe(outOfOrderEvents.Add); var outevents = prog.ToEnumerable().ToList(); Assert.IsTrue(outevents.IsOrdered(t => t.SyncTime)); @@ -12116,7 +12116,7 @@ public void DisorderedStartEdgeTestColumnarSmallBatchAdjust105Diagnostic() var diagnosticStream = ingress.GetDroppedAdjustedEventsDiagnostic(); var outOfOrderEvents = new List>(); - diagnosticStream.Subscribe(o => outOfOrderEvents.Add(o)); + diagnosticStream.Subscribe(outOfOrderEvents.Add); var outevents = prog.ToEnumerable().ToList(); Assert.IsTrue(outevents.IsOrdered(t => t.SyncTime)); @@ -12178,7 +12178,7 @@ public void DisorderedIntervalTestColumnarSmallBatchAdjust105Diagnostic() var diagnosticStream = ingress.GetDroppedAdjustedEventsDiagnostic(); var outOfOrderEvents = new List>(); - diagnosticStream.Subscribe(o => outOfOrderEvents.Add(o)); + diagnosticStream.Subscribe(outOfOrderEvents.Add); var outevents = prog.ToEnumerable().ToList(); Assert.IsTrue(outevents.IsOrdered(t => t.SyncTime)); @@ -12339,7 +12339,7 @@ public void DisorderedStartEdgeTestColumnarSmallBatchAdjust1020Diagnostic() var diagnosticStream = ingress.GetDroppedAdjustedEventsDiagnostic(); var outOfOrderEvents = new List>(); - diagnosticStream.Subscribe(o => outOfOrderEvents.Add(o)); + diagnosticStream.Subscribe(outOfOrderEvents.Add); var outevents = prog.ToEnumerable().ToList(); Assert.IsTrue(outevents.IsOrdered(t => t.SyncTime)); @@ -12394,7 +12394,7 @@ public void DisorderedIntervalTestColumnarSmallBatchAdjust1020Diagnostic() var diagnosticStream = ingress.GetDroppedAdjustedEventsDiagnostic(); var outOfOrderEvents = new List>(); - diagnosticStream.Subscribe(o => outOfOrderEvents.Add(o)); + diagnosticStream.Subscribe(outOfOrderEvents.Add); var outevents = prog.ToEnumerable().ToList(); Assert.IsTrue(outevents.IsOrdered(t => t.SyncTime)); @@ -12628,7 +12628,7 @@ public void DisorderedStartEdgeTestColumnarSmallBatchAdjust105TimeDiagnostic() var diagnosticStream = ingress.GetDroppedAdjustedEventsDiagnostic(); var outOfOrderEvents = new List>(); - diagnosticStream.Subscribe(o => outOfOrderEvents.Add(o)); + diagnosticStream.Subscribe(outOfOrderEvents.Add); var outevents = prog.ToEnumerable().ToList(); Assert.IsTrue(outevents.IsOrdered(t => t.SyncTime)); @@ -12723,7 +12723,7 @@ public void DisorderedIntervalTestColumnarSmallBatchAdjust105TimeDiagnostic() var diagnosticStream = ingress.GetDroppedAdjustedEventsDiagnostic(); var outOfOrderEvents = new List>(); - diagnosticStream.Subscribe(o => outOfOrderEvents.Add(o)); + diagnosticStream.Subscribe(outOfOrderEvents.Add); var outevents = prog.ToEnumerable().ToList(); Assert.IsTrue(outevents.IsOrdered(t => t.SyncTime)); @@ -12983,7 +12983,7 @@ public void DisorderedStartEdgeTestColumnarSmallBatchAdjust1020TimeDiagnostic() var diagnosticStream = ingress.GetDroppedAdjustedEventsDiagnostic(); var outOfOrderEvents = new List>(); - diagnosticStream.Subscribe(o => outOfOrderEvents.Add(o)); + diagnosticStream.Subscribe(outOfOrderEvents.Add); var outevents = prog.ToEnumerable().ToList(); Assert.IsTrue(outevents.IsOrdered(t => t.SyncTime)); @@ -13071,7 +13071,7 @@ public void DisorderedIntervalTestColumnarSmallBatchAdjust1020TimeDiagnostic() var diagnosticStream = ingress.GetDroppedAdjustedEventsDiagnostic(); var outOfOrderEvents = new List>(); - diagnosticStream.Subscribe(o => outOfOrderEvents.Add(o)); + diagnosticStream.Subscribe(outOfOrderEvents.Add); var outevents = prog.ToEnumerable().ToList(); Assert.IsTrue(outevents.IsOrdered(t => t.SyncTime)); diff --git a/Sources/Test/SimpleTesting/IngressEgress/FlushPolicyTestMatrixBase.cs b/Sources/Test/SimpleTesting/IngressEgress/FlushPolicyTestMatrixBase.cs index e0af14413..9960524b9 100644 --- a/Sources/Test/SimpleTesting/IngressEgress/FlushPolicyTestMatrixBase.cs +++ b/Sources/Test/SimpleTesting/IngressEgress/FlushPolicyTestMatrixBase.cs @@ -12,7 +12,7 @@ namespace SimpleTesting.Flush { - public class FlushTestBase : TestWithConfigSettingsAndMemoryLeakDetection + public abstract class FlushTestBase : TestWithConfigSettingsAndMemoryLeakDetection { private const int IntervalLength = 5; private const int BatchSize = 10; // TODO: this will be identical for FlushPolicy.None and FlushOnBatchBoundary without some filter operator @@ -45,7 +45,7 @@ public void FilterTest() query = query.Where(this.FilterExpression); query = query.ClipEventDuration(IntervalLength); - var filtered = qc.RegisterOutput(query).ForEachAsync(o => OnEgress(o)); + var filtered = qc.RegisterOutput(query).ForEachAsync(OnEgress); var process = qc.Restore(); for (int i = 0; i < IngressEventCount; i++) @@ -55,7 +55,7 @@ public void FilterTest() OnIngress(inputSubject, StreamEvent.CreatePunctuation(i)); // Make sure we don't have any pending events we expected to be egressed at this point - Assert.IsTrue(this.expectedOutput.Count == 0); + Assert.IsEmpty(this.expectedOutput); } OnCompleted(inputSubject); @@ -115,7 +115,7 @@ private void MoveFilteredBatchBatchToOutput() private void OnEgress(StreamEvent egressEvent) { - Assert.IsTrue(this.expectedOutput.Count > 0); + Assert.IsNotEmpty(this.expectedOutput); var expectedEvent = this.expectedOutput.Dequeue(); Assert.IsTrue(expectedEvent.Equals(egressEvent)); @@ -150,16 +150,16 @@ private void OnCompleted(Subject> inputSubject) private readonly PeriodicPunctuationPolicy punctuationPolicy; private readonly OnCompletedPolicy completedPolicy; - private readonly Queue> expectedOutput = new Queue>(); + private readonly Queue> expectedOutput = new(); // Events expected to be batched at ingress but not egressed - private readonly Queue> expectedBatch = new Queue>(); + private readonly Queue> expectedBatch = new(); // Events expected to be batched at the filtered operator but not egressed (only used for FlushPolicy.None) - private readonly Queue> filteredBatch = new Queue>(); + private readonly Queue> filteredBatch = new(); private int ingressCount = 0; // Events that have already been validated (kept around for debugging purposes) - private readonly List> validatedOutput = new List>(); + private readonly List> validatedOutput = new(); } } \ No newline at end of file diff --git a/Sources/Test/SimpleTesting/IngressEgress/IngressAndEgressTests.cs b/Sources/Test/SimpleTesting/IngressEgress/IngressAndEgressTests.cs index 17c35bc6b..10ef8af6c 100644 --- a/Sources/Test/SimpleTesting/IngressEgress/IngressAndEgressTests.cs +++ b/Sources/Test/SimpleTesting/IngressEgress/IngressAndEgressTests.cs @@ -28,7 +28,7 @@ public void Level1InLevel1OutTrivialRow() var input = Enumerable.Range(0, 1000).ToList(); var subject = new Subject(); var prog = subject.ToAtemporalStreamable(TimelinePolicy.Sequence(100)).ToEnumerable(); - input.ForEach(o => subject.OnNext(o)); + input.ForEach(subject.OnNext); subject.OnCompleted(); while (!prog.Completed) { } var output = prog.OrderBy(o => o); @@ -43,8 +43,8 @@ public void Level1InLevel3OutTrivialRow() var subject = new Subject(); var output = new List>(); - var outputAwait = subject.ToAtemporalStreamable(TimelinePolicy.Sequence(100)).ToStreamEventObservable().Where(o => o.IsData).ForEachAsync(o => output.Add(o)); - input.ForEach(o => subject.OnNext(o)); + var outputAwait = subject.ToAtemporalStreamable(TimelinePolicy.Sequence(100)).ToStreamEventObservable().Where(o => o.IsData).ForEachAsync(output.Add); + input.ForEach(subject.OnNext); subject.OnCompleted(); outputAwait.Wait(); @@ -999,7 +999,7 @@ public void Level1InLevel1OutTrivialRowSmallBatch() var input = Enumerable.Range(0, 1000).ToList(); var subject = new Subject(); var prog = subject.ToAtemporalStreamable(TimelinePolicy.Sequence(100)).ToEnumerable(); - input.ForEach(o => subject.OnNext(o)); + input.ForEach(subject.OnNext); subject.OnCompleted(); while (!prog.Completed) { } var output = prog.OrderBy(o => o); @@ -1014,8 +1014,8 @@ public void Level1InLevel3OutTrivialRowSmallBatch() var subject = new Subject(); var output = new List>(); - var outputAwait = subject.ToAtemporalStreamable(TimelinePolicy.Sequence(100)).ToStreamEventObservable().Where(o => o.IsData).ForEachAsync(o => output.Add(o)); - input.ForEach(o => subject.OnNext(o)); + var outputAwait = subject.ToAtemporalStreamable(TimelinePolicy.Sequence(100)).ToStreamEventObservable().Where(o => o.IsData).ForEachAsync(output.Add); + input.ForEach(subject.OnNext); subject.OnCompleted(); outputAwait.Wait(); @@ -1988,7 +1988,7 @@ public void Level1InLevel1OutTrivialColumnar() var input = Enumerable.Range(0, 1000).ToList(); var subject = new Subject(); var prog = subject.ToAtemporalStreamable(TimelinePolicy.Sequence(100)).ToEnumerable(); - input.ForEach(o => subject.OnNext(o)); + input.ForEach(subject.OnNext); subject.OnCompleted(); while (!prog.Completed) { } var output = prog.OrderBy(o => o); @@ -2003,8 +2003,8 @@ public void Level1InLevel3OutTrivialColumnar() var subject = new Subject(); var output = new List>(); - var outputAwait = subject.ToAtemporalStreamable(TimelinePolicy.Sequence(100)).ToStreamEventObservable().Where(o => o.IsData).ForEachAsync(o => output.Add(o)); - input.ForEach(o => subject.OnNext(o)); + var outputAwait = subject.ToAtemporalStreamable(TimelinePolicy.Sequence(100)).ToStreamEventObservable().Where(o => o.IsData).ForEachAsync(output.Add); + input.ForEach(subject.OnNext); subject.OnCompleted(); outputAwait.Wait(); @@ -2959,7 +2959,7 @@ public void Level1InLevel1OutTrivialColumnarSmallBatch() var input = Enumerable.Range(0, 1000).ToList(); var subject = new Subject(); var prog = subject.ToAtemporalStreamable(TimelinePolicy.Sequence(100)).ToEnumerable(); - input.ForEach(o => subject.OnNext(o)); + input.ForEach(subject.OnNext); subject.OnCompleted(); while (!prog.Completed) { } var output = prog.OrderBy(o => o); @@ -2974,8 +2974,8 @@ public void Level1InLevel3OutTrivialColumnarSmallBatch() var subject = new Subject(); var output = new List>(); - var outputAwait = subject.ToAtemporalStreamable(TimelinePolicy.Sequence(100)).ToStreamEventObservable().Where(o => o.IsData).ForEachAsync(o => output.Add(o)); - input.ForEach(o => subject.OnNext(o)); + var outputAwait = subject.ToAtemporalStreamable(TimelinePolicy.Sequence(100)).ToStreamEventObservable().Where(o => o.IsData).ForEachAsync(output.Add); + input.ForEach(subject.OnNext); subject.OnCompleted(); outputAwait.Wait(); diff --git a/Sources/Test/SimpleTesting/Macros/LeftOuterJoinTests.cs b/Sources/Test/SimpleTesting/Macros/LeftOuterJoinTests.cs index 6b778f07d..5133559ec 100644 --- a/Sources/Test/SimpleTesting/Macros/LeftOuterJoinTests.cs +++ b/Sources/Test/SimpleTesting/Macros/LeftOuterJoinTests.cs @@ -86,7 +86,7 @@ public void LOJ1Row() (l, r) => new MyData3 { field1 = l.field1, field2 = l.field2, field3 = r.field3, field4 = r.field4 }); var result = container.RegisterOutput(query, ReshapingPolicy.CoalesceEndEdges).Where(e => e.IsData); - var resultAsync = result.ForEachAsync(o => output.Add(o)); + var resultAsync = result.ForEachAsync(output.Add); container.Restore(null); // start the query Assert.IsTrue(output.ToArray().SequenceEqual(expected)); @@ -148,7 +148,7 @@ public void LOJ1RowSmallBatch() (l, r) => new MyData3 { field1 = l.field1, field2 = l.field2, field3 = r.field3, field4 = r.field4 }); var result = container.RegisterOutput(query, ReshapingPolicy.CoalesceEndEdges).Where(e => e.IsData); - var resultAsync = result.ForEachAsync(o => output.Add(o)); + var resultAsync = result.ForEachAsync(output.Add); container.Restore(null); // start the query Assert.IsTrue(output.ToArray().SequenceEqual(expected)); @@ -209,7 +209,7 @@ public void LOJ1Columnar() (l, r) => new MyData3 { field1 = l.field1, field2 = l.field2, field3 = r.field3, field4 = r.field4 }); var result = container.RegisterOutput(query, ReshapingPolicy.CoalesceEndEdges).Where(e => e.IsData); - var resultAsync = result.ForEachAsync(o => output.Add(o)); + var resultAsync = result.ForEachAsync(output.Add); container.Restore(null); // start the query Assert.IsTrue(output.ToArray().SequenceEqual(expected)); @@ -271,7 +271,7 @@ public void LOJ1ColumnarSmallBatch() (l, r) => new MyData3 { field1 = l.field1, field2 = l.field2, field3 = r.field3, field4 = r.field4 }); var result = container.RegisterOutput(query, ReshapingPolicy.CoalesceEndEdges).Where(e => e.IsData); - var resultAsync = result.ForEachAsync(o => output.Add(o)); + var resultAsync = result.ForEachAsync(output.Add); container.Restore(null); // start the query Assert.IsTrue(output.ToArray().SequenceEqual(expected)); diff --git a/Sources/Test/SimpleTesting/Macros/PivotUnpivot.cs b/Sources/Test/SimpleTesting/Macros/PivotUnpivot.cs index c71310e56..c59a62ade 100644 --- a/Sources/Test/SimpleTesting/Macros/PivotUnpivot.cs +++ b/Sources/Test/SimpleTesting/Macros/PivotUnpivot.cs @@ -66,13 +66,13 @@ public void Unpivot1AllRow() var expected = new List { - new UnpivotStruct1 { Key1 = "a", Attribute = "i5", Value = 5 }, - new UnpivotStruct1 { Key1 = "a", Attribute = "i9", Value = 9 }, - new UnpivotStruct1 { Key1 = "b", Attribute = "i1", Value = 11 }, - new UnpivotStruct1 { Key1 = "b", Attribute = "i14", Value = 100 }, - new UnpivotStruct1 { Key1 = "b", Attribute = "i2", Value = 9 }, - new UnpivotStruct1 { Key1 = "c", Attribute = "i15", Value = 0 }, - new UnpivotStruct1 { Key1 = "c", Attribute = "o", Value = 9 }, + new() { Key1 = "a", Attribute = "i5", Value = 5 }, + new() { Key1 = "a", Attribute = "i9", Value = 9 }, + new() { Key1 = "b", Attribute = "i1", Value = 11 }, + new() { Key1 = "b", Attribute = "i14", Value = 100 }, + new() { Key1 = "b", Attribute = "i2", Value = 9 }, + new() { Key1 = "c", Attribute = "i15", Value = 0 }, + new() { Key1 = "c", Attribute = "o", Value = 9 }, }; Assert.IsTrue(input.SequenceEqual(expected)); @@ -94,13 +94,13 @@ public void Unpivot2AllRow() var expected = new List { - new UnpivotStruct2 { Key1 = "a", Key2 = "d", Attribute = "i5", Value = 5 }, - new UnpivotStruct2 { Key1 = "a", Key2 = "d", Attribute = "i9", Value = 9 }, - new UnpivotStruct2 { Key1 = "b", Key2 = "d", Attribute = "i1", Value = 11 }, - new UnpivotStruct2 { Key1 = "b", Key2 = "d", Attribute = "i14", Value = 100 }, - new UnpivotStruct2 { Key1 = "b", Key2 = "d", Attribute = "i2", Value = 9 }, - new UnpivotStruct2 { Key1 = "c", Key2 = "e", Attribute = "i15", Value = 0 }, - new UnpivotStruct2 { Key1 = "c", Key2 = "e", Attribute = "o", Value = 9 }, + new() { Key1 = "a", Key2 = "d", Attribute = "i5", Value = 5 }, + new() { Key1 = "a", Key2 = "d", Attribute = "i9", Value = 9 }, + new() { Key1 = "b", Key2 = "d", Attribute = "i1", Value = 11 }, + new() { Key1 = "b", Key2 = "d", Attribute = "i14", Value = 100 }, + new() { Key1 = "b", Key2 = "d", Attribute = "i2", Value = 9 }, + new() { Key1 = "c", Key2 = "e", Attribute = "i15", Value = 0 }, + new() { Key1 = "c", Key2 = "e", Attribute = "o", Value = 9 }, }; Assert.IsTrue(input.SequenceEqual(expected)); @@ -122,13 +122,13 @@ public void Pivot1AllRow() { var input = new List { - new UnpivotStruct1N { Key1 = "a", Attribute = "i5", Value = 5 }, - new UnpivotStruct1N { Key1 = "a", Attribute = "i9", Value = 9 }, - new UnpivotStruct1N { Key1 = "b", Attribute = "i1", Value = 11 }, - new UnpivotStruct1N { Key1 = "b", Attribute = "i2", Value = 9 }, - new UnpivotStruct1N { Key1 = "b", Attribute = "i14", Value = 100 }, - new UnpivotStruct1N { Key1 = "c", Attribute = "i15", Value = 0 }, - new UnpivotStruct1N { Key1 = "c", Attribute = "o", Value = 9 }, + new() { Key1 = "a", Attribute = "i5", Value = 5 }, + new() { Key1 = "a", Attribute = "i9", Value = 9 }, + new() { Key1 = "b", Attribute = "i1", Value = 11 }, + new() { Key1 = "b", Attribute = "i2", Value = 9 }, + new() { Key1 = "b", Attribute = "i14", Value = 100 }, + new() { Key1 = "c", Attribute = "i15", Value = 0 }, + new() { Key1 = "c", Attribute = "o", Value = 9 }, }.ToStreamable() .Pivot( () => new WideStruct1(), @@ -150,13 +150,13 @@ public void Pivot2AllRow() { var input = new List { - new UnpivotStruct2N { Key1 = "a", Key2 = "d", Attribute = "i5", Value = 5 }, - new UnpivotStruct2N { Key1 = "a", Key2 = "d", Attribute = "i9", Value = 9 }, - new UnpivotStruct2N { Key1 = "b", Key2 = "d", Attribute = "i1", Value = 11 }, - new UnpivotStruct2N { Key1 = "b", Key2 = "d", Attribute = "i14", Value = 100 }, - new UnpivotStruct2N { Key1 = "b", Key2 = "d", Attribute = "i2", Value = 9 }, - new UnpivotStruct2N { Key1 = "c", Key2 = "e", Attribute = "i15", Value = 0 }, - new UnpivotStruct2N { Key1 = "c", Key2 = "e", Attribute = "o", Value = 9 }, + new() { Key1 = "a", Key2 = "d", Attribute = "i5", Value = 5 }, + new() { Key1 = "a", Key2 = "d", Attribute = "i9", Value = 9 }, + new() { Key1 = "b", Key2 = "d", Attribute = "i1", Value = 11 }, + new() { Key1 = "b", Key2 = "d", Attribute = "i14", Value = 100 }, + new() { Key1 = "b", Key2 = "d", Attribute = "i2", Value = 9 }, + new() { Key1 = "c", Key2 = "e", Attribute = "i15", Value = 0 }, + new() { Key1 = "c", Key2 = "e", Attribute = "o", Value = 9 }, }.ToStreamable() .Pivot( () => new WideStruct2(), @@ -201,13 +201,13 @@ public void Unpivot1AllRowSmallBatch() var expected = new List { - new UnpivotStruct1 { Key1 = "a", Attribute = "i5", Value = 5 }, - new UnpivotStruct1 { Key1 = "a", Attribute = "i9", Value = 9 }, - new UnpivotStruct1 { Key1 = "b", Attribute = "i1", Value = 11 }, - new UnpivotStruct1 { Key1 = "b", Attribute = "i14", Value = 100 }, - new UnpivotStruct1 { Key1 = "b", Attribute = "i2", Value = 9 }, - new UnpivotStruct1 { Key1 = "c", Attribute = "i15", Value = 0 }, - new UnpivotStruct1 { Key1 = "c", Attribute = "o", Value = 9 }, + new() { Key1 = "a", Attribute = "i5", Value = 5 }, + new() { Key1 = "a", Attribute = "i9", Value = 9 }, + new() { Key1 = "b", Attribute = "i1", Value = 11 }, + new() { Key1 = "b", Attribute = "i14", Value = 100 }, + new() { Key1 = "b", Attribute = "i2", Value = 9 }, + new() { Key1 = "c", Attribute = "i15", Value = 0 }, + new() { Key1 = "c", Attribute = "o", Value = 9 }, }; Assert.IsTrue(input.SequenceEqual(expected)); @@ -229,13 +229,13 @@ public void Unpivot2AllRowSmallBatch() var expected = new List { - new UnpivotStruct2 { Key1 = "a", Key2 = "d", Attribute = "i5", Value = 5 }, - new UnpivotStruct2 { Key1 = "a", Key2 = "d", Attribute = "i9", Value = 9 }, - new UnpivotStruct2 { Key1 = "b", Key2 = "d", Attribute = "i1", Value = 11 }, - new UnpivotStruct2 { Key1 = "b", Key2 = "d", Attribute = "i14", Value = 100 }, - new UnpivotStruct2 { Key1 = "b", Key2 = "d", Attribute = "i2", Value = 9 }, - new UnpivotStruct2 { Key1 = "c", Key2 = "e", Attribute = "i15", Value = 0 }, - new UnpivotStruct2 { Key1 = "c", Key2 = "e", Attribute = "o", Value = 9 }, + new() { Key1 = "a", Key2 = "d", Attribute = "i5", Value = 5 }, + new() { Key1 = "a", Key2 = "d", Attribute = "i9", Value = 9 }, + new() { Key1 = "b", Key2 = "d", Attribute = "i1", Value = 11 }, + new() { Key1 = "b", Key2 = "d", Attribute = "i14", Value = 100 }, + new() { Key1 = "b", Key2 = "d", Attribute = "i2", Value = 9 }, + new() { Key1 = "c", Key2 = "e", Attribute = "i15", Value = 0 }, + new() { Key1 = "c", Key2 = "e", Attribute = "o", Value = 9 }, }; Assert.IsTrue(input.SequenceEqual(expected)); @@ -258,13 +258,13 @@ public void Pivot1AllRowSmallBatch() { var input = new List { - new UnpivotStruct1N { Key1 = "a", Attribute = "i5", Value = 5 }, - new UnpivotStruct1N { Key1 = "a", Attribute = "i9", Value = 9 }, - new UnpivotStruct1N { Key1 = "b", Attribute = "i1", Value = 11 }, - new UnpivotStruct1N { Key1 = "b", Attribute = "i2", Value = 9 }, - new UnpivotStruct1N { Key1 = "b", Attribute = "i14", Value = 100 }, - new UnpivotStruct1N { Key1 = "c", Attribute = "i15", Value = 0 }, - new UnpivotStruct1N { Key1 = "c", Attribute = "o", Value = 9 }, + new() { Key1 = "a", Attribute = "i5", Value = 5 }, + new() { Key1 = "a", Attribute = "i9", Value = 9 }, + new() { Key1 = "b", Attribute = "i1", Value = 11 }, + new() { Key1 = "b", Attribute = "i2", Value = 9 }, + new() { Key1 = "b", Attribute = "i14", Value = 100 }, + new() { Key1 = "c", Attribute = "i15", Value = 0 }, + new() { Key1 = "c", Attribute = "o", Value = 9 }, }.ToStreamable() .Pivot( () => new WideStruct1(), @@ -286,13 +286,13 @@ public void Pivot2AllRowSmallBatch() { var input = new List { - new UnpivotStruct2N { Key1 = "a", Key2 = "d", Attribute = "i5", Value = 5 }, - new UnpivotStruct2N { Key1 = "a", Key2 = "d", Attribute = "i9", Value = 9 }, - new UnpivotStruct2N { Key1 = "b", Key2 = "d", Attribute = "i1", Value = 11 }, - new UnpivotStruct2N { Key1 = "b", Key2 = "d", Attribute = "i14", Value = 100 }, - new UnpivotStruct2N { Key1 = "b", Key2 = "d", Attribute = "i2", Value = 9 }, - new UnpivotStruct2N { Key1 = "c", Key2 = "e", Attribute = "i15", Value = 0 }, - new UnpivotStruct2N { Key1 = "c", Key2 = "e", Attribute = "o", Value = 9 }, + new() { Key1 = "a", Key2 = "d", Attribute = "i5", Value = 5 }, + new() { Key1 = "a", Key2 = "d", Attribute = "i9", Value = 9 }, + new() { Key1 = "b", Key2 = "d", Attribute = "i1", Value = 11 }, + new() { Key1 = "b", Key2 = "d", Attribute = "i14", Value = 100 }, + new() { Key1 = "b", Key2 = "d", Attribute = "i2", Value = 9 }, + new() { Key1 = "c", Key2 = "e", Attribute = "i15", Value = 0 }, + new() { Key1 = "c", Key2 = "e", Attribute = "o", Value = 9 }, }.ToStreamable() .Pivot( () => new WideStruct2(), @@ -336,13 +336,13 @@ public void Unpivot1AllColumnar() var expected = new List { - new UnpivotStruct1 { Key1 = "a", Attribute = "i5", Value = 5 }, - new UnpivotStruct1 { Key1 = "a", Attribute = "i9", Value = 9 }, - new UnpivotStruct1 { Key1 = "b", Attribute = "i1", Value = 11 }, - new UnpivotStruct1 { Key1 = "b", Attribute = "i14", Value = 100 }, - new UnpivotStruct1 { Key1 = "b", Attribute = "i2", Value = 9 }, - new UnpivotStruct1 { Key1 = "c", Attribute = "i15", Value = 0 }, - new UnpivotStruct1 { Key1 = "c", Attribute = "o", Value = 9 }, + new() { Key1 = "a", Attribute = "i5", Value = 5 }, + new() { Key1 = "a", Attribute = "i9", Value = 9 }, + new() { Key1 = "b", Attribute = "i1", Value = 11 }, + new() { Key1 = "b", Attribute = "i14", Value = 100 }, + new() { Key1 = "b", Attribute = "i2", Value = 9 }, + new() { Key1 = "c", Attribute = "i15", Value = 0 }, + new() { Key1 = "c", Attribute = "o", Value = 9 }, }; Assert.IsTrue(input.SequenceEqual(expected)); @@ -364,13 +364,13 @@ public void Unpivot2AllColumnar() var expected = new List { - new UnpivotStruct2 { Key1 = "a", Key2 = "d", Attribute = "i5", Value = 5 }, - new UnpivotStruct2 { Key1 = "a", Key2 = "d", Attribute = "i9", Value = 9 }, - new UnpivotStruct2 { Key1 = "b", Key2 = "d", Attribute = "i1", Value = 11 }, - new UnpivotStruct2 { Key1 = "b", Key2 = "d", Attribute = "i14", Value = 100 }, - new UnpivotStruct2 { Key1 = "b", Key2 = "d", Attribute = "i2", Value = 9 }, - new UnpivotStruct2 { Key1 = "c", Key2 = "e", Attribute = "i15", Value = 0 }, - new UnpivotStruct2 { Key1 = "c", Key2 = "e", Attribute = "o", Value = 9 }, + new() { Key1 = "a", Key2 = "d", Attribute = "i5", Value = 5 }, + new() { Key1 = "a", Key2 = "d", Attribute = "i9", Value = 9 }, + new() { Key1 = "b", Key2 = "d", Attribute = "i1", Value = 11 }, + new() { Key1 = "b", Key2 = "d", Attribute = "i14", Value = 100 }, + new() { Key1 = "b", Key2 = "d", Attribute = "i2", Value = 9 }, + new() { Key1 = "c", Key2 = "e", Attribute = "i15", Value = 0 }, + new() { Key1 = "c", Key2 = "e", Attribute = "o", Value = 9 }, }; Assert.IsTrue(input.SequenceEqual(expected)); @@ -392,13 +392,13 @@ public void Pivot1AllColumnar() { var input = new List { - new UnpivotStruct1N { Key1 = "a", Attribute = "i5", Value = 5 }, - new UnpivotStruct1N { Key1 = "a", Attribute = "i9", Value = 9 }, - new UnpivotStruct1N { Key1 = "b", Attribute = "i1", Value = 11 }, - new UnpivotStruct1N { Key1 = "b", Attribute = "i2", Value = 9 }, - new UnpivotStruct1N { Key1 = "b", Attribute = "i14", Value = 100 }, - new UnpivotStruct1N { Key1 = "c", Attribute = "i15", Value = 0 }, - new UnpivotStruct1N { Key1 = "c", Attribute = "o", Value = 9 }, + new() { Key1 = "a", Attribute = "i5", Value = 5 }, + new() { Key1 = "a", Attribute = "i9", Value = 9 }, + new() { Key1 = "b", Attribute = "i1", Value = 11 }, + new() { Key1 = "b", Attribute = "i2", Value = 9 }, + new() { Key1 = "b", Attribute = "i14", Value = 100 }, + new() { Key1 = "c", Attribute = "i15", Value = 0 }, + new() { Key1 = "c", Attribute = "o", Value = 9 }, }.ToStreamable() .Pivot( () => new WideStruct1(), @@ -420,13 +420,13 @@ public void Pivot2AllColumnar() { var input = new List { - new UnpivotStruct2N { Key1 = "a", Key2 = "d", Attribute = "i5", Value = 5 }, - new UnpivotStruct2N { Key1 = "a", Key2 = "d", Attribute = "i9", Value = 9 }, - new UnpivotStruct2N { Key1 = "b", Key2 = "d", Attribute = "i1", Value = 11 }, - new UnpivotStruct2N { Key1 = "b", Key2 = "d", Attribute = "i14", Value = 100 }, - new UnpivotStruct2N { Key1 = "b", Key2 = "d", Attribute = "i2", Value = 9 }, - new UnpivotStruct2N { Key1 = "c", Key2 = "e", Attribute = "i15", Value = 0 }, - new UnpivotStruct2N { Key1 = "c", Key2 = "e", Attribute = "o", Value = 9 }, + new() { Key1 = "a", Key2 = "d", Attribute = "i5", Value = 5 }, + new() { Key1 = "a", Key2 = "d", Attribute = "i9", Value = 9 }, + new() { Key1 = "b", Key2 = "d", Attribute = "i1", Value = 11 }, + new() { Key1 = "b", Key2 = "d", Attribute = "i14", Value = 100 }, + new() { Key1 = "b", Key2 = "d", Attribute = "i2", Value = 9 }, + new() { Key1 = "c", Key2 = "e", Attribute = "i15", Value = 0 }, + new() { Key1 = "c", Key2 = "e", Attribute = "o", Value = 9 }, }.ToStreamable() .Pivot( () => new WideStruct2(), @@ -471,13 +471,13 @@ public void Unpivot1AllColumnarSmallBatch() var expected = new List { - new UnpivotStruct1 { Key1 = "a", Attribute = "i5", Value = 5 }, - new UnpivotStruct1 { Key1 = "a", Attribute = "i9", Value = 9 }, - new UnpivotStruct1 { Key1 = "b", Attribute = "i1", Value = 11 }, - new UnpivotStruct1 { Key1 = "b", Attribute = "i14", Value = 100 }, - new UnpivotStruct1 { Key1 = "b", Attribute = "i2", Value = 9 }, - new UnpivotStruct1 { Key1 = "c", Attribute = "i15", Value = 0 }, - new UnpivotStruct1 { Key1 = "c", Attribute = "o", Value = 9 }, + new() { Key1 = "a", Attribute = "i5", Value = 5 }, + new() { Key1 = "a", Attribute = "i9", Value = 9 }, + new() { Key1 = "b", Attribute = "i1", Value = 11 }, + new() { Key1 = "b", Attribute = "i14", Value = 100 }, + new() { Key1 = "b", Attribute = "i2", Value = 9 }, + new() { Key1 = "c", Attribute = "i15", Value = 0 }, + new() { Key1 = "c", Attribute = "o", Value = 9 }, }; Assert.IsTrue(input.SequenceEqual(expected)); @@ -499,13 +499,13 @@ public void Unpivot2AllColumnarSmallBatch() var expected = new List { - new UnpivotStruct2 { Key1 = "a", Key2 = "d", Attribute = "i5", Value = 5 }, - new UnpivotStruct2 { Key1 = "a", Key2 = "d", Attribute = "i9", Value = 9 }, - new UnpivotStruct2 { Key1 = "b", Key2 = "d", Attribute = "i1", Value = 11 }, - new UnpivotStruct2 { Key1 = "b", Key2 = "d", Attribute = "i14", Value = 100 }, - new UnpivotStruct2 { Key1 = "b", Key2 = "d", Attribute = "i2", Value = 9 }, - new UnpivotStruct2 { Key1 = "c", Key2 = "e", Attribute = "i15", Value = 0 }, - new UnpivotStruct2 { Key1 = "c", Key2 = "e", Attribute = "o", Value = 9 }, + new() { Key1 = "a", Key2 = "d", Attribute = "i5", Value = 5 }, + new() { Key1 = "a", Key2 = "d", Attribute = "i9", Value = 9 }, + new() { Key1 = "b", Key2 = "d", Attribute = "i1", Value = 11 }, + new() { Key1 = "b", Key2 = "d", Attribute = "i14", Value = 100 }, + new() { Key1 = "b", Key2 = "d", Attribute = "i2", Value = 9 }, + new() { Key1 = "c", Key2 = "e", Attribute = "i15", Value = 0 }, + new() { Key1 = "c", Key2 = "e", Attribute = "o", Value = 9 }, }; Assert.IsTrue(input.SequenceEqual(expected)); @@ -528,13 +528,13 @@ public void Pivot1AllColumnarSmallBatch() { var input = new List { - new UnpivotStruct1N { Key1 = "a", Attribute = "i5", Value = 5 }, - new UnpivotStruct1N { Key1 = "a", Attribute = "i9", Value = 9 }, - new UnpivotStruct1N { Key1 = "b", Attribute = "i1", Value = 11 }, - new UnpivotStruct1N { Key1 = "b", Attribute = "i2", Value = 9 }, - new UnpivotStruct1N { Key1 = "b", Attribute = "i14", Value = 100 }, - new UnpivotStruct1N { Key1 = "c", Attribute = "i15", Value = 0 }, - new UnpivotStruct1N { Key1 = "c", Attribute = "o", Value = 9 }, + new() { Key1 = "a", Attribute = "i5", Value = 5 }, + new() { Key1 = "a", Attribute = "i9", Value = 9 }, + new() { Key1 = "b", Attribute = "i1", Value = 11 }, + new() { Key1 = "b", Attribute = "i2", Value = 9 }, + new() { Key1 = "b", Attribute = "i14", Value = 100 }, + new() { Key1 = "c", Attribute = "i15", Value = 0 }, + new() { Key1 = "c", Attribute = "o", Value = 9 }, }.ToStreamable() .Pivot( () => new WideStruct1(), @@ -556,13 +556,13 @@ public void Pivot2AllColumnarSmallBatch() { var input = new List { - new UnpivotStruct2N { Key1 = "a", Key2 = "d", Attribute = "i5", Value = 5 }, - new UnpivotStruct2N { Key1 = "a", Key2 = "d", Attribute = "i9", Value = 9 }, - new UnpivotStruct2N { Key1 = "b", Key2 = "d", Attribute = "i1", Value = 11 }, - new UnpivotStruct2N { Key1 = "b", Key2 = "d", Attribute = "i14", Value = 100 }, - new UnpivotStruct2N { Key1 = "b", Key2 = "d", Attribute = "i2", Value = 9 }, - new UnpivotStruct2N { Key1 = "c", Key2 = "e", Attribute = "i15", Value = 0 }, - new UnpivotStruct2N { Key1 = "c", Key2 = "e", Attribute = "o", Value = 9 }, + new() { Key1 = "a", Key2 = "d", Attribute = "i5", Value = 5 }, + new() { Key1 = "a", Key2 = "d", Attribute = "i9", Value = 9 }, + new() { Key1 = "b", Key2 = "d", Attribute = "i1", Value = 11 }, + new() { Key1 = "b", Key2 = "d", Attribute = "i14", Value = 100 }, + new() { Key1 = "b", Key2 = "d", Attribute = "i2", Value = 9 }, + new() { Key1 = "c", Key2 = "e", Attribute = "i15", Value = 0 }, + new() { Key1 = "c", Key2 = "e", Attribute = "o", Value = 9 }, }.ToStreamable() .Pivot( () => new WideStruct2(), diff --git a/Sources/Test/SimpleTesting/MultiStringTests.cs b/Sources/Test/SimpleTesting/MultiStringTests.cs index 4477d88ec..e6d3b6618 100644 --- a/Sources/Test/SimpleTesting/MultiStringTests.cs +++ b/Sources/Test/SimpleTesting/MultiStringTests.cs @@ -609,11 +609,11 @@ public void MultiStringRegex1() { if ((result.col[i >> 6] & (1L << (i & 0x3f))) == 0) { - Assert.IsTrue(input[i].Contains(pattern)); + Assert.Contains(pattern, input[i]); } else { - Assert.IsFalse(input[i].Contains(pattern)); + Assert.DoesNotContain(pattern, input[i]); } } inBV.ReturnClear(); diff --git a/Sources/Test/SimpleTesting/Partitioned/PartitionedIngressAndEgressTestMatrixBases.cs b/Sources/Test/SimpleTesting/Partitioned/PartitionedIngressAndEgressTestMatrixBases.cs index f84057087..8d9791b24 100644 --- a/Sources/Test/SimpleTesting/Partitioned/PartitionedIngressAndEgressTestMatrixBases.cs +++ b/Sources/Test/SimpleTesting/Partitioned/PartitionedIngressAndEgressTestMatrixBases.cs @@ -11,7 +11,7 @@ namespace SimpleTesting.PartitionedIngressAndEgress { - public class TriPartitionedOrderedTestsBase : TestWithConfigSettingsAndMemoryLeakDetection + public abstract class TriPartitionedOrderedTestsBase : TestWithConfigSettingsAndMemoryLeakDetection { internal TriPartitionedOrderedTestsBase( ConfigModifier config, @@ -86,8 +86,8 @@ private void ValidateOutput(IList input, IList>(); - ingress.GetDroppedAdjustedEventsDiagnostic().Subscribe(o => outOfOrderEvents.Add(o)); + ingress.GetDroppedAdjustedEventsDiagnostic().Subscribe(outOfOrderEvents.Add); var output = new List>(); - var egress = qc.RegisterOutput(ingress).ForEachAsync(o => output.Add(o)); + var egress = qc.RegisterOutput(ingress).ForEachAsync(output.Add); var process = qc.Restore(); process.Flush(); egress.Wait(); @@ -495,19 +495,19 @@ private void UpdateBatchMarker(int key, long time) private long highWatermark = 100; private long lowWatermark = 0; - private readonly List> input = new List>(); + private readonly List> input = new(); private readonly List>[] expected = new List>[] { - new List>(), - new List>(), - new List>(), + new(), + new(), + new(), }; private readonly List>[] diagnostic = new List>[] { - new List>(), - new List>(), - new List>(), + new(), + new(), + new(), }; - private readonly List> expectedLowWatermarks = new List>(); + private readonly List> expectedLowWatermarks = new(); } } diff --git a/Sources/Test/SimpleTesting/Partitioned/PartitionedStreamTests.cs b/Sources/Test/SimpleTesting/Partitioned/PartitionedStreamTests.cs index af8f600b7..1baddac3d 100644 --- a/Sources/Test/SimpleTesting/Partitioned/PartitionedStreamTests.cs +++ b/Sources/Test/SimpleTesting/Partitioned/PartitionedStreamTests.cs @@ -706,7 +706,7 @@ public void SelectManyWithFlush() j.OnNext(x); p.Flush(); - Assert.IsTrue(res.Count > data.Length, "Flush should push all events out."); + Assert.IsGreaterThan(data.Length, res.Count, "Flush should push all events out."); j.OnCompleted(); } @@ -748,7 +748,7 @@ public void AlterLifeTimeWithFlush() { } - Assert.IsTrue(res.Count > 0, "There should be some results."); + Assert.IsNotEmpty(res, "There should be some results."); } [TestMethod, TestCategory("Gated")] @@ -801,7 +801,7 @@ public void AlterLifeTimeWithFlushDoubles() { } - Assert.IsTrue(res.Count > 0, "There should be some results."); + Assert.IsNotEmpty(res, "There should be some results."); } [TestMethod, TestCategory("Gated")] @@ -813,7 +813,7 @@ public void PartitionedStitch() var input = qc.RegisterInput(subject); var output = new List>(); - var egress = qc.RegisterOutput(input.Stitch()).ForEachAsync(o => output.Add(o)); + var egress = qc.RegisterOutput(input.Stitch()).ForEachAsync(output.Add); var process = qc.Restore(); var payload = new[] { "c1payload", "c2payload" }; diff --git a/Sources/Test/SimpleTesting/Program.cs b/Sources/Test/SimpleTesting/Program.cs index 9ee2e4665..7c4e8a7bf 100644 --- a/Sources/Test/SimpleTesting/Program.cs +++ b/Sources/Test/SimpleTesting/Program.cs @@ -10,6 +10,7 @@ using System.Linq.Expressions; using System.Reactive.Concurrency; using System.Reactive.Linq; +using System.Reflection; using System.Runtime.Serialization; using Microsoft.StreamProcessing; using Microsoft.VisualStudio.TestTools.UnitTesting; @@ -55,15 +56,34 @@ public static Expression ComparerExprForAnonymousType(Type t) var negativeOne = Expression.Constant(-1, typeof(int)); var positiveOne = Expression.Constant(1, typeof(int)); var zero = Expression.Constant(0, typeof(int)); - Expression body = Expression.Condition(Expression.LessThan(Expression.Property(left, p), Expression.Property(right, p)), negativeOne, - Expression.Condition(Expression.Equal(Expression.Property(left, p), Expression.Property(right, p)), zero, positiveOne)); - for (int i = n - 2; i >= 0; i--) + var body = properties + .Reverse() + .Select(p => Compare(Expression.Property(left, p), Expression.Property(right, p))) + .Aggregate((Expression)Expression.Constant(0), (inner, outer) => Expression.Condition( + Expression.NotEqual( + outer, + Expression.Constant(0) + ), + outer, + inner + )); + return Expression.Lambda(body, left, right); + + static Expression Compare(Expression left, Expression right) { - p = properties[i]; - body = Expression.Condition(Expression.LessThan(Expression.Property(left, p), Expression.Property(right, p)), negativeOne, - Expression.Condition(Expression.Equal(Expression.Property(left, p), Expression.Property(right, p)), body, positiveOne)); + Type comparer = typeof(Comparer<>).MakeGenericType(left.Type); + PropertyInfo property = comparer.GetProperty(nameof(Comparer<>.Default), BindingFlags.Public | BindingFlags.Static); + MethodInfo compare = property.PropertyType.GetMethod(nameof(Comparer<>.Compare), BindingFlags.Public|BindingFlags.Instance, [left.Type, right.Type]); + return Expression.Call( + Expression.Property( + null, + property + ), + compare, + left, + right + ); } - return Expression.Lambda(body, left, right); } public static bool TestEquality(IEnumerable enumerable, Expression> selectFunction) @@ -101,16 +121,16 @@ private static void Alpha() var s = x3.ExpressionToCSharp(); } - public static void Main(string[] args) + public static void Main() { Alpha(); var meths = typeof(int).GetMethods(); var x = new { A = 3, B = 'a' }; var y = EqualsExprForAnonymousType(x.GetType()); var z = TestEquality(Enumerable.Range(0, 5), i => new { X = i, Y = (char)('a' + i), }); - z = TestEquality(new int[] { 3, 3, 3 }, i => new { Z = i, A = (char)('a' + i), W = "abc", }); - var ii = TestHash(new int[] { 3, 3, 3 }, i => new { Z = i, A = (char)('a' + i), W = "abc", }); - ii = TestComparer(new int[] { 3, 3, 3 }, i => new { Z = i, A = (char)('a' + i), W = "abc" }); + z = TestEquality([3, 3, 3], i => new { Z = i, A = (char)('a' + i), W = "abc", }); + var ii = TestHash([3, 3, 3], i => new { Z = i, A = (char)('a' + i), W = "abc", }); + ii = TestComparer([3, 3, 3], i => new { Z = i, A = (char)('a' + i), W = "abc" }); NativeMethods.AffinitizeThread(0); Config.ForceRowBasedExecution = true; diff --git a/Sources/Test/SimpleTesting/Serializer/NestedTypeSerializationTest.cs b/Sources/Test/SimpleTesting/Serializer/NestedTypeSerializationTest.cs index fbfffbc09..fc22c8a23 100644 --- a/Sources/Test/SimpleTesting/Serializer/NestedTypeSerializationTest.cs +++ b/Sources/Test/SimpleTesting/Serializer/NestedTypeSerializationTest.cs @@ -106,6 +106,6 @@ private static void TestSerialization(T value, CheckEquals equals) } } - private TestClass GetTestData() => new TestClass { TestMember = new TestInterfaceImpl { Number = 1 } }; + private TestClass GetTestData() => new() { TestMember = new TestInterfaceImpl { Number = 1 } }; } } diff --git a/Sources/Test/SimpleTesting/Serializer/SerializabilityTypeScan.cs b/Sources/Test/SimpleTesting/Serializer/SerializabilityTypeScan.cs index 1af3eaaed..6af4da181 100644 --- a/Sources/Test/SimpleTesting/Serializer/SerializabilityTypeScan.cs +++ b/Sources/Test/SimpleTesting/Serializer/SerializabilityTypeScan.cs @@ -73,12 +73,12 @@ orderby t.Name } #region RULES FOR IGNORING CERTAIN TYPES AS IRRELEVANT - private static readonly HashSet Assemblies = new HashSet + private static readonly HashSet Assemblies = new() { "Microsoft.StreamProcessing", }; - private static readonly List TypePartsToSkip = new List + private static readonly List TypePartsToSkip = new() { "Transformer", // transformers can be skipped "Attribute", // attributes can be skipped @@ -118,13 +118,13 @@ orderby t.Name "Microsoft.StreamProcessing.IO.TextFileDataReader", }; - private static readonly List TypeHierarchiesToSkip = new List + private static readonly List TypeHierarchiesToSkip = new() { typeof(Checkpointable), // Skip pipes typeof(Streamable<,>), // Skip streamables }; - private static readonly HashSet TypesToSkip = new HashSet + private static readonly HashSet TypesToSkip = new() { typeof(QueryContainer), typeof(Process), @@ -174,7 +174,7 @@ private static string DescribeGeneric(string name, IEnumerable args) { if (name.Contains('`')) name = name.Substring(0, name.LastIndexOf('`')); - return name + "<" + string.Join(", ", args.Select(a => DescribeType(a))) + ">"; + return name + "<" + string.Join(", ", args.Select(DescribeType)) + ">"; } private static string DescribeType(Type type) diff --git a/Sources/Test/SimpleTesting/Serializer/SurrogateTests.cs b/Sources/Test/SimpleTesting/Serializer/SurrogateTests.cs index 975e98e97..463c5ab74 100644 --- a/Sources/Test/SimpleTesting/Serializer/SurrogateTests.cs +++ b/Sources/Test/SimpleTesting/Serializer/SurrogateTests.cs @@ -87,7 +87,7 @@ public void SurrogateTest() var input = new Subject>(); var ingress = qc.RegisterInput(input); - var egress = qc.RegisterOutput(ingress).ForEachAsync(o => output1.Add(o)); + var egress = qc.RegisterOutput(ingress).ForEachAsync(output1.Add); var process = qc.Restore(); input.OnNext(StreamEvent.CreatePoint(1, (IMyInterface)new MyType(1))); @@ -103,12 +103,12 @@ public void SurrogateTest() var qc2 = new QueryContainer(new MySurrogate()); var ingress2 = qc2.RegisterInput(input2); - var egress2 = qc2.RegisterOutput(ingress2).ForEachAsync(o => output2.Add(o)); + var egress2 = qc2.RegisterOutput(ingress2).ForEachAsync(output2.Add); var process2 = qc2.Restore(stream); input2.OnCompleted(); - Assert.AreEqual(2, output2.Count); + Assert.HasCount(2, output2); Assert.AreEqual(1, output2[0].Payload.GetValue()); Assert.AreEqual(StreamEvent.InfinitySyncTime, output2[1].SyncTime); } diff --git a/Sources/Test/SimpleTesting/SimpleTesting.csproj b/Sources/Test/SimpleTesting/SimpleTesting.csproj index f1b901102..a41af72f3 100644 --- a/Sources/Test/SimpleTesting/SimpleTesting.csproj +++ b/Sources/Test/SimpleTesting/SimpleTesting.csproj @@ -1,17 +1,16 @@  - net472;netcoreapp3.1 + net10.0 AnyCPU - - - - - - + + + + +