diff --git a/Directory.Packages.props b/Directory.Packages.props index 332939a5..34cdb26a 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -1,47 +1,48 @@ - - true - true - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + true + true + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/all.sln b/all.sln index 1dd0ab3c..fb2996ea 100644 --- a/all.sln +++ b/all.sln @@ -119,6 +119,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Dapr.Common", "src\Dapr.Com EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Dapr.Common.Test", "test\Dapr.Common.Test\Dapr.Common.Test.csproj", "{CDB47863-BEBD-4841-A807-46D868962521}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WorkflowFanOutFanIn", "examples\Workflow\WorkflowFanOutFanIn\WorkflowFanOutFanIn.csproj", "{D83B27F3-4401-42F5-843E-147566B4999A}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -303,6 +305,10 @@ Global {CDB47863-BEBD-4841-A807-46D868962521}.Debug|Any CPU.Build.0 = Debug|Any CPU {CDB47863-BEBD-4841-A807-46D868962521}.Release|Any CPU.ActiveCfg = Release|Any CPU {CDB47863-BEBD-4841-A807-46D868962521}.Release|Any CPU.Build.0 = Release|Any CPU + {D83B27F3-4401-42F5-843E-147566B4999A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {D83B27F3-4401-42F5-843E-147566B4999A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D83B27F3-4401-42F5-843E-147566B4999A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {D83B27F3-4401-42F5-843E-147566B4999A}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -359,6 +365,7 @@ Global {DFBABB04-50E9-42F6-B470-310E1B545638} = {27C5D71D-0721-4221-9286-B94AB07B58CF} {B445B19C-A925-4873-8CB7-8317898B6970} = {27C5D71D-0721-4221-9286-B94AB07B58CF} {CDB47863-BEBD-4841-A807-46D868962521} = {DD020B34-460F-455F-8D17-CF4A949F100B} + {D83B27F3-4401-42F5-843E-147566B4999A} = {BF3ED6BF-ADF3-4D25-8E89-02FB8D945CA9} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {65220BF2-EAE1-4CB2-AA58-EBE80768CB40} diff --git a/examples/Workflow/WorkflowFanOutFanIn/Activities/NotifyActivity.cs b/examples/Workflow/WorkflowFanOutFanIn/Activities/NotifyActivity.cs new file mode 100644 index 00000000..df66afac --- /dev/null +++ b/examples/Workflow/WorkflowFanOutFanIn/Activities/NotifyActivity.cs @@ -0,0 +1,18 @@ +using Dapr.Workflow; + +namespace WorkflowFanOutFanIn.Activities; + +internal sealed class NotifyActivity : WorkflowActivity +{ + /// + /// Override to implement async (non-blocking) workflow activity logic. + /// + /// Provides access to additional context for the current activity execution. + /// The deserialized activity input. + /// The output of the activity as a task. + public override Task RunAsync(WorkflowActivityContext context, string input) + { + Console.WriteLine(input); + return Task.FromResult(null); + } +} diff --git a/examples/Workflow/WorkflowFanOutFanIn/Program.cs b/examples/Workflow/WorkflowFanOutFanIn/Program.cs new file mode 100644 index 00000000..80de701b --- /dev/null +++ b/examples/Workflow/WorkflowFanOutFanIn/Program.cs @@ -0,0 +1,27 @@ +using Dapr.Workflow; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; +using WorkflowFanOutFanIn.Activities; +using WorkflowFanOutFanIn.Workflows; + +var builder = Host.CreateDefaultBuilder(args).ConfigureServices(services => +{ + services.AddDaprWorkflow(options => + { + options.RegisterWorkflow(); + options.RegisterActivity(); + }); +}); + +var host = builder.Build(); +await host.StartAsync(); + +await using var scope = host.Services.CreateAsyncScope(); +var daprWorkflowClient = scope.ServiceProvider.GetRequiredService(); + +var instanceId = $"workflow-demo-{Guid.NewGuid().ToString()[..8]}"; +await daprWorkflowClient.ScheduleNewWorkflowAsync(nameof(DemoWorkflow), instanceId, "test input"); + +await daprWorkflowClient.WaitForWorkflowCompletionAsync(instanceId); +var state = await daprWorkflowClient.GetWorkflowStateAsync(instanceId); +Console.WriteLine($"Workflow state: {state.RuntimeStatus}"); diff --git a/examples/Workflow/WorkflowFanOutFanIn/WorkflowFanOutFanIn.csproj b/examples/Workflow/WorkflowFanOutFanIn/WorkflowFanOutFanIn.csproj new file mode 100644 index 00000000..af3a1b2c --- /dev/null +++ b/examples/Workflow/WorkflowFanOutFanIn/WorkflowFanOutFanIn.csproj @@ -0,0 +1,18 @@ + + + + Exe + net8.0 + enable + enable + + + + + + + + + + + diff --git a/examples/Workflow/WorkflowFanOutFanIn/Workflows/DemoWorkflow.cs b/examples/Workflow/WorkflowFanOutFanIn/Workflows/DemoWorkflow.cs new file mode 100644 index 00000000..bb83d2bd --- /dev/null +++ b/examples/Workflow/WorkflowFanOutFanIn/Workflows/DemoWorkflow.cs @@ -0,0 +1,27 @@ +using Dapr.Workflow; +using WorkflowFanOutFanIn.Activities; + +namespace WorkflowFanOutFanIn.Workflows; + +public sealed class DemoWorkflow : Workflow +{ + /// + /// Override to implement workflow logic. + /// + /// The workflow context. + /// The deserialized workflow input. + /// The output of the workflow as a task. + public override async Task RunAsync(WorkflowContext context, string input) + { + var tasks = new List(); + for (var a = 1; a <= 3; a++) + { + var task = context.CallActivityAsync(nameof(NotifyActivity), $"calling task {a}"); + tasks.Add(task); + } + + await Task.WhenAll(tasks); + + return "Workflow completed"; + } +}