From 8f03c4cee81f2e79f0c4e126e26d3e33573b0ca1 Mon Sep 17 00:00:00 2001 From: Jacob Alber Date: Thu, 16 Apr 2026 12:28:33 -0400 Subject: [PATCH] fixup: PR comments --- .../CheckpointAndRehydrate/Program.cs | 92 ++++++++++--------- .../Checkpoint/CheckpointAndResume/Program.cs | 92 ++++++++++--------- 2 files changed, 94 insertions(+), 90 deletions(-) diff --git a/dotnet/samples/03-workflows/Checkpoint/CheckpointAndRehydrate/Program.cs b/dotnet/samples/03-workflows/Checkpoint/CheckpointAndRehydrate/Program.cs index 49752e256d..d8d88aefcb 100644 --- a/dotnet/samples/03-workflows/Checkpoint/CheckpointAndRehydrate/Program.cs +++ b/dotnet/samples/03-workflows/Checkpoint/CheckpointAndRehydrate/Program.cs @@ -37,39 +37,41 @@ public static class Program await foreach (WorkflowEvent evt in checkpointedRun.WatchStreamAsync()) { - if (evt is ExecutorCompletedEvent executorCompletedEvt) + switch (evt) { - Console.WriteLine($"* Executor {executorCompletedEvt.ExecutorId} completed."); - } + case ExecutorCompletedEvent executorCompletedEvt: + Console.WriteLine($"* Executor {executorCompletedEvt.ExecutorId} completed."); + break; - if (evt is SuperStepCompletedEvent superStepCompletedEvt) - { - // Checkpoints are automatically created at the end of each super step when a - // checkpoint manager is provided. You can store the checkpoint info for later use. - CheckpointInfo? checkpoint = superStepCompletedEvt.CompletionInfo!.Checkpoint; - if (checkpoint is not null) + case SuperStepCompletedEvent superStepCompletedEvt: { - checkpoints.Add(checkpoint); - Console.WriteLine($"** Checkpoint created at step {checkpoints.Count}."); + // Checkpoints are automatically created at the end of each super step when a + // checkpoint manager is provided. You can store the checkpoint info for later use. + CheckpointInfo? checkpoint = superStepCompletedEvt.CompletionInfo!.Checkpoint; + if (checkpoint is not null) + { + checkpoints.Add(checkpoint); + Console.WriteLine($"** Checkpoint created at step {checkpoints.Count}."); + } + + break; } - } - if (evt is WorkflowOutputEvent outputEvent) - { - Console.WriteLine($"Workflow completed with result: {outputEvent.Data}"); - } + case WorkflowOutputEvent outputEvent: + Console.WriteLine($"Workflow completed with result: {outputEvent.Data}"); + break; - if (evt is WorkflowErrorEvent workflowError) - { - Console.ForegroundColor = ConsoleColor.Red; - Console.Error.WriteLine(workflowError.Exception?.ToString() ?? "Unknown workflow error occurred."); - Console.ResetColor(); - } - else if (evt is ExecutorFailedEvent executorFailed) - { - Console.ForegroundColor = ConsoleColor.Red; - Console.Error.WriteLine($"Executor '{executorFailed.ExecutorId}' failed with {(executorFailed.Data == null ? "unknown error" : $"exception {executorFailed.Data}")}."); - Console.ResetColor(); + case WorkflowErrorEvent workflowError: + Console.ForegroundColor = ConsoleColor.Red; + Console.Error.WriteLine(workflowError.Exception?.ToString() ?? "Unknown workflow error occurred."); + Console.ResetColor(); + break; + + case ExecutorFailedEvent executorFailed: + Console.ForegroundColor = ConsoleColor.Red; + Console.Error.WriteLine($"Executor '{executorFailed.ExecutorId}' failed with {(executorFailed.Data == null ? "unknown error" : $"exception {executorFailed.Data}")}."); + Console.ResetColor(); + break; } } @@ -90,27 +92,27 @@ public static class Program await foreach (WorkflowEvent evt in newCheckpointedRun.WatchStreamAsync()) { - if (evt is ExecutorCompletedEvent executorCompletedEvt) + switch (evt) { - Console.WriteLine($"* Executor {executorCompletedEvt.ExecutorId} completed."); - } + case ExecutorCompletedEvent executorCompletedEvt: + Console.WriteLine($"* Executor {executorCompletedEvt.ExecutorId} completed."); + break; - if (evt is WorkflowOutputEvent workflowOutputEvt) - { - Console.WriteLine($"Workflow completed with result: {workflowOutputEvt.Data}"); - } + case WorkflowOutputEvent workflowOutputEvt: + Console.WriteLine($"Workflow completed with result: {workflowOutputEvt.Data}"); + break; - if (evt is WorkflowErrorEvent workflowError) - { - Console.ForegroundColor = ConsoleColor.Red; - Console.Error.WriteLine(workflowError.Exception?.ToString() ?? "Unknown workflow error occurred."); - Console.ResetColor(); - } - else if (evt is ExecutorFailedEvent executorFailed) - { - Console.ForegroundColor = ConsoleColor.Red; - Console.Error.WriteLine($"Executor '{executorFailed.ExecutorId}' failed with {(executorFailed.Data == null ? "unknown error" : $"exception {executorFailed.Data}")}."); - Console.ResetColor(); + case WorkflowErrorEvent workflowError: + Console.ForegroundColor = ConsoleColor.Red; + Console.Error.WriteLine(workflowError.Exception?.ToString() ?? "Unknown workflow error occurred."); + Console.ResetColor(); + break; + + case ExecutorFailedEvent executorFailed: + Console.ForegroundColor = ConsoleColor.Red; + Console.Error.WriteLine($"Executor '{executorFailed.ExecutorId}' failed with {(executorFailed.Data == null ? "unknown error" : $"exception {executorFailed.Data}")}."); + Console.ResetColor(); + break; } } } diff --git a/dotnet/samples/03-workflows/Checkpoint/CheckpointAndResume/Program.cs b/dotnet/samples/03-workflows/Checkpoint/CheckpointAndResume/Program.cs index 510fb9f345..caa594ae08 100644 --- a/dotnet/samples/03-workflows/Checkpoint/CheckpointAndResume/Program.cs +++ b/dotnet/samples/03-workflows/Checkpoint/CheckpointAndResume/Program.cs @@ -34,39 +34,41 @@ public static class Program await using StreamingRun checkpointedRun = await InProcessExecution.RunStreamingAsync(workflow, NumberSignal.Init, checkpointManager); await foreach (WorkflowEvent evt in checkpointedRun.WatchStreamAsync()) { - if (evt is ExecutorCompletedEvent executorCompletedEvt) + switch (evt) { - Console.WriteLine($"* Executor {executorCompletedEvt.ExecutorId} completed."); - } + case ExecutorCompletedEvent executorCompletedEvt: + Console.WriteLine($"* Executor {executorCompletedEvt.ExecutorId} completed."); + break; - if (evt is SuperStepCompletedEvent superStepCompletedEvt) - { - // Checkpoints are automatically created at the end of each super step when a - // checkpoint manager is provided. You can store the checkpoint info for later use. - CheckpointInfo? checkpoint = superStepCompletedEvt.CompletionInfo!.Checkpoint; - if (checkpoint is not null) + case SuperStepCompletedEvent superStepCompletedEvt: { - checkpoints.Add(checkpoint); - Console.WriteLine($"** Checkpoint created at step {checkpoints.Count}."); + // Checkpoints are automatically created at the end of each super step when a + // checkpoint manager is provided. You can store the checkpoint info for later use. + CheckpointInfo? checkpoint = superStepCompletedEvt.CompletionInfo!.Checkpoint; + if (checkpoint is not null) + { + checkpoints.Add(checkpoint); + Console.WriteLine($"** Checkpoint created at step {checkpoints.Count}."); + } + + break; } - } - if (evt is WorkflowOutputEvent workflowOutputEvt) - { - Console.WriteLine($"Workflow completed with result: {workflowOutputEvt.Data}"); - } + case WorkflowOutputEvent outputEvent: + Console.WriteLine($"Workflow completed with result: {outputEvent.Data}"); + break; - if (evt is WorkflowErrorEvent workflowError) - { - Console.ForegroundColor = ConsoleColor.Red; - Console.Error.WriteLine(workflowError.Exception?.ToString() ?? "Unknown workflow error occurred."); - Console.ResetColor(); - } - else if (evt is ExecutorFailedEvent executorFailed) - { - Console.ForegroundColor = ConsoleColor.Red; - Console.Error.WriteLine($"Executor '{executorFailed.ExecutorId}' failed with {(executorFailed.Data == null ? "unknown error" : $"exception {executorFailed.Data}")}."); - Console.ResetColor(); + case WorkflowErrorEvent workflowError: + Console.ForegroundColor = ConsoleColor.Red; + Console.Error.WriteLine(workflowError.Exception?.ToString() ?? "Unknown workflow error occurred."); + Console.ResetColor(); + break; + + case ExecutorFailedEvent executorFailed: + Console.ForegroundColor = ConsoleColor.Red; + Console.Error.WriteLine($"Executor '{executorFailed.ExecutorId}' failed with {(executorFailed.Data == null ? "unknown error" : $"exception {executorFailed.Data}")}."); + Console.ResetColor(); + break; } } @@ -84,27 +86,27 @@ public static class Program await checkpointedRun.RestoreCheckpointAsync(savedCheckpoint, CancellationToken.None); await foreach (WorkflowEvent evt in checkpointedRun.WatchStreamAsync()) { - if (evt is ExecutorCompletedEvent executorCompletedEvt) + switch (evt) { - Console.WriteLine($"* Executor {executorCompletedEvt.ExecutorId} completed."); - } + case ExecutorCompletedEvent executorCompletedEvt: + Console.WriteLine($"* Executor {executorCompletedEvt.ExecutorId} completed."); + break; - if (evt is WorkflowOutputEvent workflowOutputEvt) - { - Console.WriteLine($"Workflow completed with result: {workflowOutputEvt.Data}"); - } + case WorkflowOutputEvent workflowOutputEvt: + Console.WriteLine($"Workflow completed with result: {workflowOutputEvt.Data}"); + break; - if (evt is WorkflowErrorEvent workflowError) - { - Console.ForegroundColor = ConsoleColor.Red; - Console.Error.WriteLine(workflowError.Exception?.ToString() ?? "Unknown workflow error occurred."); - Console.ResetColor(); - } - else if (evt is ExecutorFailedEvent executorFailed) - { - Console.ForegroundColor = ConsoleColor.Red; - Console.Error.WriteLine($"Executor '{executorFailed.ExecutorId}' failed with {(executorFailed.Data == null ? "unknown error" : $"exception {executorFailed.Data}")}."); - Console.ResetColor(); + case WorkflowErrorEvent workflowError: + Console.ForegroundColor = ConsoleColor.Red; + Console.Error.WriteLine(workflowError.Exception?.ToString() ?? "Unknown workflow error occurred."); + Console.ResetColor(); + break; + + case ExecutorFailedEvent executorFailed: + Console.ForegroundColor = ConsoleColor.Red; + Console.Error.WriteLine($"Executor '{executorFailed.ExecutorId}' failed with {(executorFailed.Data == null ? "unknown error" : $"exception {executorFailed.Data}")}."); + Console.ResetColor(); + break; } } }