@@ -22,24 +22,17 @@ namespace Dapr.Workflow
22
22
/// Context object used by workflow implementations to perform actions such as scheduling activities, durable timers, waiting for
23
23
/// external events, and for getting basic information about the current workflow instance.
24
24
/// </summary>
25
- public class WorkflowContext
25
+ public abstract class WorkflowContext
26
26
{
27
- readonly TaskOrchestrationContext innerContext ;
28
-
29
- internal WorkflowContext ( TaskOrchestrationContext innerContext )
30
- {
31
- this . innerContext = innerContext ?? throw new ArgumentNullException ( nameof ( innerContext ) ) ;
32
- }
33
-
34
27
/// <summary>
35
28
/// Gets the name of the current workflow.
36
29
/// </summary>
37
- public string Name => this . innerContext . Name ;
30
+ public abstract string Name { get ; }
38
31
39
32
/// <summary>
40
33
/// Gets the instance ID of the current workflow.
41
34
/// </summary>
42
- public string InstanceId => this . innerContext . InstanceId ;
35
+ public abstract string InstanceId { get ; }
43
36
44
37
/// <summary>
45
38
/// Gets the current workflow time in UTC.
@@ -51,7 +44,7 @@ internal WorkflowContext(TaskOrchestrationContext innerContext)
51
44
/// the current time, such as <see cref="DateTime.UtcNow"/> and <see cref="DateTimeOffset.UtcNow"/>
52
45
/// (which should not be used).
53
46
/// </remarks>
54
- public DateTime CurrentUtcDateTime => this . innerContext . CurrentUtcDateTime ;
47
+ public abstract DateTime CurrentUtcDateTime { get ; }
55
48
56
49
/// <summary>
57
50
/// Gets a value indicating whether the workflow is currently replaying a previous execution.
@@ -72,7 +65,7 @@ internal WorkflowContext(TaskOrchestrationContext innerContext)
72
65
/// <value>
73
66
/// <c>true</c> if the workflow is currently replaying a previous execution; otherwise <c>false</c>.
74
67
/// </value>
75
- public bool IsReplaying => this . innerContext . IsReplaying ;
68
+ public abstract bool IsReplaying { get ; }
76
69
77
70
/// <summary>
78
71
/// Asynchronously invokes an activity by name and with the specified input value.
@@ -108,19 +101,16 @@ internal WorkflowContext(TaskOrchestrationContext innerContext)
108
101
/// The activity failed with an unhandled exception. The details of the failure can be found in the
109
102
/// <see cref="TaskFailedException.FailureDetails"/> property.
110
103
/// </exception>
111
- public Task CallActivityAsync ( string name , object ? input = null , TaskOptions ? options = null )
104
+ public virtual Task CallActivityAsync ( string name , object ? input = null , TaskOptions ? options = null )
112
105
{
113
- return this . innerContext . CallActivityAsync ( name , input , options ) ;
106
+ return this . CallActivityAsync < object > ( name , input , options ) ;
114
107
}
115
108
116
109
/// <returns>
117
110
/// A task that completes when the activity completes or fails. The result of the task is the activity's return value.
118
111
/// </returns>
119
112
/// <inheritdoc cref="CallActivityAsync"/>
120
- public Task < T > CallActivityAsync < T > ( string name , object ? input = null , TaskOptions ? options = null )
121
- {
122
- return this . innerContext . CallActivityAsync < T > ( name , input , options ) ;
123
- }
113
+ public abstract Task < T > CallActivityAsync < T > ( string name , object ? input = null , TaskOptions ? options = null ) ;
124
114
125
115
/// <summary>
126
116
/// Creates a durable timer that expires after the specified delay.
@@ -131,9 +121,9 @@ public Task<T> CallActivityAsync<T>(string name, object? input = null, TaskOptio
131
121
/// <exception cref="InvalidOperationException">
132
122
/// Thrown if the calling thread is not the workflow dispatch thread.
133
123
/// </exception>
134
- public Task CreateTimer ( TimeSpan delay , CancellationToken cancellationToken = default )
124
+ public virtual Task CreateTimer ( TimeSpan delay , CancellationToken cancellationToken = default )
135
125
{
136
- return this . innerContext . CreateTimer ( delay , cancellationToken ) ;
126
+ return this . CreateTimer ( this . CurrentUtcDateTime . Add ( delay ) , cancellationToken ) ;
137
127
}
138
128
139
129
/// <summary>
@@ -142,10 +132,7 @@ public Task CreateTimer(TimeSpan delay, CancellationToken cancellationToken = de
142
132
/// <param name="fireAt">The time at which the timer should expire.</param>
143
133
/// <param name="cancellationToken">Used to cancel the durable timer.</param>
144
134
/// <inheritdoc cref="CreateTimer(TimeSpan, CancellationToken)"/>
145
- public Task CreateTimer ( DateTime fireAt , CancellationToken cancellationToken )
146
- {
147
- return this . innerContext . CreateTimer ( fireAt , cancellationToken ) ;
148
- }
135
+ public abstract Task CreateTimer ( DateTime fireAt , CancellationToken cancellationToken ) ;
149
136
150
137
/// <summary>
151
138
/// Waits for an event to be raised with name <paramref name="eventName"/> and returns the event data.
@@ -176,10 +163,7 @@ public Task CreateTimer(DateTime fireAt, CancellationToken cancellationToken)
176
163
/// <exception cref="InvalidOperationException">
177
164
/// Thrown if the calling thread is not the workflow dispatch thread.
178
165
/// </exception>
179
- public Task < T > WaitForExternalEventAsync < T > ( string eventName , CancellationToken cancellationToken = default )
180
- {
181
- return this . innerContext . WaitForExternalEvent < T > ( eventName , cancellationToken ) ;
182
- }
166
+ public abstract Task < T > WaitForExternalEventAsync < T > ( string eventName , CancellationToken cancellationToken = default ) ;
183
167
184
168
/// <summary>
185
169
/// Waits for an event to be raised with name <paramref name="eventName"/> and returns the event data.
@@ -190,10 +174,7 @@ public Task<T> WaitForExternalEventAsync<T>(string eventName, CancellationToken
190
174
/// </param>
191
175
/// <param name="timeout">The amount of time to wait before cancelling the external event task.</param>
192
176
/// <inheritdoc cref="WaitForExternalEventAsync{T}(string, CancellationToken)"/>
193
- public Task < T > WaitForExternalEventAsync < T > ( string eventName , TimeSpan timeout )
194
- {
195
- return this . innerContext . WaitForExternalEvent < T > ( eventName , timeout ) ;
196
- }
177
+ public abstract Task < T > WaitForExternalEventAsync < T > ( string eventName , TimeSpan timeout ) ;
197
178
198
179
/// <summary>
199
180
/// Raises an external event for the specified workflow instance.
@@ -208,10 +189,7 @@ public Task<T> WaitForExternalEventAsync<T>(string eventName, TimeSpan timeout)
208
189
/// <param name="instanceId">The ID of the workflow instance to send the event to.</param>
209
190
/// <param name="eventName">The name of the event to wait for. Event names are case-insensitive.</param>
210
191
/// <param name="payload">The serializable payload of the external event.</param>
211
- public void SendEvent ( string instanceId , string eventName , object payload )
212
- {
213
- this . SendEvent ( instanceId , eventName , payload ) ;
214
- }
192
+ public abstract void SendEvent ( string instanceId , string eventName , object payload ) ;
215
193
216
194
/// <summary>
217
195
/// Assigns a custom status value to the current workflow.
@@ -226,10 +204,7 @@ public void SendEvent(string instanceId, string eventName, object payload)
226
204
/// <exception cref="InvalidOperationException">
227
205
/// Thrown if the calling thread is not the workflow dispatch thread.
228
206
/// </exception>
229
- public void SetCustomStatus ( object ? customStatus )
230
- {
231
- this . innerContext . SetCustomStatus ( customStatus ) ;
232
- }
207
+ public abstract void SetCustomStatus ( object ? customStatus ) ;
233
208
234
209
/// <summary>
235
210
/// Executes the specified workflow as a child workflow and returns the result.
@@ -238,10 +213,7 @@ public void SetCustomStatus(object? customStatus)
238
213
/// The type into which to deserialize the child workflow's output.
239
214
/// </typeparam>
240
215
/// <inheritdoc cref="CallChildWorkflowAsync(string, object?, TaskOptions?)"/>
241
- public Task < TResult > CallChildWorkflowAsync < TResult > ( string workflowName , object ? input = null , TaskOptions ? options = null )
242
- {
243
- return this . innerContext . CallSubOrchestratorAsync < TResult > ( workflowName , input , options ) ;
244
- }
216
+ public abstract Task < TResult > CallChildWorkflowAsync < TResult > ( string workflowName , object ? input = null , TaskOptions ? options = null ) ;
245
217
246
218
/// <summary>
247
219
/// Executes the specified workflow as a child workflow.
@@ -284,9 +256,9 @@ public Task<TResult> CallChildWorkflowAsync<TResult>(string workflowName, object
284
256
/// The child workflow failed with an unhandled exception. The details of the failure can be found in the
285
257
/// <see cref="TaskFailedException.FailureDetails"/> property.
286
258
/// </exception>
287
- public Task CallChildWorkflowAsync ( string workflowName , object ? input = null , TaskOptions ? options = null )
259
+ public virtual Task CallChildWorkflowAsync ( string workflowName , object ? input = null , TaskOptions ? options = null )
288
260
{
289
- return this . innerContext . CallSubOrchestratorAsync ( workflowName , input , options ) ;
261
+ return this . CallChildWorkflowAsync < object > ( workflowName , input , options ) ;
290
262
}
291
263
292
264
/// <summary>
@@ -320,10 +292,7 @@ public Task CallChildWorkflowAsync(string workflowName, object? input = null, Ta
320
292
/// history when the workflow instance restarts. If <c>false</c>, any unprocessed
321
293
/// external events will be discarded when the workflow instance restarts.
322
294
/// </param>
323
- public void ContinueAsNew ( object ? newInput = null , bool preserveUnprocessedEvents = true )
324
- {
325
- this . innerContext . ContinueAsNew ( newInput ! , preserveUnprocessedEvents ) ;
326
- }
295
+ public abstract void ContinueAsNew ( object ? newInput = null , bool preserveUnprocessedEvents = true ) ;
327
296
328
297
/// <summary>
329
298
/// Creates a new GUID that is safe for replay within a workflow.
@@ -334,9 +303,6 @@ public void ContinueAsNew(object? newInput = null, bool preserveUnprocessedEvent
334
303
/// and an internally managed sequence number.
335
304
/// </remarks>
336
305
/// <returns>The new <see cref="Guid"/> value.</returns>
337
- public Guid NewGuid ( )
338
- {
339
- return this . innerContext . NewGuid ( ) ;
340
- }
306
+ public abstract Guid NewGuid ( ) ;
341
307
}
342
308
}
0 commit comments