Skip to content

Commit 499df12

Browse files
author
George Ndungu
committed
Emit Signal method and delegate to provide a hook into events
1 parent 8603b46 commit 499df12

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

powershell/cmdlets/class.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1023,6 +1023,11 @@ export class CmdletClass extends Class {
10231023
yield `await ${$this.state.project.serviceNamespace.moduleClass.declaration}.Instance.Signal(${id.value}, ${token.value}, ${messageData.value}, (i,t,m) => ((${ClientRuntime.IEventListener})this).Signal(i,t,()=> ${ClientRuntime.EventDataConverter}.ConvertFrom( m() ) as ${ClientRuntime.EventData} ), ${$this.invocationInfo.value}, this.ParameterSetName, ${$this.correlationId.value}, ${$this.processRecordId.value}, null );`;
10241024
yield If(`${token.value}.IsCancellationRequested`, Return());
10251025
}
1026+
else {
1027+
// In Non-Azure Modes, emit the Signal method without coorelation and processrecordid
1028+
yield `await ${$this.state.project.serviceNamespace.moduleClass.declaration}.Instance.Signal(${id.value}, ${token.value}, ${messageData.value}, (i,t,m) => ((${ClientRuntime.IEventListener})this).Signal(i,t,()=> ${ClientRuntime.EventDataConverter}.ConvertFrom( m() ) as ${ClientRuntime.EventData} ), ${$this.invocationInfo.value}, this.ParameterSetName, null );`;
1029+
yield If(`${token.value}.IsCancellationRequested`, Return());
1030+
}
10261031
yield `WriteDebug($"{id}: {(messageData().Message ?? ${System.String.Empty})}");`;
10271032
// any handling of the signal on our side...
10281033
});

powershell/module/module-class.ts

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ export class ModuleClass extends Class {
105105

106106
yield $this.fPipeline.assignPrivate(ClientRuntime.HttpPipeline.new(ClientRuntime.HttpClientFactory.new(System.Net.Http.HttpClient.new())));
107107
yield $this.fPipelineWithProxy.assignPrivate(ClientRuntime.HttpPipeline.new(ClientRuntime.HttpClientFactory.new(System.Net.Http.HttpClient.new($this.fHandler))));
108+
yield "Init();";
108109
}
109110
}));
110111

@@ -113,6 +114,7 @@ export class ModuleClass extends Class {
113114
this.add(new PartialMethod('AfterCreatePipeline', dotnet.Void, { parameters: [this.pInvocationInfo, this.pPipeline] }));
114115
this.add(new PartialMethod('CustomInit', dotnet.Void));
115116

117+
116118
/* Setting the Proxy */
117119
this.add(new Method('SetProxyConfiguration', dotnet.Void, {
118120
parameters: [this.pProxy, this.pProxyCredential, this.pUseDefaultCredentials],
@@ -128,8 +130,23 @@ export class ModuleClass extends Class {
128130
}
129131

130132
createInitAndPipeline(namespace: Namespace) {
133+
131134
const $this = this;
132-
// non-azure init method
135+
// Custom Event Listener without Azure Spefic concepts. (ProcessId and CorelationId)
136+
const customEventListenerFunc = System.Func(
137+
dotnet.String,
138+
System.Threading.CancellationToken,
139+
System.Func(System.EventArgs),
140+
this.incomingSignalFunc,
141+
InvocationInfo,
142+
dotnet.String,
143+
System.Exception,
144+
/* returns */ System.Threading.Tasks.Task());
145+
146+
const incomingSignalDelegate = namespace.add(new Alias('SignalDelegate', this.incomingSignalFunc));
147+
const eventListenerDelegate = namespace.add(new Alias('EventListenerDelegate', customEventListenerFunc));
148+
const EventListener = this.add(new Property('EventListener', eventListenerDelegate, { description: 'A delegate that gets called for each signalled event' }));
149+
133150
this.initMethod.add(function* () {
134151
yield '// called at module init time...';
135152
yield 'CustomInit();';
@@ -152,6 +169,20 @@ export class ModuleClass extends Class {
152169
});
153170

154171
this.add(new LambdaProperty('Name', dotnet.String, new StringExpression(this.state.project.moduleName), { description: 'The Name of this module ' }));
172+
173+
// Add Signal extensibility point
174+
const pSignal = new Parameter('signal', incomingSignalDelegate, { description: 'The callback for the event dispatcher ' });
175+
// Emit signal extensibility points that called EventListenerDelegate, allowing us to handle Signals emitted by the Pipeline in the Auth Module
176+
const signalImpl = this.add(new Method('Signal', System.Threading.Tasks.Task(), {
177+
parameters: [this.pId, this.pToken, this.pGetEventData, pSignal, this.pInvocationInfo, this.pParameterSetName, this.pException], async: Modifier.Async,
178+
description: 'Called to dispatch events to the common module listener',
179+
returnsDescription: `A <see cref="${System.Threading.Tasks.Task()}" /> that will be complete when handling of the event is completed.`
180+
}));
181+
182+
signalImpl.push(Using('NoSynchronizationContext', ''));
183+
signalImpl.add(function* () {
184+
yield `await ${EventListener.value}?.Invoke(${$this.pId.value},${$this.pToken.value},${$this.pGetEventData.value}, ${pSignal.value}, ${$this.pInvocationInfo}, ${$this.pParameterSetName},${$this.pException});`;
185+
});
155186
}
156187

157188
createAzureInitAndPipeline(namespace: Namespace) {

0 commit comments

Comments
 (0)