Update middleware to also inspect memory block for output values
This commit is contained in:
parent
e16d11f262
commit
287442ca7e
|
|
@ -470,15 +470,9 @@ public class ActivityExecutionContext : IExecutionContext
|
|||
/// <exception cref="InvalidOperationException">The memory block does not exist.</exception>
|
||||
public object? Get(MemoryBlockReference blockReference)
|
||||
{
|
||||
var memoryBlock = GetMemoryBlock(blockReference);
|
||||
|
||||
if (memoryBlock != null)
|
||||
return memoryBlock.Value;
|
||||
|
||||
if (blockReference is Literal literal)
|
||||
return literal.Value;
|
||||
|
||||
throw new InvalidOperationException($"The memory block '{blockReference}' does not exist.");
|
||||
return !TryGet(blockReference, out var value)
|
||||
? throw new InvalidOperationException($"The memory block '{blockReference}' does not exist.")
|
||||
: value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -493,6 +487,32 @@ public class ActivityExecutionContext : IExecutionContext
|
|||
return value != default ? value.ConvertTo<T>() : default;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tries to get the value of the specified memory block.
|
||||
/// </summary>
|
||||
/// <param name="blockReference">The memory block reference.</param>
|
||||
/// <param name="value">The memory block value.</param>
|
||||
/// <returns>True if the memory block exists, false otherwise.</returns>
|
||||
public bool TryGet(MemoryBlockReference blockReference, out object? value)
|
||||
{
|
||||
var memoryBlock = GetMemoryBlock(blockReference);
|
||||
|
||||
if (memoryBlock != null)
|
||||
{
|
||||
value = memoryBlock.Value;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (blockReference is Literal literal)
|
||||
{
|
||||
value = literal.Value;
|
||||
return true;
|
||||
}
|
||||
|
||||
value = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets a value at the specified memory block.
|
||||
/// </summary>
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
using Elsa.Extensions;
|
||||
using Elsa.Mediator.Contracts;
|
||||
using Elsa.Workflows.Core;
|
||||
using Elsa.Workflows.Core.Models;
|
||||
using Elsa.Workflows.Core.Pipelines.WorkflowExecution;
|
||||
using Elsa.Workflows.Core.State;
|
||||
using Elsa.Workflows.Runtime.Contracts;
|
||||
|
|
@ -48,7 +49,19 @@ public class PersistActivityExecutionLogMiddleware : WorkflowExecutionMiddleware
|
|||
var expressionExecutionContext = activityExecutionContext.ExpressionExecutionContext;
|
||||
var activityDescriptor = activityExecutionContext.ActivityDescriptor;
|
||||
var outputDescriptors = activityDescriptor.Outputs;
|
||||
var outputs = outputDescriptors.ToDictionary(x => x.Name, x => activity.GetOutput(expressionExecutionContext, x.Name)!);
|
||||
|
||||
var outputs = outputDescriptors.ToDictionary(x => x.Name, x =>
|
||||
{
|
||||
var cachedValue = activity.GetOutput(expressionExecutionContext, x.Name);
|
||||
|
||||
if(cachedValue != default)
|
||||
return cachedValue;
|
||||
|
||||
if(x.ValueGetter(activity) is Output output && activityExecutionContext.TryGet(output.MemoryBlockReference(), out var outputValue))
|
||||
return outputValue;
|
||||
|
||||
return default;
|
||||
});
|
||||
|
||||
return new ActivityExecutionRecord
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in a new issue