|
| 1 | +// Copyright (c) Microsoft Corporation. |
| 2 | +// Licensed under the MIT License. |
| 3 | + |
| 4 | +namespace Microsoft.DurableTask; |
| 5 | + |
| 6 | +/// <summary> |
| 7 | +/// Represents the base request to run a <see cref="ITaskOrchestrator" />. |
| 8 | +/// </summary> |
| 9 | +public interface IBaseOrchestrationRequest |
| 10 | +{ |
| 11 | + /// <summary> |
| 12 | + /// Gets the <see cref="TaskName" /> representing the <see cref="ITaskOrchestrator" /> to run. |
| 13 | + /// </summary> |
| 14 | + /// <returns>A <see cref="TaskName" />.</returns> |
| 15 | + /// <remarks> |
| 16 | + /// This is a function instead of a property so it is excluded in serialization without needing to use a |
| 17 | + /// serialization library specific attribute to exclude it. |
| 18 | + /// </remarks> |
| 19 | + TaskName GetTaskName(); |
| 20 | +} |
| 21 | + |
| 22 | +/// <summary> |
| 23 | +/// Represents a request to run a <see cref="ITaskOrchestrator" /> which returns <typeparamref name="TResult" />. |
| 24 | +/// </summary> |
| 25 | +/// <typeparam name="TResult">The result of the orchestrator that is to be ran.</typeparam> |
| 26 | +public interface IOrchestrationRequest<out TResult> : IBaseOrchestrationRequest |
| 27 | +{ |
| 28 | +} |
| 29 | + |
| 30 | +/// <summary> |
| 31 | +/// Represents a request to run a <see cref="ITaskOrchestrator" /> which has no return. |
| 32 | +/// </summary> |
| 33 | +public interface IOrchestrationRequest : IOrchestrationRequest<Unit> |
| 34 | +{ |
| 35 | +} |
| 36 | + |
| 37 | +/// <summary> |
| 38 | +/// Helpers for creating orchestration requests. |
| 39 | +/// </summary> |
| 40 | +public static class OrchestrationRequest |
| 41 | +{ |
| 42 | + /// <summary> |
| 43 | + /// Gets an <see cref="IOrchestrationRequest{TResult}" /> which has an explicitly provided input. |
| 44 | + /// </summary> |
| 45 | + /// <remarks> |
| 46 | + /// This is useful when you want to use an existing type for input (like <see cref="string" />) and not derive an |
| 47 | + /// entirely new type. |
| 48 | + /// </remarks> |
| 49 | + /// <typeparam name="TResult">The result type of the orchestration.</typeparam> |
| 50 | + /// <param name="name">The name of the orchestration to run.</param> |
| 51 | + /// <param name="input">The input for the orchestration.</param> |
| 52 | + /// <returns>A request that can be used to enqueue an orchestration.</returns> |
| 53 | + public static IOrchestrationRequest<TResult> Create<TResult>(TaskName name, object? input = null) |
| 54 | + => new Request<TResult>(name, input); |
| 55 | + |
| 56 | + /// <summary> |
| 57 | + /// Represents an orchestration request where the input is not the request itself. |
| 58 | + /// </summary> |
| 59 | + /// <typeparam name="TResult">The result type.</typeparam> |
| 60 | + class Request<TResult> : IOrchestrationRequest<TResult>, IProvidesInput |
| 61 | + { |
| 62 | + readonly TaskName name; |
| 63 | + readonly object? input; |
| 64 | + |
| 65 | + /// <summary> |
| 66 | + /// Initializes a new instance of the <see cref="Request{TResult}"/> class. |
| 67 | + /// </summary> |
| 68 | + /// <param name="name">The task name.</param> |
| 69 | + /// <param name="input">The input.</param> |
| 70 | + public Request(TaskName name, object? input) |
| 71 | + { |
| 72 | + this.name = name; |
| 73 | + this.input = input; |
| 74 | + } |
| 75 | + |
| 76 | + /// <inheritdoc/> |
| 77 | + public object? GetInput() => this.input; |
| 78 | + |
| 79 | + /// <inheritdoc/> |
| 80 | + public TaskName GetTaskName() => this.name; |
| 81 | + } |
| 82 | +} |
0 commit comments