| | | 1 | | using System.ComponentModel.DataAnnotations; |
| | | 2 | | |
| | | 3 | | namespace Elsa.Workflows; |
| | | 4 | | |
| | | 5 | | /// <summary> |
| | | 6 | | /// A storage driver that stores objects in memory. |
| | | 7 | | /// </summary> |
| | | 8 | | [Display(Name = "Memory")] |
| | | 9 | | public class MemoryStorageDriver : IStorageDriver |
| | | 10 | | { |
| | 421 | 11 | | private readonly IDictionary<string, object> _dictionary = new Dictionary<string, object>(); |
| | | 12 | | /// <inheritdoc /> |
| | 0 | 13 | | public double Priority => 0; |
| | | 14 | | /// <inheritdoc /> |
| | 0 | 15 | | public IEnumerable<string> Tags => []; |
| | | 16 | | |
| | | 17 | | /// <inheritdoc /> |
| | | 18 | | public ValueTask WriteAsync(string id, object value, StorageDriverContext context) |
| | | 19 | | { |
| | 0 | 20 | | _dictionary[id] = value; |
| | 0 | 21 | | return ValueTask.CompletedTask; |
| | | 22 | | } |
| | | 23 | | |
| | | 24 | | /// <inheritdoc /> |
| | | 25 | | public ValueTask<object?> ReadAsync(string id, StorageDriverContext context) |
| | | 26 | | { |
| | 0 | 27 | | var value = _dictionary.TryGetValue(id, out var v) ? v : default; |
| | 0 | 28 | | return new (value); |
| | | 29 | | } |
| | | 30 | | |
| | | 31 | | /// <inheritdoc /> |
| | | 32 | | public ValueTask DeleteAsync(string id, StorageDriverContext context) |
| | | 33 | | { |
| | 0 | 34 | | _dictionary.Remove(id); |
| | 0 | 35 | | return ValueTask.CompletedTask; |
| | | 36 | | } |
| | | 37 | | } |