From a7008ca6d663c3c5f40966fbdb302d273c616eb6 Mon Sep 17 00:00:00 2001 From: WilliamBZA Date: Thu, 12 May 2016 15:32:57 +0200 Subject: [PATCH] Perform a case-insensitive lookup for the manifest resource --- .../Nancy/SpecialEmbeddedFileResponse.cs | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/ServicePulse.Host/Nancy/SpecialEmbeddedFileResponse.cs b/src/ServicePulse.Host/Nancy/SpecialEmbeddedFileResponse.cs index 25ddd74340..c5e33373ef 100644 --- a/src/ServicePulse.Host/Nancy/SpecialEmbeddedFileResponse.cs +++ b/src/ServicePulse.Host/Nancy/SpecialEmbeddedFileResponse.cs @@ -2,6 +2,7 @@ { using System; using System.IO; + using System.Linq; using System.Reflection; using System.Security.Cryptography; using System.Text; @@ -14,7 +15,7 @@ public SpecialEmbeddedFileResponse(Assembly assembly, string resourcePath) ContentType = MimeTypes.GetMimeType(Path.GetFileName(resourcePath)); StatusCode = HttpStatusCode.OK; - var content = assembly.GetManifestResourceStream(resourcePath); + var content = LoadContentFromManifest(assembly, resourcePath); if (content == null) { @@ -26,6 +27,22 @@ public SpecialEmbeddedFileResponse(Assembly assembly, string resourcePath) Contents = GetFileContent(content); } + private Stream LoadContentFromManifest(Assembly assembly, string resourcePath) + { + var resource = assembly.GetManifestResourceStream(resourcePath); + + if (resource != null) + { + return resource; + } + + var matchingKey = + assembly.GetManifestResourceNames() + .FirstOrDefault(name => string.Compare(resourcePath, name, StringComparison.OrdinalIgnoreCase) == 0); + + return assembly.GetManifestResourceStream(matchingKey); + } + private static Action GetFileContent(Stream content) { return stream =>