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)); }
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)); }
public async Task <Result <Pointer> > AddAsync(string key, StoredValue value) { if (_head.IsFull) { // create new head, add pointer to current head in to it. // the level > 0 indicates its role as pointer holder var newHead = await MdAccess.CreateAsync(_head.Level + 1).ConfigureAwait(false); var pointer = new Pointer { MdLocator = _head.MdLocator, ValueType = typeof(Pointer).Name }; await newHead.AddAsync(pointer).ConfigureAwait(false); _head = newHead; await _onHeadAddressChange(newHead.MdLocator).ConfigureAwait(false); } return(await DirectlyAddToLeaf(key, value).ConfigureAwait(false)); }