/// <summary>
        /// When overridden in a derived class, returns a read-only stream to the virtual resource.
        /// </summary>
        /// <returns>
        /// A read-only stream to the virtual file.
        /// </returns>
        public Stream Open()
        {
            string resourceName;

            // Get this assembly.
            Assembly assembly = typeof(ZoombracoEmbeddedResourceController).Assembly;
            Stream   output   = EmbeddedResourceHelper.GetResource(assembly, this.virtualPath, out resourceName);

            if (output == null)
            {
                // We need to loop through the loaded resources and check each one.
                Assembly           localAssembly    = assembly;
                IEnumerable <Type> externalResource = PluginManager.Current.ResolveTypes <IZoombracoEmbeddedResource>()
                                                      .Where(t => t.Assembly != localAssembly);

                foreach (Type type in externalResource)
                {
                    string resource = EmbeddedResourceHelper.SanitizeResourceName(this.virtualPath);

                    assembly     = type.Assembly;
                    resourceName = assembly.GetManifestResourceNames().FirstOrDefault(r => r.InvariantEndsWith(resource));

                    if (!string.IsNullOrWhiteSpace(resourceName))
                    {
                        return(EmbeddedResourceHelper.GetResource(assembly, resource, out resourceName));
                    }
                }
            }

            return(output);
        }
Example #2
0
        /// <inheritdoc/>
        public bool FileExists(string virtualPath)
        {
            if (!virtualPath.InvariantEndsWith(ZoombracoConstants.EmbeddedResources.ResourceExtension))
            {
                return(false);
            }

            return(EmbeddedResourceHelper.ResourceExists(virtualPath));
        }