public async Task Initilize(IEnumerable <IFileChain> chain) { IEnumerable <ManagedCollection> collections = (await Task.WhenAll( chain.Select(async x => { ICollection toClone = await x.Root.Task; if (toClone == null) { return(null); } else { return(await toClone?.CloneManagedAsync(this, FileSystem)); } })) ).Where(x => x != null).Reverse(); ManagedCollection root = collections.First(); foreach (ManagedCollection mc in collections.Skip(1)) { //TODO: diff-add file structure trees } Queue <ManagedCollection> colQueue = new Queue <ManagedCollection>(); colQueue.Enqueue(root); CollectionFastAccess.Add(root.Name, root); ManagedCollection deq = null; while (colQueue.Count > 0 && (deq = colQueue.Dequeue()) != null) { foreach (ManagedCollection col in deq.Collections) { CollectionFastAccess.Add(Uri.UnescapeDataString(col.Path.OriginalString), col); colQueue.Enqueue(col); } foreach (ManagedDocument doc in deq.Documents) { DocumentFastAccess.Add(Uri.UnescapeDataString(doc.Path.OriginalString), doc); } } Root = root; }
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))); } }