コード例 #1
0
        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
        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]);
        }
コード例 #3
0
 public static Task <Result <IMdNode> > LocateAsync(MdLocator location)
 {
     return(_locator(location));
 }
コード例 #4
0
 InMemoryMd(MdLocator locator, int level)
 {
     MdLocator         = locator;
     _valueFields["0"] = new StoredValue(level);
 }
コード例 #5
0
 private InMemoryMd(int level)
 {
     MdLocator = new MdLocator(new byte[32], DataProtocol.DEFAULT_PROTOCOL, null, null);
     _rand.NextBytes(MdLocator.XORName);
     _valueFields["0"] = new StoredValue(level);
 }
コード例 #6
0
 public async Task AddAsync(string type, MdLocator location)
 {
     var value = new StoredValue(location);
     await _dataTree.AddAsync(type, value).ConfigureAwait(false);
 }