-
Notifications
You must be signed in to change notification settings - Fork 34
Expand file tree
/
Copy pathProgram.cs
More file actions
90 lines (56 loc) · 2.59 KB
/
Program.cs
File metadata and controls
90 lines (56 loc) · 2.59 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
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
using DurableTask.Core;
using DurableTask.Netherite;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
// ----------- construct the Netherite orchestration service
Console.WriteLine("Starting Netherite...");
var netheriteSettings = new NetheriteOrchestrationServiceSettings()
{
HubName = "HelloDTFx",
PartitionCount = 4,
StorageConnectionName = "MyStorageConnection",
EventHubsConnectionName = "MyEventHubsConnection",
};
netheriteSettings.Validate(connectionStringResolver);
// we use pseudo-connection strings here for demonstration purposes.
// See the sample "TokenCredentialDTFX" if you want to use Azure token credentials instead.
string connectionStringResolver(string connectionName)
{
switch (connectionName)
{
case "MyStorageConnection":
return "UseDevelopmentStorage=true;"; // use the local storage emulater
case "MyEventHubsConnection":
return "SingleHost"; // run Netherite in SingleHost mode, which does not require an Azure Event Hubs namespace resource
default:
throw new ArgumentException("invalid connection name");
}
};
var loggerFactory = LoggerFactory.Create(builder =>
{
builder.AddSimpleConsole(options => options.SingleLine = true);
});
NetheriteOrchestrationService netherite = new NetheriteOrchestrationService(netheriteSettings, loggerFactory);
// ---------- create the task hub in storage, if it does not already exist
await ((IOrchestrationService) netherite).CreateIfNotExistsAsync();
// ---------- configure and start the DTFx worker
var worker = new TaskHubWorker(netherite, loggerFactory);
worker.AddTaskOrchestrations(typeof(HelloSequence));
worker.AddTaskActivities(typeof(SayHello));
await worker.StartAsync();
// ---------- configure the taskhub client
var client = new TaskHubClient(netherite);
// --------- start the orchestration, then wait for it to complete
Console.WriteLine("Starting the orchestration...");
OrchestrationInstance instance = await client.CreateOrchestrationInstanceAsync(typeof(HelloSequence), null);
Console.WriteLine("Waiting for completion...");
OrchestrationState taskResult = await client.WaitForOrchestrationAsync(instance, TimeSpan.FromSeconds(30), CancellationToken.None);
Console.WriteLine($"Result:\n{JsonConvert.SerializeObject(taskResult, Formatting.Indented)}\n");
// --------- shut down the service
Console.WriteLine("Press any key to shut down...");
Console.ReadKey();
Console.WriteLine($"Shutting down...");
await worker.StopAsync();
Console.WriteLine("Done.");