Exemplo n.º 1
0
        public static async Task <TypeStoreInfo> GetOrAddTypeStoreAsync(IMd dbInfoMd, string dbId)
        {
            IMd typeStoreHead;
            var typeStoreResult = await dbInfoMd.GetValueAsync(TYPE_STORE_HEAD_KEY).ConfigureAwait(false);

            if (!typeStoreResult.HasValue)
            {
                typeStoreHead = await MdAccess.CreateAsync(0)
                                .ConfigureAwait(false);

                await dbInfoMd.AddAsync(TYPE_STORE_HEAD_KEY, new StoredValue(typeStoreHead.MdLocator))
                .ConfigureAwait(false);
            }
            else
            {
                var typeStoreHeadLocation = typeStoreResult.Value.Payload.Parse <MdLocator>();
                typeStoreHead = (await MdAccess.LocateAsync(typeStoreHeadLocation)
                                 .ConfigureAwait(false)).Value;
            }

            Task onHeadChange(MdLocator newLocation) => dbInfoMd.SetAsync(TYPE_STORE_HEAD_KEY, new StoredValue(newLocation));

            var dataTree = new DataTree(typeStoreHead, onHeadChange);

            return(new TypeStoreInfo(dataTree));
        }
Exemplo n.º 2
0
 DirectoryInfo SetupDirectoryInfo(FileSystemPath path, IMd md)
 {
     return(new DirectoryInfo(path.Path, md.MdLocator,
                              (key) => md.GetValueAsync(key).GetAwaiter().GetResult(),
                              (key, val) => md.SetAsync(key, val).GetAwaiter().GetResult()));
 }