string IWebSiteFolder.ReadFile(string virtualPath, bool actualContent)
        {
            if (!_virtualPathProvider.FileExists(virtualPath))
            {
                return(null);
            }

            if (actualContent)
            {
                var physicalPath = _virtualPathProvider.MapPath(virtualPath);
                using (var stream = File.Open(physicalPath, FileMode.Open, FileAccess.Read))
                {
                    using (var reader = new StreamReader(stream))
                    {
                        return(reader.ReadToEnd());
                    }
                }
            }
            else
            {
                using (var stream = _virtualPathProvider.OpenFile(virtualPath))
                {
                    using (var reader = new StreamReader(stream))
                    {
                        return(reader.ReadToEnd());
                    }
                }
            }
        }
Esempio n. 2
0
        public string ReadFile(string virtualPath, bool actualContent)
        {
            if (!virtualPathProvider.FileExists(virtualPath))
            {
                return(null);
            }

            if (actualContent)
            {
                var physicalPath = virtualPathProvider.MapPath(virtualPath);
                using (var stream = File.Open(physicalPath, FileMode.Open, FileAccess.Read))
                {
                    using (var reader = new StreamReader(stream))
                    {
                        return(reader.ReadToEnd());
                    }
                }
            }

            using (var stream = virtualPathProvider.OpenFile(Normalize(virtualPath)))
            {
                using (var reader = new StreamReader(stream))
                {
                    return(reader.ReadToEnd());
                }
            }
        }
Esempio n. 3
0
        public string ReadFile(string virtualPath)
        {
            if (!_virtualPathProvider.FileExists(virtualPath))
            {
                return(null);
            }

            using (var stream = _virtualPathProvider.OpenFile(Normalize(virtualPath)))
            {
                using (var reader = new StreamReader(stream))
                {
                    return(reader.ReadToEnd());
                }
            }
        }
Esempio n. 4
0
 private string ReadAllText(string virtualPath)
 {
     using (var reader = new StreamReader(_virtualPathProvider.OpenFile(virtualPath)))
     {
         return(reader.ReadToEnd());
     }
 }
Esempio n. 5
0
        private string GetContents(string virtualPath)
        {
            string contents;

            using (var stream = _virtualPathProvider.OpenFile(virtualPath)) {
                using (var reader = new StreamReader(stream)) {
                    contents = reader.ReadToEnd();
                }
            }
            return(contents);
        }
Esempio n. 6
0
        /// <summary>
        /// 打开一个文件。
        /// </summary>
        /// <typeparam name="T">返回值类型。</typeparam>
        /// <param name="virtualPathProvider">虚拟路径提供者。</param>
        /// <param name="virtualPath">虚拟路径。</param>
        /// <param name="func">对流的操作。</param>
        /// <returns>文件流。</returns>
        public static T OpenFileFunc <T>(this IVirtualPathProvider virtualPathProvider, string virtualPath, Func <Stream, T> func)
        {
            virtualPathProvider.NotNull("virtualPathProvider");
            virtualPath.NotEmptyOrWhiteSpace("virtualPath");
            func.NotNull("func");

            var result = default(T);

            virtualPathProvider.OpenFile(virtualPath, stream =>
            {
                result = func(stream);
            });
            return(result);
        }
Esempio n. 7
0
        //public ITestModel CreateTestModelFor(BaseEntity entity, string modelPrefix)
        //{
        //    return new TestDrop(entity, modelPrefix);
        //   }

        private string ReadTemplateFileInternal(string virtualPath)
        {
            if (virtualPath.IsEmpty())
            {
                return(string.Empty);
            }

            if (!_vpp.FileExists(virtualPath))
            {
                throw new FileNotFoundException($"Include file '{virtualPath}' does not exist.");
            }

            using (var stream = _vpp.OpenFile(virtualPath))
            {
                return(stream.AsString());
            }
        }
Esempio n. 8
0
 protected SkinsManifest GetSkinsManifest()
 {
     if (_skinsManifest == null)
     {
         _skinsManifest = new SkinsManifest();
         var themePath = GetThemePath();
         // find the manifest
         var manifestFile = PathCombine(themePath, "skinsconfig.json");
         if (_virtualPathProvider.FileExists(manifestFile))
         {
             using (var manifestStream = _virtualPathProvider.OpenFile(manifestFile)) {
                 using (var reader = new StreamReader(manifestStream)) {
                     _skinsManifest = JsonConvert.DeserializeObject <SkinsManifest>(reader.ReadToEnd());
                 }
             }
         }
     }
     return(_skinsManifest);
 }
Esempio n. 9
0
        public string GetLocalResourceContent(CombinatorResource resource)
        {
            var relativeVirtualPath = resource.RelativeVirtualPath;

            // Maybe TryFileExists would be better?
            if (!_virtualPathProvider.FileExists(relativeVirtualPath))
            {
                throw new OrchardException(T("Local resource file not found under {0}", relativeVirtualPath));
            }

            string content;

            using (var stream = _virtualPathProvider.OpenFile(relativeVirtualPath))
            {
                content = new StreamReader(stream).ReadToEnd();
            }

            return(content);
        }
Esempio n. 10
0
 public void CopyFileTo(string virtualPath, Stream destination, bool actualContent)
 {
     if (actualContent)
     {
         // This is an unfortunate side-effect of the dynamic compilation work.
         // Orchard has a custom virtual path provider which adds "<@Assembly xxx@>"
         // directives to WebForm view files. There are cases when this side effect
         // is not expected by the consumer of the WebSiteFolder API.
         // The workaround here is to go directly to the file system.
         var physicalPath = _virtualPathProvider.MapPath(virtualPath);
         using (var stream = File.Open(physicalPath, FileMode.Open, FileAccess.Read))
         {
             stream.CopyTo(destination);
         }
     }
     else
     {
         using (var stream = _virtualPathProvider.OpenFile(Normalize(virtualPath)))
         {
             stream.CopyTo(destination);
         }
     }
 }
Esempio n. 11
0
 public virtual Stream OpenFile(string relativePath)
 {
     return(_vpp.OpenFile(GetVirtualPath(relativePath)));
 }