Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion src/ServicePulse.Host/Nancy/SpecialEmbeddedFileResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
{
using System;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Security.Cryptography;
using System.Text;
Expand All @@ -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)
{
Expand All @@ -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<Stream> GetFileContent(Stream content)
{
return stream =>
Expand Down