public async Task <IActionResult> Handle(TriggerWorkflowsRequestModel request, CancellationToken cancellationToken = default) { var tenantId = await _tenantAccessor.GetTenantIdAsync(cancellationToken); var context = new WorkflowsQuery(request.ActivityType, request.Bookmark, request.CorrelationId, request.WorkflowInstanceId, request.ContextId, tenantId); ICollection <TriggeredWorkflowModel> triggeredWorkflows; if (request.Dispatch) { var result = await _workflowLaunchpad.CollectAndDispatchWorkflowsAsync(context, new WorkflowInput(request.Input), cancellationToken).ToList(); triggeredWorkflows = result.Select(x => new TriggeredWorkflowModel(x.WorkflowInstanceId, x.ActivityId)).ToList(); } else { var result = await _workflowLaunchpad.CollectAndExecuteWorkflowsAsync(context, new WorkflowInput(request.Input), cancellationToken).ToList(); triggeredWorkflows = result.Select(x => new TriggeredWorkflowModel(x.WorkflowInstanceId, x.ActivityId)).ToList(); } if (Response.HasStarted) { return(new EmptyResult()); } return(Ok(new TriggerWorkflowsResponseModel(triggeredWorkflows))); }
public async Task <ActionResult <WorkflowDefinition> > Handle([FromBody] SaveWorkflowDefinitionRequest request, [FromRoute] ApiVersion apiVersion, CancellationToken cancellationToken) { var workflowDefinitionId = request.WorkflowDefinitionId; var workflowDefinition = !string.IsNullOrWhiteSpace(workflowDefinitionId) ? await _workflowPublisher.GetDraftAsync(workflowDefinitionId, cancellationToken) : default; var isNew = workflowDefinition == null; if (workflowDefinition == null) { workflowDefinition = _workflowPublisher.New(); if (!string.IsNullOrWhiteSpace(workflowDefinitionId)) { workflowDefinition.DefinitionId = workflowDefinitionId; } } if (!TryParseVariables(request.Variables, out var variables)) { return(BadRequest("Cannot parse variables")); } if (!TryParseVariables(request.CustomAttributes, out var customAttributes)) { return(BadRequest("Cannot parse customAttributes")); } workflowDefinition.Activities = request.Activities; workflowDefinition.Connections = FilterInvalidConnections(request).ToList(); workflowDefinition.Description = request.Description?.Trim(); workflowDefinition.Name = request.Name?.Trim(); workflowDefinition.Variables = variables; workflowDefinition.CustomAttributes = customAttributes; workflowDefinition.IsSingleton = request.IsSingleton; workflowDefinition.PersistenceBehavior = request.PersistenceBehavior; workflowDefinition.DeleteCompletedInstances = request.DeleteCompletedInstances; workflowDefinition.ContextOptions = request.ContextOptions; workflowDefinition.DisplayName = request.DisplayName?.Trim(); workflowDefinition.Tag = request.Tag?.Trim(); workflowDefinition.Channel = request.Channel?.Trim(); workflowDefinition.TenantId = await _tenantAccessor.GetTenantIdAsync(cancellationToken); if (request.Publish) { workflowDefinition = await _workflowPublisher.PublishAsync(workflowDefinition, cancellationToken); } else { workflowDefinition = await _workflowPublisher.SaveDraftAsync(workflowDefinition, cancellationToken); } if (!isNew) { return(Json(workflowDefinition, SerializationHelper.GetSettingsForWorkflowDefinition())); } return(CreatedAtAction("Handle", "GetByVersionId", new { versionId = workflowDefinition.Id, apiVersion = apiVersion.ToString() }, workflowDefinition) .ConfigureForWorkflowDefinition()); }
public async Task <ActionResult <PagedList <WorkflowDefinitionSummaryModel> > > Handle( [FromQuery] string?ids, [FromQuery] string?searchTerm = default, int?page = default, int?pageSize = default, VersionOptions?version = default, CancellationToken cancellationToken = default) { var tenantId = await _tenantAccessor.GetTenantIdAsync(cancellationToken); version ??= VersionOptions.Latest; var specification = GetSpecification(ids, version.Value).And(new TenantSpecification <WorkflowDefinition>(tenantId)); if (!string.IsNullOrWhiteSpace(searchTerm)) { specification = specification.And(new WorkflowDefinitionSearchTermSpecification(searchTerm)); } var totalCount = await _workflowDefinitionStore.CountAsync(specification, cancellationToken); var paging = page == null || pageSize == null ? default : Paging.Page(page.Value, pageSize.Value); var items = await _workflowDefinitionStore.FindManyAsync(specification, new OrderBy <WorkflowDefinition>(x => x.Name !, SortDirection.Ascending), paging, cancellationToken); var summaries = _mapper.Map <IList <WorkflowDefinitionSummaryModel> >(items); var pagedList = new PagedList <WorkflowDefinitionSummaryModel>(summaries, page, pageSize, totalCount); return(Json(pagedList, SerializationHelper.GetSettingsForWorkflowDefinition())); }
public async Task <IActionResult> Handle(string workflowDefinitionId, [FromForm] IFormFile?file, CancellationToken cancellationToken) { if (file == null) { return(BadRequest()); } var json = await file.OpenReadStream().ReadStringToEndAsync(cancellationToken); var workflowDefinition = await _workflowPublisher.GetDraftAsync(workflowDefinitionId, cancellationToken) ?? _workflowPublisher.New(); var postedModel = _contentSerializer.Deserialize <WorkflowDefinition>(json); workflowDefinition.Activities = postedModel.Activities; workflowDefinition.Channel = postedModel.Channel; workflowDefinition.Connections = postedModel.Connections; workflowDefinition.Description = postedModel.Description; workflowDefinition.Name = postedModel.Name; workflowDefinition.Tag = postedModel.Tag; workflowDefinition.Variables = postedModel.Variables; workflowDefinition.ContextOptions = postedModel.ContextOptions; workflowDefinition.CustomAttributes = postedModel.CustomAttributes; workflowDefinition.DisplayName = postedModel.DisplayName; workflowDefinition.IsSingleton = postedModel.IsSingleton; workflowDefinition.DeleteCompletedInstances = postedModel.DeleteCompletedInstances; workflowDefinition.PersistenceBehavior = postedModel.PersistenceBehavior; workflowDefinition.TenantId = await _tenantAccessor.GetTenantIdAsync(cancellationToken); await _workflowPublisher.SaveDraftAsync(workflowDefinition, cancellationToken); return(Ok(workflowDefinition)); }
public async Task <IActionResult> Handle(VersionOptions?version = default, CancellationToken cancellationToken = default) { version ??= VersionOptions.Latest; var tenantId = await _tenantAccessor.GetTenantIdAsync(cancellationToken); var workflowBlueprints = await ListAllAsync(tenantId, version.Value, cancellationToken).OrderBy(x => x.DisplayName ?? x.Name ?? "(Untitled)").ToListAsync(cancellationToken); var model = _mapper.Map <IEnumerable <WorkflowBlueprintSummaryModel> >(workflowBlueprints).ToList(); return(Ok(model).ConfigureForWorkflowDefinition()); }
public async Task <IActionResult> Handle(string workflowDefinitionId, DispatchWorkflowDefinitionRequestModel request, CancellationToken cancellationToken = default) { var tenantId = await _tenantAccessor.GetTenantIdAsync(cancellationToken); var startableWorkflow = await _workflowLaunchpad.FindStartableWorkflowAsync(workflowDefinitionId, request.ActivityId, request.CorrelationId, request.ContextId, tenantId, cancellationToken); if (startableWorkflow == null) { return(NotFound()); } var result = await _workflowLaunchpad.DispatchStartableWorkflowAsync(startableWorkflow, new WorkflowInput(request.Input), cancellationToken); return(Ok(new DispatchWorkflowDefinitionResponseModel(result.WorkflowInstanceId, result.ActivityId)).ConfigureForEndpoint()); }
public async Task <IActionResult> Handle(string definitionId, CancellationToken cancellationToken = default) { var tenantId = await _tenantAccessor.GetTenantIdAsync(cancellationToken); var specification = GetSpecification(definitionId).And(new TenantSpecification <WorkflowDefinition>(tenantId)); var definitions = await _workflowDefinitionStore.FindManyAsync(specification, new OrderBy <WorkflowDefinition>(x => x.Version, SortDirection.Descending), cancellationToken : cancellationToken); var versionModels = _mapper.Map <IList <WorkflowDefinitionVersionModel> >(definitions); var model = new { Items = versionModels }; return(Json(model, SerializationHelper.GetSettingsForWorkflowDefinition())); }
public async Task <ActionResult <PagedList <WorkflowDefinitionSummaryModel> > > Handle(int?page = default, int?pageSize = default, VersionOptions?version = default, CancellationToken cancellationToken = default) { var tenantId = await _tenantAccessor.GetTenantIdAsync(cancellationToken); version ??= VersionOptions.Latest; var specification = new VersionOptionsSpecification(version.Value).And(new TenantSpecification <WorkflowDefinition>(tenantId)); var totalCount = await _workflowDefinitionStore.CountAsync(specification, cancellationToken); var paging = page == null || pageSize == null ? default : Paging.Page(page.Value, pageSize.Value); var items = await _workflowDefinitionStore.FindManyAsync(specification, paging: paging, cancellationToken : cancellationToken); var summaries = _mapper.Map <IList <WorkflowDefinitionSummaryModel> >(items); var pagedList = new PagedList <WorkflowDefinitionSummaryModel>(summaries, page, pageSize, totalCount); return(Json(pagedList, _serializer.GetSettings())); }
public async Task <IActionResult> Handle(string id, CancellationToken cancellationToken = default) { var workflowInstance = await _workflowInstanceStore.FindByIdAsync(id, cancellationToken); if (workflowInstance == null) { return(NotFound()); } var tenantId = await _tenantAccessor.GetTenantIdAsync(cancellationToken); var workflowBlueprint = await _workflowRegistry.FindByDefinitionVersionIdAsync(workflowInstance.DefinitionVersionId, tenantId, cancellationToken); await _publisher.Publish(new RequestingWorkflowInstance(workflowInstance, workflowBlueprint !), cancellationToken); return(Json(workflowInstance, _contentSerializer.GetSettings())); }
public async Task <ActionResult <WorkflowDefinition> > Handle([FromBody] SaveWorkflowDefinitionRequest request, [FromRoute] ApiVersion apiVersion, CancellationToken cancellationToken) { var workflowDefinitionId = request.WorkflowDefinitionId; var workflowDefinition = !string.IsNullOrWhiteSpace(workflowDefinitionId) ? await _workflowPublisher.GetDraftAsync(workflowDefinitionId, cancellationToken) : default; var isNew = workflowDefinition == null; if (workflowDefinition == null) { workflowDefinition = _workflowPublisher.New(); if (!string.IsNullOrWhiteSpace(workflowDefinitionId)) { workflowDefinition.DefinitionId = workflowDefinitionId; } } workflowDefinition.Activities = request.Activities; workflowDefinition.Connections = FilterInvalidConnections(request).ToList(); workflowDefinition.Description = request.Description?.Trim(); workflowDefinition.Name = request.Name?.Trim(); workflowDefinition.Variables = request.Variables ?? new Variables(); workflowDefinition.IsSingleton = request.IsSingleton; workflowDefinition.PersistenceBehavior = request.PersistenceBehavior; workflowDefinition.DeleteCompletedInstances = request.DeleteCompletedInstances; workflowDefinition.ContextOptions = request.ContextOptions; workflowDefinition.DisplayName = request.DisplayName?.Trim(); workflowDefinition.Tag = request.Tag?.Trim(); workflowDefinition.Channel = request.Channel?.Trim(); workflowDefinition.TenantId = await _tenantAccessor.GetTenantIdAsync(cancellationToken); if (request.Publish) { workflowDefinition = await _workflowPublisher.PublishAsync(workflowDefinition, cancellationToken); } else { workflowDefinition = await _workflowPublisher.SaveDraftAsync(workflowDefinition, cancellationToken); } return(isNew ? CreatedAtAction("Handle", "GetByVersionId", new { versionId = workflowDefinition.Id, apiVersion = apiVersion.ToString() }, workflowDefinition) : Ok(workflowDefinition)); }
public async Task <IActionResult> Handle([FromBody] WorkflowTestRestartFromActivityRequest request, CancellationToken cancellationToken = default) { var tenantId = await _tenantAccessor.GetTenantIdAsync(cancellationToken); var result = await _workflowTestLaunchpad.FindAndRestartTestWorkflowAsync(request.WorkflowDefinitionId, request.ActivityId, request.Version, request.SignalRConnectionId, request.LastWorkflowInstanceId, tenantId, cancellationToken); if (result == null) { return(NotFound()); } if (Response.HasStarted) { return(new EmptyResult()); } return(Ok()); }
public async Task <IActionResult> Handle(string providerName, int?page = default, int?pageSize = default, VersionOptions?version = default, CancellationToken cancellationToken = default) { var workflowProvider = _workflowProviders.FirstOrDefault(x => x.GetType().Name == providerName); if (workflowProvider == null) { return(BadRequest(new { Error = $"Unknown workflow provider: {providerName}" })); } version ??= VersionOptions.Latest; var tenantId = await _tenantAccessor.GetTenantIdAsync(cancellationToken); var skip = page * pageSize; var workflowBlueprints = await workflowProvider.ListAsync(version.Value, skip, pageSize, tenantId, cancellationToken).ToListAsync(cancellationToken); var totalCount = await workflowProvider.CountAsync(version.Value, tenantId, cancellationToken); var mappedItems = _mapper.Map <IEnumerable <WorkflowBlueprintSummaryModel> >(workflowBlueprints).ToList(); var model = new PagedList <WorkflowBlueprintSummaryModel>(mappedItems, page, pageSize, totalCount); return(Ok(model).ConfigureForWorkflowDefinition()); }
public async Task <IActionResult> Handle(string workflowDefinitionId, ExecuteWorkflowDefinitionRequestModel request, CancellationToken cancellationToken = default) { var tenantId = await _tenantAccessor.GetTenantIdAsync(cancellationToken); var startableWorkflow = await _workflowLaunchpad.FindStartableWorkflowAsync(workflowDefinitionId, request.ActivityId, request.CorrelationId, request.ContextId, tenantId, cancellationToken); if (startableWorkflow == null) { return(NotFound()); } var result = await _workflowLaunchpad.ExecuteStartableWorkflowAsync(startableWorkflow, new WorkflowInput(request.Input), cancellationToken); if (Response.HasStarted) { return(new EmptyResult()); } return(Ok(new ExecuteWorkflowDefinitionResponseModel( result.Executed, result.ActivityId, result.WorkflowInstance ))); }
public async Task <IActionResult> Handle([FromBody] WorkflowTestExecuteRequest request, CancellationToken cancellationToken = default) { var tenantId = await _tenantAccessor.GetTenantIdAsync(cancellationToken); var testCorrelation = "test-" + request.WorkflowDefinitionId; var startableWorkflow = await _workflowLaunchpad.FindStartableWorkflowAsync(request.WorkflowDefinitionId !, request.Version, default, testCorrelation, default, tenantId, cancellationToken);
public async Task <IActionResult> Handle( [FromQuery(Name = "workflow")] string?workflowDefinitionId = default, [FromQuery(Name = "status")] WorkflowStatus?workflowStatus = default, [FromQuery] string?correlationId = default, [FromQuery] OrderBy?orderBy = default, [FromQuery] string?searchTerm = default, int page = 0, int pageSize = 25, CancellationToken cancellationToken = default) { _stopwatch.Restart(); var specification = Specification <WorkflowInstance> .Identity; if (!string.IsNullOrWhiteSpace(workflowDefinitionId)) { specification = specification.WithWorkflowDefinition(workflowDefinitionId); } if (!string.IsNullOrWhiteSpace(correlationId)) { specification = specification.WithCorrelationId(correlationId); } if (workflowStatus != null) { specification = specification.WithStatus(workflowStatus.Value); } if (!string.IsNullOrWhiteSpace(searchTerm)) { specification = specification.WithSearchTerm(searchTerm); } var tenantId = await _tenantAccessor.GetTenantIdAsync(cancellationToken); specification = specification.And(new TenantSpecification <WorkflowInstance>(tenantId)); var orderBySpecification = default(OrderBy <WorkflowInstance>); if (orderBy != null) { orderBySpecification = orderBy switch { OrderBy.Started => OrderBySpecification.OrderByDescending <WorkflowInstance>(x => x.CreatedAt), OrderBy.LastExecuted => OrderBySpecification.OrderByDescending <WorkflowInstance>(x => x.LastExecutedAt !), OrderBy.Finished => OrderBySpecification.OrderByDescending <WorkflowInstance>(x => x.FinishedAt !), _ => OrderBySpecification.OrderByDescending <WorkflowInstance>(x => x.FinishedAt !) }; } var totalCount = await _workflowInstanceStore.CountAsync(specification, cancellationToken : cancellationToken); var paging = Paging.Page(page, pageSize); var workflowInstances = await _workflowInstanceStore.FindManyAsync(specification, orderBySpecification, paging, cancellationToken).ToList(); var items = _mapper.Map <ICollection <WorkflowInstanceSummaryModel> >(workflowInstances); _stopwatch.Stop(); _logger.LogDebug("Handle took {TimeElapsed}", _stopwatch.Elapsed); var model = new PagedList <WorkflowInstanceSummaryModel>(items, page, pageSize, totalCount); return(Json(model, _contentSerializer.GetSettings())); } }