本文整理汇总了C#中System.Web.Hosting.VirtualPathProvider.GetDirectory方法的典型用法代码示例。如果您正苦于以下问题:C# VirtualPathProvider.GetDirectory方法的具体用法?C# VirtualPathProvider.GetDirectory怎么用?C# VirtualPathProvider.GetDirectory使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Web.Hosting.VirtualPathProvider
的用法示例。
在下文中一共展示了VirtualPathProvider.GetDirectory方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AnalyzeViews
public virtual IEnumerable<ContentRegistration> AnalyzeViews(VirtualPathProvider vpp, HttpContextBase httpContext, IEnumerable<ViewTemplateSource> sources)
{
var registrations = new List<ContentRegistration>();
foreach (var source in sources)
{
var virtualDirList = new List<string>
{
Url.ResolveTokens(Url.ThemesUrlToken) + "Default/Views/" + source.ControllerName,
"~/Views/" + source.ControllerName
};
virtualDirList.AddRange(
from virtualDirectory in vpp.GetDirectory("~/Areas/").Directories.Cast<VirtualDirectory>()
let virtualPath = String.Format("~/Areas/{0}/Views/{1}", virtualDirectory.Name, source.ControllerName)
select virtualPath);
foreach (var virtualDir in virtualDirList.Where(vpp.DirectoryExists))
{
logger.Debug(String.Format("Analyzing directory {0}", virtualDir));
foreach (var file in vpp.GetDirectory(virtualDir).Files.OfType<VirtualFile>())
{
Debug.Assert(file.Name != null, "file.Name != null");
if (!file.Name.EndsWith(source.ViewFileExtension) || file.Name.StartsWith("_"))
{
logger.Info(String.Format("Skipping file {0}", file.VirtualPath));
continue;
}
logger.Debug(String.Format("Analyzing file {0}", file.VirtualPath));
ContentRegistration registration = null;
if (httpContext.IsDebuggingEnabled)
{
registration = AnalyzeView(httpContext, file, source.ControllerName, source.ModelType);
}
else
{
try
{
registration = AnalyzeView(httpContext, file, source.ControllerName, source.ModelType);
}
catch (Exception ex)
{
logger.Error(ex);
}
}
if (registration != null)
registrations.Add(registration);
}
}
}
return registrations;
}
示例2: 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;
}
示例3: 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;
}
}
示例4: 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)
yield return description;
}
}
示例5: FindMatchingFile
/// <summary>
/// Try and find a file in the specified folder that matches name.
/// </summary>
/// <returns>The full path to the file that matches the requested file
/// or null if no matching file is found</returns>
internal static string FindMatchingFile(VirtualPathProvider vpp, string folder, string name) {
Debug.Assert(vpp != null);
Debug.Assert(!String.IsNullOrEmpty(folder));
Debug.Assert(!String.IsNullOrEmpty(name));
// Get the virtual path information
VirtualDirectory directory = vpp.GetDirectory(folder);
// If the folder specified doesn't exist
// or it doesn't contain any files
if (directory == null || directory.Files == null) {
return null;
}
// Go through every file in the directory
foreach (VirtualFile file in directory.Files) {
string path = file.VirtualPath;
// Compare the filename to the filename that we passed
if (Path.GetFileName(path).Equals(name, StringComparison.OrdinalIgnoreCase)) {
return path;
}
}
// If no matching files, return null
return null;
}
示例6: GetAvailableThemes
internal static ReadOnlyCollection<string> GetAvailableThemes(VirtualPathProvider vpp, string themeDirectory) {
VirtualDirectory directory = vpp.GetDirectory(themeDirectory);
var themes = new List<string>();
// Go through every file in the directory
foreach (VirtualDirectory dir in directory.Directories) {
themes.Add(dir.Name);
}
return themes.AsReadOnly();
}