private async Task <ActivityType?> CreateActivityTypeAsync(Type activityType, CancellationToken cancellationToken) { var info = await _describesActivityType.DescribeAsync(activityType, cancellationToken); return(new ActivityType { TypeName = info.Type, Type = activityType, Description = info.Description, DisplayName = info.DisplayName, ActivateAsync = async context => await ActivateActivity(context, activityType), DescribeAsync = async() => (await _describesActivityType.DescribeAsync(activityType, cancellationToken)) !, 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> 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), }); }
private async Task <ActivityType?> CreateActivityTypeAsync(Type activityType, CancellationToken cancellationToken) { var info = await _describesActivityType.DescribeAsync(activityType, cancellationToken); if (info == null) { return(default);
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) }); }
private async Task <ActivityType> CreateActivityTypeAsync(Type activityType, CancellationToken cancellationToken) { var info = await _describesActivityType.DescribeAsync(activityType, cancellationToken); return(new ActivityType { TypeName = info.Type, Type = activityType, Description = info.Description, DisplayName = info.DisplayName, IsBrowsable = activityType.GetCustomAttribute <BrowsableAttribute>(false)?.Browsable ?? true, ActivateAsync = async context => await ActivateActivity(context, activityType), DescribeAsync = async() => (await _describesActivityType.DescribeAsync(activityType, cancellationToken)) !, 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> 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) }); }
public static async Task <ActivityDescriptor> DescribeAsync <T>(this IDescribesActivityType type, CancellationToken cancellationToken = default) where T : IActivity => (await type.DescribeAsync(typeof(T), cancellationToken)) !;