本文整理汇总了C#中System.Web.Hosting.VirtualPathProvider类的典型用法代码示例。如果您正苦于以下问题:C# VirtualPathProvider类的具体用法?C# VirtualPathProvider怎么用?C# VirtualPathProvider使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
VirtualPathProvider类属于System.Web.Hosting命名空间,在下文中一共展示了VirtualPathProvider类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BuildManagerViewEngine
internal BuildManagerViewEngine(IViewPageActivator viewPageActivator, IResolver<IViewPageActivator> activatorResolver,
IDependencyResolver dependencyResolver, VirtualPathProvider pathProvider)
{
if (viewPageActivator != null)
{
_viewPageActivator = viewPageActivator;
}
else
{
_activatorResolver = activatorResolver ?? new SingleServiceResolver<IViewPageActivator>(
() => null,
new DefaultViewPageActivator(dependencyResolver),
"BuildManagerViewEngine constructor");
}
if (pathProvider != null)
{
Func<VirtualPathProvider> providerFunc = () => pathProvider;
_fileExistsCache = new FileExistenceCache(providerFunc);
VirtualPathProviderFunc = providerFunc;
}
else
{
if (_sharedFileExistsCache == null)
{
// Startup initialization race is OK providing service remains read-only
_sharedFileExistsCache = new FileExistenceCache(() => HostingEnvironment.VirtualPathProvider);
}
_fileExistsCache = _sharedFileExistsCache;
}
}
示例2: LoadContent
/// <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 );
}
示例3: RegisterVirtualPathProvider
public void RegisterVirtualPathProvider(VirtualPathProvider virtualPathProvider)
{
// Sets up the provider chain
var previousField = typeof(VirtualPathProvider).GetField("_previous", BindingFlags.NonPublic | BindingFlags.Instance);
previousField.SetValue(virtualPathProvider, VirtualPathProvider);
VirtualPathProvider = virtualPathProvider;
}
示例4: EPiServerHostingEnvironment
public EPiServerHostingEnvironment()
{
//We need the first provider to be one that doesn't delegates to its parent.
//The default hosting environment uses a MapPathBasedVirtualPathProvider but that's internal
//so we use our custom dummy provider.
_provider = new DummyVirtualPathProvider();
}
示例5: Write
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);
}
}
}
示例6: ContentPathProvider
public ContentPathProvider(VirtualPathProvider baseProvider, Configuration.Configuration services)
{
_baseProvider = baseProvider;
_config = services;
_internalResources = new Dictionary<string, string>();
switch (_config.ViewEngineOptions.Type)
{
case Configuration.ViewEngineType.Razor:
_extension = ".cshtml";
break;
case Configuration.ViewEngineType.ASPX:
_extension = ".aspx";
break;
default:
throw new ArgumentException("Invalid ViewEngine Specified.");
}
Action<string> addResource = (file) =>
_internalResources.Add(file + _extension, string.Format("Meek.Content.{0}.{1}{2}", _config.ViewEngineOptions.Type.ToString(), file, _extension));
addResource("Manage");
addResource("CreatePartial");
addResource("List");
addResource("BrowseFiles");
addResource("UploadFileSuccess");
}
示例7: FindRegistrations
public virtual IEnumerable<ViewTemplateDescription> FindRegistrations(VirtualPathProvider vpp, HttpContextBase httpContext, IEnumerable<ViewTemplateSource> sources)
{
foreach (var source in sources)
{
string virtualDir = "~/Views/" + source.ControllerName;
if (!vpp.DirectoryExists(virtualDir))
continue;
List<ViewTemplateDescription> descriptions = new List<ViewTemplateDescription>();
foreach (var file in vpp.GetDirectory(virtualDir).Files.OfType<VirtualFile>().Where(f => f.Name.EndsWith(source.ViewFileExtension)))
{
var description = AnalyzeView(httpContext, file, source.ControllerName, source.ModelType);
if (description != null)
descriptions.Add(description);
}
foreach (var description in descriptions)
{
description.Definition.Add(new TemplateSelectorAttribute
{
Name = "TemplateName",
Title = "Template",
AllTemplates = descriptions.Select(d => new TemplateSelectorAttribute.Info { Name = d.Registration.Template, Title = d.Registration.Title }).ToArray(),
ContainerName = source.TemplateSelectorContainerName,
Required = true,
HelpTitle = "The page must be saved for another template's fields to appear",
RequiredPermission = Security.Permission.Administer
});
}
foreach (var description in descriptions)
yield return description;
}
}
示例8: Register
public void Register(VirtualPathProvider provider)
{
if (provider == null)
throw new ArgumentNullException("provider");
_providers.Add(provider);
}
示例9: AnalyzeViews
public virtual IEnumerable<ContentRegistration> AnalyzeViews(VirtualPathProvider vpp, HttpContextBase httpContext, IEnumerable<ViewTemplateSource> sources)
{
var registrations = new List<ContentRegistration>();
foreach (var source in sources)
{
string virtualDir = Url.ResolveTokens(Url.ThemesUrlToken) + "Default/Views/" + source.ControllerName;
logger.DebugFormat("Analyzing directory {0}", virtualDir);
if (!vpp.DirectoryExists(virtualDir))
{
virtualDir = "~/Views/" + source.ControllerName;
if (!vpp.DirectoryExists(virtualDir))
continue;
}
foreach (var file in vpp.GetDirectory(virtualDir).Files.OfType<VirtualFile>().Where(f => f.Name.EndsWith(source.ViewFileExtension)))
{
logger.DebugFormat("Analyzing file {0}", file.VirtualPath);
var registration = AnalyzeView(httpContext, file, source.ControllerName, source.ModelType);
if (registration != null)
registrations.Add(registration);
}
}
return registrations;
}
示例10: FileExistenceCache
public FileExistenceCache(VirtualPathProvider virtualPathProvider, int milliSecondsBeforeReset = 1000)
{
Contract.Assert(virtualPathProvider != null);
_virtualPathProvider = virtualPathProvider;
_virtualPathFileExists = virtualPathProvider.FileExists;
_ticksBeforeReset = milliSecondsBeforeReset * TicksPerMillisecond;
Reset();
}
示例11: BuildManagerDirectoryBuilder
public BuildManagerDirectoryBuilder (VirtualPath virtualPath)
{
if (virtualPath == null)
throw new ArgumentNullException ("virtualPath");
this.vpp = HostingEnvironment.VirtualPathProvider;
this.virtualPath = virtualPath;
this.virtualPathDirectory = VirtualPathUtility.GetDirectory (virtualPath.Absolute);
}
示例12: SetUp
public override void SetUp()
{
base.SetUp();
var routeData = new RouteData();
routeData.Values["controller"] = "MyController";
virtualPathProvider = new XsltTestVirtualPathProvider();
_context = new ControllerContext(HttpContext, routeData, MockRepository.GenerateStub<ControllerBase>());
mockRepository.ReplayAll();
}
示例13: MustacheView
/// <summary>
/// Initialise a new Pattern Lab view
/// </summary>
/// <param name="engine">The current view engine</param>
/// <param name="controllerContext">The current controller context</param>
/// <param name="virtualPathProvider">The current virtual path provider</param>
/// <param name="viewPath">The path to the view</param>
/// <param name="masterPath">The optional path to the master view</param>
/// <param name="parameters">Any pattern parameters</param>
public MustacheView(MustacheViewEngine engine, ControllerContext controllerContext,
VirtualPathProvider virtualPathProvider, string viewPath, string masterPath, Dictionary<string, object> parameters)
{
_engine = engine;
_controllerContext = controllerContext;
_masterPath = masterPath;
_parameters = parameters;
_viewPath = viewPath;
_virtualPathProvider = virtualPathProvider;
}
示例14: ResourcePathProvider
public ResourcePathProvider(IEnumerable<Assembly> assemblies, VirtualPathProvider previous)
{
this.previous = previous;
resources = new Dictionary<string, EmbeddedFile>();
foreach (var embeddedFile in assemblies.SelectMany(a => a.GetManifestResourceNames().Select(n => new EmbeddedFile(a, n))))
{
if (!resources.ContainsKey(embeddedFile.Key))
{
resources.Add(embeddedFile.Key, embeddedFile);
}
}
}
示例15: ResolveThemedContent
private static string ResolveThemedContent(HttpContextBase httpContext, VirtualPathProvider vpp, string contentPath)
{
string theme = httpContext.GetTheme();
if (string.IsNullOrEmpty(theme))
return Url.ToAbsolute(contentPath);
string themeContentPath = "~/Themes/" + theme + contentPath.TrimStart('~');
if (!vpp.FileExists(themeContentPath))
return Url.ToAbsolute(contentPath);
return Url.ToAbsolute(themeContentPath);
}