< Summary

Information
Class: Elsa.Workflows.Services.WorkflowStorageDriver
Assembly: Elsa.Workflows.Core
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Core/VariableStorageDrivers/WorkflowStorageDriver.cs
Line coverage
53%
Covered lines: 8
Uncovered lines: 7
Coverable lines: 15
Total lines: 57
Line coverage: 53.3%
Branch coverage
0%
Covered branches: 0
Total branches: 2
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
get_Priority()100%210%
get_Tags()100%210%
WriteAsync(...)100%210%
ReadAsync(...)0%620%
DeleteAsync(...)100%11100%
GetVariablesDictionary(...)100%11100%
SetVariablesDictionary(...)100%11100%
UpdateVariablesDictionary(...)100%11100%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Core/VariableStorageDrivers/WorkflowStorageDriver.cs

#LineLine coverage
 1using System.ComponentModel.DataAnnotations;
 2using Elsa.Extensions;
 3
 4
 5// ReSharper disable once CheckNamespace
 6// Backwards compatibility for the old namespace.
 7namespace Elsa.Workflows.Services;
 8
 9/// <summary>
 10/// A storage driver that stores objects in the workflow state itself.
 11/// </summary>
 12[Display(Name = "Workflow")]
 13[Obsolete("This is no longer used and will be removed in a future version. Use the WorkflowInstanceStorageDriver instead
 14public class WorkflowStorageDriver : IStorageDriver
 15{
 16    /// <summary>
 17    /// The key used to store the variables in the workflow state.
 18    /// </summary>
 19    public const string VariablesDictionaryStateKey = "PersistentVariablesDictionary";
 20
 21    /// <inheritdoc />
 022    public double Priority => -1;
 23    /// <inheritdoc />
 024    public IEnumerable<string> Tags => [];
 25
 26    /// <inheritdoc />
 27    public ValueTask WriteAsync(string id, object value, StorageDriverContext context)
 28    {
 029        UpdateVariablesDictionary(context, dictionary => dictionary[id] = value);
 030        return ValueTask.CompletedTask;
 31    }
 32
 33    /// <inheritdoc />
 34    public ValueTask<object?> ReadAsync(string id, StorageDriverContext context)
 35    {
 036        var dictionary = GetVariablesDictionary(context);
 037        var value = dictionary.TryGetValue(id, out var v) ? v : default;
 038        return new(value);
 39    }
 40
 41    /// <inheritdoc />
 42    public ValueTask DeleteAsync(string id, StorageDriverContext context)
 43    {
 244        UpdateVariablesDictionary(context, dictionary => dictionary.Remove(id));
 145        return ValueTask.CompletedTask;
 46    }
 47
 248    private IDictionary<string, object> GetVariablesDictionary(StorageDriverContext context) => context.ExecutionContext
 149    private void SetVariablesDictionary(StorageDriverContext context, IDictionary<string, object> dictionary) => context
 50
 51    private void UpdateVariablesDictionary(StorageDriverContext context, Action<IDictionary<string, object>> update)
 52    {
 153        var dictionary = GetVariablesDictionary(context);
 154        update(dictionary);
 155        SetVariablesDictionary(context, dictionary);
 156    }
 57}