Added support for accessing activity data when providing available endpoints

This commit is contained in:
Sipke Schoorstra 2019-01-01 22:25:26 +01:00
parent 7f32b09fa7
commit 57875e3aa3
4 changed files with 6 additions and 4 deletions

View file

@ -32,7 +32,9 @@ namespace Elsa.Handlers
protected virtual ActivityExecutionResult OnResume(T activity, WorkflowExecutionContext workflowContext) => Noop();
protected NoopResult Noop() => new NoopResult();
protected IEnumerable<LocalizedString> Endpoints(params LocalizedString[] endpoints) => endpoints;
public virtual IEnumerable<LocalizedString> GetEndpoints(IActivity activity) => Endpoints();
public virtual IEnumerable<LocalizedString> GetEndpoints() => Endpoints(GetEndpoint());
protected virtual LocalizedString GetEndpoint() => throw new NotImplementedException("At least GetEndpoints or GetEndpoint must be overridden.");
protected virtual LocalizedString GetEndpoint(IActivity activity) => GetEndpoint();
protected virtual LocalizedString GetEndpoint() => new LocalizedString("Done", "Done", true);
}
}

View file

@ -39,7 +39,7 @@ namespace Elsa
/// Returns the available endpoints that can be triggered.
/// </summary>
/// <returns></returns>
IEnumerable<LocalizedString> GetEndpoints();
IEnumerable<LocalizedString> GetEndpoints(IActivity activity);
/// <summary>
/// Returns a value of whether the specified activity can execute.

View file

@ -16,7 +16,7 @@ namespace Elsa.Models
public Type ActivityType { get; set; }
public LocalizedString DisplayText { get; set; }
public LocalizedString Description { get; set; }
public Func<IEnumerable<LocalizedString>> GetEndpoints { get; set; }
public Func<IActivity, IEnumerable<LocalizedString>> GetEndpoints { get; set; }
public Func<ActivityExecutionContext, WorkflowExecutionContext, CancellationToken, Task<bool>> CanExecuteAsync { get; set; }
public Func<ActivityExecutionContext, WorkflowExecutionContext, CancellationToken, Task<ActivityExecutionResult>> ExecuteAsync { get; set; }
public Func<ActivityExecutionContext, WorkflowExecutionContext, CancellationToken, Task<ActivityExecutionResult>> ResumeAsync { get; set; }

View file

@ -25,7 +25,7 @@ namespace Elsa.Web.Components.Services
var designerMetadata = customFields.GetValue("Designer", StringComparison.OrdinalIgnoreCase)?.ToObject<ActivityDesignerMetadata>() ?? new ActivityDesignerMetadata();
shape.Metadata.Type = $"Activity_Design";
shape.Endpoints = descriptor.GetEndpoints().ToList();
shape.Endpoints = descriptor.GetEndpoints(activity).ToList();
shape.ActivityDescriptor = descriptor;
shape.Activity = activity;
shape.Designer = designerMetadata;