Exemplo n.º 1
0
        private Stream FindStreamFromPath(string path, out string storeLocalPath, out IFileStore fileStore)
        {
            var pathEnumerator = new PathFragmentEnumerator(path);

            try { return(FindStream(path, pathEnumerator, out storeLocalPath, out fileStore)); }
            catch (Exception) { throw new Exception($"The file '{path}' could not be found"); }
        }
Exemplo n.º 2
0
        private IEnumerable <string> EnumerateFilesInNestedFilestores(string path)
        {
            var pathEnumerator = new PathFragmentEnumerator(path);

            return(EnumerateNestedFilestores(path, pathEnumerator)
                   .SelectMany(s => s.EnumerateFiles(null))
                   .Select(s => FormatRootPath(path) + s));
        }
Exemplo n.º 3
0
        private Stream FindStream(string fullPath, PathFragmentEnumerator fragmentEnumerator, out string storeLocalPath, out IFileStore fileStore, List <IFileStore> fileStoresToSearch = null)
        {
            fileStoresToSearch = fileStoresToSearch ?? fileStores;

            var search = new List <IFileStore>(fileStoresToSearch.Count);

            search.AddRange(fileStoresToSearch);

            var localPath = string.Empty;

            while (fragmentEnumerator.MoveNext())
            {
                localPath += fragmentEnumerator.Current;

                var dirFrontier = search
                                  .Where(s => s.DirectoryExists(localPath))
                                  .ToList();

                if (dirFrontier.Count == 0)
                {
                    //  no FileStore found that includes this path as a directory, but it might be a file
                    var fileFrontier = search
                                       .Where(s => s.FileExists(localPath))
                                       .ToList();

                    //  none of our FileStores have this file
                    if (fileFrontier.Count == 0)
                    {
                        throw new Exception("Couldn't find the file");
                    }

                    if (fragmentEnumerator.HasNext)
                    {
                        //  there's still more to the path
                        //  recurse and try to find it inside the file we've found
                        var newFileStoreFrontier = fileFrontier
                                                   .Select(s => s.OpenFileEntryStream(localPath))
                                                   .Select(s => EstablishFileStore(localPath, s))
                                                   .ToList();

                        return(FindStream(fullPath, fragmentEnumerator, out storeLocalPath, out fileStore, newFileStoreFrontier));
                    }
                    else
                    {
                        storeLocalPath = localPath;
                        fileStore      = fileFrontier.Last();
                        return(fileStore.OpenFileEntryStream(localPath));
                    }
                }

                localPath += "/";
            }

            throw new Exception("Couldn't find the file");
        }
Exemplo n.º 4
0
        private IEnumerable <IFileStore> EnumerateNestedFilestores(string fullPath, PathFragmentEnumerator fragmentEnumerator, List <IFileStore> fileStoresToSearch = null)
        {
            fileStoresToSearch = fileStoresToSearch ?? fileStores;
            var search = new List <IFileStore>(fileStoresToSearch.Count);

            search.AddRange(fileStoresToSearch);

            var localPath = string.Empty;

            while (fragmentEnumerator.MoveNext())
            {
                localPath += fragmentEnumerator.Current;

                var fileFrontier = search
                                   .Where(s => s.FileExists(localPath))
                                   .ToList();

                if (fileFrontier.Count == 0)
                {
                    var dirFrontier = search
                                      .Where(s => s.DirectoryExists(localPath))
                                      .ToList();

                    //  no FileStore found that includes this path as a file, but it might be a directory
                    if (dirFrontier.Count == 0)
                    {
                        return(Enumerable.Empty <IFileStore>());
                    }
                }
                else
                {
                    var newFileStoreFrontier = fileFrontier
                                               .Select(s => s.OpenFileEntryStream(localPath))
                                               .Select(s => EstablishFileStore(localPath, s))
                                               .ToList();

                    if (fragmentEnumerator.HasNext)
                    {
                        //  there's still more to the path
                        //  recurse and try to find it inside the file we've found
                        return(EnumerateNestedFilestores(fullPath, fragmentEnumerator, newFileStoreFrontier));
                    }
                    else
                    {
                        return(newFileStoreFrontier);
                    }
                }

                localPath += "/";
            }

            return(Enumerable.Empty <IFileStore>());
        }