Example #1
0
        public virtual IFileInfo GetFileInfo(string filepath)
        {
            if (string.IsNullOrWhiteSpace(filepath))
            {
                return(new NotFoundFileInfo(filepath));
            }

            if (HostingEnvironment != null) //? && Path.GetFileName(subpath) != "_ViewImports.cshtml")
            {
                // ... if the file is found locally anywhere then abort to allow the user to load the local one instead as an override ...

                var physicalFilepath = Path.Combine(HostingEnvironment.ContentRootPath, filepath.TrimStart('/'));
                if (File.Exists(physicalFilepath))
                {
                    return(new NotFoundFileInfo(physicalFilepath));
                }

                physicalFilepath = Path.Combine(HostingEnvironment.WebRootPath, filepath.TrimStart('/'));
                if (File.Exists(physicalFilepath))
                {
                    return(new NotFoundFileInfo(physicalFilepath));
                }
            }

            var result = VolumeRoot.GetFile(filepath);

            if (result != null)
            {
                return((IFileInfo)result);
            }

            // ... if the path is absolute then fail, otherwise it is relative, so try any "wwwroot" folder ...

            if (filepath[0] == '\\' || filepath[0] == '/' || filepath.Contains(":"))
            {
                return(new NotFoundFileInfo(filepath));
            }

            // ... try looking for a "wwwroot" folder ...

            result = VolumeRoot.GetFile(Path.Combine("wwwroot", filepath));

            return((IFileInfo)result ?? new NotFoundFileInfo(filepath));
        }
Example #2
0
        public virtual IDirectoryContents GetDirectoryContents(string subpath)
        {
            var dir = VolumeRoot.GetDirectory(subpath);

            return((IDirectoryContents)dir ?? NotFoundDirectoryContents.Singleton);
        }