-
Notifications
You must be signed in to change notification settings - Fork 325
Expand file tree
/
Copy pathProgram.cs
More file actions
111 lines (93 loc) · 3.69 KB
/
Program.cs
File metadata and controls
111 lines (93 loc) · 3.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
using System.Reflection;
using DurableTask.Core;
using DurableTask.Emulator;
using Microsoft.Extensions.Logging;
Console.WriteLine("=== DurableTask Emulator Smoke Test ===");
Console.WriteLine();
using ILoggerFactory loggerFactory = LoggerFactory.Create(builder =>
{
builder.AddConsole();
builder.SetMinimumLevel(LogLevel.Warning);
});
// Create the in-memory orchestration service
var orchestrationService = new LocalOrchestrationService();
// Start the worker with our orchestration and activities
var worker = new TaskHubWorker(orchestrationService, loggerFactory);
await worker
.AddTaskOrchestrations(typeof(HelloCitiesOrchestration))
.AddTaskActivities(typeof(SayHelloActivity))
.StartAsync();
// Create a client and start the orchestration
var client = new TaskHubClient(orchestrationService, loggerFactory: loggerFactory);
OrchestrationInstance instance = await client.CreateOrchestrationInstanceAsync(
typeof(HelloCitiesOrchestration), input: null);
Console.WriteLine($"Started orchestration: {instance.InstanceId}");
// Wait for completion
OrchestrationState result = await client.WaitForOrchestrationAsync(
instance, TimeSpan.FromSeconds(30), CancellationToken.None);
Console.WriteLine($"Orchestration status: {result.OrchestrationStatus}");
Console.WriteLine($"Orchestration output: {result.Output}");
await worker.StopAsync(true);
// Print loaded DTFx assembly versions (after usage to ensure all assemblies are loaded)
Console.WriteLine();
Console.WriteLine("Loaded DTFx assembly versions:");
foreach (var asm in AppDomain.CurrentDomain.GetAssemblies())
{
string? name = asm.GetName().Name;
if (name != null && name.StartsWith("DurableTask.", StringComparison.OrdinalIgnoreCase))
{
string? infoVersion = asm
.GetCustomAttribute<AssemblyInformationalVersionAttribute>()
?.InformationalVersion;
if (infoVersion != null && infoVersion.Contains('+'))
{
infoVersion = infoVersion[..infoVersion.IndexOf('+')];
}
Console.WriteLine($" {name} = {infoVersion ?? asm.GetName().Version?.ToString() ?? "unknown"}");
}
}
// Validate result
if (result.OrchestrationStatus != OrchestrationStatus.Completed)
{
Console.WriteLine("FAIL: Orchestration did not complete successfully.");
return 1;
}
if (result.Output == null ||
!result.Output.Contains("Hello, Tokyo!") ||
!result.Output.Contains("Hello, London!") ||
!result.Output.Contains("Hello, Seattle!"))
{
Console.WriteLine("FAIL: Orchestration output did not contain expected greetings.");
return 1;
}
Console.WriteLine();
Console.WriteLine("PASS: HelloCities orchestration completed with expected output.");
return 0;
// ---- Orchestration ----
/// <summary>
/// A simple function chaining orchestration that calls SayHello for three cities.
/// </summary>
public class HelloCitiesOrchestration : TaskOrchestration<string, object>
{
public override async Task<string> RunTask(OrchestrationContext context, object input)
{
string result = "";
result += await context.ScheduleTask<string>(typeof(SayHelloActivity), "Tokyo") + " ";
result += await context.ScheduleTask<string>(typeof(SayHelloActivity), "London") + " ";
result += await context.ScheduleTask<string>(typeof(SayHelloActivity), "Seattle");
return result;
}
}
// ---- Activity ----
/// <summary>
/// A simple activity that returns a greeting for the given city name.
/// </summary>
public class SayHelloActivity : TaskActivity<string, string>
{
protected override string Execute(TaskContext context, string cityName)
{
return $"Hello, {cityName}!";
}
}