async Task <Result <IStreamDb> > GetOrAddAsync(MdHead streamDbHead) { var streamDbRoot = new DataTree(streamDbHead.Md, (s) => throw new ArgumentOutOfRangeException("Can only add 999 items to this collection.")); var streamCollection = await _streamCollectionFactory.GetOrAddCollectionAsync(streamDbRoot); var db = new StreamDb(streamCollection, NodeFactory); return(Result.OK((IStreamDb)db)); }
public static async Task <Result <Directory> > GetOrAddAsync(MdHead mdHead, IIndexer indexer) { var typeInfo = await TypeStoreInfoFactory.GetOrAddTypeStoreAsync(mdHead.Md, mdHead.Id).ConfigureAwait(false); var db = new Directory(mdHead.Md, typeInfo, indexer); var typeStores = await typeInfo.GetAllAsync().ConfigureAwait(false); db._dataTreeAddresses = typeStores .ToDictionary(c => c.Item1, c => c.Item2); return(Result.OK(db)); }
public static async Task <Result <IIndexer> > GetOrAddAsync(string directoryPath) { var indexLocation = new MdLocator(Encoding.UTF8.GetBytes($"{directoryPath}_indexer"), DataProtocol.DEFAULT_PROTOCOL); var indexMd = await MdAccess.LocateAsync(indexLocation).ConfigureAwait(false); if (!indexMd.HasValue) { indexMd = Result.OK(await MdAccess.CreateAsync(0)); } var indexHead = new MdHead(indexMd.Value, directoryPath); var indexer = await Indexer.GetOrAddAsync(indexHead); return(Result.OK((IIndexer)indexer)); }
public static async Task <Result <Directory> > GetOrAddAsync(string directoryPath, MdLocator dirLocator) { var indexer = await IndexerFactory.GetOrAddAsync(directoryPath); if (!indexer.HasValue) { return(Result.Fail <Directory>(indexer.ErrorCode.Value, indexer.ErrorMsg)); } var dirMd = await MdAccess.LocateAsync(dirLocator).ConfigureAwait(false); if (!dirMd.HasValue) { return(Result.Fail <Directory>(dirMd.ErrorCode.Value, dirMd.ErrorMsg)); } var dirHead = new MdHead(dirMd.Value, directoryPath); var dirResult = await Directory.GetOrAddAsync(dirHead, indexer.Value); return(dirResult); }
public static async Task <Result <Directory> > GetOrAddAsync(string directoryPath) { var indexer = await IndexerFactory.GetOrAddAsync(directoryPath); if (!indexer.HasValue) { return(Result.Fail <Directory>(indexer.ErrorCode.Value, indexer.ErrorMsg)); } var dirLocation = new MdLocator(Encoding.UTF8.GetBytes(directoryPath), DataProtocol.DEFAULT_PROTOCOL); var dirMd = await MdAccess.LocateAsync(dirLocation).ConfigureAwait(false); if (!dirMd.HasValue) { dirMd = Result.OK(await MdAccess.CreateAsync(0)); } var dirHead = new MdHead(dirMd.Value, directoryPath); var dirResult = await Directory.GetOrAddAsync(dirHead, indexer.Value); return(dirResult); }
public async Task <IDatabase> GetOrAddDataBaseAsync(string dbName) { var indexLocation = new MdLocator(System.Text.Encoding.UTF8.GetBytes($"{dbName}_indexer"), DataProtocol.DEFAULT_PROTOCOL, null, null); var indexMd = await MdAccess.LocateAsync(indexLocation).ConfigureAwait(false); if (!indexMd.HasValue) { throw new System.Exception(indexMd.ErrorMsg); } var indexHead = new MdHead(indexMd.Value, dbName); var indexer = await Indexer.GetOrAddAsync(indexHead); var dbLocation = new MdLocator(System.Text.Encoding.UTF8.GetBytes(dbName), DataProtocol.DEFAULT_PROTOCOL, null, null); var dbMd = await MdAccess.LocateAsync(dbLocation).ConfigureAwait(false); if (!dbMd.HasValue) { throw new System.Exception(dbMd.ErrorMsg); } var dbHead = new MdHead(dbMd.Value, dbName); var dbResult = await Database.GetOrAddAsync(dbHead, indexer); return(dbResult.Value); }