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)); }
public static IMdNode Locate(MdLocator locator) { // try find on network var key = locator.Json(); if (!_allMds.ContainsKey(key)) { // if not found, create with level 0 var newMd = new InMemoryMd(locator, 0); _allMds[key] = newMd; return(newMd); } return(_allMds[key]); }
public static Task <Result <IMdNode> > LocateAsync(MdLocator location) { return(_locator(location)); }
InMemoryMd(MdLocator locator, int level) { MdLocator = locator; _valueFields["0"] = new StoredValue(level); }
private InMemoryMd(int level) { MdLocator = new MdLocator(new byte[32], DataProtocol.DEFAULT_PROTOCOL, null, null); _rand.NextBytes(MdLocator.XORName); _valueFields["0"] = new StoredValue(level); }
public async Task AddAsync(string type, MdLocator location) { var value = new StoredValue(location); await _dataTree.AddAsync(type, value).ConfigureAwait(false); }