/// <summary> /// Update the content of the store with the content of <paramref name="update"/>. /// Any value present in <paramref name="update"/> overwrite the existing value in the store /// if present. /// Similarly, any deleted value in <paramref name="update"/> trigger the deletion of /// the value with the corresponding category and key in the store if present. /// <remarks>As part of this operation, the content of <paramref name="update"/> is cleared.</remarks> /// </summary> /// <param name="update">The store containing the updated values</param> public void Update(InMemoryStateStore update) { if (update == null) { throw new ArgumentNullException(nameof(update)); } foreach (var category in update._removedItems.Keys) { if (update._removedItems.TryGetValue(category, out var items)) { while (items.TryTake(out var key)) { RemoveItem(category, key); } } } foreach (var category in update._internalStore.Keys) { if (update._internalStore.TryGetValue(category, out var items)) { foreach (var key in items.Keys) { if (items.TryGetValue(key, out var value)) { AddOrUpdateItem(category, key, value); } } } } update.Clear(); }
private static InMemoryStateStore Load(XDocument doc) { var store = doc.Element("Store"); var id = store.Attribute("Id").Value; var res = new InMemoryStateStore(id); var categories = store.Elements("Category"); foreach (var category in categories) { var categoryName = category.Attribute("Name").Value; var entries = category.Elements("Entry"); foreach (var entry in entries) { var keyName = entry.Attribute("Name").Value; var base64 = entry.Nodes().OfType <XCData>().Single().Value; var value = Convert.FromBase64String(base64); res.AddOrUpdateItem(categoryName, keyName, value); } } return(res); }
/// <summary> /// Create a new instance of <see cref="InMemoryStateWriter"/>. /// </summary> /// <param name="stateStore">The store where the state is persisted.</param> /// <param name="checkpointKind">The checkpoint kind.</param> /// <param name="onCommit">The action to be called when committing.</param> /// <param name="onRollback">The action to be called when rolling back.</param> public InMemoryStateWriter( InMemoryStateStore stateStore, CheckpointKind checkpointKind, Action onCommit = null, Action onRollback = null) { _onRollback = onRollback; _onCommit = onCommit; _stateStore = stateStore ?? throw new ArgumentNullException(nameof(stateStore)); CheckpointKind = checkpointKind; }
/// <summary> /// Create a new instance of <see cref="InMemoryStateReader"/>. /// </summary> /// <param name="store">The store containing the state.</param> public InMemoryStateReader(InMemoryStateStore store) { _store = store ?? throw new ArgumentNullException(nameof(store)); }