예제 #1
0
        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());
        }
예제 #2
0
        private IEnumerable <ConnectionDefinition> FilterInvalidConnections(SaveWorkflowDefinitionRequest request)
        {
            var validConnections =
                from connection in request.Connections
                let sourceActivity = request.Activities.FirstOrDefault(x => x.ActivityId == connection.SourceActivityId)
                                     let targetActivity = request.Activities.FirstOrDefault(x => x.ActivityId == connection.TargetActivityId)
                                                          where sourceActivity != null && targetActivity != null && connection.Outcome is not null and not ""
                                                          select connection;

            return(validConnections);
        }
예제 #3
0
        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));
        }
예제 #4
0
 public async Task <WorkflowDefinition> SaveAsync(SaveWorkflowDefinitionRequest request, CallContext context) => await _elsaClient.WorkflowDefinitions.SaveAsync(request, context.CancellationToken);