public string GetPhysicalFilePath(AssemblyVirtualFileLocation location) { // Work out the file path, rewriting it to use the correct project based on the assembly name string path = null; string virtualPathWithoutTilda = location.VirtualPath.TrimStart('~'); var virtualPath = location.VirtualPath; if (!string.IsNullOrWhiteSpace(_assemblyResourceProviderSettings.EmbeddedContentPhysicalPathRootOverride)) { path = Path.Combine(_assemblyResourceProviderSettings.EmbeddedContentPhysicalPathRootOverride.Trim('/'), virtualPath.Replace('\\', '/').Trim('/')); } else { path = _pathResolver.MapPath(virtualPath); } var basePath = path.Substring(0, path.Length - virtualPathWithoutTilda.Length); var filePath = path.Substring(path.Length - virtualPathWithoutTilda.Length); var pathParts = basePath.Split(Path.DirectorySeparatorChar); // Assumes the folder name is the same as the assembly name var allPathParts = pathParts .Take(pathParts.Length - 1) .Concat(new string[] { location.Assembly.GetName().Name }) .ToList(); var newPath = string.Join(Path.DirectorySeparatorChar.ToString(), allPathParts); var completePath = newPath + filePath; return(completePath); }
public Stream Open(AssemblyVirtualFileLocation location) { Condition.Requires(location).IsNotNull(); Condition.Requires(location.VirtualPath).IsNotNullOrEmpty(); var physicalPath = GetPhysicalFilePath(location); return(ReadFile(physicalPath)); }
private string MakeVirtualFileName(AssemblyVirtualFileLocation resource) { var resourcePath = resource.PathWithoutAssemblyName; var fileExt = Path.GetExtension(resourcePath); var fileExtIndex = resourcePath.LastIndexOf(fileExt); var basePath = resourcePath.Substring(0, fileExtIndex); var virtualDir = "~/" + basePath .Replace("_", "-") .Replace(".", "/") + fileExt; return(virtualDir); }
public AssemblyResourceVirtualFile( AssemblyVirtualFileLocation location, IAssemblyResourcePhysicaFileRepository assemblyPhysicalFileService, AssemblyResourceProviderSettings assemblyResourceProviderSettings ) : base(location.VirtualPath) { Condition.Requires(location).IsNotNull(); Condition.Requires(location.VirtualPath).IsNotNullOrEmpty(); _location = location; _assemblyPhysicalFileService = assemblyPhysicalFileService; _assemblyResourceProviderSettings = assemblyResourceProviderSettings; }
public DateTime GetModifiedDate(AssemblyVirtualFileLocation location) { var physicalPath = GetPhysicalFilePath(location); return(File.GetLastWriteTimeUtc(physicalPath)); }