public async Task <Result <Pointer> > UpdateAsync(string type, MdLocator location)
        {
            var(pointer, value) = (await _dataTree.GetAllPointerValuesAsync().ConfigureAwait(false))
                                  .Single(c => c.Item1.MdKey == type);
            var mdResult = await MdAccess.LocateAsync(pointer.MdLocator).ConfigureAwait(false);

            if (!mdResult.HasValue)
            {
                return(Result.Fail <Pointer>(mdResult.ErrorCode.Value, mdResult.ErrorMsg));
            }
            value.Payload = location.Json();
            return(await mdResult.Value.SetAsync(type, value).ConfigureAwait(false));
        }
示例#2
0
        /// <summary>
        /// Instead of traversing through the tree on every add,
        /// we keep a reference to current leaf, and add to it directly.
        /// </summary>
        /// <param name="key">Key under which the value will be stored.</param>
        /// <param name="value">The value to store.</param>
        /// <returns>A pointer to the value that was added.</returns>
        async Task <Result <Pointer> > DirectlyAddToLeaf(string key, StoredValue value)
        {
            if (_currentLeaf == null)
            {
                _currentLeaf = _head;
            }
            else if (_currentLeaf.IsFull)
            {
                var result = await _head.AddAsync(key, value).ConfigureAwait(false);

                var leafResult = await MdAccess.LocateAsync(result.Value.MdLocator);

                if (leafResult.HasValue)
                {
                    _currentLeaf = leafResult.Value;
                }
                return(result);
            }

            return(await _currentLeaf.AddAsync(key, value));
        }