private MarkdownResource LoadResource(IFileProvider fileProvider, string resourceName) { var file = fileProvider.GetFileInfo($"{ContentDirectory}/{resourceName}"); if (!file.Exists) { if (ParentBundle == null) { throw new Exception($"Unable to find {file.Name} for bundle {Name} and no parent bundle exists"); } var resource = ParentBundle.TryGetResource(resourceName); if (resource == null) { throw new Exception($"Unable to find {file.Name} for bundle {Name} and parent bundle doesn't have the resource"); } return(resource); } using (var stream = file.CreateReadStream()) { var memoryStream = new MemoryStream(); stream.CopyTo(memoryStream); var extension = Path.GetExtension(resourceName); if (!ExtensionToMimeType.TryGetValue(extension, out string mimeType)) { throw new InvalidOperationException($"Unhandled resource extension: {extension}"); } return(new MarkdownResource(resourceName, memoryStream.ToArray(), mimeType)); } }
private MarkdownResource LoadResource(IFileProvider fileProvider, string resourceName) { var file = fileProvider.GetFileInfo($"{ContentDirectory}/{resourceName}"); if (!file.Exists) { if (ParentBundle == null) { throw new Exception($"Unable to find {file.Name} for bundle {Name} and no parent bundle exists"); } var resource = ParentBundle.TryGetResource(resourceName); if (resource == null) { throw new Exception($"Unable to find {file.Name} for bundle {Name} and parent bundle doesn't have the resource"); } return(resource); } using (var stream = file.CreateReadStream()) { var memoryStream = new MemoryStream(); stream.CopyTo(memoryStream); if (!resourceName.EndsWith(".png")) { throw new InvalidOperationException("We only know how to deal with .png at the moment!"); } return(new MarkdownResource(resourceName, memoryStream.ToArray(), "image/png")); } }