public string Read(WebAssetGroup group) { var appliesTo = filter.AppliesTo(group.ContentType); var result = new StringBuilder(); foreach (var asset in group.Items) { var path = locator.Locate(asset.Source, group.Version); var text = provider.ReadAllText(path); if (appliesTo) { var basePath = provider.GetDirectory(path); text = filter.Filter(basePath, text); } result.Append(text); result.AppendLine(); } return(result.ToString()); }
private bool TryPath(string path, string modifier, out string result) { var directory = virtualPathProvider.GetDirectory(path); var fileName = virtualPathProvider.GetFile(path); var pathToProbe = modifier.HasValue() ? virtualPathProvider.CombinePaths(directory, modifier) + Path.AltDirectorySeparatorChar + fileName : path; result = virtualPathProvider.FileExists(pathToProbe) ? pathToProbe : null; return(result != null); }
public void CombineVirtualPath_ReturnCorrectPath() { var path1 = "folder1"; var path2 = "folder2"; var dir = Provider.CreateDirectory(path1).CreateDirectory(path2); var path = Provider.CombineVirtualPath(path1, path2); Assert.That(Provider.GetDirectory(path), Is.EqualTo(dir)); }
/// <summary> /// Get the path to the script. /// </summary> /// <param name="virtualPath">The virtual path.</param> /// <param name="version">The version.</param> /// <param name="extensions">The collection of extensions.</param> /// <returns>The path.</returns> private string ProbePath(string virtualPath, string version, IEnumerable <string> extensions) { string result = null; Func <string, string> fixPath = path => { string directory = _virtualPathProvider.GetDirectory(path); string fileName = _virtualPathProvider.GetFile(path); if (!directory.EndsWith(version + Path.AltDirectorySeparatorChar, StringComparison.OrdinalIgnoreCase)) { string newDirectory = _virtualPathProvider.CombinePaths(directory, version); string newPath = newDirectory + Path.AltDirectorySeparatorChar + fileName; if (_virtualPathProvider.FileExists(newPath)) { return(newPath); } } return(path); }; foreach (string extension in extensions) { string changedPath = Path.ChangeExtension(virtualPath, extension); string newVirtualPath = string.IsNullOrEmpty(version) ? changedPath : fixPath(changedPath); if (_virtualPathProvider.FileExists(newVirtualPath)) { result = newVirtualPath; break; } } if (string.IsNullOrEmpty(result)) { result = virtualPath; if (!_virtualPathProvider.FileExists(result)) { throw new FileNotFoundException("The specified file does not exist : '" + result + "'"); } } // Return the virtual file. return(result); }
public IEnumerable <IVirtualFile> dirFilesFind(IVirtualPathProvider vfs, string dirPath, string globPattern) => vfs.GetDirectory(dirPath)?.GetAllMatchingFiles(globPattern);
public IEnumerable <IVirtualDirectory> dirDirectories(IVirtualPathProvider vfs, string dirPath) => vfs.GetDirectory(dirPath)?.GetDirectories() ?? new List <IVirtualDirectory>();
public IVirtualDirectory dirDirectory(IVirtualPathProvider vfs, string dirPath, string dirName) => vfs.GetDirectory(dirPath)?.GetDirectory(dirName);
public IVirtualFile dirFile(IVirtualPathProvider vfs, string dirPath, string fileName) => vfs.GetDirectory(dirPath)?.GetFile(fileName);
public IVirtualDirectory dir(IVirtualPathProvider vfs, string virtualPath) => vfs.GetDirectory(virtualPath);
public static IVirtualNode GetVirtualNode(this IVirtualPathProvider pathProvider, string virtualPath) { return((IVirtualNode)pathProvider.GetFile(virtualPath) ?? pathProvider.GetDirectory(virtualPath)); }