Exemplo n.º 1
0
        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);
            }
        }
Exemplo n.º 2
0
        public async Task <Stream> OpenReadAsync(IDocument entry, CancellationToken ct)
        {
            string path         = entry.FullPath();
            bool   manualUnlock = true;

            try {
                RequestLockManager.LockAndWait(path);

                int    i   = 0;
                Stream ret = null;
                for (; i < FileChain.Length; i++)
                {
                    var v = await FileChain[i].TryOpenReadAsync(entry, ct);
                    if (v.success || i >= FileChain.Length - 1)
                    {
                        ret = v.result;
                        break;
                    }
                }

                if (ret is ReceiveBytesStream)
                {
                    manualUnlock = false;
                    (ret as ReceiveBytesStream).OnDispose.Add(() => RequestLockManager.Unlock(path));
                }

                //ret = new PushReadStream(ret);

                for (--i; i > 0; --i)
                {
                    await FileChain[i].TryOpenReadAsync_Bubbleup(entry, ret, ct);
                }

                await CacheManager.Flush_OpenReadAsync(entry);

                //await Task.WhenAll(FileChain.Take(i - 1).Select(x => x.TryOpenReadAsync_Bubbleup(entry, ret, ct)));

                return(ret);
            } finally {
                if (manualUnlock)
                {
                    RequestLockManager.Unlock(path);
                }
            }
        }