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... } }
/// <summary> /// Creates a new <see cref="TextLineCollectionSelection"/> based on the specified list and span. /// </summary> /// <param name="lines"></param> /// <param name="span"></param> /// <returns></returns> public static TextLineCollectionSelection Create(TextLineCollection lines, TextSpan span) { if (lines == null) { throw new ArgumentNullException(nameof(lines)); } SelectionResult result = SelectionResult.Create(lines, span); return(new TextLineCollectionSelection(lines, span, result)); }
private static MemberDeclarationListSelection Create(MemberDeclarationSyntax declaration, SyntaxList <MemberDeclarationSyntax> members, TextSpan span, int minCount, int maxCount) { SelectionResult result = SelectionResult.Create(members, span, minCount, maxCount); if (!result.Success) { return(null); } return(new MemberDeclarationListSelection(declaration, members, span, result)); }
private static StatementListSelection CreateImpl(SyntaxList <StatementSyntax> statements, TextSpan span) { SelectionResult result = SelectionResult.Create(statements, span); if (!result.Success) { throw new InvalidOperationException("No selected statement(s) found."); } return(new StatementListSelection(statements, span, result)); }
private static StatementListSelection Create(SyntaxList <StatementSyntax> statements, TextSpan span, int minCount, int maxCount) { SelectionResult result = SelectionResult.Create(statements, span, minCount, maxCount); if (!result.Success) { return(null); } return(new StatementListSelection(statements, span, result)); }
public async Task <SelectionResult> SelectAsync(string path, CancellationToken ct, bool wrapSelection = true) { try { RequestLockManager.LockAndWait(path); int i = 0; SelectionResult ret = null; for (; i < FileChain.Length; i++) { var v = await FileChain[i].TrySelectAsync(path, ct); ret = v.result; if (v.success || i >= FileChain.Length - 1) { break; } } if (wrapSelection) { switch (ret.ResultType) { case SelectionResultType.FoundCollection: ICollection collection = new RoutedCollection(this, ret.Collection); ret = SelectionResult.Create(collection); break; case SelectionResultType.FoundDocument: IDocument document = new RoutedDocument(this, ret.Document); ret = SelectionResult.Create(document.Parent, document); break; case SelectionResultType.MissingCollection: break; case SelectionResultType.MissingDocumentOrCollection: break; } } for (i--; i >= 0; i--) { await FileChain[i].TrySelectAsync_Bubbleup(path, ret, ct); } return(ret); } finally { RequestLockManager.Unlock(path); } }
private static TextLineCollectionSelection Create(TextLineCollection lines, TextSpan span, int minCount, int maxCount) { if (lines == null) { return(null); } SelectionResult result = SelectionResult.Create(lines, span, minCount, maxCount); if (!result.Success) { return(null); } return(new TextLineCollectionSelection(lines, span, result)); }
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); }
private static MemberDeclarationListSelection Create(SyntaxNode parent, SyntaxList <MemberDeclarationSyntax> members, TextSpan span) { SelectionResult result = SelectionResult.Create(members, span); return(new MemberDeclarationListSelection(parent, members, span, result)); }