Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
71 commits
Select commit Hold shift + click to select a range
3ce6f18
Add C# TaskChaining
marcduiker Mar 18, 2025
4f59915
Add C# FanOutFanIn
marcduiker Mar 18, 2025
eaeaaae
Add C# Monitor
marcduiker Mar 19, 2025
2da416e
Add C# ExternalEvent
marcduiker Mar 19, 2025
b2d70f1
Add C# ChildWorkflows
marcduiker Mar 20, 2025
72668f5
Add C# CombinedPatterns
marcduiker Mar 20, 2025
8ee7b05
Add C# WorkflowManagement
marcduiker Mar 21, 2025
9cc59c6
Fix port numbers
marcduiker Mar 21, 2025
53996a5
Add C# Basics
marcduiker Mar 21, 2025
ca2f2ad
Add READMEs
marcduiker Mar 21, 2025
7ed9923
Update READMEs
marcduiker Mar 21, 2025
4bc32fd
Update folder structure
marcduiker Mar 21, 2025
b2f3dbc
Update Basic Workflow
marcduiker Mar 21, 2025
790c73e
Add BasicWorkflow comments
marcduiker Mar 24, 2025
551f81e
Add mermaid diagrams
marcduiker Mar 24, 2025
a44a0bd
Add code comments
marcduiker Mar 25, 2025
2f154ea
Merge branch 'master' into workflow-tutorials
marcduiker Mar 25, 2025
d2eeaac
Combine pattern examples is working
marcduiker Mar 26, 2025
2f67550
Add diagram
marcduiker Mar 26, 2025
92ffc2e
Add README content for challenges& tips
marcduiker Mar 26, 2025
9c04f72
Update to .NET 9
marcduiker Mar 31, 2025
9562e15
Use file based namespaces, make classes internal sealed
marcduiker Apr 1, 2025
39fcfcf
Make classes internal sealed
marcduiker Apr 1, 2025
45d3a43
Fix paths for multi-app run
marcduiker Apr 1, 2025
c369d3d
Merge branch 'master' into workflow-tutorials
WhitWaldo Apr 1, 2025
7214b5b
Add workflow input and outputs to READMEs
marcduiker Apr 14, 2025
c3906d1
Add resiliency-and-compensation
marcduiker Apr 14, 2025
29443b0
Add mechanical markdown
marcduiker Apr 15, 2025
5c3e991
Add make files
marcduiker Apr 15, 2025
c47bd4d
Update prerequisites
marcduiker Apr 15, 2025
fffb2c2
Add workflow validation to GH WF
marcduiker Apr 15, 2025
762e1d2
PR review updates
marcduiker Apr 16, 2025
d9e0010
Update tutorials/workflow/csharp/fundamentals/README.md
marcduiker Apr 22, 2025
7346acb
Update tutorials/workflow/csharp/fundamentals/README.md
marcduiker Apr 22, 2025
238b45c
Update fundamentals
marcduiker Apr 22, 2025
db727ed
Add cURL to task chaining
marcduiker Apr 22, 2025
80af9f5
Add comments to Program
marcduiker Apr 22, 2025
dfbee09
Update tutorials/workflow/csharp/fan-out-fan-in/README.md
marcduiker Apr 22, 2025
61dfa56
Update tutorials/workflow/csharp/fan-out-fan-in/README.md
marcduiker Apr 22, 2025
7f96082
Add cURL for fanout/fanin
marcduiker Apr 22, 2025
dcd7dba
Update tutorials/workflow/csharp/monitor-pattern/README.md
marcduiker Apr 22, 2025
4d9cc1b
Clarify workflow
marcduiker Apr 22, 2025
ef2329e
Update tutorials/workflow/csharp/monitor-pattern/README.md
marcduiker Apr 22, 2025
c468185
Add cURL commands
marcduiker Apr 22, 2025
040191f
Add optional IDE
marcduiker Apr 22, 2025
61843f3
Update tutorials/workflow/csharp/external-system-interaction/README.md
marcduiker Apr 22, 2025
3d46dea
Update tutorials/workflow/csharp/external-system-interaction/README.md
marcduiker Apr 22, 2025
b26da7a
Update tutorials/workflow/csharp/external-system-interaction/README.md
marcduiker Apr 22, 2025
0545347
Update tutorials/workflow/csharp/external-system-interaction/External…
marcduiker Apr 22, 2025
a6d3e04
Add cURL
marcduiker Apr 22, 2025
1ab6965
Update tutorials/workflow/csharp/child-workflows/README.md
marcduiker Apr 22, 2025
e5808e8
Update tutorials/workflow/csharp/child-workflows/README.md
marcduiker Apr 22, 2025
a9334b2
Update tutorials/workflow/csharp/child-workflows/README.md
marcduiker Apr 22, 2025
9bc26ea
Add cURL
marcduiker Apr 22, 2025
496adf1
Disable workflow tutorial validation until mechanical markdown can in…
marcduiker Apr 22, 2025
48ff1d6
Update tutorials/workflow/csharp/resiliency-and-compensation/README.md
marcduiker Apr 22, 2025
79d52b3
Update tutorials/workflow/csharp/resiliency-and-compensation/README.md
marcduiker Apr 22, 2025
ca9c95e
Update tutorials/workflow/csharp/resiliency-and-compensation/README.md
marcduiker Apr 22, 2025
ddce003
Update tutorials/workflow/csharp/resiliency-and-compensation/README.md
marcduiker Apr 22, 2025
61873a1
Add SetCustomStatus and cURL commands
marcduiker Apr 22, 2025
1403628
Update tutorials/workflow/csharp/combined-patterns/README.md
marcduiker Apr 22, 2025
7ac2aed
Update tutorials/workflow/csharp/combined-patterns/WorkflowApp/Activi…
marcduiker Apr 22, 2025
4ccd420
Update tutorials/workflow/csharp/combined-patterns/WorkflowApp/Activi…
marcduiker Apr 22, 2025
4fdb24d
Add clarifying comments
marcduiker Apr 22, 2025
85e5523
Update tutorials/workflow/csharp/combined-patterns/README.md
marcduiker Apr 22, 2025
eacb636
Update tutorials/workflow/csharp/combined-patterns/README.md
marcduiker Apr 22, 2025
7512c2e
Add cURL
marcduiker Apr 22, 2025
9faee39
Update tutorials/workflow/csharp/workflow-management/README.md
marcduiker Apr 22, 2025
11ee6db
Add clarifying comments
marcduiker Apr 22, 2025
1dc008f
Update tutorials/workflow/csharp/challenges-tips/README.md
marcduiker Apr 22, 2025
4918bda
Add -i to get the headers
marcduiker Apr 22, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
using System;
using Dapr.Workflow;

namespace WorkflowApp
{
public class NonDeterministicWorkflow : Workflow<string, string>
{
public override async Task<string> RunAsync(WorkflowContext context, string orderItem)
{
// Do not use non-deterministic operations in a workflow!
// These operations will create a new value every time the
// workflow is replayed.
var orderId = Guid.NewGuid().ToString();
var orderDate = DateTime.UtcNow;

var idResult = await context.CallActivityAsync<string>(
"SubmitId",
orderId);

await context.CallActivityAsync<string>(
"SubmitDate",
orderDate);

return idResult;
}
}

public class DeterministicWorkflow : Workflow<string, string>
{
public override async Task<string> RunAsync(WorkflowContext context, string orderItem)
{
// Do use these deterministic methods and properties on the WorkflowContext instead.
// These operations create the same value when the workflow is replayed.
var orderId = context.NewGuid().ToString();
var orderDate = context.CurrentUtcDateTime;

var idResult = await context.CallActivityAsync<string>(
"SubmitId",
orderId);

await context.CallActivityAsync<string>(
"SubmitDate",
orderDate);

return idResult;
}
}
}
19 changes: 19 additions & 0 deletions tutorials/workflow/csharp/challenges-tips/IdempotentActivity.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using Dapr.Client;
using Dapr.Workflow;

namespace WorkflowApp
{
public class IdempotentActivity : WorkflowActivity<string, string>
{
public override async Task<InventoryResult> RunAsync(WorkflowActivityContext context, OrderItem orderItem)
{
// Beware of non-idempotent operations in an activity.
// Dapr Workflow guarantees at-least-once execution of activities, so activities might be executed more than once.
// For instance, can you insert a record to a database twice without side effects?
// var insertSql = $"INSERT INTO Orders (Id, Description, UnitPrice, Quantity) VALUES ('{orderItem.Id}', '{orderItem.Description}', {orderItem.UnitPrice}, {orderItem.Quantity})";
// It's best to perform a check if an record already exists before inserting it.
}
}

record OrderItem(string Id, string Description, double UnitPrice, int Quantity);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using Dapr.Workflow;

namespace WorkflowApp
{
public class LargePayloadSizeWorkflow : Workflow<string, LargeDocument>
{
public override async Task<LargeDocument> RunAsync(WorkflowContext context, string id)
{
// Do not pass large payloads between activities.
// They are stored in the Dapr state store twice, one as output argument
// for GetDocument, and once as input argument for UpdateDocument.
var document = await context.CallActivityAsync<LargeDocument>(
"GetDocument",
id);

var updatedDocument = await context.CallActivityAsync<LargeDocument>(
"UpdateDocument",
document);

// More activities to process the updated document...

return updatedDocument;
}
}


public class SmallPayloadSizeWorkflow : Workflow<string, string>
{
public override async Task<string> RunAsync(WorkflowContext context, string id)
{
// Do pass small payloads between activities, preferably IDs only, or objects that are quick to (de)serialize in large volumes.
// Combine multiple actions, such as document retrieval and update, into a single activity.
var documentId = await context.CallActivityAsync<string>(
"GetAndUpdateDocument",
id);

// More activities to process the updated document...

return documentId;
}
}

public record LargeDocument(string Id, object Data);
}
42 changes: 42 additions & 0 deletions tutorials/workflow/csharp/challenges-tips/VersioningWorkflow.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using Dapr.Workflow;

namespace WorkflowApp
{
public class VersioningWorkflow1 : Workflow<string, int>
{
public override async Task<int> RunAsync(WorkflowContext context, string orderItem)
{
int resultA = await context.CallActivityAsync<int>(
"ActivityA",
orderItem);

int resultB = await context.CallActivityAsync<int>(
"ActivityB",
orderItem);

return resultA + resultB;
}
}

public class VersioningWorkflow2 : Workflow<string, int>
{
public override async Task<int> RunAsync(WorkflowContext context, string orderItem)
{
int resultA = await context.CallActivityAsync<int>(
"ActivityA",
orderItem);

// The input for ActivityB has changed from orderItem (string) to resultA (int).
// If there are in-flight workflows that were started with the previous version
// of this workflow, but have not yet completed, these will fail when the new version
// of the workflow is deployed, since the parameters do not match with the persisted state.
// It is recommended to version workflows by creating a new workflow class with a new name:
// {workflowname}v1 -> {workflowname}v2
int resultB = await context.CallActivityAsync<int>(
"ActivityB",
resultA);

return resultA + resultB;
}
}
}
4 changes: 4 additions & 0 deletions tutorials/workflow/csharp/workflow-management/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ This tutorial demonstrates the various APIs to manage a workflow instance, these

For more information on workflow management, see the [Dapr docs](https://docs.dapr.io/developing-applications/building-blocks/workflow/howto-manage-workflow/).

## Inspect the code

Open the `Program.cs` file in the `tutorials/workflow/csharp/child-workflows/WorkflowManagement` folder. This file contains the endpoint definitions that use the workflow management API. The workflow that is being managed is named `NeverEndingWorkflow` and will keep running once it's started.

## Run the tutorial

1. Use a terminal to navigate to the `tutorials/workflow/csharp/workflow-management` folder.
Expand Down
Loading