Пример #1
0
        // level 0 gives new leaf
        public static IMdNode 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 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]);
        }
Пример #4
0
 public static void UseInMemoryDb()
 {
     SetCreator(level => Task.FromResult(InMemoryMd.Create(level)));
     SetLocator(location => Task.FromResult(Result.OK(InMemoryMd.Locate(location))));
 }