2019-07-06 18:36:10 +00:00
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using Elsa.Activities.Http.Models;
|
|
|
|
|
using Elsa.Activities.Http.Services;
|
|
|
|
|
using Elsa.Models;
|
|
|
|
|
using Elsa.Persistence;
|
|
|
|
|
using Elsa.Services;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
|
|
|
|
|
namespace Elsa.Activities.Http.Controllers
|
|
|
|
|
{
|
|
|
|
|
[ApiController]
|
|
|
|
|
[Route("workflows")]
|
|
|
|
|
public class HttpWorkflowsController : ControllerBase
|
|
|
|
|
{
|
2019-09-15 10:16:24 +00:00
|
|
|
private readonly ITokenService tokenService;
|
2019-07-06 18:36:10 +00:00
|
|
|
private readonly IWorkflowInvoker workflowInvoker;
|
|
|
|
|
private readonly IWorkflowInstanceStore workflowInstanceStore;
|
|
|
|
|
|
|
|
|
|
public HttpWorkflowsController(
|
2019-09-15 10:16:24 +00:00
|
|
|
ITokenService tokenService,
|
2019-07-06 18:36:10 +00:00
|
|
|
IWorkflowInvoker workflowInvoker,
|
|
|
|
|
IWorkflowInstanceStore workflowInstanceStore)
|
|
|
|
|
{
|
2019-09-15 10:16:24 +00:00
|
|
|
this.tokenService = tokenService;
|
2019-07-06 18:36:10 +00:00
|
|
|
this.workflowInvoker = workflowInvoker;
|
|
|
|
|
this.workflowInstanceStore = workflowInstanceStore;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Route("trigger/{token}")]
|
2019-10-04 16:22:25 +00:00
|
|
|
[HttpGet, HttpPost]
|
2019-07-06 18:36:10 +00:00
|
|
|
public async Task<IActionResult> Trigger(string token, CancellationToken cancellationToken)
|
|
|
|
|
{
|
2019-09-15 10:16:24 +00:00
|
|
|
if (!tokenService.TryDecryptToken(token, out Signal signal))
|
2019-07-06 18:36:10 +00:00
|
|
|
return NotFound();
|
|
|
|
|
|
|
|
|
|
var workflowInstance = await workflowInstanceStore.GetByIdAsync(signal.WorkflowInstanceId, cancellationToken);
|
|
|
|
|
|
|
|
|
|
if (workflowInstance == null)
|
|
|
|
|
return NotFound();
|
|
|
|
|
|
|
|
|
|
var input = new Variables
|
|
|
|
|
{
|
|
|
|
|
["signal"] = signal.Name
|
|
|
|
|
};
|
|
|
|
|
|
2019-09-15 10:16:24 +00:00
|
|
|
await workflowInvoker.ResumeAsync(workflowInstance, input, cancellationToken: cancellationToken);
|
2019-07-06 18:36:10 +00:00
|
|
|
|
|
|
|
|
return HttpContext.Items.ContainsKey(WorkflowHttpResult.Instance)
|
|
|
|
|
? (IActionResult) new EmptyResult()
|
|
|
|
|
: Accepted();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|