public EmbeddedResourceAssemblyAttribute(string virtualPathMask, string assembly, string theNamespace) { VirtualPathMask = virtualPathMask; Namespace = theNamespace; AllowOverride = true; AllowDefaultDocument = true; try { // load the related assembly and resource tree Assembly = Assembly.Load(assembly); ResourceLookup = new Dictionary <string, EmbeddedResourceNode>(StringComparer.InvariantCultureIgnoreCase); Resources = new EmbeddedResourceNode(string.Empty, true, false, "~", Namespace); // convert resource names to virtual paths var paths = GetVirtualPaths(Assembly.GetManifestResourceNames()); foreach (var path in paths) { AddResource(Resources, ResourceLookup, path.VirtualPath, path.ResourceName); } } catch (FileNotFoundException) { // Silently fail if the resource assembly isn't found. } }
private object CreateChild(EmbeddedResourceNode resource) { if (resource.IsDirectory) { var virtualPath = Path.Combine(VirtualPath, resource.Name); return(new EmbeddedResourceVirtualDirectory(virtualPath, _assembly, resource)); } if (resource.IsFile) { var virtualPath = Path.Combine(VirtualPath, resource.Name); return(new EmbeddedResourceVirtualFile(virtualPath, _assembly, resource.ResourceName)); } return(null); }
private static void AddResource(EmbeddedResourceNode node, IDictionary <string, EmbeddedResourceNode> lookup, IEnumerable <string> path, string resourceName) { if (path.Any()) { var name = path.First(); var child = node.Children.SingleOrDefault(n => n.Name == name); if (child == null) { var isFile = path.Count() == 1; var resource = isFile ? resourceName : GetResourceName(node, name); child = new EmbeddedResourceNode(name, !isFile, isFile, GetVirtualPath(node, name), resource); node.Children.Add(child); lookup.Add(resource, child); } AddResource(child, lookup, path.Skip(1), resourceName); } }
private static string GetResourceName(EmbeddedResourceNode node, string name) { return("{0}.{1}".FormatWith(node.VirtualPath, name)); }
private static void AddResource(EmbeddedResourceNode resources, IDictionary <string, EmbeddedResourceNode> lookup, string path, string resourceName) { var parts = path.Split(_directoryDelimiters, StringSplitOptions.RemoveEmptyEntries); AddResource(resources, lookup, parts, resourceName); }
public EmbeddedResourceVirtualDirectory(string virtualPath, Assembly assembly, EmbeddedResourceNode resources) : base(virtualPath) { _assembly = assembly; _resources = resources; }
public EmbeddedResourceVirtualFile(string virtualPath, Assembly assembly, EmbeddedResourceNode resources) : this(virtualPath, assembly, resources.ResourceName) { }