@@ -123,7 +123,7 @@ protected virtual async Task CorrelateEventAsync(CloudEvent e, CancellationToken
123123 {
124124 Id = Guid . NewGuid ( ) . ToString ( "N" ) [ ..12 ] ,
125125 Events = [ new ( filter . Key , e ) ] ,
126- Keys = CorrelationKeys == null ? new ( ) : new ( CorrelationKeys )
126+ Keys = CorrelationKeys == null ? this . Correlation . Resource . Spec . Keys ?? [ ] : new ( CorrelationKeys )
127127 } ;
128128 this . Logger . LogInformation ( "Correlation context with id '{contextId}' successfully created" , context . Id ) ;
129129 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
152152 {
153153 Id = Guid . NewGuid ( ) . ToString ( "N" ) [ ..12 ] ,
154154 Events = [ new ( filter . Key , e ) ] ,
155- Keys = CorrelationKeys == null ? new ( ) : new ( CorrelationKeys )
155+ Keys = CorrelationKeys == null ? this . Correlation . Resource . Spec . Keys ?? [ ] : new ( CorrelationKeys )
156156 } ;
157157 await this . CreateOrUpdateContextAsync ( context , cancellationToken ) . ConfigureAwait ( false ) ;
158158 this . Logger . LogInformation ( "Correlation context with id '{contextId}' successfully created" , context . Id ) ;
@@ -289,7 +289,7 @@ protected virtual async Task<bool> TryFilterEventAsync(EventFilterDefinition fil
289289 protected virtual async Task < ( bool Succeeded , IDictionary < string , string > ? CorrelationKeys ) > TryExtractCorrelationKeysAsync ( CloudEvent e , IDictionary < string , CorrelationKeyDefinition > ? keyDefinitions , CancellationToken cancellationToken )
290290 {
291291 ArgumentNullException . ThrowIfNull ( e ) ;
292- var correlationKeys = new Dictionary < string , string > ( ) ;
292+ var correlationKeys = this . Correlation . Resource . Spec . Keys ?? [ ] ;
293293 if ( keyDefinitions == null || keyDefinitions . Count < 1 ) return ( true , correlationKeys ) ;
294294 foreach ( var keyDefinition in keyDefinitions )
295295 {
@@ -305,6 +305,7 @@ protected virtual async Task<bool> TryFilterEventAsync(EventFilterDefinition fil
305305 }
306306 else if ( ! keyDefinition . Value . Expect . Equals ( correlationTerm , StringComparison . OrdinalIgnoreCase ) ) return ( false , null ) ;
307307 }
308+ if ( correlationKeys . ContainsKey ( keyDefinition . Key ) && correlationTerm != correlationKeys [ keyDefinition . Key ] ) return ( false , null ) ;
308309 correlationKeys [ keyDefinition . Key ] = correlationTerm ;
309310 }
310311 return ( true , correlationKeys ) ;
@@ -361,7 +362,7 @@ protected virtual async Task CreateOrUpdateContextAsync(CorrelationContext conte
361362 await this . Resources . PatchStatusAsync < WorkflowInstance > ( new ( PatchType . JsonPatch , patch ) , workflowInstance . GetName ( ) , workflowInstance . GetNamespace ( ) , null , false , cancellationToken ) . ConfigureAwait ( false ) ;
362363 break ;
363364 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 ) ) ;
365366 workflowInstance = new ( )
366367 {
367368 Metadata = new ( )
@@ -373,6 +374,13 @@ protected virtual async Task CreateOrUpdateContextAsync(CorrelationContext conte
373374 {
374375 Definition = this . Correlation . Resource . Spec . Outcome . Start ! . Workflow ,
375376 Input = input
377+ } ,
378+ Status = new ( )
379+ {
380+ Correlation = new ( )
381+ {
382+ Keys = context . Keys
383+ }
376384 }
377385 } ;
378386 await this . Resources . AddAsync ( workflowInstance , false , cancellationToken ) . ConfigureAwait ( false ) ;
0 commit comments