3
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
4
*--------------------------------------------------------------------------------------------*/
5
5
6
- import { Access , Alias , Class , ClassType , Constructor , dotnet , Field , LambdaMethod , LambdaProperty , LazyProperty , LiteralExpression , LocalVariable , MemberVariable , Method , Modifier , Namespace , Parameter , ParameterModifier , PartialMethod , Property , Return , Statements , StringExpression , System , TypeDeclaration , Using , valueOf , Variable } from '@azure-tools/codegen-csharp' ;
6
+ import { Access , Alias , Class , ClassType , Constructor , dotnet , Field , LambdaMethod , LambdaProperty , LazyProperty , LiteralExpression , LocalVariable , MemberVariable , Method , Modifier , Namespace , Parameter , ParameterModifier , PartialMethod , Property , Return , Statements , StringExpression , System , TypeDeclaration , Using , valueOf , Variable , If } from '@azure-tools/codegen-csharp' ;
7
7
8
8
import { InvocationInfo , PSCredential , IArgumentCompleter , CompletionResult , CommandAst , CompletionResultType , } from '../internal/powershell-declarations' ;
9
9
import { State } from '../internal/state' ;
@@ -129,6 +129,21 @@ export class ModuleClass extends Class {
129
129
130
130
createInitAndPipeline ( namespace : Namespace ) {
131
131
const $this = this ;
132
+ // Custom Event Listener without Azure Spefic concepts. (ProcessId and CorelationId)
133
+ const customEventListenerFunc = System . Func (
134
+ dotnet . String ,
135
+ System . Threading . CancellationToken ,
136
+ System . Func ( System . EventArgs ) ,
137
+ this . incomingSignalFunc ,
138
+ InvocationInfo ,
139
+ dotnet . String ,
140
+ System . Exception ,
141
+ /* returns */ System . Threading . Tasks . Task ( ) ) ;
142
+
143
+ const incomingSignalDelegate = namespace . add ( new Alias ( 'SignalDelegate' , this . incomingSignalFunc ) ) ;
144
+ const eventListenerDelegate = namespace . add ( new Alias ( 'EventListenerDelegate' , customEventListenerFunc ) ) ;
145
+ const EventListener = this . add ( new Property ( 'EventListener' , eventListenerDelegate , { description : 'A delegate that gets called for each signalled event' } ) ) ;
146
+
132
147
// non-azure init method
133
148
this . initMethod . add ( function * ( ) {
134
149
yield '// called at module init time...' ;
@@ -152,6 +167,22 @@ export class ModuleClass extends Class {
152
167
} ) ;
153
168
154
169
this . add ( new LambdaProperty ( 'Name' , dotnet . String , new StringExpression ( this . state . project . moduleName ) , { description : 'The Name of this module ' } ) ) ;
170
+
171
+ // Add Signal extensibility point
172
+ const pSignal = new Parameter ( 'signal' , incomingSignalDelegate , { description : 'The callback for the event dispatcher ' } ) ;
173
+ // Emit signal extensibility points that called EventListenerDelegate, allowing us to handle Signals emitted by the Pipeline in the Auth Module
174
+ const signalImpl = this . add ( new Method ( 'Signal' , System . Threading . Tasks . Task ( ) , {
175
+ parameters : [ this . pId , this . pToken , this . pGetEventData , pSignal , this . pInvocationInfo , this . pParameterSetName , this . pException ] , async : Modifier . Async ,
176
+ description : 'Called to dispatch events to the common module listener' ,
177
+ returnsDescription : `A <see cref="${ System . Threading . Tasks . Task ( ) } " /> that will be complete when handling of the event is completed.`
178
+ } ) ) ;
179
+
180
+ signalImpl . push ( Using ( 'NoSynchronizationContext' , '' ) ) ;
181
+ signalImpl . add ( function * ( ) {
182
+ // Emit call to EventListener after explicit null check.
183
+ // Not using Null-Conditional operator causes Null Reference exception when Func<Task> is null, due to awaiting null Task.
184
+ yield If ( `${ EventListener . value } != null` , `await ${ EventListener . value } .Invoke(${ $this . pId . value } ,${ $this . pToken . value } ,${ $this . pGetEventData . value } , ${ pSignal . value } , ${ $this . pInvocationInfo } , ${ $this . pParameterSetName } ,${ $this . pException } );` )
185
+ } ) ;
155
186
}
156
187
157
188
createAzureInitAndPipeline ( namespace : Namespace ) {
0 commit comments