Exemplo n.º 1
0
        /// <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(BloodhoundEmbeddedResourceController).Assembly;

            return(EmbeddedResourceHelper.GetResource(assembly, this.virtualPath, out resourceName));
        }
        /// <summary>
        /// Returns a value indicating whether the virtual file exists for the given path.
        /// </summary>
        /// <param name="virtualPath">The virtual path.</param>
        /// <returns>
        /// The <see cref="bool"/>.
        /// </returns>
        public bool FileExists(string virtualPath)
        {
            if (!virtualPath.InvariantEndsWith(EmbeddedResourceConstants.ResourceExtension))
            {
                return(false);
            }

            return(EmbeddedResourceHelper.ResourceExists(virtualPath));
        }
        /// <summary>
        /// Gets an embedded resource from the main assembly
        /// </summary>
        /// <param name="fileName">Name of resource</param>
        /// <returns>File stream of resource</returns>
        public ActionResult GetResource(string fileName)
        {
            Mandate.ParameterNotNullOrEmpty(fileName, "fileName");

            // Get this assembly.
            Assembly assembly = typeof(BloodhoundEmbeddedResourceController).Assembly;
            string   resourceName;
            Stream   resourceStream = EmbeddedResourceHelper.GetResource(assembly, fileName, out resourceName);

            if (resourceStream != null)
            {
                return(new FileStreamResult(resourceStream, this.GetMimeType(resourceName)));
            }

            return(this.HttpNotFound());
        }