示例#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());
        }
        public ViewResult Create()
        {
            var workflowDefinition = publisher.New();

            var model = new WorkflowDefinitionEditModel
            {
                Name = workflowDefinition.Name,
                Json = serializer.Serialize(workflowDefinition, JsonTokenFormatter.FormatName),
                ActivityDefinitions = options.Value.ActivityDefinitions.ToArray(),
                IsSingleton         = workflowDefinition.IsSingleton,
                IsDisabled          = workflowDefinition.IsDisabled,
                Description         = workflowDefinition.Description
            };

            return(View(model));
        }
示例#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
文件: Import.cs 项目: tle5/elsa-core
        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.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;

            await _workflowPublisher.SaveDraftAsync(workflowDefinition, cancellationToken);

            return(Ok(workflowDefinition));
        }