Пример #1
0
        public async Task <IActionResult> StartStateMachine(
            [HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "statemachine/{instanceId}")] HttpRequest req,
            [DurableClient] IDurableClient client,
            string instanceId,
            ILogger log)
        {
            StateMachine?workflow = null;
            JObject?     input    = null;

            ObservableAction[]? actions = null;

            if (req.ContentLength != 0)
            {
                var json = JObject.Parse(await req.ReadAsStringAsync());

                workflow = json.Property("workflow")?.Value.ToObject <StateMachine>();

                input = (JObject)(json.Property("input")?.Value ?? new JObject());

                actions = json.Property("actions")?.Value.ToObject <ObservableAction[]>();
            }

            if (workflow == null)
            {
                return(new BadRequestObjectResult("Unable to deserialize state machine definition in request payload."));
            }

            var args = new StartWorkflowArgs(workflow, input, actions, _config["TELEMETRY_URI"]);

            await client.StartWorkflowAsync(args, instanceId);

            log.LogInformation($"Started new workflow '{workflow.Name}' with ID = '{instanceId}.");

            return(client.CreateCheckStatusResponse(req, instanceId));
        }