elsa-core/src/activities/Elsa.Activities.Http/Controllers/HttpWorkflowsController.cs
Rafael Carnucci 3b35d9ff0a
Seperate YesSql (#504)
* Seperate YesSql and added InMemory, MongoDb

* Error fixed, if DatabaseInitializer is run through several times

* icon.png was not packed

* Added AddWorkflowProvider to AddElsaPersistenceMongoDb

* Wrong primary keys were used for MongoDb

* Refactorig MongoDb

* Register IMongoCollection<WorkflowDefinition> and IMongoCollection<WorkflowInstance> with DI

* Wrong Parameter Type in Constructor (MongoDbWorkflowInstanceRepository)

* Add workflowDefinition.WorkflowDefinitionId = _idGenerator.Generate(); to Initialize

* Removed duplicated code

* Correct wrong Commit

Co-authored-by: Rafael Carnucci <rafael.carnucci@icn.de>
Co-authored-by: Sipke Schoorstra <sipkeschoorstra@outlook.com>
2020-12-11 21:03:49 +01:00

50 lines
1.7 KiB
C#

using System.Threading;
using System.Threading.Tasks;
using Elsa.Activities.Http.Models;
using Elsa.Activities.Http.Services;
using Elsa.Repositories;
using Elsa.Services;
using Microsoft.AspNetCore.Mvc;
namespace Elsa.Activities.Http.Controllers
{
[ApiController]
[Route("workflows")]
public class HttpWorkflowsController : ControllerBase
{
private readonly ITokenService _tokenService;
private readonly IWorkflowRunner _workflowRunner;
private readonly IWorkflowInstanceRepository _workflowInstanceManager;
public HttpWorkflowsController(
ITokenService tokenService,
IWorkflowRunner workflowRunner,
IWorkflowInstanceRepository workflowInstanceRepository)
{
_tokenService = tokenService;
_workflowRunner = workflowRunner;
_workflowInstanceManager = workflowInstanceRepository;
}
[Route("trigger/{token}")]
[HttpGet, HttpPost]
public async Task<IActionResult> Trigger(string token, CancellationToken cancellationToken)
{
if (!_tokenService.TryDecryptToken(token, out Signal signal))
return NotFound();
var workflowInstance = await _workflowInstanceManager.GetByIdAsync(signal.WorkflowInstanceId, cancellationToken);
if (workflowInstance == null)
return NotFound();
var input = signal.Name;
await _workflowRunner.RunWorkflowAsync(workflowInstance, input, cancellationToken: cancellationToken);
return HttpContext.Items.ContainsKey(WorkflowHttpResult.Instance)
? (IActionResult)new EmptyResult()
: Accepted();
}
}
}