@@ -123,7 +123,7 @@ protected virtual async Task CorrelateEventAsync(CloudEvent e, CancellationToken
123
123
{
124
124
Id = Guid . NewGuid ( ) . ToString ( "N" ) [ ..12 ] ,
125
125
Events = [ new ( filter . Key , e ) ] ,
126
- Keys = CorrelationKeys == null ? new ( ) : new ( CorrelationKeys )
126
+ Keys = CorrelationKeys == null ? this . Correlation . Resource . Spec . Keys ?? [ ] : new ( CorrelationKeys )
127
127
} ;
128
128
this . Logger . LogInformation ( "Correlation context with id '{contextId}' successfully created" , context . Id ) ;
129
129
this . Logger . LogInformation ( "Event successfully correlated to context with id '{contextId}'" , context . Id ) ;
@@ -152,7 +152,7 @@ protected virtual async Task CorrelateEventAsync(CloudEvent e, CancellationToken
152
152
{
153
153
Id = Guid . NewGuid ( ) . ToString ( "N" ) [ ..12 ] ,
154
154
Events = [ new ( filter . Key , e ) ] ,
155
- Keys = CorrelationKeys == null ? new ( ) : new ( CorrelationKeys )
155
+ Keys = CorrelationKeys == null ? this . Correlation . Resource . Spec . Keys ?? [ ] : new ( CorrelationKeys )
156
156
} ;
157
157
await this . CreateOrUpdateContextAsync ( context , cancellationToken ) . ConfigureAwait ( false ) ;
158
158
this . Logger . LogInformation ( "Correlation context with id '{contextId}' successfully created" , context . Id ) ;
@@ -289,7 +289,7 @@ protected virtual async Task<bool> TryFilterEventAsync(EventFilterDefinition fil
289
289
protected virtual async Task < ( bool Succeeded , IDictionary < string , string > ? CorrelationKeys ) > TryExtractCorrelationKeysAsync ( CloudEvent e , IDictionary < string , CorrelationKeyDefinition > ? keyDefinitions , CancellationToken cancellationToken )
290
290
{
291
291
ArgumentNullException . ThrowIfNull ( e ) ;
292
- var correlationKeys = new Dictionary < string , string > ( ) ;
292
+ var correlationKeys = this . Correlation . Resource . Spec . Keys ?? [ ] ;
293
293
if ( keyDefinitions == null || keyDefinitions . Count < 1 ) return ( true , correlationKeys ) ;
294
294
foreach ( var keyDefinition in keyDefinitions )
295
295
{
@@ -305,6 +305,7 @@ protected virtual async Task<bool> TryFilterEventAsync(EventFilterDefinition fil
305
305
}
306
306
else if ( ! keyDefinition . Value . Expect . Equals ( correlationTerm , StringComparison . OrdinalIgnoreCase ) ) return ( false , null ) ;
307
307
}
308
+ if ( correlationKeys . ContainsKey ( keyDefinition . Key ) && correlationTerm != correlationKeys [ keyDefinition . Key ] ) return ( false , null ) ;
308
309
correlationKeys [ keyDefinition . Key ] = correlationTerm ;
309
310
}
310
311
return ( true , correlationKeys ) ;
@@ -361,7 +362,7 @@ protected virtual async Task CreateOrUpdateContextAsync(CorrelationContext conte
361
362
await this . Resources . PatchStatusAsync < WorkflowInstance > ( new ( PatchType . JsonPatch , patch ) , workflowInstance . GetName ( ) , workflowInstance . GetNamespace ( ) , null , false , cancellationToken ) . ConfigureAwait ( false ) ;
362
363
break ;
363
364
case CorrelationOutcomeType . Start :
364
- var input = this . Correlation . Resource . Spec . Outcome . Start ! . Input == null ? [ ] : await this . ExpressionEvaluator . EvaluateAsync < EquatableDictionary < string , object > > ( this . Correlation . Resource . Spec . Outcome . Start ! . Input ! , context , cancellationToken : cancellationToken ) . ConfigureAwait ( false ) ;
365
+ var input = ( this . Correlation . Resource . Spec . Outcome . Start ! . Input == null ? new ( ) { { "events" , context . Events . Values } } : await this . ExpressionEvaluator . EvaluateAsync < EquatableDictionary < string , object > > ( this . Correlation . Resource . Spec . Outcome . Start ! . Input ! , context , cancellationToken : cancellationToken ) . ConfigureAwait ( false ) ) ;
365
366
workflowInstance = new ( )
366
367
{
367
368
Metadata = new ( )
@@ -373,6 +374,13 @@ protected virtual async Task CreateOrUpdateContextAsync(CorrelationContext conte
373
374
{
374
375
Definition = this . Correlation . Resource . Spec . Outcome . Start ! . Workflow ,
375
376
Input = input
377
+ } ,
378
+ Status = new ( )
379
+ {
380
+ Correlation = new ( )
381
+ {
382
+ Keys = context . Keys
383
+ }
376
384
}
377
385
} ;
378
386
await this . Resources . AddAsync ( workflowInstance , false , cancellationToken ) . ConfigureAwait ( false ) ;
0 commit comments