public void ProcessRequest(HttpContext context)
        {
            var routeDataValues = _routeData.Values;
            var client          = routeDataValues["client"].ToString();
            var assemblyName    = UrlToAssemblyMapping.GetAssemblyByUrl(client).GetName().Name;
            var fileName        = routeDataValues["file"].ToString();
            var fileExtension   = routeDataValues["extension"].ToString();
            var prefix          = _routeData.DataTokens["name"] + ".";
            var resourcePath    = string.Format("{0}.{1}{2}.{3}", assemblyName, prefix, fileName, fileExtension);
            var pathInfo        = new EmbeddedResourcePathInfo(resourcePath);

            AssemblyNameResolution assemblyNameResolution;

            if (_embeddedResourceNameResolver.TryResolve(pathInfo, out assemblyNameResolution))
            {
                var stream = _streamFetcher.Fetch(assemblyNameResolution.Assembly, assemblyNameResolution.Name);
                context.Response.Clear();
                context.Response.ContentType = MimeTypeMap.GetMimeType(fileExtension);
                stream.CopyTo(context.Response.OutputStream);
            }
            else
            {
                throw new Exception("Unable to find resource: " + resourcePath);
            }
        }
 public EmbeddedResourceVirtualFile(IEmbeddedResourceNameResolver embeddedResourceNameResolver, string virtualPath)
     : base(virtualPath)
 {
     _embeddedResourceNameResolver = embeddedResourceNameResolver;
     var path = VirtualPathUtility.ToAppRelative(virtualPath);
     _pathInfo = new EmbeddedResourcePathInfo(path);
     _streamFetcher = new VirtualFileStreamFetcher();
 }
Exemple #3
0
        public EmbeddedResourceVirtualFile(IEmbeddedResourceNameResolver embeddedResourceNameResolver, string virtualPath) : base(virtualPath)
        {
            _embeddedResourceNameResolver = embeddedResourceNameResolver;
            var path = VirtualPathUtility.ToAppRelative(virtualPath);

            _pathInfo      = new EmbeddedResourcePathInfo(path);
            _streamFetcher = new VirtualFileStreamFetcher();
        }
 bool IsEmbeddedResourcePath(string virtualPath)
 {
     //if path is serving a file... need to fail resolve and pass to httpHandler
     if (virtualPath.EndsWith(".js", StringComparison.InvariantCultureIgnoreCase) || virtualPath.EndsWith(".css", StringComparison.InvariantCultureIgnoreCase)) {
         return false;
     }
     AssemblyNameResolution result;
     var pathInfo = new EmbeddedResourcePathInfo(virtualPath);
     return _embeddedResourceNameResolver.TryResolve(pathInfo, out result);
 }
Exemple #5
0
 public bool TryResolve(EmbeddedResourcePathInfo pathInfo, out AssemblyNameResolution result)
 {
     try {
         result = Resolve(pathInfo);
     } catch {
         result = null;
         return(false);
     }
     return(true);
 }
 bool IsEmbeddedResourcePath(string virtualPath)
 {
     //if path is serving a file... need to fail resolve and pass to httpHandler
     //todo: figure out all extensions that should go here (fonts, images, etc)
     if (virtualPath.EndsWith(".js", StringComparison.InvariantCultureIgnoreCase) || virtualPath.EndsWith(".css", StringComparison.InvariantCultureIgnoreCase)) {
         return false;
     }
     AssemblyNameResolution result;
     var pathInfo = new EmbeddedResourcePathInfo(virtualPath);
     return _embeddedResourceNameResolver.TryResolve(pathInfo, out result);
 }
Exemple #7
0
        bool IsEmbeddedResourcePath(string virtualPath)
        {
            //if path is serving a file... need to fail resolve and pass to httpHandler
            //todo: figure out all extensions that should go here (fonts, images, etc)
            if (virtualPath.EndsWith(".js", StringComparison.InvariantCultureIgnoreCase) || virtualPath.EndsWith(".css", StringComparison.InvariantCultureIgnoreCase))
            {
                return(false);
            }
            AssemblyNameResolution result;
            var pathInfo = new EmbeddedResourcePathInfo(virtualPath);

            return(_embeddedResourceNameResolver.TryResolve(pathInfo, out result));
        }
        public AssemblyNameResolution Resolve(EmbeddedResourcePathInfo pathInfo)
        {
            var normalizedResourceName = GetNormalizedResourceName(pathInfo);
            AssemblyNameResolution result;
            if (ResourceMap.TryGetValue(normalizedResourceName, out result)) {
                return result;
            }
            foreach (var resource in Resources) {
                if (normalizedResourceName.EndsWith(resource.Name, StringComparison.InvariantCultureIgnoreCase)) {
                    ResourceMap.Add(normalizedResourceName, resource);
                    return resource;
                }
            }
            if (TryGetByName(pathInfo.GetFileName().ToLowerInvariant(), out result)) {
                return result;
            }

            throw new Exception(string.Format("Resource ({0}) did not exist in assembly.", pathInfo.Path));
        }
Exemple #9
0
        public AssemblyNameResolution Resolve(EmbeddedResourcePathInfo pathInfo)
        {
            var normalizedResourceName = GetNormalizedResourceName(pathInfo);
            AssemblyNameResolution result;

            if (ResourceMap.TryGetValue(normalizedResourceName, out result))
            {
                return(result);
            }
            foreach (var resource in Resources)
            {
                if (normalizedResourceName.EndsWith(resource.Name, StringComparison.InvariantCultureIgnoreCase))
                {
                    ResourceMap.Add(normalizedResourceName, resource);
                    return(resource);
                }
            }
            if (TryGetByName(pathInfo.GetFileName().ToLowerInvariant(), out result))
            {
                return(result);
            }

            throw new Exception(string.Format("Resource ({0}) did not exist in assembly.", pathInfo.Path));
        }
 public bool TryResolve(EmbeddedResourcePathInfo pathInfo, out AssemblyNameResolution result)
 {
     try {
          result = Resolve(pathInfo);
     } catch {
         result = null;
         return false;
     }
     return true;
 }
 string GetNormalizedResourceName(EmbeddedResourcePathInfo pathInfo)
 {
     var result = pathInfo.Path.Replace("~/", "").Replace("/", ".").ToLowerInvariant();
     return result;
 }
Exemple #12
0
        string GetNormalizedResourceName(EmbeddedResourcePathInfo pathInfo)
        {
            var result = pathInfo.Path.Replace("~/", "").Replace("/", ".").ToLowerInvariant();

            return(result);
        }