Пример #1
0
        private async Task <ActivityType> CreateActivityTypeAsync(TaskDefinition taskDefinition, CancellationToken cancellationToken)
        {
            var descriptor = await _describesActivityType.DescribeAsync <RunTask>(cancellationToken);

            descriptor.Type            = taskDefinition.Name;
            descriptor.DisplayName     = taskDefinition.DisplayName ?? taskDefinition.Name;
            descriptor.Description     = taskDefinition.Description;
            descriptor.InputProperties = Array.Empty <ActivityInputDescriptor>();
            descriptor.Outcomes        = taskDefinition.Outcomes?.ToArray() ?? new[] { OutcomeNames.Done };

            return(new ActivityType
            {
                Type = typeof(RunTask),
                TypeName = descriptor.Type,
                DisplayName = descriptor.DisplayName,
                Describe = () => descriptor,
                Description = descriptor.Description,
                ActivateAsync = async context =>
                {
                    var activity = await _activityActivator.ActivateActivityAsync <RunTask>(context, cancellationToken);

                    activity.TaskName = taskDefinition.Name;
                    return activity;
                },
                CanExecuteAsync = async(context, instance) => await instance.CanExecuteAsync(context),
                ExecuteAsync = async(context, instance) => await instance.ExecuteAsync(context),
                ResumeAsync = async(context, instance) => await instance.ResumeAsync(context)
            });
        }
        private async Task <ActivityType> CreateWebhookActivityTypeAsync(Type payloadType, WebhookAttribute webhookAttribute, CancellationToken cancellationToken)
        {
            var descriptor = await _describesActivityType.DescribeAsync <Webhook>(cancellationToken);

            descriptor.Description = webhookAttribute.Description;
            descriptor.DisplayName = webhookAttribute.DisplayName;
            descriptor.Type        = webhookAttribute.ActivityType;

            var outputProperties = descriptor.OutputProperties.Where(x => x.Name != nameof(Webhook.Output)).ToList();

            outputProperties.Add(new ActivityOutputDescriptor(nameof(Webhook.Output), payloadType));
            descriptor.OutputProperties = outputProperties.ToArray();

            return(new ActivityType
            {
                Describe = () => descriptor,
                Description = descriptor.Description,
                DisplayName = descriptor.DisplayName,
                TypeName = descriptor.Type,
                Attributes = new Dictionary <string, object>
                {
                    [NotificationAttribute] = true,
                    [EventTypeAttribute] = webhookAttribute.EventType
                },
                ActivateAsync = async context => await _activityActivator.ActivateActivityAsync <Webhook>(context, cancellationToken),
                CanExecuteAsync = (context, instance) => instance.CanExecuteAsync(context),
                ExecuteAsync = (context, instance) => instance.ExecuteAsync(context),
                ResumeAsync = (context, instance) => instance.ResumeAsync(context),
            });
        }
Пример #3
0
        private async Task <ActivityType> CreateActivityTypeAsync(CommandDefinition command, CancellationToken cancellationToken)
        {
            async ValueTask <ActivityDescriptor> CreateDescriptorAsync()
            {
                var des = await _describesActivityType.DescribeAsync <SendCommand>(cancellationToken);

                des.Type            = command.Name;
                des.DisplayName     = command.DisplayName ?? command.Name;
                des.Description     = command.Description;
                des.InputProperties = des.InputProperties.Where(x => x.Name != nameof(SendCommand.CommandName)).ToArray();

                return(des);
            }

            var descriptor = await CreateDescriptorAsync();

            return(new ActivityType
            {
                Type = typeof(SendCommand),
                TypeName = descriptor.Type,
                DisplayName = descriptor.DisplayName,
                DescribeAsync = CreateDescriptorAsync,
                Description = descriptor.Description,
                ActivateAsync = async context =>
                {
                    var activity = await _activityActivator.ActivateActivityAsync <SendCommand>(context, cancellationToken);

                    activity.CommandName = command.Name;
                    return activity;
                },
                CanExecuteAsync = async(context, instance) => await instance.CanExecuteAsync(context),
                ExecuteAsync = async(context, instance) => await instance.ExecuteAsync(context),
                ResumeAsync = async(context, instance) => await instance.ResumeAsync(context)
            });
        }
Пример #4
0
        private ActivityType CreateWebhookActivityType(WebhookDefinition webhook)
        {
            var typeName    = webhook.Name;
            var displayName = webhook.Name;

            var descriptor = new ActivityDescriptor
            {
                Type            = typeName,
                DisplayName     = displayName,
                Category        = WebhookActivityCategory,
                Outcomes        = new[] { OutcomeNames.Done },
                Traits          = ActivityTraits.Trigger,
                InputProperties = new[]
                {
                    new ActivityInputDescriptor(
                        nameof(HttpEndpoint.Methods),
                        typeof(HashSet <string>),
                        ActivityInputUIHints.Dropdown,
                        "Request Method",
                        "Specify what request method this webhook should handle. Leave empty to handle both GET and POST requests",
                        new[] { "", "GET", "POST" },
                        "Webhooks",
                        0,
                        "POST",
                        SyntaxNames.Literal,
                        new[] { SyntaxNames.JavaScript, SyntaxNames.Liquid })
                }
            };

            async ValueTask <IActivity> ActivateActivityAsync(ActivityExecutionContext context)
            {
                var activity = await _activityActivator.ActivateActivityAsync <HttpEndpoint>(context);

                activity.Path        = webhook.Path;
                activity.ReadContent = true;
                activity.TargetType  = webhook.PayloadTypeName is not null and not "" ? Type.GetType(webhook.PayloadTypeName) : throw new Exception($"Type {webhook.PayloadTypeName} not found");
                return(activity);
            }

            return(new ActivityType
            {
                TypeName = webhook.Name,
                Type = typeof(HttpEndpoint),
                Description = webhook.Description is not null and not "" ? webhook.Description : $"A webhook at {webhook.Path}",
                DisplayName = webhook.Name,
                ActivateAsync = ActivateActivityAsync,
                Describe = () => descriptor
            });
        private async Task <ActivityType> CreateActivityTypeAsync(EventDefinition eventDefinition, CancellationToken cancellationToken)
        {
            async ValueTask <ActivityDescriptor> CreateDescriptorAsync()
            {
                var des = await _describesActivityType.DescribeAsync <EventReceived>(cancellationToken);

                des.Type            = eventDefinition.Name;
                des.DisplayName     = eventDefinition.DisplayName ?? eventDefinition.Name;
                des.Description     = eventDefinition.Description;
                des.InputProperties = Array.Empty <ActivityInputDescriptor>();
                des.Outcomes        = eventDefinition.Outcomes?.ToArray() ?? new[] { OutcomeNames.Done };

                return(des);
            }

            var descriptor = await CreateDescriptorAsync();

            return(new ActivityType
            {
                Type = typeof(EventReceived),
                TypeName = descriptor.Type,
                DisplayName = descriptor.DisplayName,
                DescribeAsync = CreateDescriptorAsync,
                Description = descriptor.Description,
                ActivateAsync = async context =>
                {
                    var activity = await _activityActivator.ActivateActivityAsync <EventReceived>(context, cancellationToken);

                    activity.EventName = eventDefinition.Name;
                    return activity;
                },
                CanExecuteAsync = async(context, instance) => await instance.CanExecuteAsync(context),
                ExecuteAsync = async(context, instance) => await instance.ExecuteAsync(context),
                ResumeAsync = async(context, instance) => await instance.ResumeAsync(context)
            });
        }
Пример #6
0
 public static async Task <T> ActivateActivityAsync <T>(this IActivityActivator activityActivator, ActivityExecutionContext context, CancellationToken cancellationToken = default) where T : IActivity =>
 (T)await activityActivator.ActivateActivityAsync(context, typeof(T), cancellationToken);