async Task <Result <MdFileInfo> > FindFileInfoAsync(FileSystemPath path) { if (!_path.IsParentOf(path)) { return(new InvalidOperation <MdFileInfo>("Incorrect path")); } if (!path.IsFile) { return(new InvalidOperation <MdFileInfo>("Path is not a file")); } // a stored MdFileInfo is a reference (i.e. the locator) to the actual Md holding data var(data, errors) = await _indexer.GetAllValuesAsync <MdFileInfo>(path.Path).ConfigureAwait(false); var list = data.ToList(); if (list.Count == 0) { return(new KeyNotFound <MdFileInfo>(string.Join(',', errors))); } if (list.Count > 1) { return(new MultipleResults <MdFileInfo>($"Expected 1 result, found: {list.Count}.")); } var md = await MdAccess.LocateAsync(list.Single().Locator); // finally locate the actual md, which our stored MdFileInfo uses to return(Result.OK(SetupFileInfo(path, md.Value))); // Get / Set actions will be injected into the encapsulating MdFileInfo, which acts directly upon its Md }
public async Task <Result <T> > FindByKeyAsync <T>(string key) { var type = typeof(T).Name; var indexKey = $"{type}/{key}"; var(data, errors) = await _indexer.GetAllValuesAsync <T>(indexKey).ConfigureAwait(false); var list = data.ToList(); if (list.Count == 0) { return(new KeyNotFound <T>(string.Join(',', errors))); } if (list.Count > 1) { return(new MultipleResults <T>($"Expected 1 result, found: {list.Count}.")); } return(Result.OK(list.Single())); }