-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathHttpGetStatusForOne.cs
68 lines (62 loc) · 2.9 KB
/
HttpGetStatusForOne.cs
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
using System.Net.Http;
using System.Threading.Tasks;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.DurableTask;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.Extensions.Logging;
// ReSharper disable once CheckNamespace
namespace DurableFunctions.Demo.DotNetCore.Status
{
public class HttpGetStatusForOne
{
/// <summary>
/// This function retrives the status for one Orchestrator in the same Function App
/// which matches the OrchestratorName parameter.
/// </summary>
/// <param name="req">The HttpRequestMessage which can contain input data for the Orchestrator.</param>
/// <param name="orchestratorClient">An instance of the DurableOrchestrationClient used to start a new Orchestrator.</param>
/// <param name="id">Orchestrator instance id to get the status for.</param>
/// <param name="log">ILogger implementation.</param>
/// <returns>A DurableOrchestrationStatus message.</returns>
[FunctionName(nameof(HttpGetStatusForOne))]
public async Task<DurableOrchestrationStatus> Run(
[HttpTrigger(AuthorizationLevel.Function, "get", Route = "status/{id}")]HttpRequestMessage request,
[DurableClient]IDurableClient orchestratorClient,
string id,
ILogger log)
{
DurableOrchestrationStatus status;
var parameters = GetQueryStringParameters(request);
if (parameters.hasParameters)
{
status = await orchestratorClient.GetStatusAsync(
id,
parameters.showHistory,
parameters.showHistoryOutput,
parameters.showInput);
}
else
{
status = await orchestratorClient.GetStatusAsync(id);
}
return status;
}
private static (bool hasParameters, bool showHistory, bool showHistoryOutput, bool showInput) GetQueryStringParameters(HttpRequestMessage request)
{
bool hasParameters = request.RequestUri.ParseQueryString().HasKeys();
bool showHistory = false;
bool showHistoryOutput = false;
bool showInput = false;
if (hasParameters)
{
string showHistoryString = request.RequestUri.ParseQueryString().Get("showHistory");
bool.TryParse(showHistoryString, out showHistory);
string showHistoryOutputString = request.RequestUri.ParseQueryString().Get("showHistoryOutput");
bool.TryParse(showHistoryOutputString, out showHistoryOutput);
string showInputString = request.RequestUri.ParseQueryString().Get("showInput");
bool.TryParse(showInputString, out showInput);
}
return (hasParameters, showHistory, showHistoryOutput, showInput);
}
}
}