Allow access to parent activity state from child activity
This commit is contained in:
parent
0cdd46f8ca
commit
e23cf08f81
|
|
@ -15,6 +15,7 @@ namespace Elsa.Models
|
|||
ExecutionLog = new List<ExecutionLogEntry>();
|
||||
ScheduledActivities = new Stack<ScheduledActivity>();
|
||||
PostScheduledActivities = new Stack<ScheduledActivity>();
|
||||
ParentActivities = new Stack<string>();
|
||||
}
|
||||
|
||||
public int Id { get; set; }
|
||||
|
|
@ -40,5 +41,6 @@ namespace Elsa.Models
|
|||
public WorkflowFault? Fault { get; set; }
|
||||
public Stack<ScheduledActivity> ScheduledActivities { get; set; }
|
||||
public Stack<ScheduledActivity> PostScheduledActivities { get; set; }
|
||||
public Stack<string> ParentActivities { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
@ -20,10 +20,14 @@ namespace Elsa.Services
|
|||
protected override IActivityExecutionResult OnExecute(ActivityExecutionContext context)
|
||||
{
|
||||
if (IsScheduled)
|
||||
{
|
||||
context.WorkflowExecutionContext.WorkflowInstance.ParentActivities.Pop();
|
||||
return Complete(context);
|
||||
}
|
||||
|
||||
var compositeActivityBlueprint = (ICompositeActivityBlueprint)context.ActivityBlueprint;
|
||||
var startActivities = compositeActivityBlueprint.GetStartActivities().Select(x => x.Id).ToList();
|
||||
context.WorkflowExecutionContext.WorkflowInstance.ParentActivities.Push(Id);
|
||||
context.WorkflowExecutionContext.PostScheduleActivity(Id);
|
||||
IsScheduled = true;
|
||||
return Schedule(startActivities, context.Input);
|
||||
|
|
|
|||
|
|
@ -30,12 +30,12 @@ namespace Elsa.Services.Models
|
|||
var workflowBlueprint = ActivityExecutionContext.WorkflowExecutionContext.WorkflowBlueprint;
|
||||
var activityId = ActivityExecutionContext.ActivityBlueprint.Id;
|
||||
|
||||
// Computed property setters that depend on actual workflow state might fault, since we are using a fake activity execution context.
|
||||
// Computed property setters that depend on actual workflow state might fault, since we might be using a fake activity execution context.
|
||||
try
|
||||
{
|
||||
return await workflowBlueprint.GetActivityPropertyValue(activityId, propertyExpression, ActivityExecutionContext, cancellationToken);
|
||||
}
|
||||
catch (Exception e)
|
||||
catch (Exception)
|
||||
{
|
||||
return default;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -42,6 +42,10 @@ namespace Elsa.Services.Models
|
|||
set => ActivityInstance.Output = value;
|
||||
}
|
||||
|
||||
public ActivityBlueprintWrapper<T> Parent<T>() where T : IActivity => new(new ActivityExecutionContext(ServiceScope, WorkflowExecutionContext,
|
||||
WorkflowExecutionContext.GetActivityBlueprintById(WorkflowExecutionContext.WorkflowInstance.ParentActivities.Peek()),
|
||||
null, CancellationToken));
|
||||
|
||||
public void SetVariable(string name, object? value) => WorkflowExecutionContext.SetVariable(name, value);
|
||||
public object? GetVariable(string name) => WorkflowExecutionContext.GetVariable(name);
|
||||
public T GetVariable<T>(string name) => WorkflowExecutionContext.GetVariable<T>(name);
|
||||
|
|
|
|||
Loading…
Reference in a new issue