本文整理汇总了C#中Bundle.EnumerateFiles方法的典型用法代码示例。如果您正苦于以下问题:C# Bundle.EnumerateFiles方法的具体用法?C# Bundle.EnumerateFiles怎么用?C# Bundle.EnumerateFiles使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Bundle
的用法示例。
在下文中一共展示了Bundle.EnumerateFiles方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetFileDependencies
/// <summary>
/// Returns virtual paths of included files in <paramref name="virtualPath" /> file, according to
/// <paramref name="context" />.
/// If not added yet and <see cref="LessTransform" /> included in bundle transforms, executes
/// <see cref="LessTransform" /> transformation for the specified <paramref name="bundle" />
/// and ensures the dependencies are saved.
/// </summary>
/// <param name="bundle">Bundle to process, if not yet</param>
/// <param name="virtualPath">Root file to get dependencies for.</param>
/// <param name="context">Current context.</param>
/// <returns>Virtual paths of included files.</returns>
private static IEnumerable<string> GetFileDependencies(Bundle bundle, string virtualPath, BundleContext context)
{
string key = BundleTable.VirtualPathProvider.GetCacheKey(virtualPath) ?? virtualPath;
Func<string, IList<string>> process;
if (bundle.Transforms.Any(transform => transform is LessTransform))
{
process = s =>
{
IEnumerable<BundleFile> files = bundle.EnumerateFiles(context);
LessTransform.Process(ref files);
return files.Select(file => file.IncludedVirtualPath).ToArray();
};
}
else
{
process = s => new string[0];
}
_fileDependencies.GetOrAdd(key, process);
// returns more specific dependencies by the key containing transient file paths
return _fileDependencies.GetOrAdd(GetTransientFileKey(virtualPath), process);
}
示例2: GetSingleFileBundleResponse
private BundleResponse GetSingleFileBundleResponse(Bundle bundle, BundleContext bundleContext, string filepath)
{
var files = bundle.EnumerateFiles(bundleContext);
var file = files.FirstOrDefault(f => f.VirtualFile.VirtualPath.TrimStart(new[] { '/' }) == filepath);
if (file == null)
{
throw new FileNotFoundException(string.Format("File not found '{0}'", filepath));
}
string contents;
var virtualPathProvider = HostingEnvironment.VirtualPathProvider;
var virtualFile = virtualPathProvider.GetFile(VirtualPathUtility.ToAppRelative(file.VirtualFile.VirtualPath));
using (var streamReader = new StreamReader(virtualFile.Open()))
{
contents = streamReader.ReadToEnd();
}
return bundle.ApplyTransforms(bundleContext, contents, new List<BundleFile> { file });
}
示例3: GetTimeStamp
private static string GetTimeStamp(Bundle bundle, BundleContext bundleContext)
{
var lastdate = DateTime.MinValue;
foreach (var file in bundle.EnumerateFiles(bundleContext))
{
var mappedPath = HostingEnvironment.MapPath(file.IncludedVirtualPath);
if (mappedPath != null && File.Exists(mappedPath))
{
var fileDate = File.GetLastWriteTime(mappedPath);
if (fileDate > lastdate)
{
lastdate = fileDate;
}
}
}
return lastdate.ToString("yyyyMMddHHmmss");
}