Example #1
0
        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);
        }
Example #2
0
        /// <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();
        }
 public void DeserializeStateStore(byte[] bytes)
 {
     using var stream = new MemoryStream(bytes);
     _stateStore      = InMemoryStateStore.Load(stream);
 }
 public StateStoreConnection()
 {
     _stateStore = new InMemoryStateStore(StateStoreId);
 }