/// <summary>
    /// 利用指定 VirtualPathProvider 将虚拟路径所指向文件当作静态文件加载。
    /// </summary>
    /// <param name="provider">指定的 VirtualPathProvider</param>
    /// <param name="virtualPath">虚拟路径</param>
    /// <returns>加载结果</returns>
    public HtmlContentResult LoadContent( VirtualPathProvider provider, string virtualPath )
    {

      if ( !VirtualPathUtility.IsAppRelative( virtualPath ) )
        return null;

      if ( !provider.FileExists( virtualPath ) )
        return null;

      var file = provider.GetFile( virtualPath );

      if ( file == null )
        return null;



      var key = provider.GetCacheKey( virtualPath ) ?? "StaticFile_" + virtualPath;

      var content = HttpRuntime.Cache.Get( key ) as string;


      if ( content == null )
      {
        var dependency = HtmlServices.CreateCacheDependency( provider, virtualPath );
        content = LoadContent( file );

        HttpRuntime.Cache.Insert( key, content, dependency );
      }


      return new HtmlContentResult( content, key );
    }
示例#2
0
        private void Write(HttpContext context, VirtualPathProvider vpp, string cssPath)
        {
            var mappedPath = context.Server.MapPath(cssPath);
            if(File.Exists(mappedPath))
                context.Response.AddFileDependency(mappedPath);

            var file = vpp.GetFile(cssPath);
            using (var s = file.Open())
            using (var tr = new StreamReader(s))
            {
                while (tr.Peek() >= 0)
                {
                    var line = tr.ReadLine();
                    string importPath = GetImportedPath(context, vpp, cssPath, line);

                    if (string.IsNullOrEmpty(importPath))
                        // process all lines except imports
                        context.Response.Write(Process(line, VirtualPathUtility.GetDirectory(cssPath)));
                    else if (vpp.FileExists(importPath))
                        // recurse into imports and output
                        Write(context, vpp, importPath);
                    else
                        // fallback just write the line
                        context.Response.Write(line);

                    context.Response.Write(Environment.NewLine);
            
                }
            }
        }
示例#3
0
        public virtual VirtualFile GetFile(string virtualPath)
        {
            if (prev != null)
            {
                return(prev.GetFile(virtualPath));
            }

            return(null);
        }
示例#4
0
        /*
         * Returns a VirtualFile object for the passed in virtual path
         */

        public virtual VirtualFile GetFile(string virtualPath)
        {
            // Delegate to the previous VirtualPathProvider, if any

            if (_previous == null)
            {
                return(null);
            }

            return(_previous.GetFile(virtualPath));
        }
示例#5
0
        public static Stream OpenFile(string virtualPath)
        {
            // This thing throws a nullref when we're not inside an ASP.NET appdomain, which is what MS does.
            VirtualPathProvider provider = HostingEnvironment.VirtualPathProvider;
            VirtualFile         file     = provider.GetFile(virtualPath);

            if (file != null)
            {
                return(file.Open());
            }

            return(null);
        }
示例#6
0
        private static IEnumerable<SkinTemplate> GetSkinTemplates(VirtualPathProvider virtualPathProvider, string path)
        {
            VirtualFile virtualConfigFile = virtualPathProvider.GetFile(path);

            using(Stream configStream = virtualConfigFile.Open())
            {
                var templates = SerializationHelper.Load<SkinTemplates>(configStream);
                return templates.Templates;
            }
        }
示例#7
0
        private void RenderDirectory(HtmlTextWriter writer, VirtualPathProvider vpp, VirtualDirectory dir)
        {
            RenderCssAttribute(writer, false);
            writer.RenderBeginTag("ul");

            var dirpath = VirtualPathUtility.ToAppRelative(dir.VirtualPath);
            var pagedir = VirtualPathUtility.GetDirectory(Page.AppRelativeVirtualPath);
            var rootpath = VirtualPathUtility.AppendTrailingSlash(RootPath);

            // Render root directory
            foreach (var vf in dir.Children.Cast<VirtualFileBase>().OrderBy(f => f.Name))
            {
                var filepath = VirtualPathUtility.ToAppRelative(vf.VirtualPath);
                var filedir = VirtualPathUtility.GetDirectory(filepath);
                var filename = VirtualPathUtility.GetFileName(filepath);

                var isinpath = pagedir.StartsWith(filepath);

                if (vf.IsDirectory)
                {
                    filepath = VirtualPathUtility.Combine(filepath, "00_index.aspx");

                    if (!vpp.FileExists(filepath))
                    {
                        // Skip directory, if there's no index file
                        continue;
                    }
                }
                else if (comparer.Compare(dirpath, rootpath) != 0 &&
                         comparer.Compare(filename, "00_index.aspx") == 0 ||
                         comparer.Compare(filename, "Default.aspx") == 0 ||
                         comparer.Compare(VirtualPathUtility.GetExtension(filepath), ".aspx") != 0)
                {
                    // Skip index file and default.aspx in root or non aspx files
                    continue;
                }

                var isselected = comparer.Compare(filepath, Page.AppRelativeVirtualPath) == 0;
                var isinroot = comparer.Compare(filedir, rootpath) == 0;
                var title = GetPageTitle(vpp.GetFile(filepath));

                // Apply css to <li>
                RenderCssAttribute(writer, isselected);
                writer.RenderBeginTag("li");

                // Apply css to <a>
                RenderCssAttribute(writer, isselected);
                writer.AddAttribute("href", VirtualPathUtility.MakeRelative(Page.AppRelativeVirtualPath, filepath));
                writer.RenderBeginTag("a");
                writer.Write(title);
                writer.RenderEndTag();

                writer.RenderEndTag();

                // Render children, if
                //      - it is the current page
                //      - the current page is under this directory
                if (vf.IsDirectory && (isselected || isinpath || (isinroot && ExpandRootLevel)))
                {
                    RenderDirectory(writer, vpp, (VirtualDirectory)vf);
                }
            }

            writer.RenderEndTag();
        }
		/// <summary>
		/// Configures a bundle bundleResponse
		/// </summary>
		/// <param name="combinedAsset">Combined asset</param>
		/// <param name="bundleResponse">Object BundleResponse</param>
		/// <param name="virtualPathProvider">Virtual path provider</param>
		protected virtual void ConfigureBundleResponse(IAsset combinedAsset, BundleResponse bundleResponse,
			VirtualPathProvider virtualPathProvider)
		{
			var bundleFiles = combinedAsset.VirtualPathDependencies.Select(assetVirtualPath =>
				new BundleFile(assetVirtualPath, virtualPathProvider.GetFile(assetVirtualPath))).ToList();

			bundleResponse.Content = combinedAsset.Content;
			bundleResponse.Files = bundleFiles;
			bundleResponse.ContentType = ContentType;
		}