public SelectionResult AsSelectionResult() { Collection.FileSystem = FileSystem; Collection.Serializer = Serializer; Collection.Transport = Transport; switch (SelectionResultType) { case SelectionResultType.FoundCollection: return(SelectionResult.Create(Collection)); case SelectionResultType.FoundDocument: Document.FileSystem = FileSystem; Document.Serializer = Serializer; Document.Transport = Transport; return(SelectionResult.Create(Collection, Document)); case SelectionResultType.MissingCollection: return(SelectionResult.CreateMissingCollection(Collection, MissingNames)); case SelectionResultType.MissingDocumentOrCollection: return(SelectionResult.CreateMissingDocumentOrCollection(Collection, MissingNames)); default: return(null); //can't be reached, but the compiler requires it... } }
public async Task <(bool success, SelectionResult result)> TrySelectAsync(string path, CancellationToken ct) { path = path.Replace(System.IO.Path.DirectorySeparatorChar, '/').Replace("//", "/"); string fullPath = FullPath(path); LocalDiskEntry ldd = null; if (DocDict.ContainsKey(fullPath)) { ldd = DocDict[fullPath]; } else if (ColDict.ContainsKey(fullPath)) { ldd = ColDict[fullPath]; } SelectionResult sel = null; if (ldd == null) { if (path.Any()) { string[] comps = path.Split('/'); ICollection found = FastRoot; IEntry tmp = null; int index = 0; do { tmp = await found.GetChildAsync(comps[index], ct); if (tmp != null) { index++; if (tmp is ICollection) { found = tmp as ICollection; } } } while(tmp != null && tmp is ICollection && index < comps.Length); string[] missingComps = comps.Skip(index).Select(x => x + '/').ToArray(); if (!missingComps.Any()) { ldd = tmp as LocalDiskEntry; } else { if (path.Last() != '/') { sel = SelectionResult.CreateMissingDocumentOrCollection(found, missingComps); } else { sel = SelectionResult.CreateMissingCollection(found, missingComps); } } } else { ICollection col = await Root.Task; sel = SelectionResult.Create(col); } } if (ldd != null && ldd is ICollection) { sel = SelectionResult.Create(ldd as ICollection); } else if (ldd != null) { sel = SelectionResult.Create((ldd as LocalDiskDocument).Parent, ldd as LocalDiskDocument); } return(ldd != null, sel); }