Skip to content

Instantly share code, notes, and snippets.

@liddellj
Created August 8, 2011 08:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save liddellj/1131389 to your computer and use it in GitHub Desktop.
Save liddellj/1131389 to your computer and use it in GitHub Desktop.
ResourceSpace.Has
.ResourcesOfType<Stream>()
.AtUri("/content/{path}")
.And.AtUri("/content/images/{path}")
.And.AtUri("/content/colors/{path}")
.HandledBy<EmbeddedResourceHandler>()
.TranscodedBy<ApplicationOctetStreamCodec>().ForMediaType("text/html").ForExtension(".html")
.And.TranscodedBy<ApplicationOctetStreamCodec>().ForMediaType("text/javascript").ForExtension(".js")
.And.TranscodedBy<ApplicationOctetStreamCodec>().ForMediaType("text/css").ForExtension(".css")
.And.TranscodedBy<ApplicationOctetStreamCodec>().ForMediaType("image/png").ForExtension(".png");
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using OpenRasta.Web;
namespace TeamBuildScreen.Server.Handlers
{
public class EmbeddedResourceHandler
{
private readonly ICommunicationContext context;
private Assembly assembly;
private Dictionary<string, Stream> cache;
public EmbeddedResourceHandler(ICommunicationContext context)
{
this.context = context;
this.assembly = this.GetType().Assembly;
this.cache = new Dictionary<string, Stream>();
}
public Stream Get(string path)
{
var fileName = "TeamBuildScreen.Server.Views" + this.context.Request.Uri.AbsolutePath.Substring(8).Replace('/', '.');
if (!this.cache.ContainsKey(fileName))
{
this.cache[fileName] = this.assembly.GetManifestResourceStream(fileName);
}
return this.cache[fileName];
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment