Simplify memory API names

This commit is contained in:
Sipke Schoorstra 2022-06-04 20:03:40 +02:00
parent 1fc93afcb2
commit ea40b05a6b
10 changed files with 17 additions and 17 deletions

View file

@ -8,13 +8,13 @@ public class ExpressionExecutionContext
public ExpressionExecutionContext(
IServiceProvider serviceProvider,
MemoryRegister memoryRegister,
MemoryRegister memory,
ExpressionExecutionContext? parentContext = default,
IDictionary<object, object>? applicationProperties = default,
CancellationToken cancellationToken = default)
{
_serviceProvider = serviceProvider;
MemoryRegister = memoryRegister;
Memory = memory;
ApplicationProperties = applicationProperties ?? new Dictionary<object, object>();
ParentContext = parentContext;
@ -24,7 +24,7 @@ public class ExpressionExecutionContext
/// <summary>
/// A shared register of computer memory.
/// </summary>
public MemoryRegister MemoryRegister { get; }
public MemoryRegister Memory { get; }
public IDictionary<object, object> ApplicationProperties { get; set; }
public ExpressionExecutionContext? ParentContext { get; set; }
@ -36,12 +36,12 @@ public class ExpressionExecutionContext
public void Set(MemoryReference reference, object? value)
{
var datum = GetMemoryDatumInternal(reference) ?? MemoryRegister.Declare(reference);
var datum = GetMemoryDatumInternal(reference) ?? Memory.Declare(reference);
datum.Value = value;
}
public T GetRequiredService<T>() where T : notnull => _serviceProvider.GetRequiredService<T>();
//private MemoryDatum? GetMemoryDatumInternal(MemoryDatumReference locationReference) => MemoryRegister.TryGetMemoryDatum(locationReference.Id, out var location) ? location : ParentContext?.GetMemoryDatumInternal(locationReference);
private MemoryBlock? GetMemoryDatumInternal(MemoryReference reference) => MemoryRegister.TryGetMemoryDatum(reference.Id, out var location) ? location : default;
private MemoryBlock? GetMemoryDatumInternal(MemoryReference reference) => Memory.TryGetMemoryDatum(reference.Id, out var location) ? location : default;
}

View file

@ -8,17 +8,17 @@ public class MemoryRegister
public MemoryRegister(MemoryRegister? parent = default, IDictionary<string, MemoryBlock>? locations = default)
{
Parent = parent;
MemoryBlocks = locations ?? new Dictionary<string, MemoryBlock>();
Blocks = locations ?? new Dictionary<string, MemoryBlock>();
}
public MemoryRegister? Parent { get; }
public IDictionary<string, MemoryBlock> MemoryBlocks { get; }
public IDictionary<string, MemoryBlock> Blocks { get; }
public bool TryGetMemoryDatum(string id, out MemoryBlock datum)
{
datum = null!;
if (MemoryBlocks.TryGetValue(id, out datum!))
if (Blocks.TryGetValue(id, out datum!))
return true;
return Parent?.TryGetMemoryDatum(id, out datum) == true;
@ -33,7 +33,7 @@ public class MemoryRegister
public MemoryBlock Declare(MemoryReference reference)
{
var datum = reference.Declare();
MemoryBlocks[reference.Id] = datum;
Blocks[reference.Id] = datum;
return datum;
}
}

View file

@ -22,7 +22,7 @@ public class ConfigureJavaScriptEngineWithActivityOutput : INotificationHandler<
var engine = notification.Engine;
var workflow = notification.Context.GetWorkflow();
var graph = _activityWalker.Walk(workflow.Root).Flatten();
var register = notification.Context.MemoryRegister;
var register = notification.Context.Memory;
var jsActivities = new Dictionary<string, object>();
foreach (var node in graph)

View file

@ -71,7 +71,7 @@ namespace Elsa.JavaScript.Implementations
while (currentContext != null)
{
foreach (var l in currentContext.MemoryRegister.MemoryBlocks)
foreach (var l in currentContext.Memory.Blocks)
{
if(!dictionary.ContainsKey(l.Key))
dictionary.Add(l.Key, l.Value);

View file

@ -32,7 +32,7 @@ public abstract class Container : Activity, IContainer
protected override async ValueTask ExecuteAsync(ActivityExecutionContext context)
{
// Register variables.
context.ExpressionExecutionContext.MemoryRegister.Declare(Variables);
context.ExpressionExecutionContext.Memory.Declare(Variables);
// Schedule children.
await ScheduleChildrenAsync(context);

View file

@ -45,7 +45,7 @@ public class For : Activity
if (iterateNode == null)
return;
context.ExpressionExecutionContext.MemoryRegister.Declare(CurrentValue);
context.ExpressionExecutionContext.Memory.Declare(CurrentValue);
HandleIteration(context);
}

View file

@ -33,7 +33,7 @@ public class ActivityInvoker : IActivityInvoker
var transientProperties = workflowExecutionContext.TransientProperties;
var input = workflowExecutionContext.Input;
var applicationProperties = ExpressionExecutionContextExtensions.CreateApplicationPropertiesFrom(workflow, transientProperties, input);
var parentMemory = parentActivityExecutionContext?.ExpressionExecutionContext.MemoryRegister ?? workflowMemory;
var parentMemory = parentActivityExecutionContext?.ExpressionExecutionContext.Memory ?? workflowMemory;
var activityMemory = new MemoryRegister(workflowMemory);
var expressionExecutionContext = new ExpressionExecutionContext(_serviceProvider, parentMemory, parentExpressionExecutionContext, applicationProperties, cancellationToken);
var activityExecutionContext = new ActivityExecutionContext(workflowExecutionContext, parentActivityExecutionContext, expressionExecutionContext, activity, cancellationToken);

View file

@ -109,7 +109,7 @@ public class WorkflowStateSerializer : IWorkflowStateSerializer
{
ActivityExecutionContextState CreateActivityExecutionContextState(ActivityExecutionContext activityExecutionContext)
{
var registerState = new RegisterState(activityExecutionContext.ExpressionExecutionContext.MemoryRegister.MemoryBlocks);
var registerState = new RegisterState(activityExecutionContext.ExpressionExecutionContext.Memory.Blocks);
var activityExecutionContextState = new ActivityExecutionContextState
{
Id = activityExecutionContext.Id,

View file

@ -177,7 +177,7 @@ public class ActivityExecutionContext
}
private MemoryBlock? GetLocation(MemoryReference locationReference) =>
ExpressionExecutionContext.MemoryRegister.TryGetMemoryDatum(locationReference.Id, out var location)
ExpressionExecutionContext.Memory.TryGetMemoryDatum(locationReference.Id, out var location)
? location
: ParentActivityExecutionContext?.GetLocation(locationReference);
}

View file

@ -171,5 +171,5 @@ public class WorkflowExecutionContext
return currentMainStatus != WorkflowStatus.Finished;
}
private IEnumerable<MemoryRegister> GetMergedRegistersView() => new[] { MemoryRegister }.Concat(ActivityExecutionContexts.Select(x => x.ExpressionExecutionContext.MemoryRegister)).ToList();
private IEnumerable<MemoryRegister> GetMergedRegistersView() => new[] { MemoryRegister }.Concat(ActivityExecutionContexts.Select(x => x.ExpressionExecutionContext.Memory)).ToList();
}