示例#1
0
        // level 0 gives new leaf
        public static IMd Create(int level)
        {
            var newMd = new InMemoryMd(level);

            _allMds[newMd.MdLocator.Json()] = newMd;
            return(newMd);
        }
示例#2
0
        Result <Pointer> ExpandLevel(string key, StoredValue value)
        {
            if (Level == 0)
            {
                return(new ArgumentOutOfRange <Pointer>(nameof(Level)));
            }

            var md          = InMemoryMd.Create(Level - 1);
            var leafPointer = (md as InMemoryMd).Add(key, value);

            if (!leafPointer.HasValue)
            {
                return(leafPointer);
            }

            switch (md.Type)
            {
            case MdType.Pointers:     // i.e. we have still not reached the end of the tree
                Add(new Pointer
                {
                    MdLocator = md.MdLocator,
                    ValueType = typeof(Pointer).Name
                });
                break;

            case MdType.Values:      // i.e. we are now right above leaf level
                Add(leafPointer.Value);
                break;

            default:
                return(new ArgumentOutOfRange <Pointer>(nameof(md.Type)));
            }

            return(leafPointer);
        }
示例#3
0
        public static IMd Locate(MdLocator location)
        {
            // try find on network
            var key = location.Json();

            if (!_allMds.ContainsKey(key)) // if not found, create with level 0
            {
                var md = InMemoryMd.Create(level: 0);
                _allMds[md.MdLocator.Json()] = md;
                return(md);
            }

            return(_allMds[key]);
        }
示例#4
0
 public static void UseInMemoryDb()
 {
     SetCreator(level => Task.FromResult(InMemoryMd.Create(level)));
     SetLocator(location => Task.FromResult(Result.OK(InMemoryMd.Locate(location))));
 }