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
| [Route("api/[controller]")] [Controller] public class WorkflowsController : Controller { private readonly IWorkflowController _workflowService; private readonly IWorkflowRegistry _registry; private readonly IPersistenceProvider _workflowStore; private readonly ISearchIndex _searchService;
public WorkflowsController(IWorkflowController workflowService, ISearchIndex searchService, IWorkflowRegistry registry, IPersistenceProvider workflowStore) { _workflowService = workflowService; _workflowStore = workflowStore; _registry = registry; _searchService = searchService; }
[HttpGet] public async Task<IActionResult> Get(string terms, WorkflowStatus? status, string type, DateTime? createdFrom, DateTime? createdTo, int skip, int take = 10) { var filters = new List<SearchFilter>();
if (status.HasValue) filters.Add(StatusFilter.Equals(status.Value));
if (createdFrom.HasValue) filters.Add(DateRangeFilter.After(x => x.CreateTime, createdFrom.Value));
if (createdTo.HasValue) filters.Add(DateRangeFilter.Before(x => x.CreateTime, createdTo.Value));
if (!string.IsNullOrEmpty(type)) filters.Add(ScalarFilter.Equals(x => x.WorkflowDefinitionId, type));
var result = await _searchService.Search(terms, skip, take, filters.ToArray());
return Json(result); }
[HttpGet("{id}")] public async Task<IActionResult> Get(string id) { var result = await _workflowStore.GetWorkflowInstance(id); return Json(result); }
[HttpPost("{id}")] public async Task<IActionResult> Post1(string id, int? version) { string workflowId = null; var def = _registry.GetDefinition(id, version); if (def == null) return BadRequest(String.Format("Workflow defintion {0} for version {1} not found", id, version));
workflowId = await _workflowService.StartWorkflow(id, version);
return Ok(workflowId); }
[HttpPut("{id}/suspend")] public Task<bool> Suspend(string id) { return _workflowService.SuspendWorkflow(id); }
[HttpPut("{id}/resume")] public Task<bool> Resume(string id) { return _workflowService.ResumeWorkflow(id); }
[HttpDelete("{id}")] public Task<bool> Terminate(string id) { return _workflowService.TerminateWorkflow(id); } }
|