| | | 1 | | using Elsa.Mediator.Contracts; |
| | | 2 | | using Elsa.Workflows.Management.Models; |
| | | 3 | | using Elsa.Workflows.Management.Notifications; |
| | | 4 | | using Elsa.Workflows.Models; |
| | | 5 | | |
| | | 6 | | namespace Elsa.Workflows.Management.Handlers.Notifications; |
| | | 7 | | |
| | | 8 | | public class ValidateWorkflow : INotificationHandler<WorkflowDefinitionValidating> |
| | | 9 | | { |
| | | 10 | | public Task HandleAsync(WorkflowDefinitionValidating notification, CancellationToken cancellationToken) |
| | | 11 | | { |
| | 5 | 12 | | var workflow = notification.Workflow; |
| | 5 | 13 | | var inputs = workflow.Inputs; |
| | 5 | 14 | | var outputs = workflow.Outputs; |
| | | 15 | | |
| | 5 | 16 | | ValidateUniqueNames(inputs, "inputs", notification.ValidationErrors); |
| | 5 | 17 | | ValidateUniqueNames(outputs, "outputs", notification.ValidationErrors); |
| | | 18 | | |
| | 5 | 19 | | return Task.CompletedTask; |
| | | 20 | | } |
| | | 21 | | |
| | | 22 | | private void ValidateUniqueNames(IEnumerable<ArgumentDefinition> variables, string variableType, ICollection<Workflo |
| | | 23 | | { |
| | 10 | 24 | | var duplicateNames = variables.GroupBy(x => x.Name).Where(x => x.Count() > 1).Select(x => x.Key).ToList(); |
| | 10 | 25 | | if (duplicateNames.Any()) |
| | | 26 | | { |
| | 0 | 27 | | var message = $"The following {variableType} are defined more than once: {string.Join(", ", duplicateNames)} |
| | 0 | 28 | | validationErrors.Add(new(message)); |
| | | 29 | | } |
| | 10 | 30 | | } |
| | | 31 | | } |