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 <SelectionResult> SelectAsync(string path, CancellationToken ct) { if (string.IsNullOrEmpty(path)) { return(SelectionResult.Create(CollectionFastAccess[path])); } else if (CollectionFastAccess.ContainsKey(path)) { return(SelectionResult.Create(CollectionFastAccess[path])); } else if (CollectionFastAccess.ContainsKey(path + '\\')) { return(SelectionResult.Create(CollectionFastAccess[path + '\\'])); } else if (CollectionFastAccess.ContainsKey(path + '/')) { return(SelectionResult.Create(CollectionFastAccess[path + '/'])); } else if (DocumentFastAccess.ContainsKey(path)) { ManagedDocument manDoc = DocumentFastAccess[path]; return(SelectionResult.Create(manDoc.Parent, manDoc)); } else { string[] pathParts = path.Split('\\', '/'); int i = 0; ManagedCollection mc = Root; for (; i < pathParts.Length; i++) { ManagedCollection nmc = mc.Collections.Where(x => x.Name.Equals(pathParts[i])).SingleOrDefault(); if (nmc == null) { break; } mc = nmc; } return(SelectionResult.CreateMissingDocumentOrCollection(mc, new ArraySegment <string>(pathParts, i, pathParts.Length - i))); } }
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); }