From fb70022e87b492bb70a5cac9d52e2d206d1c82a9 Mon Sep 17 00:00:00 2001 From: Sipke Schoorstra Date: Wed, 18 Dec 2024 15:37:38 +0100 Subject: [PATCH] Add `Variable` parameter to `StorageDriverContext` Updated `StorageDriverContext` to include a `Variable` parameter, ensuring more precise context handling for variable-related operations. Adjusted relevant method calls to pass the required `Variable` argument where necessary. --- .../Elsa.Workflows.Core/Contexts/StorageDriverContext.cs | 3 ++- .../Services/VariablePersistenceManager.cs | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/modules/Elsa.Workflows.Core/Contexts/StorageDriverContext.cs b/src/modules/Elsa.Workflows.Core/Contexts/StorageDriverContext.cs index ea39f67cf..aed6ed1d5 100644 --- a/src/modules/Elsa.Workflows.Core/Contexts/StorageDriverContext.cs +++ b/src/modules/Elsa.Workflows.Core/Contexts/StorageDriverContext.cs @@ -1,8 +1,9 @@ using Elsa.Workflows.Contracts; +using Elsa.Workflows.Memory; namespace Elsa.Workflows; /// /// Provides context for storage drivers. /// -public record StorageDriverContext(IExecutionContext ExecutionContext, CancellationToken CancellationToken); \ No newline at end of file +public record StorageDriverContext(IExecutionContext ExecutionContext, Variable Variable, CancellationToken CancellationToken); \ No newline at end of file diff --git a/src/modules/Elsa.Workflows.Core/Services/VariablePersistenceManager.cs b/src/modules/Elsa.Workflows.Core/Services/VariablePersistenceManager.cs index 0bd89f183..fa9f10b9a 100644 --- a/src/modules/Elsa.Workflows.Core/Services/VariablePersistenceManager.cs +++ b/src/modules/Elsa.Workflows.Core/Services/VariablePersistenceManager.cs @@ -31,7 +31,7 @@ public class VariablePersistenceManager : IVariablePersistenceManager foreach (var variable in variables) { context.ExpressionExecutionContext.Memory.Declare(variable); - var storageDriverContext = new StorageDriverContext(context, cancellationToken); + var storageDriverContext = new StorageDriverContext(context, variable, cancellationToken); var register = context.ExpressionExecutionContext.Memory; var block = EnsureBlock(register, variable); var metadata = (VariableBlockMetadata)block.Metadata!; @@ -62,7 +62,6 @@ public class VariablePersistenceManager : IVariablePersistenceManager foreach (var context in contexts) { var variables = GetLocalVariables(context).ToList(); - var storageDriverContext = new StorageDriverContext(context, cancellationToken); foreach (var variable in variables) { @@ -75,6 +74,7 @@ public class VariablePersistenceManager : IVariablePersistenceManager var id = GetStateId(variable); var value = block.Value; + var storageDriverContext = new StorageDriverContext(context, variable, cancellationToken); if (value == null) await driver.DeleteAsync(id, storageDriverContext); @@ -91,7 +91,6 @@ public class VariablePersistenceManager : IVariablePersistenceManager var register = context.ExpressionExecutionContext.Memory; var variableList = GetLocalVariables(context).ToList(); var cancellationToken = context.CancellationToken; - var storageDriverContext = new StorageDriverContext(context, cancellationToken); foreach (var variable in variableList) { @@ -105,6 +104,7 @@ public class VariablePersistenceManager : IVariablePersistenceManager continue; var id = GetStateId(variable); + var storageDriverContext = new StorageDriverContext(context, variable, cancellationToken); await driver.DeleteAsync(id, storageDriverContext); register.Blocks.Remove(variable.Id); }